Commit b330bdb
committed
fix(path-c): clear Metal mamba3_mimo_bwd pipeline crash — pool oversized reverse-scan shared scratch into one global workspace
ROOT CAUSE (re-bisected on-device at full local_gb10_quarter scale, hidden=3584,
seq=4096, segment chain_12_13) — the prior "in-loop barriers" hypothesis is
FALSIFIED:
* Removing ALL T.sync_threads() from the mamba3 backward (monkeypatch, on
device) -> STILL XPC_ERROR_CONNECTION_INTERRUPTED at newComputePipelineState.
* Running the ENTIRE reverse-time loop single-lane (if lane==0, the exact
m2rnn_bwd idiom) -> STILL XPC crash.
* Decisive evidence: the generated MSL declares
`threadgroup float buf_dyn_shmem[7731424]` = 30.9 MB of THREADGROUP memory
(logical ~7.4 MB of T.alloc_shared: h_prev/h_next/dh/dh_prev are 1.75 MB
EACH, plus the per-step in-proj/conv/B-C scratch). Apple GPUs cap threadgroup
memory at 32 KiB, so the driver crashes MTLCompilerService when creating the
pipeline-state. m2rnn_bwd compiles (65 KB) NOT because its replay loop is
barrier-free but because its reverse state is T.alloc_LOCAL (per-lane,
single-lane) — it declares ~0 KB threadgroup scratch.
The existing _demote_residual_shared_scratch_to_global pass fixes exactly this on
CUDA (demotes oversized T.alloc_shared -> T.alloc_global) but is GATED OFF on
Metal (its comment wrongly assumed "Metal spills oversized scratch to device
memory in its own backend"). It does not; it overflows threadgroup memory.
THE FIX (durable, gradient-exact):
_pool_oversized_shared_scratch_to_metal_workspace pools every oversized residual
T.alloc_shared float32 buffer into ONE coalesced T.alloc_global workspace and
rewrites each `name[idx]` -> `pool[offset + (idx)]` (reusing the existing
_replace_one_dimensional_buffer_refs remapper). Per-buffer demotion is NOT viable
on Metal — each global buffer is a kernel-buffer ARGUMENT and the backward kernel
already binds ~28 of Metal's ~31-arg limit, so demoting even the four 1.75 MB
state buffers blows the arg limit and the metal source fails to compile. Pooling
adds exactly ONE argument. The kernel launches single-block, so a global
workspace preserves the cross-lane visibility threadgroup memory provided. Only
float32 is pooled; a non-float32 oversized buffer RAISES (no silent degrade).
Scope: gated to Metal AND to the recurrent reverse-scan BACKWARD kernels only
(matches the distinctive `_bwd_mamba3_h_next/_bwd_m2rnn_h_next = T.alloc_shared`
state buffers), so it NEVER perturbs the forward fusion planner's buffer-count
grouping (the forward newComputePipelineState split already handles forward).
TRIGGER 28 KiB logical / DEMOTE-TARGET 8 KiB logical (TileLang pads the coalesced
buf_dyn_shmem, so 8 KiB logical -> ~29.5 KiB physical, under the 32 KiB cap).
VERIFIED ON-DEVICE (Apple M4 Max, Metal):
* COMPILE: mamba3_mimo_bwd creates its Metal pipeline-state at FULL scale —
repro_fullscale_directchain.py: ALL 11 segment shaders COMPILED ok; no XPC.
Threadgroup buf_dyn_shmem 30.9 MB -> 29.5 KiB; one path_c_metal_shared_pool
global arg added. _bwdgate_per_segment_probe.py --only-index 9: no longer
XPC-crashes — now reaches EXECUTION and trips only the GPU watchdog
(kIOGPUCommandBufferCallbackErrorTimeout), the documented time-chunking
follow-up (NOT the compile blocker).
* GRADIENT PARITY: _mamba3_bwd_parity.py before vs after = max-abs-diff
0.000e+00 (BITWISE IDENTICAL), no NaN, 15 non-zero buffers (== baseline). The
pool only relocates scratch; arithmetic is untouched.
* NO REGRESSION: 119/119 test_path_c_fusion_ir.py + 32/32
test_path_c_physical_abi.py/test_path_c_fusion_templates.py pass. m2rnn_bwd
untouched (its state is T.alloc_local; gate does not match). Off Metal the
pass is a strict no-op (CUDA path unchanged).
FOLLOW-UP (not this commit): mamba3_mimo_bwd now COMPILES but the full-scale
single launch trips the macOS GPU watchdog; the existing launcher_chunks
time-chunking is the path to clear that (already wired; rd=launcher_chunks).1 parent 8936ce4 commit b330bdb
1 file changed
Lines changed: 157 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2801 | 2801 | | |
2802 | 2802 | | |
2803 | 2803 | | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
| 2807 | + | |
| 2808 | + | |
| 2809 | + | |
| 2810 | + | |
| 2811 | + | |
2804 | 2812 | | |
2805 | 2813 | | |
2806 | 2814 | | |
| |||
10357 | 10365 | | |
10358 | 10366 | | |
10359 | 10367 | | |
| 10368 | + | |
| 10369 | + | |
| 10370 | + | |
| 10371 | + | |
| 10372 | + | |
| 10373 | + | |
| 10374 | + | |
| 10375 | + | |
| 10376 | + | |
| 10377 | + | |
| 10378 | + | |
| 10379 | + | |
| 10380 | + | |
| 10381 | + | |
| 10382 | + | |
| 10383 | + | |
| 10384 | + | |
| 10385 | + | |
| 10386 | + | |
| 10387 | + | |
| 10388 | + | |
| 10389 | + | |
| 10390 | + | |
| 10391 | + | |
| 10392 | + | |
10360 | 10393 | | |
10361 | 10394 | | |
10362 | 10395 | | |
| |||
10447 | 10480 | | |
10448 | 10481 | | |
10449 | 10482 | | |
| 10483 | + | |
| 10484 | + | |
| 10485 | + | |
| 10486 | + | |
| 10487 | + | |
| 10488 | + | |
| 10489 | + | |
| 10490 | + | |
| 10491 | + | |
| 10492 | + | |
| 10493 | + | |
| 10494 | + | |
| 10495 | + | |
| 10496 | + | |
| 10497 | + | |
| 10498 | + | |
| 10499 | + | |
| 10500 | + | |
| 10501 | + | |
| 10502 | + | |
| 10503 | + | |
| 10504 | + | |
| 10505 | + | |
| 10506 | + | |
| 10507 | + | |
| 10508 | + | |
| 10509 | + | |
| 10510 | + | |
| 10511 | + | |
| 10512 | + | |
| 10513 | + | |
| 10514 | + | |
| 10515 | + | |
| 10516 | + | |
| 10517 | + | |
| 10518 | + | |
| 10519 | + | |
| 10520 | + | |
| 10521 | + | |
| 10522 | + | |
| 10523 | + | |
| 10524 | + | |
| 10525 | + | |
| 10526 | + | |
| 10527 | + | |
| 10528 | + | |
| 10529 | + | |
| 10530 | + | |
| 10531 | + | |
| 10532 | + | |
| 10533 | + | |
| 10534 | + | |
| 10535 | + | |
| 10536 | + | |
| 10537 | + | |
| 10538 | + | |
| 10539 | + | |
| 10540 | + | |
| 10541 | + | |
| 10542 | + | |
| 10543 | + | |
| 10544 | + | |
| 10545 | + | |
| 10546 | + | |
| 10547 | + | |
| 10548 | + | |
| 10549 | + | |
| 10550 | + | |
| 10551 | + | |
| 10552 | + | |
| 10553 | + | |
| 10554 | + | |
| 10555 | + | |
| 10556 | + | |
| 10557 | + | |
| 10558 | + | |
| 10559 | + | |
| 10560 | + | |
| 10561 | + | |
| 10562 | + | |
| 10563 | + | |
| 10564 | + | |
| 10565 | + | |
| 10566 | + | |
| 10567 | + | |
| 10568 | + | |
| 10569 | + | |
| 10570 | + | |
| 10571 | + | |
| 10572 | + | |
| 10573 | + | |
| 10574 | + | |
| 10575 | + | |
| 10576 | + | |
| 10577 | + | |
| 10578 | + | |
| 10579 | + | |
| 10580 | + | |
| 10581 | + | |
| 10582 | + | |
| 10583 | + | |
| 10584 | + | |
| 10585 | + | |
| 10586 | + | |
| 10587 | + | |
| 10588 | + | |
| 10589 | + | |
| 10590 | + | |
| 10591 | + | |
| 10592 | + | |
| 10593 | + | |
| 10594 | + | |
| 10595 | + | |
| 10596 | + | |
| 10597 | + | |
| 10598 | + | |
| 10599 | + | |
| 10600 | + | |
| 10601 | + | |
| 10602 | + | |
| 10603 | + | |
| 10604 | + | |
| 10605 | + | |
| 10606 | + | |
10450 | 10607 | | |
10451 | 10608 | | |
10452 | 10609 | | |
| |||
0 commit comments