Skip to content

The wait is worth two thirds as much where something is covering it, and the epilogue was never gemm_ws's problem (#118) - #119

Merged
feitreim merged 1 commit into
mainfrom
ws-epilogue-widths
Jul 29, 2026
Merged

feitreim merged 1 commit into
mainfrom
ws-epilogue-widths

Conversation

@feitreim

Copy link
Copy Markdown
Owner

.x8 LDTM and stmatrix.x4 on gemm_ws (#117's two widths on the kernel that had never had them), plus the two no drain controls the ladder is subtracted from. One lever pays, one is a null, and a hypothesis this repo has carried since #112 dies.

Every timed row was checked element-by-element against the CPU reference before it was timed; check_c compares bf16 words with == and no tolerance. The two no drain rungs write no C on purpose and say so in their own label. One container, min of 30 timed launches, static schedule, GROUP = 8.

The levers

shape ws s4 ms staged staged8 staged4 staged84 8 vs 4 vs 84 vs
4096³ 0.1382 0.1340 0.1158 0.1324 0.1171 +15.7% +1.2% +14.5%
8192³ 0.7881 0.7649 0.7201 0.7648 0.7199 +6.2% +0.0% +6.2%
16384³ 5.7904 5.6645 5.5015 5.6604 5.5028 +3.0% +0.1% +2.9%

Best rung is +19.4% / +9.5% / +5.2% over the shipped register epilogue, taking the kernel from 0.615 to 0.726, 0.782 to 0.856 and 0.810 to 0.852 of cuBLASLt.

They do not compose here, and the register column said so in advance. .x8 costs the same +50 registers either side (44 → 94); .x4 recovers 2 here against 14 on gemm_cg2, and that recovery was gemm_cg2's composition gain. staged8 and staged84 are within 1.1% and trade places between sessions. Zero spill everywhere; 94 is the largest count in the file against a reachable 255 at six warps.

The mechanism predicted the shortfall and got it

#117 established that the win is the wait and not the issue. gemm_ws already covers that wait — the drain is deferred one item, on four warps of its own, producer never stopping — so .x8 had to be worth less here, and it is: 67%, 72% and 83% of its value on gemm_cg2.

By #114's whole − no drain, in µs a tile:

shape ws s4 staged staged8 staged84 LDTM half
4096³ 8.90 8.65 4.10 4.42 4.55
8192³ 8.62 6.97 3.77 3.76 3.20
16384³ 9.06 6.76 3.85 3.87 2.91

The same epilogue is exposed at 8.62 µs here against #114's 20.43, and its LDTM half at 3.20 against #117's 8.07 — 40–47%. That is what warp specialization and the accumulator ping-pong buy, as a number for the first time.

"Twice the LDTM (16 against 8)" is true of the PTX and false of the work. Every census column doubles — stmatrix 8 against 4, cvt 16 against 8 — because gemm_ws emits its epilogue at two call sites (Ws::work and Ws::finish) where the fused job has one. The bands are RegTile<32, 64> in both files, so dynamic LDTM per tile is identical, and it measures 2.5× cheaper, not twice as dear.

The floor, and the answer to "does gemm_ws beat gemm"

gemm_ws_no_drain is the shipped kernel with the epilogue deleted — #114's probe, which put gemm_cg2 at 1850 TF/s against the library's 1808.

shape ws no drain ms TFLOP/s of cuBLASLt vs gemm's staged84
4096³ 0.1026 1339.2 0.829 +3.0%
8192³ 0.6674 1647.4 0.923 −2.2%
16384³ 5.2828 1665.1 0.888 −3.0%

No. At 8192³ and 16384³ this kernel loses to gemm's complete launch while running no epilogue at all. Best against best is −9.7% / −9.4% / −6.9%, and deleting the epilogue recovers only 12.7 / 7.2 / 3.9 of those points. #112's 7.3% at 16384³ closes to 6.9% after both kernels have spent everything #116 and #117 found.

#112 blamed the peer CTA hiding gemm_cg2's epilogue and #114 refuted it; gemm_ws.rs then blamed the missing peer CTA, and this refutes that too — by deleting the epilogue and losing anyway. The stale paragraph is corrected in place rather than removed. What is left is the multiply and the operand stream at one CTA an SM; the two epilogue-free kernels are ~10% apart at 8192³ (1.02 of cuBLASLt against 0.923). StoreRing (#111) no longer has "about 7% to find" here — it has at most 3.0%.

Against the library, same container

cuBLASLt 1616.5 / 1784.9 / 1876.0 TFLOP/s. The gemm 84 column reproduces #117's 0.796 / 0.944 / 0.922 from another session, which is the drift control.

shape gemm gemm 84 ws s4 ws staged ws staged84 ws floor
4096³ 0.595 0.804 0.615 0.635 0.726 0.829
8192³ 0.831 0.944 0.782 0.805 0.856 0.923
16384³ 0.871 0.915 0.810 0.828 0.852 0.888

Residency, counted

cuOccupancyMaxActiveBlocksPerMultiprocessor returns 1 for anything containing a tcgen05.alloc (#77). Two new %smid/%globaltimer census rungs at this kernel's own 131 176 B and 147 584 B count 1 resident, 1 holding at both, against a budget of 1. That also closes the gap the cg2 512 rung left at a 32 B plan — 1 holding but 2 resident, the second CTA parked 100.9 µs inside a blocking allocator, against 0.9 µs here.

Shape of the change

  • Tile::drain_staged<WIDE, X4>, and Ws's epilogue selector becomes one const DRAIN: u8 (drain::REGISTER/STAGED/STAGED_X8/STAGED_X4/STAGED_X8_X4/REMOVED) rather than a fourth positional bool.
  • Five new entry points: three widths and two no drain controls, one per envelope.
  • gemm::bench_with so this file can measure gemm's best rung as a control in its own session rather than quoting it.
  • ws_bench grows from four tables to six; the sweep is ~90 s of B200.

No default moved. staged8 is the rung to ship on gemm_ws — .x4 is a null here alone and in composition — and that is a change worth making on its own, on #116's and #117's precedent.

…and the epilogue was never gemm_ws's problem (#118)

`.x8` LDTM and `stmatrix.x4` on `gemm_ws`, plus the two `no drain` controls the
ladder is subtracted from, and the result is a lever that pays and a hypothesis
that dies.

The levers. Against #116's `staged`, `.x8` is +15.7% / +6.2% / +3.0% at
4096/8192/16384 cubed and `.x4` is +1.2% / +0.0% / +0.1% — the same clean null
it was on `gemm_cg2`. They do not compose here: `staged8` and `staged84` are
within 1.1% and trade places between sessions, and the register column said so
in advance, `.x4` recovering 2 registers (94 -> 92) where on `gemm_cg2` it
recovered 14 (94 -> 80) and that recovery *was* the composition gain. Best rung
is +19.4% / +9.5% / +5.2% over the shipped register epilogue, 0.615 -> 0.726,
0.782 -> 0.856, 0.810 -> 0.852 of cuBLASLt. Zero spill in every rung; 94 is the
largest count in the file against a reachable 255.

#117's mechanism predicted the shortfall and got it. `.x8` removes a latency
the drain never overlaps; this kernel already overlaps it, so `.x8` is worth
67%, 72% and 83% of what it was worth on `gemm_cg2`. By `whole - no drain` the
same epilogue is exposed at 8.62 us a tile here against #114's 20.43, and its
LDTM half at 3.20 against #117's 8.07 — 40-47%, which is what warp
specialization and the accumulator ping-pong buy, stated as a number for the
first time.

"Twice the LDTM (16 against 8)" is true of the PTX and false of the work. Every
census column doubles, not just LDTM, because `gemm_ws` emits its epilogue at
two call sites (`Ws::work` and `Ws::finish`) where the fused job has one. The
bands are `RegTile<32, 64>` in both files.

The floor is the finding. `gemm_ws_no_drain` — the shipped kernel with the
epilogue deleted, the probe that put `gemm_cg2` at 1850 TF/s against the
library's 1808 — reaches 0.829 / 0.923 / 0.888 of cuBLASLt, and at 8192 and
16384 cubed it is *slower than `gemm`'s complete `staged84` launch*. Best
against best is -9.7% / -9.4% / -6.9%; deleting the epilogue outright recovers
12.7 / 7.2 / 3.9 of those points. So no, `gemm_ws` does not beat `gemm`, and it
could not have: #112's 7.3% closes to 6.9% after both kernels spent everything
#116 and #117 found. The deficit is the multiply and the operand stream at one
CTA an SM. #112 blamed the peer CTA and #114 refuted it; `gemm_ws.rs` blamed the
missing peer CTA and this refutes that, by deleting the epilogue and losing
anyway. The stale paragraph is corrected in place rather than removed.

Residency counted, not queried (#77): two new census rungs at this kernel's own
131 176 B and 147 584 B read 1 resident, 1 holding at both, closing the gap the
`cg2 512` rung left at a 32 B plan (1 holding, 2 resident, 100.9 us parked in a
blocking alloc; 0.9 us here).

No default moved. `staged8` is the rung to ship on `gemm_ws` — `.x4` is a null
here alone and in composition — and that is a change worth making on its own.
@feitreim
feitreim merged commit dc5d4cd into main Jul 29, 2026
3 checks passed
feitreim added a commit that referenced this pull request Jul 29, 2026
…ce (#119) (#120)

`gemm`'s default epilogue becomes `staged84` and `gemm_ws`'s becomes `staged8`.
#116, #117 and #118 each ended by saying the rung was worth shipping and that
shipping it belonged in its own change; this is that change and it is the whole
of it. No rung added, none deleted, nothing retuned — every entry point still
launches and is still on the correctness gate.

The two differ on purpose. `.x8` costs +52 and +50 registers identically; what
differs is what `.x4` hands back — 14 on `gemm_cg2` (94 -> 80) and 2 on
`gemm_ws` (94 -> 92) — and that recovery IS the composition gain. There the
pair is +5.1% at 16384^3 against `.x8` alone's +3.6%; here `staged8` and
`staged84` land inside 1.1% and trade places between sessions, so the tie goes
to the rung with less surface.

Confirmed in one container with cuBLASLt re-measured in it (#109's lesson):
`gemm` 0.1432 -> 0.1044, 0.7584 -> 0.6684 and 5.5157 -> 5.0132 ms, which is
+37.2% / +13.5% / +10.0% and 0.583 -> 0.801, 0.827 -> 0.939 and 0.871 -> 0.958
of the library. `gemm_ws` +19.6% / +8.7% / +6.3% and 0.599 -> 0.717,
0.790 -> 0.858, 0.812 -> 0.863. Both reproduce their published ratios; the
16384^3 rows moved because the denominator did.

The constants that describe the shipped launch moved with it: `main.rs` reports
114 816 B and 147 584 B, and `CTAS_PER_SM` does not move on either kernel
because the tensor-memory term of `min(512 / columns, shared per SM / plan)`
binds at both envelopes. `regcount`'s occupancy gate gained
`gemm_cg2_staged_x8x4` and reads 166 / 42 / 80 against a ceiling of 255.

Deliberately unmoved: the ablation cube, `bench --case epilogue` and
`bench --case staged` stay built at `lcf`, and `ws_bench` table 1 now NAMES
`lcf` on both sides rather than taking `gemm`'s default, so its one variable is
still where the overlap comes from.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant