Commit 3568ad8
committed
feat(mamba3): fused smem-resident SSD forward (F0+F1+F2) + fix N=64 F2 prev_states dtype segfault
NEW: cppmega_mlx/nn/_tilelang/mamba3_ssd_fused_fwd.py — ONE smem-resident CUDA
kernel (gb10/sm_121) that fuses F0 precompute + intra-chunk scan + F1 inter-chunk
carry per (batch,chunk,head). Persistent per-(batch,head) threadgroup loops the
chunk axis serially carrying state[headdim,dstate] fp32 RESIDENT in shared memory
— cb/dA_cumsum/summary_states/prev_states never round-trip to global (the MEASURED
16.37 ms F0 lever). Env-gated CPPMEGA_MAMBA3_SSD_FUSED_FWD (default OFF); the
un-fused F0/F1/F2 + Metal path stay byte-identical.
smem budget @ prod N=64,P=64,L=64 = 82,688 B (80.75 KiB) < GB10 99 KB (101,376 B)
cap, 18,688 B headroom (fp16 operand tiles + fp32 accumulation; all-fp32 staging
would be 112.75 KiB and OVERFLOW). The builder RAISES (RULE #1) if the budget
exceeds the cap — never truncates dstate columns, never falls back to the slow
un-fused chain. Algebra verified fp64-exact (5.6e-17) vs the eager F0+F1+F2
reference for BOTH Output and final_state.
FIX (Phase 0, the prod N=64 'segfault'): chunk_scan_fwd_cuda_prim declared
prev_states fp16, but F1 writes it fp32 (accum_dtype, design §3.3) and the bwd B2
prim already declares it fp32 — the 2B-typed read of a 4B buffer walked the dstate
stride OOB -> launch crash at N=64. Declare prev_states accum_dtype (the producer's
dtype); the T.copy downcasts to the fp16 GEMM operand. Metal prim untouched.
No GPU on Mac: validated py_compile + ast + cross-symbol + fp64 algebra parity.
GB10 phase builds/measures.1 parent 81a9f51 commit 3568ad8
2 files changed
Lines changed: 521 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
409 | 409 | | |
410 | 410 | | |
411 | 411 | | |
412 | | - | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
413 | 424 | | |
414 | 425 | | |
415 | 426 | | |
| |||
432 | 443 | | |
433 | 444 | | |
434 | 445 | | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
435 | 452 | | |
436 | 453 | | |
437 | 454 | | |
| |||
0 commit comments