Skip to content

Commit 1f2e8ef

Browse files
committed
metal : always set cv to ggml_metal_library_compile_pipeline
1 parent 62c3b64 commit 1f2e8ef

File tree

2 files changed

+103
-35
lines changed

2 files changed

+103
-35
lines changed

ggml/src/ggml-metal/ggml-metal-device.cpp

Lines changed: 102 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_base(ggml_metal_library_t
7272
return res;
7373
}
7474

75-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
75+
ggml_metal_cv_t cv = ggml_metal_cv_init();
76+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
77+
ggml_metal_cv_free(cv);
7678

7779
return res;
7880
}
@@ -89,7 +91,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_cpy(ggml_metal_library_t l
8991
return res;
9092
}
9193

92-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
94+
ggml_metal_cv_t cv = ggml_metal_cv_init();
95+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
96+
ggml_metal_cv_free(cv);
9397

9498
return res;
9599
}
@@ -116,7 +120,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_pool_2d(ggml_metal_library
116120
return res;
117121
}
118122

119-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
123+
ggml_metal_cv_t cv = ggml_metal_cv_init();
124+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
125+
ggml_metal_cv_free(cv);
120126

121127
return res;
122128
}
@@ -133,7 +139,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_get_rows(ggml_metal_librar
133139
return res;
134140
}
135141

136-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
142+
ggml_metal_cv_t cv = ggml_metal_cv_init();
143+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
144+
ggml_metal_cv_free(cv);
137145

138146
return res;
139147
}
@@ -150,7 +158,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_set_rows(ggml_metal_librar
150158
return res;
151159
}
152160

153-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
161+
ggml_metal_cv_t cv = ggml_metal_cv_init();
162+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
163+
ggml_metal_cv_free(cv);
154164

155165
return res;
156166
}
@@ -167,7 +177,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_repeat(ggml_metal_library_
167177
return res;
168178
}
169179

170-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
180+
ggml_metal_cv_t cv = ggml_metal_cv_init();
181+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
182+
ggml_metal_cv_free(cv);
171183

172184
return res;
173185
}
@@ -225,7 +237,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_unary(ggml_metal_library_t
225237
return res;
226238
}
227239

228-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
240+
ggml_metal_cv_t cv = ggml_metal_cv_init();
241+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
242+
ggml_metal_cv_free(cv);
229243

230244
return res;
231245
}
@@ -259,7 +273,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_glu(ggml_metal_library_t l
259273
return res;
260274
}
261275

262-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
276+
ggml_metal_cv_t cv = ggml_metal_cv_init();
277+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
278+
ggml_metal_cv_free(cv);
263279

264280
return res;
265281
}
@@ -288,7 +304,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_sum_rows(ggml_metal_librar
288304
return res;
289305
}
290306

291-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
307+
ggml_metal_cv_t cv = ggml_metal_cv_init();
308+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
309+
ggml_metal_cv_free(cv);
292310

293311
ggml_metal_pipeline_set_smem(res, 32*sizeof(float));
294312

@@ -317,7 +335,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_soft_max(ggml_metal_librar
317335
return res;
318336
}
319337

320-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
338+
ggml_metal_cv_t cv = ggml_metal_cv_init();
339+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
340+
ggml_metal_cv_free(cv);
321341

322342
ggml_metal_pipeline_set_smem(res, 32*sizeof(float));
323343

@@ -342,7 +362,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_ssm_conv(ggml_metal_librar
342362
return res;
343363
}
344364

345-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
365+
ggml_metal_cv_t cv = ggml_metal_cv_init();
366+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
367+
ggml_metal_cv_free(cv);
346368

347369
return res;
348370
}
@@ -363,7 +385,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_ssm_scan(ggml_metal_librar
363385
return res;
364386
}
365387

366-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
388+
ggml_metal_cv_t cv = ggml_metal_cv_init();
389+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
390+
ggml_metal_cv_free(cv);
367391

368392
ggml_metal_pipeline_set_smem(res, 32*sizeof(float));
369393

@@ -405,7 +429,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_rwkv(ggml_metal_library_t
405429
return res;
406430
}
407431

