Repository navigation
Merged
Conversation
…per SM examples/src/gemm_ws.rs is NVIDIA's gemm_sol_final (cuda-oxide b099f64, crates/rustc-codegen-cuda/examples/gemm_sol_final/) in this repo's idiom: six warps to a CTA -- 0-3 epilogue, 4 TMA, 5 pair-UMMA -- and two accumulator stages in tensor memory, which is 512 columns and therefore one CTA an SM. examples/src/gemm.rs is untouched. Its overlap comes from the second CTA; this one's comes from the warp split plus the double-buffered accumulator, and the point of the file is that the two can be A/B'd. The epilogue is deliberately kittens::global::store_rows, unchanged, so the delta is the occupancy/specialization structure and not a store path. It needed no modification at six warps: warps 0-3 still cover 128 accumulator rows at 32 each and store_rows is not warp-collective. src/pipeline.rs is unmodified -- run, run_stealing, ClcQueue and grouped all carry over, and the rewrite is inside work().
One B200 session, min of 30 timed launches, every row checked first: shape gemm ws s4 ws s6 best vs gemm 4096^3 951.9 988.0 1002.3 +5.3% 8192^3 1492.9 1390.1 1451.5 -2.8% 16384^3 1669.1 1536.5 1547.6 -7.3% TFLOP/s. Against cuBLASLt in the same container that is 0.876 -> 0.807 at 16384^3. CLC adds +0.6/+1.0/+1.2% and changes no sign. Two facts narrow the mechanism. regcount says 168 registers and no spill against gemm's 166 -- the 255-register headroom this design point buys is real and nothing asked for it. And six pipeline stages, which tensor memory has already made free, are worth +1.4/+4.4/+0.7% -- so the K pipeline was mildly starved and is not where the 7% is. What is left is that an SM holding one CTA has nothing else to hide the epilogue behind, where gemm's second CTA covered it for free. #108 priced that epilogue at 20.2% of an 8192^3 launch serial. Which is the argument for having kept it identical: the stmatrix follow-up now has a number to beat rather than a hope. Counted residency: device-tests' cg2 512 rung reads 1 holding / 2 resident; the second CTA is admitted and parked in tcgen05.alloc there and is not admitted at all here, because this declares 131176 B where the census declares 32.
feitreim
added a commit
that referenced
this pull request
Jul 29, 2026
…and the epilogue was never gemm_ws's problem (#118) (#119) `.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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A second GEMM kernel at a different design point, in
examples/src/gemm_ws.rs.examples/src/gemm.rsis untouched — this repo keeps losers on purpose, and this one is a loser at the sizes that matter.The design
NVIDIA's
gemm_sol_final(cuda-oxide at our pinnedb099f64,crates/rustc-codegen-cuda/examples/gemm_sol_final/{src/kernels.rs,README.md}) in our idiom: 6 warps per CTA — 0–3 epilogue, 4 TMA, 5 pair-UMMA — and two accumulator stages in TMEM, so the MMA warp fills stageswhile the epilogue warps drain stage1-sfrom the item before.Two stages × 256 columns is 512 columns, the whole SM's tensor memory, so 1 CTA/SM falls out of the double-buffer rather than being imposed. The shared plan (131 176 B) lands on the same 1. Where
gemm.rsgets its overlap across CTAs (2/SM, one CTA's epilogue against another's MMA), this gets it inside one CTA.The result — a loss
One B200 session, min of 30 timed launches, every row checked element-by-element against the same CPU reference before it was timed, control re-measured in the same container (#98/#109):
gemmgemmTFLOP/s. Against cuBLASLt in the same container (1569.8 / 1828.9 / 1904.6):
gemm0.606 / 0.816 / 0.876, this 0.629 / 0.760 / 0.807. CLC is a further +0.6% / +1.0% / +1.2% and changes no sign.A small win where the launch is short, a growing loss where it is not. The 4096³ row is not a wave artifact: both kernels tile
Cidentically and both run at 86.5% wave efficiency there.Registers / spill: 168 and no spill (
gemm_cg2is 166). Counted residency:device-tests'tmem residency censuscg2 512rung reads 1 holding / 2 resident; the extra CTA is parked in a blockingtcgen05.allocat the census's 32 B plan and is not admitted at all at ours.Where the loss is, and why the scope discipline paid
Two facts narrow it. The 255-register headroom this design point buys is real and inert — nothing asked for it, and
DRAIN_N = 128is a 255-register architectural limit rather than an occupancy one. And six pipeline stages, which tensor memory has already made free, are worth +1.4% / +4.4% / +0.7% — so the K pipeline was mildly starved and is not where the 7% is.What is left is that an SM holding one CTA has nothing else to hide the epilogue behind. #108 priced this epilogue at 21.4 µs a tile serial, 20.2% of an 8192³ launch — more than enough to be the whole gap, and exactly the thing
gemm.rs's second CTA covered for free.Which is the argument for having kept
kittens::global::store_rowsbyte-identical, as briefed: thestmatrixfollow-up (kittens::epilogue::StoreRing, #111, plus the shared→global mover in flight) now has a number to beat — about 7% at 16384³ before this design point is level — instead of a general hope, and it will be measured on the kernel that has ~100 KB of shared memory to spend on it.Findings about the abstractions
src/pipeline.rsis unmodified.run,run_stealing,ClcQueueandgroupedall carried over; the rewrite is insidework(), asJob::work's doc promises. The per-itemcluster_syncturns out to be exactly the rendezvous the accumulator ping-pong needs, at exactly the right scope —Lcsf's finding again.TILE_INFO/TILE_READY; aJobis entered by every thread with oneitem, so the epilogue here lags the MMA by exactly one item where the reference allows two. That is the price of the trait's guarantee that barriers are re-armed per item — and the same guarantee is why our shape contract isk % 64 == 0where the reference needsk % 256 == 0. Contract:m % 256,n % 256,k % 64.store_rowsis not warp-collective, so warps 4–5 simply do not enter it.Files
examples/src/gemm_ws.rs— new; module docs carry the mechanism, the numbers and the negative.examples/src/main.rs—pub mod, a status row, achecks()row, and a-- wsarm.modal_app.py— one additivews_benchentry point (bench's--caseroutes throughbench.rs, which is another agent's file).Not touched:
examples/src/gemm.rs,examples/src/bench.rs,src/pipeline.rs,src/global.rs,src/. Noexamples/README.md§7 row — that file has an ablation-ladder change in flight; the table above is a §7 row waiting to land.Gates run
scripts/modal-run buildclean (the post-monomorphization asserts fire only there) ·scripts/modal-run examples—gemm_wsexact at 512×512×256 and 4096×4096×256, both schedulers, both depths, three traversal widths ·scripts/modal-run regcount·scripts/modal-run device_tests·scripts/modal-run ws_bench·scripts/fmt --checkclean on all three manifests.