Repository navigation
The epilogue is the gap, and at 4K it is only a fifth of it (#138) - #144
Merged
Merged
Conversation
…s too (#138) #138 asks which of TMA feed cadence, MMA issue cadence or epilogue overlap the remaining gap is, with no profiler to ask. This decomposes it two ways that do not depend on one — arithmetic, then ablation — and they agree. `bench sol` leads with the term that needs no measurement. Both shared plans admit one CTA per SM, a cluster is two CTAs, so a wave is 74 clusters and the launch is one cluster per output tile: 4096^3 is 256 clusters over four waves, a 0.865 ceiling before any cadence is measured, and 8192^3 is 0.988. The sawtooth table proves that is the whole shape dependence rather than asserting it — `N` in tile steps, and the quantization-corrected rate is flat to 0.6% at M512 across five shapes whose predicted ceiling spans 0.865 to 1.000. The three suspects are the same device body at three values of a new `ABLATE` const, so no arm can drift from the kernel it decomposes and the shipped kernels are that body at `WHOLE`. Every barrier survives every arm; only a phase leaves. `regcount`'s census is the proof and reads exactly that way, and the two shipped kernels stay opcode-identical between the crates. The depth ladder is a straight line in `K` — 0.5% over an eightfold range at M512 — so the launch is a per-tile constant plus a per-K-block rate, and both fall out. The M512 K loop runs at **99.4% of tensor-core peak**; its entire deficit is 12.7 us per tile, of which the drain is 9.99. M256's K loop runs at 75.8%, which is a cadence and not a constant. Subtracting the arms gives an additive budget that reproduces both launches: | term | 4096^3 M256 | 8192^3 M512 | | --- | ---: | ---: | | arithmetic at peak | 58.1% | 83.4% | | wave quantization | 9.1% | 1.0% | | epilogue | 19.7% | 11.9% | | TMA feed in situ | 5.3% | 1.4% | | MMA issue cadence | 7.9% | 2.2% | The epilogue is the largest single loss at both shapes and is 11.9 of the 13.2 points between 8192^3 and peak. It costs the same per byte of `C` in both variants — 25.3 and 26.2 GB/s per cluster — so it is the LDTM/stmatrix/store chain running at a fixed rate, not a bandwidth and not a variant. The feed is not the problem anywhere: it moves the whole launch's operands in half the launch, at 18-22 TB/s. Also: #138's profiler finding re-derived and its two escapes closed. `NVIDIA_DRIVER_CAPABILITIES=all` is already in the container and is not the lever, `ncu` fails identically on a four-line nvcc kernel, and NVIDIA's own 580 component list has no performance-counter library to withhold. `scripts/fmt` also picked up three pre-existing hunks in `src/shared.rs`.
This was referenced Jul 29, 2026
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
cuda-oxide goes from b099f64 to 20a5616 across all four manifests, all four locks and `CUDA_OXIDE_REF` in `modal_app.py` — nine build files that move together, since the codegen backend and the device/host/core crates have to come from one revision. The lockfile diffs are the rev string and nothing else: zero non-rev changed lines across the four, and `cargo metadata --locked` passes on each. #142's 41-case validation predates the #144–#148 stack, so it no longer covers the tree and is not leaned on. What is leaned on is re-verification: every claim this commit repoints was read out of a checkout whose `git rev-parse HEAD` was confirmed to be `20a56163f258e09f2c51e4c27ae4e4ff17582443` first, which is #106's rule. Six of the seven checkouts in that cargo directory are not the pin, `/Users/finn/projects/cuda-oxide` (at `29396b7`) among them. **Two claims did not just need a new hash.** `src/lib.rs` said libdevice math is legal beside tcgen05 in one pure-PTX artifact "at cuda-oxide b099f64". Moving that hash would have asserted it at a revision nothing checks, because **nothing in this tree makes a libdevice call** — `Abs` clears the sign bit rather than calling `fabsf`, `fmax`/`fmin` are comparison-selects, `Sqrt`/`rsqrt` lower to native `sqrt.rn.f32`, and `exp2`/`log2` are FMA polynomials or the `ex2` SFU. So no gate re-establishes it, a green `build` says nothing either way, and the citation stays at `b099f64` with the reason written down. `GAPS.md` said `cp.reduce.async.bulk.tensor` was absent from cuda-oxide "in every form — not in the generated crate and not in `intrinsics/imported.json` either", and argued from that that reduction stores were a lowering to contribute. The records are there, and were there at `b099f64` too: 64 of them at both revisions, spelled `int_nvvm_cp_async_bulk_tensor_reduce_*` — which is why a grep for `cp_reduce_*` finds nothing and how the claim lasted. They are simply not admitted to the generated crate, where the count is zero. That makes #42 the same shape as prefetch one row below it, a generation-list change rather than a lowering, and a smaller ask than the file claimed. **Provenance kept where it is the historical fact.** The `gemm_sol_upstream` copy was taken at `b099f64` and the port measured there; `gemm_sol_final/` is byte-identical at `20a5616` and upstream's `kernels.rs` and the vendored copy all hash to `6746e517…`, so those citations keep `b099f64` and say why. The `stmatrix` defect is annotated rather than rewritten: #145 proved it survives the bump, so `ldst.rs`'s `ptx_asm!` workaround stays and `upstream_ptx`'s docstring now records that the bump drops neither workaround. **One retracted argument removed rather than repointed.** `gemm.rs`'s `.pack::16b` doc still carried "the register count does not fall, so nothing is packed" — the sixth instance of the register-count error (#47, #63, #67, #76, #81) that #147 refuted and corrected in `experiments/README.md`. Repointing the hash beside it would have asserted the retracted reasoning at the new pin, so the doc now carries #147's two answers instead: `cvt.rn.bf16x2` censuses at 0 and the arm faults with `Xid 13`.
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.
feitreim
added a commit
that referenced
this pull request
Jul 30, 2026
cuda-oxide goes from b099f64 to 20a5616 across all four manifests, all four locks and `CUDA_OXIDE_REF` in `modal_app.py` — nine build files that move together, since the codegen backend and the device/host/core crates have to come from one revision. The lockfile diffs are the rev string and nothing else: zero non-rev changed lines across the four, and `cargo metadata --locked` passes on each. #142's 41-case validation predates the #144–#148 stack, so it no longer covers the tree and is not leaned on. What is leaned on is re-verification: every claim this commit repoints was read out of a checkout whose `git rev-parse HEAD` was confirmed to be `20a56163f258e09f2c51e4c27ae4e4ff17582443` first, which is #106's rule. Six of the seven checkouts in that cargo directory are not the pin, `/Users/finn/projects/cuda-oxide` (at `29396b7`) among them. **Two claims did not just need a new hash.** `src/lib.rs` said libdevice math is legal beside tcgen05 in one pure-PTX artifact "at cuda-oxide b099f64". Moving that hash would have asserted it at a revision nothing checks, because **nothing in this tree makes a libdevice call** — `Abs` clears the sign bit rather than calling `fabsf`, `fmax`/`fmin` are comparison-selects, `Sqrt`/`rsqrt` lower to native `sqrt.rn.f32`, and `exp2`/`log2` are FMA polynomials or the `ex2` SFU. So no gate re-establishes it, a green `build` says nothing either way, and the citation stays at `b099f64` with the reason written down. `GAPS.md` said `cp.reduce.async.bulk.tensor` was absent from cuda-oxide "in every form — not in the generated crate and not in `intrinsics/imported.json` either", and argued from that that reduction stores were a lowering to contribute. The records are there, and were there at `b099f64` too: 64 of them at both revisions, spelled `int_nvvm_cp_async_bulk_tensor_reduce_*` — which is why a grep for `cp_reduce_*` finds nothing and how the claim lasted. They are simply not admitted to the generated crate, where the count is zero. That makes #42 the same shape as prefetch one row below it, a generation-list change rather than a lowering, and a smaller ask than the file claimed. **Provenance kept where it is the historical fact.** The `gemm_sol_upstream` copy was taken at `b099f64` and the port measured there; `gemm_sol_final/` is byte-identical at `20a5616` and upstream's `kernels.rs` and the vendored copy all hash to `6746e517…`, so those citations keep `b099f64` and say why. The `stmatrix` defect is annotated rather than rewritten: #145 proved it survives the bump, so `ldst.rs`'s `ptx_asm!` workaround stays and `upstream_ptx`'s docstring now records that the bump drops neither workaround. **One retracted argument removed rather than repointed.** `gemm.rs`'s `.pack::16b` doc still carried "the register count does not fall, so nothing is packed" — the sixth instance of the register-count error (#47, #63, #67, #76, #81) that #147 refuted and corrected in `experiments/README.md`. Repointing the hash beside it would have asserted the retracted reasoning at the new pin, so the doc now carries #147's two answers instead: `cvt.rn.bf16x2` censuses at 0 and the arm faults with `Xid 13`.
This was referenced Jul 31, 2026
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.
What this answers
#138's remaining-work list asks which of TMA feed cadence, MMA issue cadence or
epilogue overlap the 4K/8K gap is, and says a profiler is unavailable. Both
halves are answered here: the profiler finding is re-derived with its two
obvious escapes closed, and the gap is decomposed two ways that need no
counter — arithmetic first, then ablation. They agree, and together they
reproduce both launches to under 1%.
The epilogue is the largest single loss at both shapes. At 8192³ it is 11.9
of the 13.2 points between the launch and tensor-core peak; the other two
suspects are 1.4% and 2.2% between them. At 4096³ it is still the largest at
19.7%, but it is no longer alone.
The arithmetic, before any kernel
Both shared plans (196 864 B and 229 632 B) admit one CTA per SM, a cluster
is two CTAs, and the launch is exactly one cluster per output tile — so a wave
is 74 clusters on a 148-SM B200 and the ceiling is
clusters / (74 · ceil(clusters / 74)):The two shapes with a gap are therefore not the same problem, and 13.5% of the
4096³ deficit is settled before a kernel runs.
bench solmeasures that rather than asserting it. SweepingNin tile stepsat fixed
MandK, the quantization-corrected rate is flat to 0.6% atM512 across five shapes whose predicted ceiling spans 0.865 to 1.000 — including
8192x7168x8192, which does less work than 8192³ and takes the same time:
Wave quantization is the whole of the shape dependence. It is not the level.
The ablation arms
Three arms, each the shipped device body at a different
ABLATEconst, so noarm can drift from the kernel it decomposes — the shipped kernels are that same
body at
WHOLE. Every barrier survives every arm; only a phase leaves,which is what makes
whole − no drainthe epilogue's cost including itsoverlap failure.
regcount's opcode census is the proof, and reads exactly that way:mbar.arriveis 6 on every M256 arm and 8 on every M512 arm — no arm dropped abarrier — and
gemm_sol_m256/gemm_sol_m512remain opcode-identical betweenthe two crates, so putting the dial on the shipped body moved no instruction
in the shipped kernel. Registers fall to 31–33 on the arms and cannot buy them
occupancy: shared memory binds residency at one CTA in every arm.
The depth ladder, and what the launch is made of
Kalone, with the tile grid and the waves held. It is a straight line — towithin 0.5% over an eightfold range at M512 — so the launch is a per-tile
constant plus a per-K-block rate, and both fall out of it:
Fed back:
4 × (3.25 + 64 × 0.364) = 106.2 µsagainst 105.5 measured, and7 × (12.7 + 128 × 0.555) = 586 µsagainst 586.0.The M512 K loop already runs at 99.4% of tensor-core peak. Nothing in its
steady state is worth another look — its whole deficit is the 12.7 µs it pays
per tile, of which the drain is 9.99. M256's K loop runs at 75.8%, which is a
cadence and not a constant.
Subtracting the arms gives an additive budget, in milliseconds and as a share
of each launch:
whole − no drainno drain − issue onlyissue onlyThe drain costs the same per byte of
Cin both variants — 5.18 µs for131 072 B at M256 and 9.99 µs for 262 144 B at M512, which is 25.3 and
26.2 GB/s per cluster. 74 clusters of that is 1.9 TB/s of stores against a part
that does 8, so it is not store-bandwidth-bound and not variant-specific: it is
the
tcgen05.ld→stmatrix→st.globalchain running at a fixed rate infour warps.
The feed is not the problem at either shape.
feed onlymoves the launch'swhole operand traffic — 1.07 GB at 4096³, 6.44 GB at 8192³ — in 57% and 49% of
the launch, at 18.0 and 22.4 TB/s against 10.2 and 11.0 in situ. Those are far
above the part's 8 TB/s of HBM, which is
Afitting in L2 at these sizes.So the direction is different at the two shapes. At 8192³ the epilogue is
essentially the entire gap and a fix that took only it would leave 3.6% behind.
At 4096³ taking only the epilogue would leave 22% — quantization, M256's MMA
issue cadence and the feed are all live there, and the M512 crossover is
suggestive: it issues two MMA chains per barrier handshake where M256 issues
one, and loses 0.6% on the
issue onlyarm where M256 loses 10.5%.What this does not separate
Kept as rows rather than dropped:
whole − no drainisboth. That it is not purely serial is visible anyway: M256's per-tile constant
is 3.25 µs and its drain difference is 5.18 µs per tile, so removing the drain
also sped the K loop up — the epilogue is taking issue bandwidth from the MMA
warp, not merely appending to it. Splitting them needs a fifth arm.
issue onlykeepsthe whole
load/freehandshake, so the 24.2% M256 is short of peak is thosetwo fused.
feed only's ceiling from the feed under contention. That arm has no MMAreading the same shared memory, so 18–22 TB/s is an upper bound. The in-situ
number is the
no drain − issue onlyrow, which is what the budget quotes.correcteddrifts ~6% downward withNatM256 and that is not separated from
B's growing L2 footprint.of ceilingcolumn divides our ratio byour quantization; the library has its own, unknown. It reads 0.878 at both
shapes, which the budget says is a coincidence of two different budgets.
Nsight Compute
Re-derived on a fresh B200 container and the two escapes closed.
ncu2025.3.0fails identically on a four-line
nvcckernel that has nothing to do with thisrepo, so it is not the codegen.
NVIDIA_DRIVER_CAPABILITIES=allis already inthe container's environment and the graphics libraries are already injected, so
the capability set is not the lever it looks like. And NVIDIA's own component
list for the 580 branch names exactly one
pccfile —nvidia-pcc, theVulkanSC pipeline cache compiler — and no performance-counter library at all, so
this is not something the runtime withheld from a package that has it.
libnvperf_host.soandlibnvperf_target.soare both present and both uselesswithout it;
nsysis not in the image and would trace rather than count.modal_app.py::profile's docstring now carries this.Runs
scripts/modal-run build— pass, including bothexperimentscodegensscripts/modal-run regcount— pass, census above, occupancy gate cleanscripts/modal-run examples— pass;gemm_solM256 and M512 both exact over1 048 576 BF16 outputs, which is the shipped kernel unchanged by the dial
scripts/modal-run bench --case sol— the four tables abovecargo test,scripts/fmt --check— passwholereproduced to 1.5% across the four tables that measure it. cuBLASLtmeasured 1695.6 TFLOP/s at 4096³ in this container against #138's 1620.7, so
the ratio here reads 0.759 rather than 0.795 — container drift on the baseline,
worth knowing before comparing the two runs.
scripts/fmtalso picked up three pre-existing hunks insrc/shared.rsthatwould have taken tier 1 red.
Next, if this is acted on
At 8192³ and 16384³ the epilogue is the only thing left worth touching. At
4096³ it is a quarter of the work and the M256 issue cadence is another
quarter — the M512 crossover already in #138 is pointing at the same thing, and
moving it lower may be cheaper than a new epilogue.