Commit 8344356
committed
feat(path_c B2): batched large-tile tensor-core GEMM twin (CUDA mma.sync + Metal simdgroup)
NEW prims (flag-gated, the ONE path when on, RAISE on failure — RULE #1; serial/§27
prims kept byte-identical):
* chunk_scan_combine_bwd_cuda_prim_gemm_batched (sm_121, fragment-C):
grid (batch*nchunks, nheads//HEADS_PER_CTA); each CTA owns HEADS_PER_CTA heads and
issues the 4 GEMM-able contractions (DYX, dC_off, dC_diag masked, dchunk_states
transpose_A) as a HEAD-LOOP over a SHARED tall-M operand band (M = HEADS_PER_CTA*64),
amortizing ldmatrix/staging/sync over the band — the P1/Tri-Dao lever the §27
single-64-tile twin (0.749x) lacked. dinp 3-index term + dz/dx/dD + dseg stay
threaded (documented scope boundary). HEADS_PER_CTA default 4.
* chunk_scan_combine_bwd_metal_gemm_prim_batched (simdgroup, C-in-frag): batches
DYX+dchunk_states only (Apple 32KB pool); HEADS_PER_CTA default 2.
Flags: CPPMEGA_PATH_C_B2_GEMM_BATCHED (cuda) / CPPMEGA_PATH_C_METAL_GEMM_BATCHED (metal),
HEADS_PER_CTA via CPPMEGA_PATH_C_B2_HEADS_PER_CTA / CPPMEGA_PATH_C_METAL_HEADS_PER_CTA.
Mutually exclusive with the other B2 flags (RAISE). Per-backend smem budget gate RAISES
over-budget (gb10 99KB / Apple 32KB), no silent re-tile.
z3 PROOF WIRED (RULE #1, fail-closed): _gemm_rewrite_proof.py gains
b2_batched_dchunk/dcoff/dcdiag_contraction + b2_batched_tiling (m_blocks=HEADS_PER_CTA,
m_stride=tile_m per-head-band single-writer disjointness). build dispatcher calls
require_gemm_rewrite_proof before emitting the batched prim — RAISES GemmRewriteNotProven
on sat/unknown/disabled. Verified locally: 3 rewrites discharge z3_proved=True, single_writer
True; non-vacuous (overlap-band -> single_writer False, transpose bug -> maps False);
fail-closed when z3 disabled.
probe_chunked_backward_cuda_gb10.py: B2-BATCHED-AB arm (vs v1 + vs single-tile gemm,
HEADS_PER_CTA-parametrized) for the gb10 measure (bs1 isolates tiling; bs4 = full recipe).
8-grad parity + tile microbench is the gb10/Test step (local tilelang import is broken;
no heavy local python per 80GB guard). MEASURED win is EXTRAPOLATION until gb10 runs.1 parent 2bd251d commit 8344356
3 files changed
Lines changed: 975 additions & 7 deletions
File tree
- cppmega_mlx/nn/_tilelang
- scratch
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
547 | 547 | | |
548 | 548 | | |
549 | 549 | | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
550 | 647 | | |
551 | 648 | | |
552 | 649 | | |
| |||
0 commit comments