408-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
432+
ggml_metal_cv_t cv = ggml_metal_cv_init();
433+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
434+
ggml_metal_cv_free(cv);
409435

410436
return res;
411437
}
@@ -422,7 +448,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_mul_mv_ext(ggml_metal_libr
422448
return res;
423449
}
424450

425-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
451+
ggml_metal_cv_t cv = ggml_metal_cv_init();
452+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
453+
ggml_metal_cv_free(cv);
426454

427455
return res;
428456
}
@@ -439,7 +467,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_mul_mm(ggml_metal_library_
439467
return res;
440468
}
441469

442-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
470+
ggml_metal_cv_t cv = ggml_metal_cv_init();
471+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
472+
ggml_metal_cv_free(cv);
443473

444474
ggml_metal_pipeline_set_smem(res, 8192);
445475

@@ -623,7 +653,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_mul_mv(ggml_metal_library_
623653
return res;
624654
}
625655

626-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
656+
ggml_metal_cv_t cv = ggml_metal_cv_init();
657+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
658+
ggml_metal_cv_free(cv);
627659

628660
ggml_metal_pipeline_set_nr0 (res, nr0);
629661
ggml_metal_pipeline_set_nr1 (res, nr1);
@@ -645,7 +677,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_mul_mm_id_map0(ggml_metal_
645677
return res;
646678
}
647679

648-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
680+
ggml_metal_cv_t cv = ggml_metal_cv_init();
681+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
682+
ggml_metal_cv_free(cv);
649683

650684
const size_t smem = (size_t) ne02*ne20*sizeof(uint16_t);
651685

@@ -666,7 +700,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_mul_mm_id(ggml_metal_libra
666700
return res;
667701
}
668702

669-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
703+
ggml_metal_cv_t cv = ggml_metal_cv_init();
704+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
705+
ggml_metal_cv_free(cv);
670706

671707
ggml_metal_pipeline_set_smem(res, 8192);
672708

@@ -832,7 +868,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_mul_mv_id(ggml_metal_libra
832868
return res;
833869
}
834870

835-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
871+
ggml_metal_cv_t cv = ggml_metal_cv_init();
872+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
873+
ggml_metal_cv_free(cv);
836874

837875
ggml_metal_pipeline_set_nr0 (res, nr0);
838876
ggml_metal_pipeline_set_nr1 (res, nr1);
@@ -858,7 +896,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_argmax(ggml_metal_library_
858896
return res;
859897
}
860898

861-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
899+
ggml_metal_cv_t cv = ggml_metal_cv_init();
900+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
901+
ggml_metal_cv_free(cv);
862902

863903
ggml_metal_pipeline_set_smem(res, 32*(sizeof(float) + sizeof(int32_t)));
864904

@@ -888,7 +928,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_argsort(ggml_metal_library
888928
return res;
889929
}
890930

891-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
931+
ggml_metal_cv_t cv = ggml_metal_cv_init();
932+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
933+
ggml_metal_cv_free(cv);
892934

893935
return res;
894936
}
@@ -1079,7 +1121,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_bin(
10791121
return res;
10801122
}
10811123

1082-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
1124+
ggml_metal_cv_t cv = ggml_metal_cv_init();
1125+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
1126+
ggml_metal_cv_free(cv);
10831127

10841128
return res;
10851129
}
@@ -1107,7 +1151,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_rms_norm(ggml_metal_librar
11071151
return res;
11081152
}
11091153

1110-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
1154+
ggml_metal_cv_t cv = ggml_metal_cv_init();
1155+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
1156+
ggml_metal_cv_free(cv);
11111157

11121158
ggml_metal_pipeline_set_smem(res, 32*sizeof(float));
11131159

@@ -1131,7 +1177,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_l2_norm(ggml_metal_library
11311177
return res;
11321178
}
11331179

1134-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
1180+
ggml_metal_cv_t cv = ggml_metal_cv_init();
1181+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
1182+
ggml_metal_cv_free(cv);
11351183

11361184
ggml_metal_pipeline_set_smem(res, 32*sizeof(float));
11371185

@@ -1154,7 +1202,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_group_norm(ggml_metal_libr
11541202
return res;
11551203
}
11561204

