Skip to content

Training-step GEMMs vs cuBLASLt: ~35 ms/step gap, one epilogue mechanism #80

Closed

Description

@feitreim

Tracking issue for closing the training-step GEMM gap vs cuBLASLt, measured by the 14-shape A/B harness merged in #79 (gpu/gemm/src/bin/model_shapes.rs, FEATURES=cublas ./run.sh gemm model_shapes). Baseline: main @ cebec1c profile, 472.4 ms full step, tcgen05 GEMMs 188.7 ms at an average 1.18 PF/s.

Measured state (B200, cuBLASLt 13.0, two runs within 2%)

shape M×K×N step row mode ours TF/s cuBLASLt TF/s ratio gap ms/step
3072×6144×8192 bwd gate_up dW f32 acc-T 1162 1746 0.666 8.5
4096×6144×3072 bwd down dW f32 acc-T 964 1639 0.588 6.3
6144×3072×8192 gate_up fwd f32 store 1323 1850 0.715 6.4
6144×3072×4096 bwd down dx f32 store 1214 1652 0.735 3.2
24576×3072×9216 qkv fwd f32 store 1477 1915 0.771 2.6
6144×4096×3072 down fwd f32 store 1409 1803 0.781 2.3
3072×24576×9216 bwd qkv dW f32 acc-T 1738 1973 0.881 1.2
6144×8192×3072 bwd gate_up dx f32 store 1706 1844 0.925 1.3
24576×3072×3072 o_proj fwd f32 store 1396 1848 0.756 1.0
24576×3072×50432 lm_head fwd bf16 store 1552 1927 0.806 1.0
24576×9216×3072 bwd qkv dx f32 store 1736 1867 0.929 0.7
24576×50432×3072 bwd lm_head dx bf16 store 1707 1855 0.920 0.4
3072×24576×3072 bwd o_proj dW f32 acc-T 1754 1966 0.892 0.3
3072×24576×50432 bwd lm_head dW bf16 acc-T 1721 1837 0.937 0.3

Full-parity gap: ~35 ms/step (472 → ~437 ms, ≈ +1.9 pp MFU).

Diagnosis (one mechanism, established in #79)

The ratio is a function of K depth and drain kind, not shape family. Every mode converges to 0.92–0.94× at K ≥ 8k and decays at shallow K: pipeline::run serializes the per-[256,256]-tile epilogue against the next tile's MMA — ~6–7 µs (bf16 drain), ~10–13 µs (f32 scattered), ~30 µs (f32 accumulate fold) against ~26 µs of MMA per 3072 of K. Refuted along the way: the MN-major transposed walk costs nothing (it slightly wins everywhere); the 144-tile bwd o_proj dW underfill is worth ≤3% (cuBLASLt wins that shape with the same single wave, split-K off).

Remedies, in leverage order

  1. Delete the accumulate fold's read of C — the fold is +25–29% at K=6144 and is why the two worst rows are per-expert dW. Route: ferro-kittens#42 reduction TMA stores (cp.reduce.async.bulk.tensor.add); the epilogue then stores-with-add and never reads C. Addresses ~15 ms (rows 1, 2, 7, 13; also unblocks split-K if ever wanted). fp32 add at the copy engine keeps weight-grad accumulation fp32 (SPEC decision Optimize RMSNorm with block-parallel kernels #20) and stays one-writer-per-tile deterministic.
  2. Drain–MMA overlap — the rest of the gap at shallow K, all store rows. Blocked on TMEM: overlapping needs a second 256-column accumulator slot that 2 CTAs/SM cannot allocate today. Related: ferro-kittens#105 (second tile), ferro GAPS §2.6 / ferro-kittens#174 (fp32 staging drain, re-measure condition: an epilogue affording a [32,64] fp32 staging tile).
  3. Per-shape tile selection — not a const flip (BLOCK_N=128 breaks HALF_N == BLOCK_M, MmaShape::M256_N256, the SHARED_BYTES/MAX_CLUSTERS asserts at gpu/gemm/src/optimized.rs:182-185, and TMEM-pinned residency). ferro-kittens#87/The batch the B200 holds is 21, and the one worth taking is 16 #105 territory. Only worth revisiting after 1 and 2.

Acceptance

Per remedy shipped: model_shapes ratios re-measured same-container, the affected step rows re-profiled via --baseline-ref A/B, parity suites green, KernelBudget ratchets updated in the same PR. Done when every row ≥ 0.90× or the residual is attributed to a documented blocked remedy (item 2).

Measurement logs: #79 thread (model_shapes_run1.log / run2.log).

Activity

  1. added a commit that references this issue on Aug 4, 2026
  2. feitreim commented on Aug 4, 2026

    @feitreim
    OwnerAuthor

    Remedy 1 shipped: ferro-kittens#187 (reduction TMA store, add @ rank 2 — #42's sanctioned fallback; catalog omission confirmed as a generator-input gap, upstream filed as NVIDIA/cuda-rust#660) + #82 (fold-free accumulate epilogue, both pins on ferro main @ 9b58025).

    Measured (same-container A/B): full step −17.3 ms; acc-T rows 0.666→0.886, 0.588→0.777, 0.881→0.952, 0.892→0.944; every f32 store row also improved (0.72–0.78 → 0.75–0.87) because dropping the fold's monomorphization shed 18 registers and the store kernel's whole 512 B local frame (budgets ratcheted 120/512 → 102/0; new accumulate kernel 80/0). Decompose sweep: fold premium +25–29% → +0.3…+9.8%, negative on the worst shape — bwd down dW's accumulate is now cheaper than its own store.

    Residual: the money rows' remaining sub-0.90 is entirely the shallow-K store baseline, i.e. remedy 2 (drain–MMA overlap, blocked on a second 256-col TMEM slot). Numerics caveat recorded in #82: engine-side fp32 reduce-add flushes subnormals where an FADD would not; irrelevant at gradient magnitudes, all gates green.

  3. feitreim commented on Aug 4, 2026

    @feitreim
    OwnerAuthor

    Remedy 2 progress — two candidate routes measured and killed, both informative:

    1 CTA/SM with double-buffered TMEM (ferro gemm_ws, the structure that already exists): dead in the shallow-K regime too. ferro-kittens#188 / #189 added the shallow-K arm the warp-specialized A/B never had. At the money geometries (bf16, one container, checked-then-timed): ws staged8 loses to gemm staged84 by 7.3–7.9% at every K=3072 shape, and — the kill criterion — the ws no drain floor loses too (0.822/0.880/0.884 of cuBLASLt vs the 2-CTA kernel's 0.828/0.896/0.909 with its exposed epilogue). At 1 CTA/SM the feed+MMA alone costs more than the entire drain exposure the second accumulator would remove. The −7.3% of ferro#112 was never a deep-K artifact; route closed in both regimes. One number to keep: solo no drain vs dual no drain at 8192³ = 0.6620/0.5944 ms — a lone M256_N256 chain sustains ~0.90 of two chains' aggregate.

    Anti-phase stagger at 2 CTAs/SM (branch 80-stagger-probe, bin/stagger_probe.rs): a transient, not an equilibrium. Premise: #114 measured the epilogue fully exposed (1.01×) and the 0.90 above says a co-resident CTA's MMA could absorb most of a draining neighbour's freed tensor core — so delay half the clusters once at launch and let identical item periods hold the offset. Measured (sweep 4–20 µs × two co-residency rules, six model_shapes rows, cuBLASLt in-container): best case +2.8% at 4 µs, monotonically worse at every larger delay (to −11%), same shape both rules. Reading: in-phase is an attractor — the cluster that gets solo tensor time finishes its MMA early and catches its neighbour, so a one-time nudge buys ~one item of overlap and relapses. Anti-phase would need per-item enforcement across clusters that share no barrier, and the 4 µs row caps what that could honestly win.

    Both null results point the same way: nothing outside the cluster will cover the drain, and the second accumulator is not affordable. What remains of remedy 2 is intra-cluster overlap with the single accumulator: the accumulator is only TMEM-busy until the drain's last tcgen05.ld retires, so a drain that hoists its loads (two bands live, ~+64 registers), releases TMEM through a cluster semaphore, and only then issues its stores lets the next item's MMA start while ~half the store issue (and all store completion) is still in flight — plus the whole TMA refill. That needs the deferred-drain form pipeline::Job explicitly sanctions and a fifth warp for produce/MMA so the drain warps never block the schedule. Building that next on this branch's successor; it helps every mode, and deep K too (~6.5 µs/tile of drain is fixed at all K), so the square gates should gain rather than merely survive.

  4. added a commit that references this issue on Aug 4, 2026
  5. feitreim commented on Aug 4, 2026

    @feitreim
    OwnerAuthor

    Remedy 2 shipped and closed: #83 (deferred drain — the epilogue runs beside the next item's MMA; two role warps; drains hoist loads a pass ahead of stores). Same-container full-step A/B both orders: −2.6/−2.7 ms. Deep-K model rows 0.92–0.93 → 0.955–0.967; shallow-K store rows +1–8 pts. Known tradeoff on record in the PR: 16384³ square-bench store cells −2–3% (L2 term from deferred C writeback vs operand streaming; the model has no such shape). Routes killed with data: 1 CTA/SM double-buffered TMEM (ferro#188/#189 — the design's epilogue-free floor loses to the shipped kernel at every shallow shape; #189 merged as the standing control), anti-phase stagger (branch 80-stagger-probe, +2.8% best then relapses), fp32 store via copy engine (ferro#123's finding survives deferral).

    Residual attribution after remedies 1+2 (~15 ms, 9 rows still <0.90):

    • Wave quantization — gate_up fwd, bwd down dx, gate_up dW (86.5% last-wave), down dW (64.9%, 1.3 waves). Remedy 3's rows; no epilogue work moves them.
    • The serial load half of the drain — a single-buffered accumulator cannot release before its last tcgen05.ld; overlap fraction is capped at held-registers/256 (the two-band fp32 form measured 181 regs and fell off the 2-CTA cliff). This is remedy 2's honest ceiling at the [256,256] tile.

    Remaining open remedy: 3 (per-shape tiles, ferro #87/#105) — now carrying both the wave-quantization rows and, via a smaller tile, potentially the drain-release cap.

  6. feitreim commented on Aug 5, 2026

    @feitreim
    OwnerAuthor

    Remedy 3 measured and closed as a documented negative: the [256,128] pair tile loses to [256,256] on all fourteen model rows, in both increments — wave-math alone, and fully double-buffered with the release barrier deleted. Branch 80-narrow-tile preserves both increments as separate commits; nothing merged, the dispatch never shipped.

    What was built (parity green on every mode × layout × tile, both increments)

    1. 7779b2f — [256,128] @ STAGES = 4 as a second compiled variant of the deferred-drain kernel. Same 114 816 B plan, same 2 CTAs/SM, same 148 clusters — the narrower B ring pays for the fourth stage exactly, so the A/B moves the tile and nothing else. Host-side per-shape dispatch (TcTile + Tcgen05Launch), a [64, 64]-box tensor-map twin for B's K-major 64-row stage (TmaOperand; A's box is tile-indifferent), and model_shapes times the forced other tile on every row, so the dispatch rule is accountable to the same table that would change it.
    2. 5bf1991 — the same kernel double-buffered: alloc_cluster(256) = two [128,128] slots (2 slots × 2 CTAs/SM = the 512-column budget, exactly — the door Training-step GEMMs vs cuBLASLt: ~35 ms/step gap, one epilogue mechanism #80 recorded as blocked at 256 columns). The MMA of item i writes slot cycle & 1 while the band warps drain item i−1 out of the other slot, loads included; acc_free and the whole Release discipline are deleted, because pipeline::run's item boundary (tcgen05 fence + cluster sync) already proves a slot's last reader retired. One trap worth recording: slot parity must be a per-cluster counter — the static schedule strides items by the cluster count, which is even, so a global item index's parity would park every cluster on one slot forever.

    No ferro-kittens work was needed: MmaShape::M256_N128, TmemTile::columns_right, and the [64,64] box path all exist at pin 9b58025. ferro #87 is satisfied by the sweep it already ran; this is ferro #105's dispatch question answered on the training shapes.

    Numbers (model_shapes, same-container cuBLASLt, B200)

    "narrow-1 / narrow-2" are the forced-[256,128] ratios in each increment's session; "wide" is the [256,256] ratio from the increment-2 session (its increment-1 session agrees to ±0.02).

    row mode wide narrow-1 narrow-2
    qkv fwd 24576×3072×9216 f32 store 0.827 0.710 0.707
    o_proj fwd 24576×3072×3072 f32 store 0.864 0.732 0.758
    gate_up fwd 6144×3072×8192 f32 store 0.825 0.701 0.714
    down fwd 6144×4096×3072 f32 store 0.873 0.754 0.794
    bwd qkv dx f32 store 0.966 0.787 0.802
    bwd gate_up dx f32 store 0.956 0.798 0.802
    bwd down dx 6144×3072×4096 f32 store 0.835 0.733 0.768
    bwd qkv dW f32 acc-T 0.950 0.745 0.749
    bwd o_proj dW f32 acc-T 0.950 0.824 0.820
    bwd gate_up dW 3072×6144×8192 f32 acc-T 0.892 0.757 0.774
    bwd down dW 4096×6144×3072 f32 acc-T 0.802 0.787 0.796
    lm_head fwd bf16 store 0.844 0.677 0.682
    bwd lm_head dx bf16 store 0.915 0.616 0.636
    bwd lm_head dW bf16 acc-T 0.959 0.715 0.724

    Registers for the record: narrow 132–136 / 115–117 / 127 (bf16 / f32 store / accumulate) across the two increments, zero spill; wide unchanged at 137 / 118 / 127. The wide rows match #83's post-merge sessions, so the dual-descriptor plumbing did not disturb the control.

    Reading

    • Double-buffering bought +1–4 points — the narrow kernel is not epilogue-bound. Mechanically coherent rather than a bug: at two passes a band, increment 1's deferred drain already released with every bf16 store behind it, so the serial term left for increment 2 to delete was two LDTM latencies. It deleted them, and it did not matter.
    • The wave term is real and worth exactly its arithmetic, no more. down dW (64.9% → 86.5% predicted last-wave efficiency) is the one row where narrow reaches within noise of wide (0.796 vs 0.802): the ~21-point wave win was consumed, to the point, by the tile's cost. Rows with no wave win lose 5–28 points.
    • The cost is the tile itself: M·N/(M+N) falls 128 → 85.3 (+50% operand traffic per output), and the deficit tracks it — worst on the big-N bf16 rows (−23 to −28 points), mildest where wave math pays most. The neighboring rungs are not untuned territory: ferro Every AdamW write-back reads a pair before writing it, and the router's zeroing walks the dead tail (#99) #104 priced [256,128] @ s2 (4 CTAs/SM) at −35%, and @ s4 — this kernel's occupancy twin — at −7.7% / +2.1% on squares. There is no adjacent configuration left that its sweep did not already rank below the wide tile.

    Residual attribution, revised

    #83 attributed the remaining ~15 ms to (a) wave quantization at the [256,256] tile and (b) the serial load half of its drain. Remedy 3 built the one configuration that fixes both — the wave arithmetic improves and the drain serialization goes to zero — and it loses every row, because the fix costs more in feed than (a) and (b) are worth combined at every training shape. Both mechanisms stand as descriptions of the wide kernel's residual, but neither is recoverable by tiling. With remedies 1 and 2 shipped and remedy 3 measured closed, #80's open remedies are exhausted; the residual gap is bounded below by the wide tile's wave quantization (down dW's 0.649 last-wave term above all) plus a drain-release path already cut to its two-LDTM floor per pass.

  7. feitreim commented on Aug 5, 2026

    @feitreim
    OwnerAuthor

    Closing per the acceptance clause: every row is either ≥0.90× or its residual is attributed with a measured, closed remedy. Final state: remedies 1 (#82, −17.3 ms) and 2 (#83, −2.6 ms) shipped; remedy 3 measured through full double-buffering on branch 80-narrow-tile and closed as a documented negative (narrow loses all 14 rows; feed-boundedness — intensity 128 → 85.3 — outweighs the wave and drain terms combined at every training shape; ferro #104's sweep prices all adjacent rungs). The ~15 ms residual vs cuBLASLt is attributed and, on current evidence, not recoverable at this kernel architecture: cuBLASLt's remaining edge is epilogue overlap depth we cannot buy without paying more in feed or occupancy than it returns. Preserved controls: 80-stagger-probe, 80-narrow-tile, ferro ws shallow arm (#189).

  8. feitreim commented on Aug 5, 2026

    @feitreim
    OwnerAuthor

    Reopened by owner direction: the residual is attributed but not accepted. Revised acceptance: every model_shapes row ≥ 0.90× cuBLASLt, architectural changes in scope if needed — 'attributed to a closed remedy' is no longer a done-state. One observation motivating the reopen: the narrow-tile experiment inadvertently showed the standing attribution under-explains the gap — it priced the wave-quantization and residual-drain terms at only a few points combined, yet the shallow-K store rows sit 10–17 points below cuBLASLt. Something else is being paid at shallow K (pipeline fill per tile? feed steady-state? K-loop tail?) that the store-vs-fold decomposition never isolated. Next step is forensic: decompose the remaining per-item time against what cuBLASLt actually runs at these shapes before designing anything.

  9. feitreim commented on Aug 5, 2026

    @feitreim
    OwnerAuthor

    Phase 1, forensics before design. Two instruments on branch 80-forensics (bin/budget.rs + src/phase_probe.rs), one B200 container, --features cublas.

    The standing attribution is wrong, and so was my own first guess. The shallow-K deficit is not the epilogue, not the wave term, not the pipeline fill, and not the feed. It is a fixed per-item cost of ~15 100 SM ticks (~8.6 µs) that cuBLASLt does not pay at all — and our steady state is already better than cuBLASLt's.

    Instrument 1 — the depth sweep

    Fix the output geometry (so tile count, wave quantization and the grouped walk are all held still), sweep K, and fit per-item time = fixed + per_block · K/64 for both sides. us/tile is ms × 148 / tiles.

    24576 × K × 9216 (qkv fwd's geometry), 3456 tiles, 23.35 waves:

    K blocks ours ms cuBLASLt ms ratio ours µs/tile theirs µs/tile
    1024 16 0.4075 0.2816 0.691 17.45 12.06
    2048 32 0.6272 0.4812 0.767 26.86 20.61
    3072 48 0.8382 0.7022 0.838 35.89 30.07
    4096 64 1.0592 0.9244 0.873 45.36 39.58
    6144 96 1.5201 1.4675 0.965 65.10 62.85
    9216 144 2.2843 2.3116 1.012 97.82 98.99
    12288 192 3.0872 3.4243 1.109 132.21 146.64

    6144 × K × 8192 (gate_up fwd's geometry), 768 tiles, 5.19 waves — 0.689 / 0.733 / 0.786 / 0.817 / 0.877 / 0.901 / 0.976 at the same depths. Every row of this geometry carries an 86.5 % last-wave efficiency that the qkv geometry (97.3 %) does not, so the qkv fit below is the clean one.

    Fits over the six depths where cuBLASLt keeps one tile (it switches at 12288, so including that point flatters us):

    fixed per item per K block K=3072 K=9216
    ours +6.32 µs 0.6264 µs 36.39 µs 96.52 µs
    cuBLASLt −1.61 µs 0.6846 µs 31.25 µs 96.97 µs
    delta +7.94 µs −0.058 µs

    Our per-K-block cost is 8.5 % lower than cuBLASLt's. The entire deficit is the intercept, and the intercept is why the ratio walks 0.69 → 0.84 → 1.01 → 1.11 as K deepens: it is a constant divided by a growing item.

    Instrument 2 — the phase probe

    src/phase_probe.rs is the fp32 store path with a clock64 on each phase of an item, its entry points declared in optimized::kernels (a binary gets one device artifact) and its C checked bit-for-bit against the shipped kernel before any tick is believed. Instrumented time is +0.4 % over the shipped kernel, so the ticks are trustworthy. Median cluster, per item, qkv geometry:

    phase K=3072 ticks K=9216 ticks what it is
    PRE 3 090 2 705 leader's mbarrier inval+init and the opening cluster_sync
    ACC 9 003 9 077 issuer waiting the previous drain to release the accumulator
    MMA 48 066 144 211 the whole multiply
    — FILL 160 137 — issuer waiting stage 0: the pipeline fill
    — FEED 24 139 73 032 — issuer waiting stages 1..
    POST 3 231 3 123 tcgen05 fence and the closing cluster_sync
    item 63 445 159 135
    (DRAIN) 9 266 9 286 a band warp's whole epilogue

    Three things fall out, and each kills a candidate:

    1. The MMA span is exactly proportional to K: 48 066 / 48 = 1001.4 ticks a block, 144 211 / 144 = 1001.5. At the measured 1.76 GHz that is 0.569 µs for 2·256·256·64 FLOP a cluster — 2182 TFLOP/s aggregate over 148 clusters, 97 % of the B200's 2250 dense bf16 peak. The steady state is not the problem and has ~3 % of headroom in it. "Feed steady-state inefficiency" is refuted as the deficit even though FEED is half the issuer's loop — that is a balanced ring, not a stall, and cuBLASLt's own slope is worse.

    2. FILL is 160 ticks — 0.09 µs, 0.25 % of the item. "Per-tile pipeline fill" is refuted outright. The stage-0 TMA has already landed when the issuer reaches it, because the issuer spent 5 µs on ACC first.

    3. Everything else is K-independent: PRE + POST + ACC = 15 324 ticks at K=3072 and 14 905 at K=9216. That is the intercept, and it closes the arithmetic exactly — 48·1001 / (48·1001 + 15 100) = 0.761, and the measured 1660 TFLOP/s at K=3072 over the 2182 steady state is 0.761. Nothing else is missing.

    The 15 100 ticks are two things:

    • 6 300 ticks (~3.6 µs, 42 %) — the item boundary. pipeline::run re-arms all eight mbarriers on one thread and takes two cluster_syncs per item, and by construction nothing may cross it: the producer cannot issue item i+1's first TMA until item i's barriers have been invalidated and re-initialized behind two cluster barriers.
    • 9 000 ticks (~5.1 µs, 58 %) — the accumulator handoff. ACC ≈ DRAIN (9 003 vs 9 266): the deferred drain of item i−1 runs almost entirely in front of item i's MMA. The drain runs beside the next item's MMA, not in front of it (#80 remedy 2) #83's deferral put the release after the fourth tcgen05.ld, but the fp32 store drain interleaves load/store/load/store — three complete load-and-store passes sit ahead of the release, so what actually overlaps the next MMA is one store pass, not the store half. The no drain arm agrees: deleting the epilogue is −14.2 % of the item at this shape, and the drain is 14.6 % of it.

    What cuBLASLt actually runs

    describe now also reads the uint16_t INNER_SHAPE_ID / CLUSTER_SHAPE_ID. Identical at every depth of both geometries up to 9216:

    id=66 tile=23 splitk=1 reduction=0 swizzle=0 stages=35 inner=0 cluster=3
    

    with waves=46.70 at the qkv geometry — exactly twice our 23.35, so its tile covers half the area ours does. At K=12288 it switches to tile=513, waves=23.35, our tile's area, and that is the row where it loses by 11 %. splitk=1 throughout: still no split-K story, at any depth.

    That comparison is the retrospective explanation of remedy 3. cuBLASLt runs a narrower tile at shallow K and wins with it; the [256, 128] branch ran the same halving and lost 5–28 points. The reason is now measurable: a smaller tile doubles the item count, and every item costs us 15 100 ticks that cuBLASLt's costs it nothing. The narrow tile was not losing to arithmetic intensity alone — it was paying our item boundary twice as often. Which also says the tile question is not settled until the per-item cost is gone.

    What this changes

    The residual is not "attributed to a closed remedy". It is a schedule artifact of pipeline::run's per-item barrier lifecycle plus a release point three passes too late, and both are ours to move:

    1. Delete the item boundary. ferro's own gemm_sol already shows the shape: arm the barriers once per launch, index the operand ring by a global sequence · k_blocks + k, gate items on their own full/empty semaphore rings, and never cluster_sync inside the loop. Our schedule is static, so this needs no CLC and no mailbox — every warp computes its own item index. Worth ~3.6 µs an item at every K, and it helps the deep-K and square rows too.
    2. Move the release to the front of the drain. The fp32 store drain must hand back the accumulator after its last tcgen05.ld, not after its fourth load-and-store pass. The drain runs beside the next item's MMA, not in front of it (#80 remedy 2) #83 measured the two-band hoist at 181 registers and the 2→1 CTA cliff, so this needs a form that holds fewer registers past the release than "two bands live" — that is the design question phase 2 opens with, not a closed door.

    Predicted at qkv K=3072 if only (1) lands: 36.39 → 32.8 µs against cuBLASLt's 31.25, i.e. 0.838 → ~0.93. With (2) it goes past parity. Building it next.

  10. feitreim commented on Aug 5, 2026

    @feitreim
    OwnerAuthor

    Phase 2 shipped as #84: the item boundary is deleted and the drain lifts half-rows behind one wait. Thirteen of the fourteen model rows improve and ten of twelve square cells do, but the bar is not met: six rows sit below 0.90, and the account of why is now much sharper than "attributed to a closed remedy".

    row mode main (A / B) #84 (C1 / C2)
    qkv fwd 24576×3072×9216 f32 store 0.855 / 0.831 0.887 / 0.893
    o_proj fwd 24576×3072×3072 f32 store 0.863 / 0.860 0.895 / 0.900
    gate_up fwd 6144×3072×8192 f32 store 0.813 / 0.827 0.873 / 0.869
    down fwd 6144×4096×3072 f32 store 0.887 / 0.883 0.905 / 0.894
    bwd qkv dx 24576×9216×3072 f32 store 0.966 / 0.963 0.984 / 0.975
    bwd gate_up dx 6144×8192×3072 f32 store 0.965 / 0.955 0.968 / 0.968
    bwd down dx 6144×3072×4096 f32 store 0.835 / 0.837 0.887 / 0.871
    bwd qkv dW 3072×24576×9216 f32 acc-T 0.942 / 0.948 0.952 / 0.940
    bwd o_proj dW 3072×24576×3072 f32 acc-T 0.952 / 0.955 0.948 / 0.947
    bwd gate_up dW 3072×6144×8192 f32 acc-T 0.886 / 0.893 0.901 / 0.906
    bwd down dW 4096×6144×3072 f32 acc-T 0.790 / 0.796 0.789 / 0.791
    lm_head fwd 24576×3072×50432 bf16 store 0.868 / 0.841 0.897 / 0.894
    bwd lm_head dx 24576×50432×3072 bf16 store 0.919 / 0.830 0.920 / 0.901
    bwd lm_head dW 3072×24576×50432 bf16 acc-T 0.959 / 0.948 0.919 / 0.958

    Squares gained too — f32 store 0.865 → 0.954 at 8192³, bf16 store 0.950 → 0.986 at 16384³ — and the depth fit at the qkv geometry went from 6.32 µs fixed + 0.6264 µs a K block to 2.75 + 0.6570, against a cuBLASLt that fits at −1.61 + 0.6846.

    The full step is −8.49 ms, mean of both build orders on compare_profile's measured pairs — 418.983 → 411.867 with main as baseline, 391.002 vs 400.867 with this branch as baseline. The fifteen GEMM rows account for −3.93 ms of that, and that is the figure I would defend: this diff can only move GEMM kernels, and the remainder reproduces in both containers but is unattributed. (An earlier revision of this comment quoted the harness's warm-up runs by mistake and reported a +1.78 ms regression; see the correction on #84.)

    The residual, in two terms and no others

    1. The accumulator handoff — 8 310 SM ticks, 14% of a K = 3072 item. After the boundary is gone the item is ACC + MMA with nothing else in it, and ACC is the drain, entire: one batched tcgen05.ld of the top half-row, one store pass, one batched load of the bottom half-row. Its floor is two facts about the register file, not about the epilogue:

    • the accumulator is 256 fp32 a lane, so no drain can hold a whole band and release before storing any of it — the fraction of store work that can run behind the release is held registers over 256;
    • at 192 threads and 2 CTAs/SM a thread gets 168 registers, of which 128 are already the half-row.

    Everything that was on #80's candidate list is now excluded by measurement rather than by argument: the pipeline fill is 160 ticks (0.25% of an item), the feed steady state is 1001 ticks a K block — hardware peak, and 8.5% ahead of cuBLASLt's own depth slope — and the store issue is worth 1%.

    2. Wave quantization, on exactly two rows. gate_up fwd runs 768 tiles at 86.5% last-wave efficiency against cuBLASLt's 94.4%; bwd down dW runs 192 tiles over 148 clusters at 64.9% against 86.4%. On down dW that term alone is larger than the whole 21-point deficit, which is why it is the one row this PR does not move: nothing in the item stream can help a launch that spends a second wave on 44 tiles.

    What cuBLASLt is doing, since we now know

    id=66 tile=23 splitk=1 stages=35 cluster=3 at every depth of both geometries up to K = 9216, switching to tile=513 at 12288. waves=46.70 at the qkv geometry against our 23.35 — its tile covers exactly half the area ours does. So the library answers both of our residual terms the same way: a smaller tile quantizes better and leaves tensor memory for a second accumulator. It pays for that in arithmetic intensity, and at K = 12288, where our fixed term has amortized away, we beat it by 6–11%.

    That reframes remedy 3. [256, 128] was measured losing all fourteen rows — but it was measured paying the item boundary twice as often, against a kernel whose per-item cost was 15 100 ticks instead of 8 300. Both of the terms above are things a narrower tile improves, and what it was compared against no longer exists. The dispatch machinery is preserved on 80-narrow-tile.

    The two increments this leaves on the table

    • A per-column-half release. Split the pair MMA into two M256_N128 chains over column sub-ranges of the same accumulator, and the next item's first chain can start after half the drain — halving ACC without a second TMEM slot, which is what closed every double-buffer route (remedy 3, ferro #188/#189). It is not free: N is split across the cluster's two ranks, so which rank stages which 64 columns of B changes, and the tensor map, the operand walk and the drain's column mapping move with it.
    • Batching the reduction drain. It still lifts eight [16, STAGE_N] half-bands one issue at a time, because its staging tile is [16, STAGE_N] and nothing slices a wider batch back into that shape. The same change was worth −8.8% on lm_head fwd when the bf16 drain got it. A RegTile column-group slice in ferro would unlock it for the acc-T rows; the fourth held band is the only thing that does not fit (177 registers).

    Preserved controls, none deleted: 80-forensics (the two instruments on main's kernel), 80-phase-probe (the same probe on this kernel), 80-narrow-tile, 80-stagger-probe, ferro #189.

  11. added a commit that references this issue on Aug 5, 2026
  12. feitreim commented on Aug 5, 2026

    @feitreim
    OwnerAuthor

    Both increments #84 left on the table turn out to be one change, and it loses on thirteen of fourteen rows. Reporting it as a negative with the mechanism measured rather than argued. Diffs preserved on 80-column-halves and 80-split-chain-probe.

    Increment A and increment B are the same change

    Increment A wanted the drain of one column half to run while the other half's chain accumulates. For a column half to be drainable on its own it has to complete on its own, so the pair MMA splits into two M256_N128 chains — and a chain covering half the accumulator's columns still needs all of A. Whether the two halves are then called one item (A) or two items (B, the [256, 128] tile), the operand bill is the same:

    shared-memory fill, bytes/FLOP
    [256, 256], one M256_N256 0.00781
    [256, 128], one M256_N128 0.01172 (×1.50)

    There is no form of increment A that costs less than increment B, so I measured the strongest form of both at once: a [256, 128] tile whose accumulator is the same 256 tensor-memory columns run as a depth-2 ping-pong. Residency stays 2 CTAs/SM (512 / 256), the release moves from empty(i + 1) to empty(i + 2), and the drain leaves the critical path entirely — item i + 1 waits on item i − 1's drain, which has had a whole item to finish. The [32, BLOCK_N] fp32 band also becomes exactly ISSUE_LIMIT issues and exactly 128 registers, so the whole band leaves TMEM in one wait with every store owed behind the release.

    It is correct (model_shapes validates all fourteen shapes numerically) and it is cheaper in registers than main: 136 / 161 / 141 against the pinned 133 / 168 / 145, zero spill, STAGES raised 3 → 4 on the bytes the half-width B ring freed.

    It loses

    model_shapes, --features cublas, one B200 container, against #84's post-merge session mean:

    row mode #84 ping-pong [256, 128] Δ
    qkv fwd 24576×3072×9216 f32 store 0.890 0.778 −0.112
    o_proj fwd 24576×3072×3072 f32 store 0.897 0.824 −0.074
    gate_up fwd 6144×3072×8192 f32 store 0.871 0.809 −0.062
    down fwd 6144×4096×3072 f32 store 0.899 0.822 −0.078
    bwd qkv dx 24576×9216×3072 f32 store 0.980 0.856 −0.124
    bwd gate_up dx 6144×8192×3072 f32 store 0.968 0.835 −0.133
    bwd down dx 6144×3072×4096 f32 store 0.879 0.825 −0.054
    bwd qkv dW 3072×24576×9216 f32 acc-T 0.946 0.849 −0.097
    bwd o_proj dW 3072×24576×3072 f32 acc-T 0.948 0.831 −0.117
    bwd gate_up dW 3072×6144×8192 f32 acc-T 0.903 0.823 −0.081
    bwd down dW 4096×6144×3072 f32 acc-T 0.790 0.825 +0.035
    lm_head fwd 24576×3072×50432 bf16 store 0.895 0.681 −0.214
    bwd lm_head dx 24576×50432×3072 bf16 store 0.911 0.628 −0.283
    bwd lm_head dW 3072×24576×50432 bf16 acc-T 0.939 0.753 −0.185

    The wave-quantization prediction was exactly right and it does not matter. bwd down dW is the one row whose deficit #84 attributed to wave quantization, and it is the one row that improves: 192 tiles at 64.9% last-wave efficiency became 384 at 86.5% — cuBLASLt's own 86.4% on that shape, on the nose — and the row moved +3.5 points. Every other row paid the operand bill and lost 5–28.

    So the tile question is settled in the direction remedy 3 already pointed, and #84's retrospective explanation of remedy 3 was wrong: [256, 128] was not losing because it paid the item boundary twice. The boundary is gone, the accumulator handoff is gone with it, and the narrow tile still loses by the same order.

    Where the ×1.50 goes

    The fill rate each configuration sustains, from the measured TFLOP/s and the bytes/FLOP above:

    row #84 fill ping-pong fill ours/theirs TF/s ratio
    qkv fwd 13.3 TB/s 17.5 TB/s 0.877
    o_proj fwd 13.0 17.9 0.921
    gate_up fwd 12.6 17.4 0.925
    down fwd 12.7 17.4 0.916
    bwd qkv dx 14.2 18.6 0.873
    bwd gate_up dx 14.0 18.0 0.862
    bwd qkv dW 14.4 19.4 0.897
    bwd o_proj dW 14.6 19.2 0.877
    bwd lm_head dx 13.8 14.2 0.682

    Two regimes, and the last row names the mechanism. Everywhere else the kernel does push more bytes — 12.6–14.6 TB/s becomes 17.4–19.4 — and pays about 10% of its time for the privilege. On bwd lm_head dx it cannot: the fill rate is the same 14 TB/s in both kernels, so the time scales exactly with the bytes and the throughput ratio is 0.682 against the 0.667 that a perfectly bandwidth-bound row would give. That row is the calibration point: it says the fill path saturates somewhere in the high teens of TB/s, that #84's kernel already runs at 10–15 of it, and that ×1.50 on the fill is not affordable out of that headroom.

    Which also answers the question #84 left open about cuBLASLt. It runs a tile of exactly half our area (tile=23, waves=46.70 against our 23.35) and reaches 1850–1970 TFLOP/s doing it, so it is not paying ×1.50 on the fill — at that tile and that rate it would need well over 20 TB/s. Its cluster=3 is the difference: a cluster wider than the cta_group::2 pair, with the A panel multicast to the pairs that share its rows, is how a half-area tile keeps a whole-area tile's fill.

    What that leaves

    The residual is no longer the accumulator handoff. Both terms #84 named are now measured and both are closed by structures this kernel cannot reach:

    1. The accumulator handoff (8 310 ticks, 14% of a K = 3072 item). The ping-pong removes it completely — that part works. It cannot be had without splitting N, splitting N cannot be had without re-reading A, and re-reading A costs more than the handoff is worth. The only way to split N without re-reading A is to keep both column halves' chains on the same staged A, which needs the two chains lagged by ~10 K blocks to cover a drain — a 13-deep A ring at 16 KiB a stage, against the 116 736 B an SM leaves a CTA at 2 CTAs/SM. Shared memory closes it the way tensor memory closed the double buffer.

    2. Wave quantization (64.9% on bwd down dW, 86.5% on gate_up fwd). The narrow tile fixes it exactly as predicted and cannot be afforded at ×1.50 fill.

    Both exits are the same structure: a 4-CTA cluster with a multicast A. Two cta_group::2 pairs in one cluster, working adjacent [256, 128] tiles of the same tile-row, with each rank's A box tma_load_2d_multicast_cg2'd to the matching rank of both pairs. Per two narrow tiles that is A once and B twice — exactly [256, 256]'s fill — with the narrow tile's wave quantization and, since each pair then owns a 128-column accumulator inside its 256, the ping-pong for free. It is what the measurements above say cuBLASLt is doing, and it is the one remaining structure that answers both residual terms at once. Not attempted here: it moves the cluster launch, the barrier accounting and the multicast masks together.

    Gates

    Only the ones a negative needs. model_shapes two sessions, square bench, the full-step A/B and the parity suites were not run for a branch that is not shipping.

    • model_shapes, one session: table above, and its own numerical validation green on all fourteen shapes — the kernel is correct, it is slower.
    • ptxas: 136 / 161 / 141 registers, zero spill on all three. The bf16 entry point is 3 over its pinned 133 (the f32 store is 7 under its 168 and the accumulate 4 under its 145), which is why --kernel gemm stops at the budget gate rather than at a parity failure. Budgets left un-ratcheted, since nothing here ships.

    Controls preserved

    • 80-column-halves — the measured kernel. It also carries a PAIRED const that pairs the two column halves back into a [2·BLOCK_M, 2·BLOCK_N] tile in the item walk, so the ping-pong can be re-measured with wave quantization held at the old tile's. Not run: with the fill bill identical either way, it separates the wave term from nothing that is in question.
    • 80-split-chain-probe — the control that would price the M256_N128 split itself with the bytes held at main's: a [256, 256] tile, B staged as two 64-row half-boxes so the accumulator's columns still come out in C's order, and two chains issued back to back per K block. It compiles and launches; it did not return. The binary printed its header and then produced no row in 75 minutes on a live container, which is a stall in the first shape rather than a slow one. Stopped rather than left running. Not diagnosed, and so the split between "the two chains cost tensor-core throughput" and "the extra bytes cost bandwidth" is not established here — the bwd lm_head dx calibration above is what carries the bandwidth claim, and it carries it on its own.
  13. feitreim commented on Aug 5, 2026

    @feitreim
    OwnerAuthor

    Phase 0 of the multicast route, and it clears the way: the M256_N128 chain split costs nothing. The stalled probe from the last comment is diagnosed, fixed and measured on 80-split-chain-fixed.

    Why it never returned

    One constant, and it was not the barrier arithmetic.

    A cta_group::2 MMA reads N / 2 columns of B from each rank, so an M256_N128 chain reads 64 — a quarter of the item's 256 columns, not a half. The kernel staged exactly that (HALF_B = HALF_N / 2 = 64). The host encoded the B-operand box at TC_N_ITEM / 2 = 128 rows.

    So every one of the two half-boxes landed 128 rows in the 64-row stage reserved for it — half 0 overrunning into half 1, half 1 past the end of the stage — and the stage barrier was charged 8 192 bytes against the 16 384 the engine delivered. load could never complete, and the launch sat there. The 75 minutes were a barrier waiting for bytes that had already been written somewhere else.

    Both files now derive the same rectangle and a const assert holds them together, which is what the original diff was missing: the box a map hands out and the stage it lands in were named in two places and nothing said they were the same thing.

    The number it was built for

    model_shapes, --features cublas, against a same-day main @ 30ca522 run (separate container — see the caveat):

    row mode main split chain Δ
    qkv fwd 24576×3072×9216 f32 store 0.878 0.882 +0.004
    o_proj fwd 24576×3072×3072 f32 store 0.894 0.887 −0.007
    gate_up fwd 6144×3072×8192 f32 store 0.846 0.858 +0.012
    down fwd 6144×4096×3072 f32 store 0.898 0.883 −0.015
    bwd qkv dx 24576×9216×3072 f32 store 0.975 0.978 +0.003
    bwd gate_up dx 6144×8192×3072 f32 store 0.967 0.955 −0.012
    bwd down dx 6144×3072×4096 f32 store 0.875 0.869 −0.006
    bwd qkv dW 3072×24576×9216 f32 acc-T 0.946 0.946 0.000
    bwd o_proj dW 3072×24576×3072 f32 acc-T 0.967 0.949 −0.018
    bwd gate_up dW 3072×6144×8192 f32 acc-T 0.898 0.901 +0.003
    bwd down dW 4096×6144×3072 f32 acc-T 0.791 0.784 −0.007
    lm_head fwd 24576×3072×50432 bf16 store 0.799 0.837 +0.038
    bwd lm_head dx 24576×50432×3072 bf16 store 0.911 0.854 −0.057
    bwd lm_head dW 3072×24576×50432 bf16 acc-T 0.941 0.940 −0.001

    Mean −0.005, median −0.006. Twelve of fourteen rows land inside ±0.018, which is inside the session spread #84 itself recorded (its own C1/C2 pair differ by 0.039 on bwd lm_head dW). The two rows outside it are both bf16 store and they disagree in sign — lm_head fwd +0.038 against bwd lm_head dx −0.057 — which is what session noise looks like and not what a mechanism looks like. lm_head fwd's cuBLASLt denominator alone moved 2009.89 → 1851.97 TF/s between the two containers, 7.9%, which is most of that +0.038 on its own.

    Caveat, stated rather than buried: two containers, not one. The ratio self-normalizes for clock and contention, which is why it is the column to read, but this bounds the split's cost at "under session noise" rather than measuring it. That is the resolution the decision needed.

    What it settles

    The narrow tile's 5–28 point loss is the operand bill and not the split. Two M256_N128 chains where one M256_N256 used to be, at identical bytes, identical tile and identical everything else, are free — so the multicast route, which also runs M256_N128 per pair, does not inherit a tensor-core cost from the shape of its MMA. It only has to pay for what it fetches.

    Going on to phase 1 with that. Branch preserved, nothing deleted.

  14. feitreim commented on Aug 5, 2026

    @feitreim
    OwnerAuthor

    The 4-CTA cluster with multicast A is built, correct, and loses by a factor of two — and the reason is not the thing anyone was worried about. The replication works perfectly and costs nothing; the cluster width is what the device will not pay for. Reporting it as a negative with the mechanism bisected rather than argued. Diff preserved on 80-mcast-cluster.

    First: the unknown that blocked it is now known, and it works

    tma_load_2d_multicast_cg2 has always taken an arbitrary cta_mask, and ferro's own doc said outright that nobody had established what that mask does to the barrier. Every multicast in this repo and in cuda-oxide's gemm_sol_final uses a one-bit mask, so the replicating form had never run. gpu/gemm/src/mcast_probe.rs — five variants over one 4-CTA cluster, every wait against a globaltimer deadline so a wrong answer is a table row and not a launch that never returns — measured it:

    The copy landing in CTA d completes on the barrier at the supplied offset, in whichever CTA of d's own cta_group::2 pair the supplied address's rank parity names.

    So an n-bit mask gives n completions of one tile each, at n different barriers; an even-rank address means "each destination's pair leader" rather than "rank 0" (mask {1,3} with at_rank(0) charges ranks 0 and 2); and the named barrier is not charged once per destination — charging it n tiles hangs the block. That last one is the trap, and it is silent.

    That is the whole reason the kernel needs no peer-progress signal: one instruction feeds and accounts for both pairs, and the single-barrier-per-pair structure of the two-CTA kernel survives intact. Upstreamed to ferro as feitreim/ferro-kittens#190 (documentation only — the surface was already there and its charge was already the right unit). tma_load_2d_multicast_cg2 also comes off GAPS §2.4's cluster-ops ask, where it was wrongly listed as hardcoding the pair.

    The kernel

    Four CTAs, two cta_group::2 pairs, adjacent [256,128] tiles of one tile-row, each pair leader multicasting one A half to the two CTAs that owe the MMA those rows. Per region A is fetched twice and B four times:

    shared-memory fill, bytes/FLOP
    [256, 256], one M256_N256 0.00781
    [256, 128] alone 0.01172 (×1.50)
    [256, 128] × 2, multicast A 0.00781

    Exactly what the last comment asked for: the narrow tile's wave quantization at the wide tile's arithmetic intensity, with the ping-pong drain for free. It is correct — model_shapes validates all fourteen shapes numerically — at 138 / 168 / 142 registers, zero spill.

    It loses by two

    model_shapes, --features cublas, against a same-day main @ 30ca522:

    row main 4-CTA multicast control: unicast A control: grid = 33
    qkv fwd 24576x3072x9216 0.878 0.463 0.463 0.489
    o_proj fwd 24576x3072x3072 0.894 0.469 0.478 0.491
    gate_up fwd 6144x3072x8192 0.846 0.488 0.489 0.485
    down fwd 6144x4096x3072 0.898 0.507 0.530 0.465
    bwd qkv dx 24576x9216x3072 0.975 0.484 0.493 0.427
    bwd gate_up dx 6144x8192x3072 0.967 0.517 0.535 0.431
    bwd down dx 6144x3072x4096 0.875 0.531 0.542 0.513
    bwd qkv dW 3072x24576x9216 0.946 0.504 0.516 0.420
    bwd o_proj dW 3072x24576x3072 0.967 0.599 0.615 0.389
    bwd gate_up dW 3072x6144x8192 0.898 0.516 0.528 0.486
    bwd down dW 4096x6144x3072 0.791 0.535 0.552 0.498
    lm_head fwd 24576x3072x50432 0.799 0.501 0.467 0.496
    bwd lm_head dx 24576x50432x3072 0.911 0.462 0.497 0.438
    bwd lm_head dW 3072x24576x50432 0.941 0.534 0.549 0.475

    Flat at ~0.5 across every row — every depth, every drain kind, every tile count. Nothing shape-dependent is doing this.

    It is not the multicast

    The control keeps the 4-CTA cluster, the region walk, the two accumulators and the per-pair barriers, and changes only that every rank fetches its own A half — back to the narrow tile's ×1.50 operand bill, with free back to a per-pair release. Column 3 above. It is the same number, row for row.

    So the replication is free and saves nothing measurable. Whatever the 4-CTA kernel loses, it loses with or without the one feature it exists for.

    What the driver says

    cuOccupancyMaxActiveClusters for the compiled shape, and the same query swept against the dynamic plan:

    cluster plan clusters resident CTAs of 148
    2-CTA (main) 114 816 B 74 148
    2-CTA 96 000 → 0 B 74 148
    4-CTA (this) 114 944 B 33 132
    4-CTA 96 000 → 0 B 33 132

    Two things. The four-CTA shape is capped at 132 of the device's 148 CTAs — 11% of the machine lost to cluster-width quantization (33 clusters ≈ 8 GPCs × 4). And the number does not move as the plan goes to zero bytes, so this is the cluster's shape and not anything this kernel spends. Shrinking STAGES cannot buy it back.

    Sizing the persistent grid to that 33, rather than to the 74 the per-CTA arithmetic allows, is column 4 — measured, and not the fix: 0.42–0.51 against 0.46–0.60, no better and mostly worse. Over-subscription is not what this loses to either.

    Where that leaves it, honestly

    Three independent variations of the 4-CTA kernel — replicating, unicast, and grid-matched — all land in the same 0.42–0.62 band against a main at 0.79–0.98. The cluster width is the cost, and the 11% residency deficit is real but does not account for a factor of two. I did not isolate the remaining term, and I would rather say so than name a mechanism I have not measured. The instrument that would split it is the one #84 already built: 80-phase-probe's per-phase clock64 on this kernel, to say whether the issuer is waiting load — a feed that now crosses pairs — or empty.

    One correction to the record this forces

    The last comment inferred that cuBLASLt's cluster=3 is "a cluster wider than the cta_group::2 pair, with the A panel multicast to the pairs that share its rows", and that this is how it affords a half-area tile. That inference is now doubtful. A wider cluster is measurably unaffordable on this device — 132 of 148 CTAs before anything else goes wrong — so whatever CLUSTER_SHAPE_ID = 3 decodes to, "4 CTAs" is an unlikely reading of it. The half-area tile at 1850–1970 TFLOP/s still needs an explanation, and cluster-multicast is no longer the leading one.

    Gates

    Only the ones a negative needs; model_shapes two sessions, the square bench, the full-step A/B and the parity suites were not run for a branch that is not shipping.

    • --kernel gemm: parity green, all shapes, both layouts, store and accumulate.
    • ptxas: 138 / 168 / 142 registers, zero spill on all three. The budget pins in main.rs were moved to those measured counts on the branch only; nothing here ships and main's 133 / 168 / 145 are untouched.
    • model_shapes: the four columns above, one session each.

    Preserved

    • 80-mcast-cluster — the kernel, plus MULTICAST: bool (the unicast control), RESIDENT_CLUSTERS (the grid control), mcast_probe (the semantics instrument) and report_residency in main.rs (the occupancy query, which is generally useful and cheap — it is the thing that would have caught this on day one).
    • 80-split-chain-fixed — phase 0, above.
    • ferro #190 — the multicast semantics, which stand on their own whatever happens here.
  15. feitreim commented on Aug 5, 2026

    @feitreim
    OwnerAuthor

    Both anomalies are resolved, and the second one overturns the model of cuBLASLt that every remedy since #84 was designed against. Instruments on 80-residency: src/residency_probe.rs + src/bin/residency.rs (the residency measurement, beside every occupancy query the driver will answer) and baselines/cublas_decode.cu (the library's own launches, read through CUPTI).

    Anomaly 1 — residency is 2 CTAs/SM. The driver query is not a residency oracle.

    Measured, one B200, %smid + %globaltimer per CTA, each holding its SM for a fixed 2.00 ms wall interval so that a grid the device runs in one wave takes 2 ms and one it runs in two takes 4:

    launch CTAs wall ms waves SMs reached max CTAs/SM peak overlap
    cg2 × 148 clusters, 114 816 B 296 2.022 1.01 148 2 296
    cg2 × 148, 96 000 B 296 2.021 1.01 148 2 296
    cg2 × 148, 1 024 B 296 2.024 1.01 148 2 296
    cg2 × 74, 114 816 B 148 2.019 1.01 148 1 148

    All 296 CTAs of main's persistent launch are co-resident, two an SM, at the full shared plan. Every wave-quantization number on this issue stands exactly as written; down dW's 192 tiles really are 1.30 waves over 148 clusters, not 2.6 over 74.

    cuOccupancyMaxActiveClusters is simply answering a different question. On this branch it reports 74 for every kernel and every plan — 114 816 B, 96 000 B, 1 024 B alike — for the 133-register bf16 entry, the 168-register store, the 145-register accumulate, and an 18-register probe. cuOccupancyMaxActiveBlocksPerMultiprocessor reports 1 block/SM for all of them, at 1 024 bytes and 18 registers, which cannot be a physical statement. Neither number moves with the L1/shared carveout (-1 → 100: no change) or with the grid it is handed (37, 74, 148, 296, 592 clusters → 74 every time). For a required-cluster function these queries return floor(SMs / cluster CTAs) and one CTA of this cluster per SM; they do not model two clusters sharing an SM.

    The shipped kernel agrees. Timed across grid widths (fp32 store, same container, its real 168 registers):

    shape 148 cl 111 cl 74 cl 37 cl
    qkv fwd 24576×3072×9216 0.8220 1.0033 1.1086 2.0968
    bwd qkv dx 24576×9216×3072 0.7681 0.9565 1.1130 2.1647
    square 8192³ 0.6050 0.7667 0.8588 1.5951

    Monotone in the grid all the way to 148. If 74 had been the resident width, 148 would have cost nothing.

    And the arithmetic is right at the edge, which is worth writing down: at 2 CTAs/SM the plan uses 229 632 of 233 472 B (98.4%), the registers 64 512 of 65 536 (98.4%), and tensor memory 512 of 512 (100%). Three limits at once, all satisfied. That is also why #83's two-band hoist at 181 registers fell off a cliff — 181 × 192 × 2 = 69 504 > 65 536 — which was read correctly at the time.

    What this reinterprets: the multicast negative's missing factor of two

    The 4-CTA kernel launched MAX_CLUSTERS = 74 clusters = 296 CTAs. Measured at that exact shape:

    launch CTAs wall ms waves SMs peak overlap
    cg4 × 74 clusters 296 4.020 2.01 142 284
    cg4 × 73 292 4.018 2.01 142 284
    cg4 × 72 288 4.019 2.01 142 284
    cg4 × 71 284 2.018 1.01 142 284
    cg4 × 70 280 2.019 1.01 142 280
    cg4 × 33 132 2.018 1.01 132 132

    A four-CTA cluster grid reaches 142 SMs, not 148, and holds two CTAs on each: 284 CTAs, 71 clusters, and the 72nd costs a whole second wave. It is placement and nothing this kernel spends — the same 2.01 waves appear at a 1 024-byte plan and at 128 tensor-memory columns.

    So the multicast kernel ran two waves for a 296-CTA grid that only 284 CTAs fit, and that is the factor of two the last comment could not isolate. Its own control went the wrong way: 33 clusters (from the driver query) is 132 CTAs, under half the machine. 71 was never tried, and it is 96% of main's 296.

    Anomaly 2 — cuBLASLt runs our tile. cluster=3 is 2×1×1 and tile=23 is [256, 256].

    Nsight Compute will not initialise on the Modal container (Failed to initialize the profiler: LibraryNotLoaded — the driver's profiling support, not an image package; ncu itself is already at /usr/local/cuda/bin/ncu). A launch configuration needs no performance counters, so baselines/cublas_decode.cu reads it from CUPTI's callback API instead — cuLaunchKernelEx parameters plus cuOccupancyMaxActiveBlocksPerMultiprocessor on the handle the library is passing. Identical at all three shapes:

    algo id=66 tile=23 splitk=1 reduction=0 swizzle=0 stages=35 inner=0 cluster=3
    grid 6912x1x1 = 6912 CTAs, block 256 threads, cluster 2x1x1
    dynamic shared memory 213 280 B
    symbol nvjet_tst_128x256_64x6_2x1_2cta_v_bz_TNT
    

    The symbol decodes the whole thing, and the launch confirms it independently:

    cuBLASLt main
    per-CTA tile 128x256 128 × 256
    pair tile [256, 256] (2cta) [256, 256]
    K per stage 64 64
    K stages x6 3
    cluster 2x1 = 2×1×1 2×1×1
    threads 256 192
    dynamic shared 213 280 B 114 816 B
    CTAs/SM 1 (2 × 213 280 > 233 472) 2
    grid 6912 CTAs = 3456 clusters = one cluster per tile, non-persistent 148 persistent clusters
    split-K none none

    Outputs over clusters confirms the tile without trusting the name: 24576×9216 / 3456 = 65 536; 6144×8192 / 768 = 65 536; 24576×50432 / 18 912 = 65 536. [256, 256] at every shape.

    Three things on the record are now wrong

    1. "Its tile covers half the area ours does." It does not. waves=46.70 against our 23.35 was never a like-for-like comparison: cuBLASLt's wavesCount counts CTAs over SMs (6912/148 = 46.70) while our 23.35 counted tiles over clusters (3456/148). In tiles the two kernels are identical — 3456 apiece. Every argument built on the half-area reading falls with it: remedy 3's retrospective explanation, the ping-pong's motivation, and the multicast route's premise.
    2. cluster=3 is not four CTAs. It is 2×1×1, the same cta_group::2 pair we run. The doubt recorded last comment is now decided, and tma_load_2d_multicast_cg2's semantics (ferro#190) stand on their own as the only durable thing that route produced.
    3. cuBLASLt is not paying ×1.50 on the fill and never was. Same tile, same intensity, same 0.00781 bytes/FLOP. The "it would need >20 TB/s" puzzle dissolves — it needs exactly what we need.

    What the difference actually is, and why it is the whole residual

    The kernels differ in four things, and three of them are consequences of the fourth:

    cuBLASLt runs one CTA per SM. With the second CTA gone it takes the SM whole:

    resource at 2 CTAs/SM (ours) at 1 CTA/SM (theirs)
    shared memory a CTA 116 736 B → 3 stages 233 472 B → 6 stages
    tensor-memory columns 256 — one accumulator 512 — two
    registers a thread 168 (192 threads) 256 (256 threads)

    Those are, one for one, the three floors this issue has been reporting as unmovable:

    Every one of them binds because we chose two CTAs an SM. cuBLASLt chose one, and bought all three at once.

    The rung that was never tested

    #80 did test 1 CTA/SM — ferro gemm_ws (#188/#189), which lost by 7.3–7.9% at every shallow shape, and that result closed the route. But gemm_ws is STAGES = 4 and SHARED_BYTES = 131 176; its own module doc says it "has the whole 233 472 B to spend and spends 131 176". It has the double accumulator and the register headroom, and it runs its operand ring two thirds as deep as the kernel it was being compared to, leaving 100 KB of the SM unused.

    The K depth is exactly what a lone MMA chain needs to stay fed, and it is the one thing that arm did not have. STAGES = 6 is 196 608 B of ring — the rung cuBLASLt picked, and the last one that fits.

    Next

    Measuring gemm_ws at STAGES = 6 before anything is designed, and re-pricing the 4-CTA multicast kernel at its measured 71-cluster knee, since both are one constant each and both were closed on a number that is now known to be wrong. 80-residency carries the two instruments; a PR follows for the residency one, which belongs in main whatever happens next — with the driver query kept beside the measurement rather than instead of it, since on its own it says 74.

  16. feitreim commented on Aug 5, 2026

    @feitreim
    OwnerAuthor

    First increment on the decoded configuration, measured and preserved rather than shipped: 80-deep-ring, two constants — STAGES 3 → 6 and CTAS_PER_SM 2 → 1. Shared memory now binds residency where tensor memory used to, and the plan lands at 213 120 B against cuBLASLt's 213 280.

    It is a wash on the mean and it moves bwd down dW, the row this issue has never moved, by ten points.

    model_shapes, --features cublas, two sessions

    Against main @ 30ca522's same-day session (the one the split-chain comment used). deep is the mean of two sessions of this branch; both are in the branch's logs and they agree to ±0.02 except on the three bf16 rows, whose cuBLASLt denominators moved 2–4% between containers.

    row mode main deep (mean) Δ wave eff. 148 cl wave eff. 74 cl
    qkv fwd 24576×3072×9216 f32 store 0.878 0.880 +0.002 0.973 0.994
    o_proj fwd 24576×3072×3072 f32 store 0.894 0.901 +0.007 0.973 0.973
    gate_up fwd 6144×3072×8192 f32 store 0.846 0.878 +0.032 0.865 0.943
    down fwd 6144×4096×3072 f32 store 0.898 0.904 +0.006 0.973 0.973
    bwd qkv dx 24576×9216×3072 f32 store 0.975 0.952 −0.023 0.973 0.973
    bwd gate_up dx 6144×8192×3072 f32 store 0.967 0.943 −0.025 0.973 0.973
    bwd down dx 6144×3072×4096 f32 store 0.875 0.855 −0.020 0.865 0.865
    bwd qkv dW 3072×24576×9216 f32 acc-T 0.946 0.928 −0.019 0.973 0.973
    bwd o_proj dW 3072×24576×3072 f32 acc-T 0.967 0.916 −0.051 0.973 0.973
    bwd gate_up dW 3072×6144×8192 f32 acc-T 0.898 0.875 −0.023 0.865 0.865
    bwd down dW 4096×6144×3072 f32 acc-T 0.791 0.884 +0.093 0.649 0.865
    lm_head fwd 24576×3072×50432 bf16 store 0.799 0.832 +0.033 0.998 0.998
    bwd lm_head dx 24576×50432×3072 bf16 store 0.911 0.901 −0.011 0.973 0.973
    bwd lm_head dW 3072×24576×50432 bf16 acc-T 0.941 0.874 −0.068 0.998 0.998

    Mean −0.005. Parity green; ptxas 133 / 168 / 145, zero spill — unchanged, so nothing here is a register story.

    The two columns on the right are the whole result

    Sort the rows by whether the wave efficiency moved and the table stops being noisy:

    • It moved (3 rows): bwd down dW 0.649 → 0.865 buys +0.093; gate_up fwd 0.865 → 0.943 buys +0.032; qkv fwd 0.973 → 0.994 buys +0.002. The gain tracks the wave arithmetic row for row.
    • It did not move (11 rows): every one loses, and they all lose by 2 to 5 points. That is the pure price of halving the CTA count at six stages, isolated.

    And 0.865 and 0.943 are not arbitrary numbers: they are exactly the 86.4% and 94.4% #84 recorded as cuBLASLt's own last-wave efficiencies on those two rows. That is the anomaly-2 prediction landing — cuBLASLt quantizes better because its resident unit is 74 clusters, not because its tile is smaller. It never was smaller.

    What this changes about the standing account

    #80 closed the 1-CTA/SM route on ferro gemm_ws losing 7.3–7.9% at every shallow shape, and every double-buffer route since has been closed by "no second 256-column TMEM slot at 2 CTAs/SM". gemm_ws runs STAGES = 4 and spends 131 176 B — its own doc says it "has the whole 233 472 B to spend and spends 131 176". At six stages the same residency costs 2–5 points, not 7–8, and pays for a third of the rows on its own.

    So the halving is roughly self-financing at the right depth, and neither thing it actually buys has been spent yet:

    1. The SM's other 256 tensor-memory columns. alloc_cluster(256) still takes half of 512 and leaves the rest idle. The second accumulator — the ping-pong that remedy 2, remedy 3 and ferro#188/#189 were each closed for lacking — is now simply available, and 80-column-halves already carries a working depth-2 ping-pong to lift the discipline from.
    2. The register file. A thread had 168 registers at two CTAs an SM and The item stream has no boundary, and the drain lifts half-rows behind one wait (#80) #84 named that the drain's floor: "168 registers, of which 128 are already the half-row". At one CTA an SM the budget is 341 (the architecture's 255 in practice), and The drain runs beside the next item's MMA, not in front of it (#80 remedy 2) #83's two-band hoist — measured at 181 registers and rejected because it fell off the 2-CTA cliff — costs nothing here.

    Both were closed by the same constraint, and the constraint was a consequence of choosing two CTAs an SM. The eleven losing rows are the bill for that choice with neither purchase made.

    Also on the record

    • PR Residency is measured, and cuBLASLt's configuration is read (#80) #85 — the two instruments, no kernel change: the residency probe (which is what established 296 CTAs are resident) and the CUPTI decode of the library. It should land whatever happens to the kernel, and it deliberately ships the driver query beside the measurement, because on its own the query says 74.
    • Not re-run: the 4-CTA multicast kernel at its measured 71-cluster knee. It is still one constant on 80-mcast-cluster and it would settle that negative honestly, but the route's premise is gone — cuBLASLt is not multicasting and its tile is not narrow — so it is a record-keeping run rather than a candidate.
    • Gates: this branch is a control, so only parity and ptxas were run. The square bench, the full-step A/B and the second-session discipline belong to whatever ships.
  17. added a commit that references this issue on Aug 5, 2026
  18. feitreim commented on Aug 5, 2026

    @feitreim
    OwnerAuthor

    The decoded configuration, with the freed resources spent: PR #86, from 80-wide-stage. The mean goes 0.906 → 0.939 against a same-day main, twelve of fourteen rows clear 0.90, and the accumulator handoff is measured at 4 815 → 100 SM ticks. bwd down dW — the row this issue has never moved — goes 0.797 → 0.928.

    It is three constants and 16 KiB: STAGES 3 → 6, ACCUM_COLS 256 → 512 (two accumulators, SLOTS = 2), STAGE_N 64 → 128. CTAS_PER_SM keeps its old formula 512 / ACCUM_COLS and reads 1; MAX_CLUSTERS falls out at 74.

    Increment 1 — the ping-pong, and the probe that prices it

    80-pingpong-probe carries #84's clock64 instrument on this kernel with the ping-pong itself behind a const, so before and after are one binary at the same residency, ring depth and plan — only SLOTS differs. Per item, rank-0 SM ticks:

    qkv fwd, K = 3072 one slot ping-pong
    ACC — issuer waiting the previous drain 4 815 100
    MMA 27 153 27 459
    FILL — 118
    FEED — 3 411
    DRAIN 7 990 10 470
    DONE 24 179 17 310
    item 32 162 27 736
    wall 0.8756 ms 0.8028 ms (−8.3%)

    Four shapes agree: ACC 4 289 → 114 and 4 244 → 114 at gate_up, 4 679 → 100 at K = 9216. The handoff is not smaller, it is off the critical path — the drain gets slower (7 990 → 10 470; it now contends with a running MMA) and the item is 14% shorter anyway. That is the term #84 left as the entire residual, and it is gone.

    What replaces it is the feed. FEED — the issuer waiting stages 1.. — is 3 411 of 27 736 ticks at K = 3072 and 9 422 of 81 045 at K = 9216. Twelve percent either way, against FILL at 118 and ACC at 100. Six stages is 196 608 B and a seventh does not fit, so this structure has no more depth to give it.

    Increment 2 — the bf16 drain's wide staging tile, which was the other thing the halving bought

    Not the register hoist. #83's two-band hoist was the named candidate, and the probe says it would buy nothing: at ACC = 100 the fp32 drain is already fully covered. What was still costing is that the bf16 band was (32/16)·(64/64) = 2 .x8 issues a pass and four exposed TMEM latencies a band, where #84 got the fp32 store down to two — and it was stuck there because four [32, 128] staging tiles are 32 768 B against 16 384, and at two CTAs an SM the plan had no such 16 KiB.

    At one CTA an SM it does. STAGE_N = 128 makes a band exactly ISSUE_LIMIT issues behind one wait and exactly the 128 registers a thread holds. Measured on the two bf16 store rows, in absolute throughput (their ratios are the noisiest in the table):

    bf16 store row inc 1 + wide stage Δ
    lm_head fwd 1 589.4 TF/s 1 635.0 +2.9%
    bwd lm_head dx 1 591.4 TF/s 1 629.9 +2.4%

    So two of the three freed resources paid — shared memory twice over (the ring and the staging tile) and tensor memory once. The register file did not, and the honest statement is that it did not need to: at one CTA an SM a thread is granted the architecture's 255 rather than the ~170 twelve warps left it, the ceiling that closed #83's hoist is gone, and the kernel came out at 134 / 168 / 146 — two counts up by one register, nothing else asking.

    model_shapes, two sessions, against a same-day main @ 0b652de

    row mode main inc 1 #86 Δ
    qkv fwd 24576×3072×9216 f32 store 0.891 0.938 0.938 +0.047
    o_proj fwd 24576×3072×3072 f32 store 0.899 0.963 0.962 +0.063
    gate_up fwd 6144×3072×8192 f32 store 0.875 0.935 0.931 +0.056
    down fwd 6144×4096×3072 f32 store 0.895 0.953 0.962 +0.067
    bwd qkv dx 24576×9216×3072 f32 store 0.982 0.973 0.972 −0.010
    bwd gate_up dx 6144×8192×3072 f32 store 0.966 0.959 0.963 −0.003
    bwd down dx 6144×3072×4096 f32 store 0.885 0.942 0.948 +0.063
    bwd qkv dW 3072×24576×9216 f32 acc-T 0.952 0.929 0.930 −0.022
    bwd o_proj dW 3072×24576×3072 f32 acc-T 0.941 0.913 0.918 −0.023
    bwd gate_up dW 3072×6144×8192 f32 acc-T 0.905 0.920 0.915 +0.010
    bwd down dW 4096×6144×3072 f32 acc-T 0.797 0.928 0.928 +0.131
    lm_head fwd 24576×3072×50432 bf16 store 0.854 0.895 0.895 +0.041
    bwd lm_head dx 24576×50432×3072 bf16 store 0.909 0.897 0.900 −0.009
    bwd lm_head dW 3072×24576×50432 bf16 acc-T 0.935 0.962 0.979 +0.044
    mean 0.906 0.936 0.939 +0.033

    The 80-deep-ring control's prediction lands exactly. The three rows whose wave efficiency moved gain (bwd down dW 64.9% → 86.5% over 74 clusters, which is cuBLASLt's own 86.4% on that shape); the eleven that paid the control's uniform 2–5 points get it all back and more, because the ping-pong is what the 2–5 points were buying and the control had not bought it yet.

    Where it does not close

    lm_head fwd is at 0.895 on the session mean. It is the one row still under the bar, by half a point, and the two bf16 store rows are also the noisiest in the table — 0.933 / 0.888 / 0.863 across three sessions of increment 1 alone, because they are the biggest matrices in the model and their cuBLASLt denominators move 3–5% between containers. Both rows are up on main in absolute throughput in every session measured; the acceptance criterion as written (every row ≥ 0.90) is not met on the mean, and I would rather say that than pick the session where it is.

    The two dW rows that lose 2 points (bwd qkv dW, bwd o_proj dW) are 432 and 144 tiles — they quantized well over 148 clusters and quantize no better over 74, so they pay the halving and are handed nothing back by it.

    Gates

    GROUP stays 8, and now for a reason rather than by inheritance

    Measured at 16 on this branch: neutral to worse in absolute throughput on every row, and nothing at all on the two bf16 rows it was aimed at. The arithmetic says why. grouped walks GROUP tile-rows down a column, so a wave of MAX_CLUSTERS clusters covers a GROUP × (MAX_CLUSTERS / GROUP) rectangle and the operand footprint in flight is smallest when it is square. At 148 clusters GROUP = 8 gave 8 × 18.5 — lopsided. At 74 it gives 8 × 9.25, and √74 = 8.60. The constant was tuned against the wrong residency and the new one is what it wanted.

    Preserved

    • 80-ping-pong — increment 1 alone, three model_shapes sessions, the point the two increments separate at.
    • 80-pingpong-probe — the phase probe on this kernel plus gemm_probe_f32_noping, the one-slot control. A stopwatch does not belong in the shipped module.

    What is left, at probe evidence grade

    ACC is 100 ticks, FILL is 118, PRE/POST are gone since #84. The item is MMA and inside it FEED at 12% — the issuer waiting an operand stage that six stages of 64-deep K did not cover. That is the whole of the remaining distance now, and it is a bandwidth question rather than a scheduling one: this kernel already runs its ring at cuBLASLt's own depth, at cuBLASLt's own tile, on cuBLASLt's own cluster, at one CTA an SM.

  19. added a commit that references this issue on Aug 5, 2026
  20. feitreim commented on Aug 5, 2026

    @feitreim
    OwnerAuthor

    Closing at owner direction. Final state: model_shapes mean 0.939 of cuBLASLt, 12/14 rows ≥0.90 (#86: 1 CTA/SM, six-stage ring, TMEM ping-pong — cuBLASLt's decoded config composed with the continuous pipeline). Residual work moves to a new low-priority issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions