metal : spread the short mat-vec lanes over src1 rows (#33034)

* metal : spread the short mat-vec lanes over src1 rows

The short mat-vec kernel (K < 32) mapped its 32 lanes to 32 src0 rows
and handled one src1 row per threadgroup, so with few src0 rows most
lanes were idle. It now covers min(ne01, 32) src0 rows of 32/that src1
rows.

This is the weighted sum over the depth states of Inkling 2 since
#32855 (1-3 src0 rows, K = number of states, 2304 src1 rows).
Inkling-2-Mini UD-Q4_K_XL, M5 Max, master -> this PR:
  pp512 888 -> 1052 t/s, pp2048 771 -> 894 t/s, tg128 unchanged.
PPL and greedy output bit-identical, the graph is unchanged.

Tested: test-backend-ops -b MTL0 -o MUL_MAT (new small-K cases).

* cont : clean-up comment

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
This commit is contained in:
Pascal 2026-11-25 22:39:14 +01:00 • committed by GitHub
parent 5917b39ff7
commit 7135e2fd69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 5 deletions

View file

@ -1067,8 +1067,8 @@ ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_mul_mv(ggml_meta
{
if (ne00 < 32) {
nsg = 1;
nr0 = 32;
nr1 = 1;
nr0 = std::min(ne01, 32);
nr1 = 32/nr0;
suffix = "_short";
} else {
nsg = std::min(4, (ne00 + 127) / 128);

View file

@ -1187,11 +1187,14 @@ void kernel_mul_mv_t_t_short_impl(
device char * dst,
uint3 tgpig,
ushort tiisg) {
const int r0 = tgpig.x*32 + tiisg;
const int r1 = tgpig.y;
const int n0 = args.nr0;
const int n1 = 32/n0;
const int r0 = tgpig.x*n0 + tiisg%n0;
const int r1 = tgpig.y*n1 + tiisg/n0;
const int im = tgpig.z;
if (r0 >= args.ne01) {
if (tiisg >= n0*n1 || r0 >= args.ne01 || r1 >= args.ne11) {
return;
}

View file

@ -12602,6 +12602,15 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
#endif
test_cases.emplace_back(new test_mul_mat(GGML_TYPE_F32, GGML_TYPE_F32, 31, 509, 2051, {1, 1}, {1, 1}));
// a few rows of a few columns against many rows, batched (the weighted sum over the depth states of Inkling 2)
for (int64_t m : {1, 3, 8, 33}) {
for (int64_t k : {2, 5, 24, 31}) {
test_cases.emplace_back(new test_mul_mat(GGML_TYPE_F32, GGML_TYPE_F32, m, 2304, k, {1, 1}, {1, 1}));
test_cases.emplace_back(new test_mul_mat(GGML_TYPE_F32, GGML_TYPE_F32, m, 97, k, {7, 2}, {1, 1}));
test_cases.emplace_back(new test_mul_mat(GGML_TYPE_F16, GGML_TYPE_F32, m, 33, k, {2, 3}, {2, 1}));
}
}
test_cases.emplace_back(new test_mul_mat(GGML_TYPE_F32, GGML_TYPE_F32, 32, 509, 2112, {1, 1}, {1, 1}));
test_cases.emplace_back(new test_mul_mat(GGML_TYPE_Q8_0, GGML_TYPE_F32, 32, 509, 2112, {1, 1}, {1, 1}));