ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op->src[1]), 2);
ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);
- const int nth = std::min(1024, ne0);
+ int nth = std::min(256, ne0);
- ggml_metal_encoder_dispatch_threadgroups(enc, ne1, ne2, ne3, nth, 1, 1);
+ // when rows are small, we can batch them together in a single threadgroup
+ int nrptg = 1;
+ if (nth < 256) {
+ nrptg = std::min((256 + nth - 1) / nth, ne1);
+ if (nrptg * nth > 256) {
+ nrptg = 256 / nth;
+ }
+ }
+
+ const int nw0 = (ne1 + nrptg - 1) / nrptg;
+
+ ggml_metal_encoder_dispatch_threadgroups(enc, nw0, ne2, ne3, nth, nrptg, 1);
return 1;
}
nk0 = ne10/ggml_blck_size(op->type);
}
- int nth = std::min<int>(nk0, ggml_metal_pipeline_max_theads_per_threadgroup(pipeline));
+ int nth = std::min<int>(nk0*ne11, 256);
// when rows are small, we can batch them together in a single threadgroup
int nrptg = 1;
nrptg = (nth + nk0 - 1)/nk0;
nth = nk0;
- if (nrptg*nth > ggml_metal_pipeline_max_theads_per_threadgroup(pipeline)) {
+ if (nrptg*nth > 256) {
nrptg--;
}
}