1157-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
1205+
ggml_metal_cv_t cv = ggml_metal_cv_init();
1206+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
1207+
ggml_metal_cv_free(cv);
11581208

11591209
ggml_metal_pipeline_set_smem(res, 32*sizeof(float));
11601210

@@ -1178,7 +1228,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_norm(ggml_metal_library_t
11781228
return res;
11791229
}
11801230

1181-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
1231+
ggml_metal_cv_t cv = ggml_metal_cv_init();
1232+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
1233+
ggml_metal_cv_free(cv);
11821234

11831235
ggml_metal_pipeline_set_smem(res, 32*sizeof(float));
11841236

@@ -1216,7 +1268,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_rope(ggml_metal_library_t
12161268
return res;
12171269
}
12181270

1219-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
1271+
ggml_metal_cv_t cv = ggml_metal_cv_init();
1272+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
1273+
ggml_metal_cv_free(cv);
12201274

12211275
return res;
12221276
}
@@ -1239,7 +1293,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_im2col(ggml_metal_library_
12391293
return res;
12401294
}
12411295

1242-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
1296+
ggml_metal_cv_t cv = ggml_metal_cv_init();
1297+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
1298+
ggml_metal_cv_free(cv);
12431299

12441300
return res;
12451301
}
@@ -1264,7 +1320,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_conv_transpose_1d(ggml_met
12641320
return res;
12651321
}
12661322

1267-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
1323+
ggml_metal_cv_t cv = ggml_metal_cv_init();
1324+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
1325+
ggml_metal_cv_free(cv);
12681326

12691327
return res;
12701328
}
@@ -1283,7 +1341,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_upscale(ggml_metal_library
12831341
return res;
12841342
}
12851343

1286-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
1344+
ggml_metal_cv_t cv = ggml_metal_cv_init();
1345+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
1346+
ggml_metal_cv_free(cv);
12871347

12881348
return res;
12891349
}
@@ -1302,7 +1362,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_pad(ggml_metal_library_t l
13021362
return res;
13031363
}
13041364

1305-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
1365+
ggml_metal_cv_t cv = ggml_metal_cv_init();
1366+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
1367+
ggml_metal_cv_free(cv);
13061368

13071369
return res;
13081370
}
@@ -1321,7 +1383,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_pad_reflect_1d(ggml_metal_
13211383
return res;
13221384
}
13231385

1324-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
1386+
ggml_metal_cv_t cv = ggml_metal_cv_init();
1387+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
1388+
ggml_metal_cv_free(cv);
13251389

13261390
return res;
13271391
}
@@ -1340,7 +1404,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_arange(ggml_metal_library_
13401404
return res;
13411405
}
13421406

1343-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
1407+
ggml_metal_cv_t cv = ggml_metal_cv_init();
1408+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
1409+
ggml_metal_cv_free(cv);
13441410

13451411
return res;
13461412
}
@@ -1359,7 +1425,9 @@ ggml_metal_pipeline_t ggml_metal_library_get_pipeline_timestep_embedding(ggml_me
13591425
return res;
13601426
}
13611427

1362-
res = ggml_metal_library_compile_pipeline(lib, base, name, nullptr);
1428+
ggml_metal_cv_t cv = ggml_metal_cv_init();
1429+
res = ggml_metal_library_compile_pipeline(lib, base, name, cv);
1430+
ggml_metal_cv_free(cv);
13631431

13641432
return res;
13651433
}

ggml/src/ggml-metal/ggml-metal-device.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ ggml_metal_pipeline_t ggml_metal_library_compile_pipeline(ggml_metal_library_t l
327327

328328
GGML_LOG_DEBUG("%s: compiling pipeline: base = '%s', name = '%s'\n", __func__, base, name);
329329

330-
id<MTLFunction> mtl_function = [lib->obj newFunctionWithName:base_func constantValues:(cv ? cv->obj : nil) error:&error];
330+
id<MTLFunction> mtl_function = [lib->obj newFunctionWithName:base_func constantValues:cv->obj error:&error];
331331
if (!mtl_function) {
332332
ggml_critical_section_end();
333333

0 commit comments

Comments
 (0)