Commit bb4dbed
committed
perf(metal): x-tiled BF16 prefill matmul — 5.6x TTFT (was 4.1x)
The plain batched BF16 matmul was bound by strided token-major x reads
(per 2-byte weight it streamed T×4 bytes of activation, ~16× the weight
traffic). `matmul_bf16_tiled` stages the T token columns into threadgroup
memory once per in_dim chunk (CHUNK=256), shared across all nsg=8
simdgroups in the threadgroup, so x global traffic drops ~8× and the
matmul becomes weight-bound. All threads cooperate on the load + barriers;
only o < out_dim writes.
508-token prompt (prefill-check --gpu), exact (max|Δlogit| = 0.000000):
Qwen3-4B BF16 batched 4216 -> 3055 ms (4.07x -> 5.59x vs 17.1 s)
forward.rs routes BF16 to the tiled kernel; the plain `matmul_bf16`
remains for the ullm-metal unit test. Next: x-tile the k-quant kernels
(same shared-x win) and tile weights too (full mul_mm).1 parent 0188e84 commit bb4dbed
2 files changed
Lines changed: 54 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
| 182 | + | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
326 | | - | |
| 326 | + | |
327 | 327 | | |
328 | 328 | | |
329 | 329 | | |
| |||
700 | 700 | | |
701 | 701 | | |
702 | 702 | | |
703 | | - | |
| 703 | + | |
704 | 704 | | |
705 | 705 | | |
706 | 706 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
510 | 510 | | |
511 | 511 | | |
512 | 512 | | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
513 | 564 | | |
514 | 565 | | |
515 | 566 | | |
| |||
0 commit comments