Repository navigation
The small end is one wave short, and no tile fixes it — three entries and the rule that picks them - #146
Merged
Conversation
… and the rule that picks them `gemm_sol`'s 0.795 at 4096³ reads like tile quantization. It is not, and the tables say so before they say anything else. Residency is one CTA an SM — both shared plans exceed half of the 233472 B an SM divides — so a `cta_group::2` pair is 74 clusters on 148 SMs. At 4096³ the `[256, 256]` tile is 256 clusters over 4 waves and 13.5% of the grid idles; `[512, 256]` is 128 over 2 and idles the same 13.5%, which is what makes that pair a controlled comparison of everything except quantization. At 8192³ both are 0.988 and quantization predicts nothing about that shape's gap at all. The model is measured, not assumed: sweeping `m` in tile steps at `n = k = 4096` swings throughput 8.7% and the same numbers divided by the predicted wave efficiency are flat to ±2%. CLC work stealing runs throughout, which settles what it is worth — it removes the static share of the tail and cannot remove the integral one. And it buys nothing against the baseline, because cuBLASLt pays the identical sawtooth: its heuristic prints 3.46 / 3.89 / 4.32 / 4.76 waves at those four shapes, which is our own tile count over 74 to three digits, on the same `tile=23` from 2048³ up. Quantization divides out of the ratio exactly, so 4096³'s deficit is a rate deficit and belongs to #144's per-tile constant and K-loop cadence. Every lever that buys the quantization back loses, and all of them are kept: - `[256, 128]`, which reaches 0.988 at 4096³, is 0.80 there and 0.63 at 8192³. The two shapes where efficiency does not move price the tile alone: 1.5× the operand traffic per flop and twice the per-tile constants, worth −7% at 2048³ and −37% at 8192³. - `[512, 256]` at 4096³ is a dead heat at 0.985, inside a 4% spread. #138's crossover at 8192 is right and now has a reason. - Split-K doubles the epilogue, which #144 prices at 19.7% of the 4096³ launch, to recover 8%. Stream-K pays 5.7% for the same 8%. cuBLASLt reports `splitk=1 reduction=0 workspace=0 B` at every shape here. - The N band is flat to 0.2% over `{1,2,4,8,16}` at 8192³ and inside its rows' own spread at 4096³, so `group` becomes a launch parameter and its default does not move. What did move is below 2048: halving `N` doubles the wave efficiency only while both tile counts fit one wave count, and there the narrow tile is 1.27–1.29×. `select_variant` is that sentence, taken twice round-robin because a 1024³ launch is 17 µs. 1024³ goes 0.567 → 0.731 of cuBLASLt and 1536³ 0.597 → 0.760, with every shape at and above 2048³ left on the entry it already had. `Small` is one width-generic entry rather than two, `Common` gives up the B ring to the entry that sizes it, and all three entries are exact over every BF16 output at 1024x1024x512.
This was referenced Jul 30, 2026
Merged
feitreim
added a commit
that referenced
this pull request
Jul 30, 2026
…to cuBLASLt is the reference's own (#138) NVLabs' canonical Blackwell `gemm_sol_final`, rebuilt through ferro-kittens' typed tiles and pipeline primitives rather than transcribed as device code: CLC work stealing, two-CTA clusters with `cta_group::2` MMA, four TMA/shared stages, two TMEM accumulator halves, an unrolled K loop, L2-aware output ordering, and three asynchronous warp streams. FP16 in, FP32 compute, BF16 out; every entry checked exact over 1 048 576 outputs. Five PRs of measurement landed with it, and between them they moved the target. **The reference is not parity.** Upstream `gemm_sol_final`, unported and timed on one device, one clock, beside cuBLASLt and beside this port, reaches only 0.877/0.911/0.966 of cuBLASLt at 4096/8192/16384 cubed (#145). Two thirds of the shortfall is upstream's own; a third is port overhead, consistently across all three sizes. Matching the reference was never a route to parity. **Wave quantization cancels.** cuBLASLt pays the identical sawtooth on the identical tile count — 3.46/3.89/4.32/4.76 waves against ours over 74 clusters — so it divides out of the ratio and 4096 cubed's deficit is a rate, not a tiling problem (#146). Every tiling lever that buys quantization back was built and lost; a third `[256, 128]` entry ships for shapes at or below half a wave, worth 1.27-1.29x at 1024/1536 cubed. **Where the time goes, laddered in K rather than read off a launch** (#144, #148). An arm's launch conflates a rate with a per-tile constant: un-laddered, the MMA-only arm read 88.7% of peak and looked like an issue ceiling; laddered it is 100.6%. The feed is a duty-cycle problem, not bandwidth and not instruction count — the narrow tile needs its feed running 95.5% of tensor-core busy time and pays 24.5% for the contention, where the wide tile needs 55.7% and pays nothing. The barrier round trip is zero. **One port defect found and fixed.** The MMA warp indexed both rings and both stage barriers off a runtime `global_k`, where `k_blocks % STAGES == 0` makes each unrolled position's stage a constant. Handing it as a const folds barrier addresses to literals, hoists both descriptors out of the K loop, and computes the parity once a turn instead of four times: +2.2 to +4.3% at 4096 cubed, null at 8192 as predicted. The gain is in the inter-stage critical path, not the spin loop — an earlier account of the mechanism was retracted when the PTX contradicted it. **The drain is exposed whole, and both of its expected levers measure zero** (#147). A doubling ladder, where an extra pass is serial by construction, separates the drain's own cost from what the launch pays: the launch pays 191% of a serial drain at 4096 cubed and 118% at 8192, so there is no overlap to fail. Doubling LDTM and its waits costs nothing; `.pack::16b` does remove the `cvt` but faults out of bounds, and a legal `nocvt` oracle is slower, so the convert was never the cost. The 62-70% is the `stmatrix` pass and its write-after-write. **A PTX count is a hypothesis; SASS or a timed arm is the evidence.** Two levers filed off PTX instruction counts turned out to be folded entirely by `ptxas` — three poll bodies differing by an instruction in PTX are byte-identical at three instructions in SASS. `modal_app.py::_print_sass_loops` disassembles a real cubin and finds loops by backward branch rather than by mnemonic. What this does and does not disturb about the repo's existing PTX conclusions is recorded in `experiments/README.md`. Against cuBLASLt 0.778 and against upstream 0.917 at 4096 cubed, from 0.758 and 0.891. Nsight Compute is confirmed unavailable on this harness and the reason has a floor under it, so ablation is the instrument. Open: **#149**, the `[256, 256]` entry does not return at 4096x4096x1024, a shape inside its own contract.
feitreim
added a commit
that referenced
this pull request
Jul 30, 2026
…ills Measured rather than assumed, because a compiler-backend bump is exactly the change that moves registers with nothing watching: `regcount` on `336e3d7` and on the same tree with the pin moved, same image, same `ptxas`. 44 of 270 rows moved. The kernel set is identical on both sides, and `regcount --determinism` passes on the new pin — 270 kernels, every counter, across two builds — which is what makes the diff a function of the revision rather than of the build. Not an LLVM bump: `rust-toolchain.toml` is byte-identical and both revisions validate against `rust-llvm-22.1.2-1cb4e383`. Two files differ inside `rustc-codegen-cuda/src` (`collector.rs`, `generated_intrinsics.rs`) beside `cargo-oxide`'s `backend.rs`. Most movement is downward — `gemm_256x256_k128_s1` 246 -> 168 — and nothing `examples/` ships regressed. But **four kernels started spilling, and three of them read as wins on the register count alone**: `gemm_ws_staged` 43 -> 40 with 16/20 spill slots appearing, `gemm_ws_staged_x8` and `_x8x4` 90 -> 80 with 8/12, and `gemm_sol_m512_mma` flat at 80 with 8/12. A count that falls while spill slots appear is `ptxas` taking a lower target and paying in local memory, which is this file's oldest error arriving from the toolchain instead of from a diff. No row stopped spilling. The occupancy gate (#95) is green on both sides — two of its six rows moved and both stay inside their step — so this is a finding and not a blocker. The opcode census moved in 3 of 74 kernels and only in `selp`, so no rung's phase claim is disturbed. One published number does not survive: `gemm_sol_m512_mma` is #144/#146's `mma only` arm at 88.7% of tensor-core peak, and it now spills at the same 80 registers. That arm is not comparable across the pin and wants re-timing.
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.
Base is
gemm-sol(#138), notmain.The arithmetic, before anything is launched
Both shared plans declare more than half of the 233472 B an SM divides
(196864 B and 229632 B, queried not written down), so residency is one CTA an
SM; a
cta_group::2MMA needs its pair co-resident, so the device holds74 clusters on 148 SMs. A launch is one cluster per output tile and takes
ceil(tiles / 74)waves of them, andtiles / (waves · 74)is the fraction ofit not idling.
[256, 256][512, 256][256, 128][256, 256][512, 256]Two consequences, both load-bearing:
8192³ is already wave-perfect on both entries, so quantization predicts
nothing about that shape's gap.
controlled comparison of everything except quantization.
This matches #144's independent derivation exactly.
The model is right, measured rather than assumed
bench soltable 2 —n = k = 4096,min tile steps, nothing else moving:Raw swings 8.7%; corrected is flat to ±2%. CLC work stealing is on for
every row, which answers what it is worth here: it removes the static share of
the tail and cannot remove the integral one, and the sawtooth is the integral one
surviving it in full.
And it buys nothing against the baseline, because cuBLASLt pays it too
The harness prints the heuristic's own wave count beside the algorithm it chose.
At those four shapes cuBLASLt reports 3.46 / 3.89 / 4.32 / 4.76 waves — our
256 / 288 / 320 / 352 tiles over 74 clusters, to three digits — on
tile=23atevery shape from 2048³ up. Its rate divided by the same efficiency is
1955 / 1964 / 2018 / 2015, equally flat.
Two implementations on the same cluster tile with the same sawtooth, so
quantization divides out of the ratio exactly. 0.795 at 4096³ is a rate
deficit, not a tiling one, and what is left is #144's per-tile constant and
K-loop cadence — not this PR's scope.
The premise that the gap grows monotonically as the problem shrinks is also not
true past three points: 1024³ 0.567, 2048³ 0.846, 4096³ 0.795, 8192³ 0.868.
2048³ beats 4096³ because cuBLASLt is also one wave short there (0.86 waves,
906.8 TFLOP/s, 40% of dense peak).
Every lever that buys the quantization back loses
All of them are built, checked exact, and kept.
[256, 128]is the tile that reaches 0.988 at 4096³:[256, 256][256, 128]The rows where efficiency does not move price the tile alone: −7% at 2048³,
−19% at 3072³, −37% at 8192³, which is 1.5× the operand traffic per flop (85.3
against 128 flops per operand byte) and twice as many per-tile constants to pay
it on. At 4096³ that price exceeds the 14% of quantization it buys, and the tile
loses 20%.
[512, 256]at 4096³ is the other direction and a dead heat: 1323.2 against1343.0, 0.985, inside a 4% spread. Its 0.75× operand traffic per flop is
worth 1.12× at 8192³ where quantization is equal, and is cancelled at 4096³ by
having half as many tiles to amortize a per-tile constant over. #138's crossover
at 8192 is right and now has a mechanism.
Split-K and stream-K are dead on arithmetic, and the vendor agrees.
Splitting K in two at 4096³ takes 256 work units to 512 and efficiency to 0.988
— about 8% of the launch. It also doubles the number of epilogues, and #144
prices the epilogue at 19.7% of that launch, so even a reduction that adds
no traffic at all pays 19.7% for an 8% return. Stream-K splits at most 74 of
256 tiles and so pays ~5.7% for the same 8%: a ~2% return inside rows that repeat
to 3–6%, in exchange for a k-range per work unit, a partial-tile MMA, a fixup
ordering, and an fp32 workspace that the exact-output gate makes mandatory. The
reduction instruction being reachable through
ptx_asm!changes neither figure.cuBLASLt reports
splitk=1 reduction=0 workspace=0 Bat every shape in bothtables.
The N band is worth nothing measurable.
groupwas a rule inside the kernelkeyed on
tiles_mand is a launch parameter now, swept over{1, 2, 4, 8, 16}:[512, 256]: 1880.3 / 1877.7 / 1876.2 / 1878.7 / 1877.6 TFLOP/s —flat to 0.2%, extending WIP: port gemm_sol_final to kittens #138's
G=4againstG=8to the whole ladder.[256, 256]: 1317.9 / 1336.3 / 1343.0 / 1311.4 / 1367.0 against rowswhose own launches spread 1.3–3.6%.
G=16is nominally best by 2.3% over theshipped
G=2and is not quotable, so the default does not move.What did move: a third rung below 2048
Halving
Nraises the efficiency only while both tile counts fit the same wavecount — at or below half a wave of wide tiles. Both 1.27–1.29× rows are
there; both losing rows are past it.
select_variantis that sentence:bench sol-smalltakes both rungs twice round-robin, because a 1024³ launchis 17 µs and its thirty samples spread 13–21% — a difference at that size is
quoted against its own repeatability or not at all. The two passes give
1.273/1.273 at 1024³, 1.273/1.278 at 1536³, 0.927/0.934 at 2048³ and
0.806/0.811 at 3072³: the ratio reproduces to 0.5%.
Against cuBLASLt that is 1024³ 0.567 → 0.731 and 1536³ 0.597 → 0.760,
and every shape at and above 2048³ stays on the entry it already had — so the
gemm-solsweep's own three rows are unchanged.What this closes at 4096³, and what it does not
measured rather than modelled, and it is not recoverable through the ratio
because the baseline pays the same 13.5% on the same tile. Three tiles, a
four-shape wave ladder, a five-point N band and a split-K costing all say so.
0.80, and nothing in tiling or scheduling moves it. The epilogue is the gap, and at 4K it is only a fifth of it (#138) #144 puts that in the
epilogue (19.7%) and the M256 K loop (75.8% of peak against M512's 99.4%),
both of which have owners.
Structure
Smallis one width-generic entry,Small<N, HALF, STAGE>, instantiatedat
[256, 256]and[256, 128]. No duplicated producer, MMA or epilogue.mma_shape(N)is aconst fnbecause the MMA warp reads the shape inside awidth-generic body.
Commongives up the B ring to the entry that sizes it, which is what let therest stay non-generic.
Common::drainandCommon::accumulatortake the widthas a const parameter.
tiles_nis now the output tile column count rather thann / 128halvedinside two kernels.
groupis a kernel parameter rather than a rule ontiles_m.[256, 128]entry widens the shape contract fromn % 256ton % 128,and
select_variantroutes annonly it admits.Note for whoever owns the epilogue:
draingained anNconst parameter andlost
BLOCK_Nin its loop bound. Nothing inside it changed otherwise.Validation
modal run modal_app.py::build: passes, includingsm_100acodegen of allfour manifests and the
cublasFFI build.modal run modal_app.py::examples: passes. All three entries exact overevery one of 1048576 BF16 outputs at 1024x1024x512, worst |rel| 3.89e-3
against the fp32 reference. Every timed row in both sweeps re-checks its own
plan at that size before it is timed.
scripts/fmt: clean, including three pre-existing unformatted hunks insrc/shared.rsthatgemm-solwas carrying and that would have taken tier 1red.
bench solandbench sol-small;no figure is mixed with WIP: port gemm_sol_final to kittens #138's or The epilogue is the gap, and at 4K it is only a fifth of it (#138) #144's containers, and the ratios quoted are
against each run's own live cuBLASLt column.
One shape did not return
4096x4096x1024on[256, 256]printed nothing for 1200 s andscripts/modal-run's watchdog stopped the container. It is out of both tablesand was not chased;
4096x4096x2048runs and is in table 4. Akshorter thanmis otherwise unexercised by this kernel, so whether that is a shape contractthe port does not hold or a one-off is open, and it is the one loose end here.