Commit 77cb4a6
committed
perf(path_c): gridded CUDA SSD chunked-scan replaces MR single-block serial mamba recurrence (6.56s -> ~7.2ms forward, sm_121)
The Path-C MR mamba sub-region's forward was a single-block T.Kernel(1, threads=1024)
O(S)=4096-step SERIAL SSD recurrence (external_state_recurrence) = 6.56 s/call (95%
of the train step @8l). This ports the already-Metal-validated chunked SSD grid
kernels (F0/F1/F2) to target=cuda/sm_121 and drives the MR mamba region with them.
WHAT CHANGED (all in cppmega_mlx; no tilelang/codegen changes needed):
- _msl_transform: add _as_cuda_target (CUDA sibling of _as_metal_target).
- mamba3_chunked_*_core: thread `target=` through all 7 build_*_metal builders
(default Metal => existing Metal callers byte-identical; "cuda" => CUDA backend).
Single _resolve_chunked_compile_target() maps intent -> tvm.target.Target.
- mamba3_chunked_scan_core: NEW chunk_scan_fwd_cuda_prim — CUDA twin of the Metal F2.
IDENTICAL SSD math; only the backend-shaped codegen differs:
* acc_o is a REGISTER FRAGMENT (CUDA T.gemm asserts fragment C accumulator;
Metal staged C in shared for the 8x8 simdgroup route).
* x_shared plain "shared" (drop Metal "shared.dyn"); no make_swizzled_layout.
* disable_tma=True on every global<->shared copy + pass_configs
{tl.disable_tma_lower, tl.disable_warp_specialized}: on sm_121 the GEMM/copy
TMA tensormap descriptor is 32/16-byte aligned where TMA needs 64-byte
("Invalid TMA descriptor arguments"); non-TMA cp.async path is correct.
compile_chunk_scan_fwd_metal selects the CUDA prim + pass_configs when target=cuda.
- path_c_fusion_schedules: _mamba3_chunked_grid_delegation_prim now passes
target=cuda on a CUDA host and block_Dstate=dstate to F2 (the default 128 would
over-slice a production dstate=64 state axis).
MEASURED on gb10 tvm.cuda(0) / sm_121 (scratch/probe_chunked_scan_cuda_gb10.py),
production local_gb10_quarter mamba shape S=4096 chunk=64 heads=112 head_dim=64
state_dim=64 groups=8, grid (112,4,64)=28672 threadgroups vs the serial forward's 1:
F2 scan+combine : 0.984 ms/call (parity vs serial fwd 4.75e-4 fp16, PASS<5e-4)
F0 precompute : 5.025 ms/call (cb exact, dA_cumsum 9.8e-4)
F1 inter-chunk : 1.209 ms/call (prev_states 1.31e-4)
TOTAL forward : ~7.2 ms/call vs the serial scan's 6559.7 ms/call (~900x).
The scan recurrence itself (F2, what literally replaced the serial carry) is
0.984 ms vs 6.56 s (~6670x). RULE #1 numeric equivalence: same SSD math, fp16 parity
verified vs the explicit per-timestep serial reference at all probed shapes.
NO REGRESSION on Metal: 21 chunked Metal tests pass (F0/F1/F2 + chained + region-flip);
disable_tma annotations are inert on Metal (TMA does not exist there), CUDA prim only
selected for target=cuda.
REMAINING (not in this commit): the BACKWARD chunked cores (B0/B1/B2) are now
target-threaded too but their CUDA run + the full flag-ON train_step (fwd+bwd) e2e
drive is a follow-up — B0/B1/B2 use NO T.gemm (plain TileLang, like F0/F1) so they
are expected to port with the same target threading; to be validated separately.1 parent cc236fd commit 77cb4a6
6 files changed
Lines changed: 714 additions & 41 deletions
File tree
- cppmega_mlx
- nn/_tilelang
- runtime
- scratch
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1469 | 1469 | | |
1470 | 1470 | | |
1471 | 1471 | | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
1472 | 1508 | | |
1473 | 1509 | | |
1474 | 1510 | | |
| |||
1496 | 1532 | | |
1497 | 1533 | | |
1498 | 1534 | | |
| 1535 | + | |
1499 | 1536 | | |
1500 | 1537 | | |
1501 | 1538 | | |
| |||
Lines changed: 31 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
| 402 | + | |
| 403 | + | |
402 | 404 | | |
403 | 405 | | |
404 | | - | |
| 406 | + | |
405 | 407 | | |
406 | | - | |
407 | | - | |
408 | | - | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
409 | 412 | | |
410 | 413 | | |
411 | 414 | | |
412 | | - | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
413 | 418 | | |
414 | 419 | | |
415 | 420 | | |
416 | 421 | | |
417 | 422 | | |
418 | 423 | | |
419 | 424 | | |
420 | | - | |
| 425 | + | |
421 | 426 | | |
422 | 427 | | |
423 | 428 | | |
| |||
571 | 576 | | |
572 | 577 | | |
573 | 578 | | |
| 579 | + | |
| 580 | + | |
574 | 581 | | |
575 | 582 | | |
576 | | - | |
| 583 | + | |
577 | 584 | | |
578 | | - | |
579 | | - | |
580 | | - | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
581 | 589 | | |
582 | 590 | | |
583 | 591 | | |
584 | | - | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
585 | 595 | | |
586 | 596 | | |
587 | 597 | | |
588 | 598 | | |
589 | 599 | | |
590 | 600 | | |
591 | 601 | | |
592 | | - | |
| 602 | + | |
593 | 603 | | |
594 | 604 | | |
595 | 605 | | |
| |||
822 | 832 | | |
823 | 833 | | |
824 | 834 | | |
| 835 | + | |
| 836 | + | |
825 | 837 | | |
826 | 838 | | |
827 | | - | |
| 839 | + | |
828 | 840 | | |
829 | | - | |
| 841 | + | |
| 842 | + | |
830 | 843 | | |
831 | 844 | | |
832 | 845 | | |
833 | 846 | | |
834 | 847 | | |
835 | | - | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
836 | 851 | | |
837 | 852 | | |
838 | 853 | | |
839 | 854 | | |
840 | 855 | | |
841 | 856 | | |
842 | 857 | | |
843 | | - | |
| 858 | + | |
844 | 859 | | |
Lines changed: 23 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
| 224 | + | |
| 225 | + | |
224 | 226 | | |
225 | 227 | | |
226 | | - | |
| 228 | + | |
227 | 229 | | |
228 | | - | |
229 | | - | |
230 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
231 | 235 | | |
232 | 236 | | |
233 | 237 | | |
234 | | - | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
235 | 241 | | |
236 | 242 | | |
237 | 243 | | |
238 | 244 | | |
239 | 245 | | |
240 | 246 | | |
241 | 247 | | |
242 | | - | |
| 248 | + | |
243 | 249 | | |
244 | 250 | | |
245 | 251 | | |
| |||
363 | 369 | | |
364 | 370 | | |
365 | 371 | | |
| 372 | + | |
| 373 | + | |
366 | 374 | | |
367 | 375 | | |
368 | | - | |
| 376 | + | |
369 | 377 | | |
370 | | - | |
371 | | - | |
372 | | - | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
373 | 382 | | |
374 | 383 | | |
375 | 384 | | |
376 | | - | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
377 | 388 | | |
378 | 389 | | |
379 | 390 | | |
380 | 391 | | |
381 | 392 | | |
382 | 393 | | |
383 | 394 | | |
384 | | - | |
| 395 | + | |
385 | 396 | | |
0 commit comments