Repository navigation
metal : stop overflow from happening in large matrix output offsets - #30072
Conversation
|
/bot review |
Automated code reviewThe diff is small and targeted: two 32-bit -> 64-bit offset fixes in the legacy Blocking - incomplete fix for the stated goal (point 1) The tensor-API variant of the same kernel is still broken.
Will slow the review (point 2) For MUL_MAT_ID the dst is Nits (point 3) In the full-tile path you fixed, a small sub-expression is still 32-bit: (point 4) Out of scope but same sweep: Test The regression test is well formed (dst = 2.22e9 elements, batch 52 offset lands just past INT32_MAX, mixes full and edge tiles so both store paths are covered), kept behind Everything else checks out: no API/scope concerns, comments follow the style rules, AI disclosure is present in the PR template, and no unrelated changes are bundled. Fixing point 1 (and ideally point 2) before merge would make this a complete fix for "stop overflow in kernel_mul_mm output offsets". This review was generated automatically by pi coding agent using |
|
Thanks — I’ve addressed points 1–3. The additional destination offsets now use 64-bit arithmetic. MUL_MAT_ID also needed its two token indices widened from short to int; casts alone wouldn’t fix the 32,768-token limit. I added two disabled regression cases. The small case fails before the update and passes afterwards on both Metal paths. All 1,859 MUL_MAT and 867 MUL_MAT_ID default tests pass on each path. The large output shapes also pass element-by-element checks using the Metal-only checker; the approximately 45 GB in-tree cases weren’t rerun. Testing used an M4 Pro, with the tensor API explicitly enabled for those runs; no M5 hardware was tested. #28748 overlaps the tensor batch-offset change and fixes a separate tensor-slice offset that this update doesn’t address. The mul_mv finding remains a separate follow-up. AI assistance: Codex applied the supplied patches and reran verification. |
|
@feni6 Thanks for the patch. Could you rebase on the latest |
|
@feni6 Friendly ping about the merge conflict. :) |
|
I'm on it. Thanks for the reminder. |
Assisted-by: Codex
Assisted-by: Codex
2e87e36 to
60d9f30
Compare
|
Done. Let me know if there's any problems with it please, or if you'd like any more information about it, including how it was tested. |
…gml-org#30072) * Metal : stop overflow from happening in large matrix output offsets Assisted-by: Codex * metal : widen batch offsets and MUL_MAT_ID token indices Assisted-by: Codex --------- Co-authored-by: feni6 <270037094+feni6@users.noreply.github.com>
…gml-org#30072) * Metal : stop overflow from happening in large matrix output offsets Assisted-by: Codex * metal : widen batch offsets and MUL_MAT_ID token indices Assisted-by: Codex --------- Co-authored-by: feni6 <270037094+feni6@users.noreply.github.com>
…gml-org#30072) * Metal : stop overflow from happening in large matrix output offsets Assisted-by: Codex * metal : widen batch offsets and MUL_MAT_ID token indices Assisted-by: Codex --------- Co-authored-by: feni6 <270037094+feni6@users.noreply.github.com>
Overview
Use 64-bit arithmetic for the destination offsets in both store paths of kernel_mul_mm. This stops mistakes from happening when those offsets are above the signed 32-bit range.
Additional information
Supplied is a regression test that covers full and edge tiles both. It’s disabled by default because it needs about 45 GB of memory. On a M4 Pro Mac mini it failed before the fix and passed afterwards. When it was enabled, 1,860 Metal MUL_MAT tests all passed.
tests/test-backend-ops.cpp:Base:
c479922ac520a08969b4c1dc154d7bbb3c386d85; Apple M4 Pro, 64 GB, macOS 26.6.2.Before: test only (abridged; ANSI colors removed)
After: fix and test (abridged; ANSI colors removed)
Full Metal MUL_MAT suite (abridged; ANSI colors removed)
Requirements