Repository navigation
Time gemm_sol_final unported: two thirds of the gap to cuBLASLt is upstream's own (#138) - #145
Merged
Merged
Conversation
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
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 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.
Branches off
gemm-sol(#138), notmain, because the measurement needs the port and the baseline it is compared to in the same process. Merge order is #138 then this.#138 measured the port at 0.806 / 0.873 / 0.946 of cuBLASLt at 4096³ / 8192³ / 16384³ and could not say what that number was: either the port dropped something NVLabs'
gemm_sol_finalhas, or the original stands there too. Nobody had timed the original on a B200.Most of the gap is not the port's.
The three arms, one container, one clock
experiments/src/gemm_sol_upstream.rsis upstream'skernels.rsatb099f64c1a32869b74be99f4f88242fb68655b51, copied without a character changed (sha256 6746e517eca19fdcc01cb0d5003e924bb638f5ee42e8c333d457a0d6f334d6e9, taken from the checkout whosegit rev-parse HEADis that revision — issue #106).gemm_sol_final/is byte-identical at20a5616, so none of this turns on which pin is in the manifest.Upstream's launch geometry, upstream's
cuTensorMapEncodeTileddescriptors, upstream's variant selector. What is not upstream's is everything outside the two CUDA events:bench::time's five warm-ups and minimum of thirty, andgemm_sol's ownstage_f16andcheck_output— the same functions, not copies — so both kernels read byte-identical operands and both pass the same exact-BF16 check before either is timed.Each arm at the variant it should be judged at. cuBLASLt is the mean of its four readings per shape; it repeats to 0.03% at 16384³, 0.15% at 8192³ and 1.3% at 4096³.
The attribution
gemm_sol_finaldoes not reach cuBLASLt at any of the three sizes, and it is furthest away at the small end — the same shape of curve the port has. Whatever closes 4096³ is not a port defect, and reading the port against upstream's source was never going to find it.The row that does not flatter the control arm
Upstream's shipped selector takes M256xN256 up to 8192³. #138 moved that crossover.
At 8192³ the port beats the kernel it is a port of by 4.0%, entirely on the crossover. At 4096³ upstream's policy is the better one (M256 1435.0 against M512 1407.7), and at 16384³ the auto selector and the forced entry agree to 0.01%.
Two toolchain workarounds, and neither is the vendoring's
modal_app.py::upstream_ptxbuilds upstream's crate from a clean clone, in its own workspace, at its own profile, in this image. It does not assemble:cuda_device::tcgen05::stmatrix_m8n8_x2reaches the NVPTX back end asllvm.nvvm.stmatrix.sync.aligned.m8n8.x2.b16.p3, is selected by nothing, and comes out as a call to an.extern .functhat does not exist —ptxas ... line 10; fatal: Parsing error near '.nvvm': syntax error.kittens::ldsthad already written this workaround for itself atb099f64; the vendored copy binds the name to it. Same signature, same instruction, upstream's file untouched.opt -O2turns upstream's four-way stage selects into sixteen lookup tables emitted as.globalarrays of.sharedaddresses —Variable used as initial value not in .global or .const state space.CUDA_OXIDE_OPTpointed at anoptwrapper carrying-switch-to-lookup=falseremoves all sixteen and the bundle assembles.Sixteen tables in upstream's own build and sixteen in ours, so this is the toolchain and not the copy. Bumping the pin to
20a5616does not fix it — same error, same line — though the whole tree does compile unchanged at that revision.cargo oxide buildpasses on both defects: it emits the PTX and never assembles it. Sobuildgained aptxasstep for this crate rather than trusting the one it had.The second workaround is global to the compilation, so
upstream_benchmeasures it rather than assuming it. The port, same container, without the flag and with it: 1320.7 / 1871.4 / 2041.0 against 1322.7 / 1871.5 / 2041.4 — 0.15%, 0.006%, 0.02% apart. And the port's rows reproduce #138's published 1289.0 / 1867.7 / 2045.5 to 2.5% / 0.2% / 0.2% across two days.What is in the diff
experiments/src/gemm_sol_upstream_kernels.rs— upstream's device code, verbatim, not formatted and not linted,include!d for upstream's own reason.experiments/src/gemm_sol_upstream.rs— the host side: upstream's descriptors and grid, this crate's clock and check, upstream's selector plus a forced-M512 entry.gemm-sol-upstream, an off-by-default feature. Off because turning it on without theoptwrapper makeskernels::loadfail for all 46 entries in the crate — a package's kernels share one bundle.bench <a,b,c>takes a comma-separated case list, so three tables that have to be read against each other are one container rather than three.modal_app.py::upstream_bench(B200) and::upstream_ptx(no GPU), and aptxasstep onbuild.gemm_sol's four operand/check functions arepubso the control arm calls them instead of re-deriving them, and two rustfmt fixes WIP: port gemm_sol_final to kittens #138 needs for tier 1.Validation
scripts/fmt --check: clean.scripts/modal-run build: passed, including the feature build and itsptxas.scripts/modal-run upstream_bench: passed twice, two sessions. Every timed row is a checked row — upstream's kernel is exact over all 1 048 576 BF16 outputs at 1024×1024×512 for both entry points, against the reference the port is held to.