Skip to content

The small entry's K loop is its feed's duty cycle, and the ring index was a port defect (#144) - #148

Merged
feitreim merged 27 commits into
gemm-solfrom
gemm-sol-integrated
Jul 30, 2026
Merged

feitreim merged 27 commits into
gemm-solfrom
gemm-sol-integrated

Conversation

@feitreim

@feitreim feitreim commented Jul 30, 2026 •

Copy link
Copy Markdown
Owner

Base is gemm-sol (#138). This branch also carries #144, #145 and #146 — see Composition at the end; none of the three contained another and the instrument this needed was split across two of them.

#144 left [256, 256]'s K loop at 75.8% of tensor-core peak against [512, 256]'s 99.4%, on the same K-loop code, and named two things it could not separate. Both are separated here. The term is one number per entry, three plausible causes measure zero, and one port defect with upstream's own source comment as its specification is fixed for +2.2% to +4.3% at 4096³.

Ladder every arm, or the number is not the K loop's

This is the methodological change the rest depends on and it is not cosmetic. An arm's launch fuses its per-K-block cadence with a per-tile constant it carries for its own reasons — TMEM allocation, the CLC query, the prologue, retire — and at 64 k blocks one microsecond of constant is 5.7 points of "of peak".

Taken as a launch, the MMA warp appeared to reach only 88.7% of peak with no barrier wait, no TMA and no drain in front of it. That read as a tcgen05 issue-rate ceiling and was the mechanism I was about to build against. Laddered in K, the same arm reaches 100.6%. One of those is a measurement of the K loop and the other is not.

At 4096² on [256, 256], µs a K block against 0.2759 at peak:

arm µs a K block of peak what it says
feed only 0.2636 104.6% the feed alone beats the tensor core by 4.6%
mma only 0.2742 100.6% no barrier wait, no TMA, no drain
issue only 0.2758 100.0% the same, with the wait back
no drain 0.3433 80.4% the feed in situ costs 24.5%
whole 0.3503 78.8% the drain costs the rate another 2.0%
runtime stage 0.3615 76.3% the spelling before this PR
upstream, unported 0.3352 82.3% the same algorithm, #145's copy

The answer: the feed's duty cycle

feed only is the operand pipeline's own time for a K block. Peak MMA is the tensor core's. Their ratio is the fraction of the tensor core's busy time the feed has to be running:

entry feed alone MMA at peak the feed's duty feed in situ
[256, 256] 0.2636 µs 0.2759 µs 95.5% +24.5%
[512, 256] 0.3075 µs 0.5518 µs 55.7% +0.0%

At 95.5% duty there is no slack for the TMA's writes and the tensor core's operand reads to stay out of each other's way, and the cost of them not doing so is the whole deficit. At 55.7% there is 44% of slack and it is free.

That 1.72× in duty is the 1.33× in operand bytes per flop between a [256, 256] cluster tile and a [512, 256] one — #146's "0.75× the operand traffic per flop" read from the other end. The term is the tile's arithmetic intensity, acting through the feed's duty cycle rather than through raw bandwidth. At [512, 256] nothing in the K loop moves at all: feed, drain, barriers and ring index give 0.5557, 0.5572, 0.5570 and 0.5547 µs, every one of them 99.0–99.5% of peak.

Three causes measured at zero

Not enough arithmetic per barrier round trip — the leading hypothesis, and the one the second A ring at [512, 256] suggests — is dead twice over.

On arithmetic: both entries execute exactly one load.wait per K block. The second A ring buys the large entry a second MMA chain per the same round-trip count, and it additionally pays two free commits where the small entry pays one. A fixed cost C of 88 ns read off the small entry's row would force the large entry to 0.640 µs and 86% of peak; it measures 0.555 and 99.4%, i.e. C = 3 ns. The same constant cannot be both.

On measurement: mma only is the fifth arm #144 said it lacked. It is issue only with the MMA warp's load.wait dropped and nothing else — one const apart, every free commit and every other barrier kept, the producer still throttled by free.wait_recycled, ready still bounding the MMA warp one output tile at a time. The two agree to 0.6%, with the arm that keeps the wait nominally faster, at both entries. The barrier round trip is zero.

A tcgen05 issue-rate ceiling is dead: issue only is 100.0% of peak and mma only 100.6%. One warp can saturate the tensor core at this tile.

The producer's instruction count is dead, and this one needed an experiment rather than an argument, because I had argued the other way. A rank's B half-panel is 128 x 64 — the same shape as A, which already arrives in one TMA — and it arrives in two 64-row boxes only because one 64-row tensor map served all three entries. Building it per entry takes the producer from 3 instructions a K block to 2 at [256, 256] and from 4 to 3 at [512, 256], at byte-for-byte identical traffic. It moves nothing:

tma/k pass 1 pass 2
whole → wide B, 4096³ 3 → 2 0.998 1.014
feed only → wide B feed, 4096³ 3 → 2 1.008 0.981
whole → wide B, 8192³ 4 → 3 1.000 0.998
K-block rate, 4096³ 3 → 2 0.3503 → 0.3484 µs

The feed only row is the one that settles it: there the feed is alone and has nothing to hide behind. So the feed's ceiling is bytes and not instructions, and my model of it — producer = n_tma·t + w fitted to two points with two free parameters, exactly determined and therefore not evidence — was wrong. Published as a loser, arms kept.

That also means #144's conclusion that the feed is not an instruction-rate problem survives, even though the comparison it drew for it cannot fail: it compared the feed's ceiling against the loop's in-situ rate, which is low because the loop is slow. The comparison that can fail is ceiling against what peak MMA demands — the duty-cycle table above — and read that way the feed is not the problem at [512, 256] and is the whole of it at [256, 256].

What did pay: the ring index is a const, and upstream's comment is the spec

The MMA warp indexed both operand rings and both stage barriers off global_k = sequence * k_blocks + k, a runtime value. But k_blocks is a multiple of STAGES — every entry's shape contract is k % (STAGES · BLOCK_K) == 0 — so global_k % STAGES == k % STAGES, and the four positions of the four-way unroll are always stages 0, 1, 2, 3 in that order.

Handing each position its stage as a const folds four things, and the PTX shows all four:

  • both barrier addresses to literals — add.s64 %rd199, %rd200, 131080, and 131088/131104/131112, where the offset used to be derived from global_k % 4;
  • the phase parity to one register carried across all four slots (%r158) instead of four computations;
  • the accumulate predicate to mov.b32 %r130, 1 at three of the four positions, where it was a setp on k > 0;
  • both operand descriptors out of the K loop entirely.

Upstream's gemm_sol_final states the same fact and spells it differently: #[unroll(4)] over a loop-local k_idx & 3 with a match on it, and the comment "k_iters % 4 == 0, so the producer's global stage and this local stage agree at every tile boundary. Keeping this expression loop-local lets the unroll pass fold each stage match." That attribute exists at our pin and nothing in this repo uses it — it is rewritten only inside a #[kernel] or #[device_function] body, so a const parameter is the spelling reachable from a plain impl method, and it does not depend on an unroll pass firing. If #[unroll] is wanted for a helper method that is a library-level gap, not a gemm_sol one.

4096³, [256, 256] runtime stage const stage ratio
container A, pass 1 1281.7 1333.8 1.041
container A, pass 2 1274.5 1329.7 1.043
container B, pass 1 1289.0 1327.2 1.030
container B, pass 2 1300.7 1328.9 1.022
K-block rate 0.3615 µs 0.3503 µs 76.3% → 78.8%

+2.2% to +4.3%, two containers, four passes, quoted as a range because each row's own launches spread 2.6–5.7% and a ratio inherits that. At 8192³ on [512, 256] it is 1.001–1.003 — the predicted null, since that K loop had nothing to give.

Its gain is on the inter-stage critical path, and it is neither of the two places I guessed. Three measurements pin it, and the third corrected the second:

  • Not the MMA issue stream. mma only against runtime mma is 1.018 / 1.001 / 1.005 / 0.998 — null across four passes — so folding the ring index does not speed up tcgen05 issue.
  • Not the mbarrier.try_wait.parity spin body, which is what an earlier revision of this PR claimed. The PTX says the poll body got one instruction longer, and the kernel got faster anyway. Pre-fold the poll body is 7 PTX instructions with the barrier address held in a register and the parity computed before the loop; post-fold it is 8, because folding the stage to a literal made LLVM re-materialize mov.b64 of the dynamic-shared symbol plus add.s64 inside the loop instead of keeping a register live. So poll-body length is not the term, and the fold cannot be used as evidence that shortening it pays.
  • What is left is the scalar work between one load.wait returning and the next being entered: pre-fold each stage computed its own parity (add.s32 then bfe.u32), its own ring offsets and its own two operand descriptors on that path; post-fold the offsets are literals, the descriptors are hoisted out of the K loop, the accumulate predicate is a constant at three of four positions, and the parity is computed once a turn rather than four times. That path exists only when the waits exist — which is exactly why whole gains 4% and mma only, which has no waits, gains nothing. It reconciles all three rows.

Reported as the measurement, not as the mechanism it was built for, and corrected once when the PTX contradicted the first reading.

Against the two bars, in one container

cuBLASLt 1707.7 and upstream 1453.5 at 4096³; ours 1294.9 before and 1328.1 after, both means of that container's two passes:

of cuBLASLt of upstream
before 0.758 0.891
after 0.778 0.917

The port's K-loop share of the deficit was 6.0 points of peak (82.3 − 76.3) and is now 3.5 — the fold closed 42% of it. 17.7 points are structural: upstream pays them too, and the duty-cycle table says why.

What remains splits two ways, neither of them the K loop's cadence. Our drain-free K loop (80.4%) is still 1.9 points behind upstream's drain-inclusive one (82.3%), so roughly two points of the residual is in the feed's interaction rather than in the epilogue — and it is not the ring index, not the barrier, not the issue rate and not the producer's instruction count, all four now measured at zero. The rest is the per-tile constant: 3.4 µs against upstream's 2.3, of which the drain is 2.9.

That 2.9 µs a tile reproduces #147's independently measured 2.82 µs of serial drain per tile, from a different instrument (a doubling ladder) run by a different agent. Two methods, one number.

The secondary task: k below m

#146's loose end — 4096x4096x1024 on [256, 256] printing nothing for 1200 s until the watchdog stopped the container — is characterized rather than fixed, in bench sol-k: a k ladder descending at m = n = 4096 that announces each row on stderr before launching it, so the last announced row is the answer even when the process does not return. It is deliberately its own case that no other table calls, because a launch that hangs takes every row after it.

The boundary is k = 1280, one container, every completed row exact:

shape k_blocks turns min ms TFLOP/s of cuBLASLt
4096x4096x2048 32 8 0.0605 1136.2 0.789
4096x4096x1792 28 7 0.0542 1109.9 0.803
4096x4096x1536 24 6 0.0500 1031.1 0.780
4096x4096x1280 20 5 0.0445 964.2 0.774
4096x4096x1024 16 4 announced, never returned

Shallow k is otherwise fine — the four completed rows are flat at 0.774–0.803 of cuBLASLt, so this is a cliff at one value and not a degradation. The stage fold above is neither its cause nor its cure: #146 saw it on the computed ring index and this ladder ran the folded one, at the same shape. Mechanism, four candidates and the experiment each needs are in #149; the container was stopped from the CLI rather than left to burn, so 768 and below are unmeasured and each costs a container to reach.

The residual against upstream: not the feed, and not the issue stream

The 3.5 points of peak still between our K loop and upstream's is the whole of the on-target gap in this half, so it is chased here — statically, because a static diff needs no container and it answered outright.

Upstream's producer is byte-for-byte and instruction-for-instruction ours. From its own source: A_TILE_BYTES = 128*64*2, B_TILE_BYTES = 128*64*2, charged as (A_TILE_BYTES + B_TILE_BYTES) * 2 per K block per cluster — 64 KB, identical to ours. Three cp_async_bulk_tensor_2d_g2s_multicast_cg2 per rank per K block: one A, then two 64-row B panels, under upstream's own comment "The fixed host descriptor exposes a 64x64 B panel. Concatenate two panels to form this CTA's 128 columns." That is our B_BOX = 64 two-box loop, for the same reason — one host descriptor shape — and the wide-B arm above already priced it at zero. The mask is self_mask, so upstream replicates nothing either, and its stage depth is 4. So the feed is the same feed: same bytes, same instructions, same mask, same depth, therefore the same 95.5% duty cycle. The residual is not the feed, and feed only on upstream's body — which the harness does not admit anyway, since #145 keeps that file byte-identical — would have nothing to find.

And our MMA warp's issue stream is now leaner than upstream's. _print_mma_stream in modal_app.py::build, off the one bundle that carries both, counting non-mma instructions between the first and last tcgen05.mma:

kernel tcgen05.mma instructions between per issue
gemm_sol_m256_runtime 16 140 8.8
upstream M256 20 149 7.5
gemm_sol_m256 16 46 2.9
gemm_sol_m512_runtime 32 223 7.0
upstream M512 40 230 5.8
gemm_sol_m512 32 78 2.4

Before the fold we were slightly worse than upstream (8.8 against 7.5); after it we are 2.6× leaner — and still 3.5 points of peak behind on the rate. So static instruction count between MMA issues is not the binding constraint.

That table does not, however, foreclose the barrier-address lever, and an earlier revision of this PR wrongly said it did. A census between MMA issues counts each instruction once; a spin loop costs its body times its iteration count, and no static count between issues can see the iterations. Those are different quantities. So the poll body was counted directly, ours against upstream's:

instructions per try_wait poll the address
gemm_sol_m256_runtime 7 held in a register across the loop
upstream M256 7 mov.b64 of a static .shared symbol, per poll
gemm_sol_m256 (ships) 8 mov.b64 of the dynamic-shared symbol plus add.s64, per poll

The lever is alive but its sign is unestablished, and this kernel contains the natural experiment that muddies it. Our shipped poll body is one instruction heavier than upstream's, and the reason is exactly the suspected one — upstream gives each mbarrier its own static .shared symbol (TMA_BAR0..3, MMA_BAR0..3, which come out as __shared_mem_27..29) where ours are const offsets into one dynamic allocation, so ours needs an add that upstream does not. But the pre-fold spelling had a 7-instruction poll body — the same as upstream's — and was 4% slower. One instruction of poll body moved in this kernel, and the launch moved the other way. That is not evidence the lever is worthless; it is evidence that poll-body length is dominated by something else here, and it means I cannot state the sign of the prediction in advance. No container was spent on it for that reason.

Both halves were filed as #150 (the per-poll add.s64) and #151 (the predicate round-trip), then the instrument that would settle them was built — modal_app.py::_print_sass_loops, CPU-only, nvdisasm -c over the cubin build already assembles, finding loops by backward branch rather than by mnemonic — and it killed both. The whole spin loop in SASS is YIELD / SYNCS.PHASECHK.TRANS64.TRYWAIT P0, [R5+URZ], R4 / @!P0 BRA: three instructions, the same three in all three kernels, against 7 / 7 / 8 in PTX. ptxas folds the predicate round-trip to nothing and keeps the barrier address in a register across the loop, so neither the add nor the five-instruction chain is a cost anything executes. Both issues closed, no container spent, and #150's advance prediction of 2.7% died because the instruction it was about does not exist.

That also settled the fold's mechanism at the machine level. The shipped and pre-fold spin loops are byte-identical at 3 instructions, so the +4% cannot have come from the poll body at any level — and the two kernels' SASS loop tables differ in exactly one row, 10 instructions an iteration against 14, in a loop that is not the poll loop. That is the inter-stage path, where this PR says the win is.

The general lesson is written up in experiments/README.md as a finding about the instrument set, because nearly every conclusion in this effort is a PTX count and this is the first time one was checked against SASS. It is concrete about what that does and does not disturb: removal claims in the ablation censuses are safe (ptxas cannot invent a tcgen05.mma), regcount's registers and the occupancy gate are already post-ptxas, and the between-MMA table read as a negative gets stronger — while absolute "this costs N instructions" readings from PTX, which is what #150 and #151 were, do not survive.

It is reachable, and it is library-level rather than gemm_sol-level. cuda_device at the pin plainly admits static .shared mbarriers: upstream's vendored copy declares eight of them in this tree, and it builds, assembles and runs. What it costs is the shared plan — src/sync.rs's Semaphore/SemaphoreRing take a *mut Barrier derived from a dynamic base, and gemm_sol.rs's load_offset/free_offset/full_offset/empty_offset/ready_offset consts are that base's layout, which #137 deliberately made one walk. Changing it would pay every kernel with a pipeline, not this one, which raises its priority and also means it should not ride in this PR.

One thing the poll body says that is new, and is nobody's current lever. Five of the seven or eight instructions are not addressing at all: selp.b32, and.b32, setp.ne.b32, not.pred, bra — a predicate turned into an i32, masked, turned back into a predicate, and inverted, because mbarrier_try_wait_parity returns a Rust bool and the loop is while !…. A tight spin is mbarrier.try_wait.parity followed by @!p bra, which is two. Upstream pays the same five, so this does not explain the gap against upstream — but it is 5 of 8 instructions in every mbarrier spin in the repo, and removing it is a cuda_device/src/sync.rs question rather than a GEMM one.

What would separate latency from ordering, since nothing in this file can. Every arm here removes a phase and reads a launch or a rate; none of them observes when a warp is waiting. The instrument for that is a per-warp %globaltimer probe writing one span per warp stream per tile to a global buffer — issued outside the timed path, so it perturbs the thing it measures and its own perturbation has to be measured against whole first. Its coarseness is a real risk against a 276 ns K block, which is why it is named here as the next instrument rather than run as a lever. No container was spent on this section.

What this does not separate

  • Why the feed in situ costs 24.5% at 95.5% duty and 0.0% at 55.7%. That is a duty-cycle argument, not a mechanism. Bank conflicts between the TMA's writes and tcgen05's operand reads are not distinguished from saturation of the shared-memory write port, and no arm in this file can distinguish them — every arm removes a phase, so each one removes both candidates together, and the feed's byte count is the only dial any of them turns. Separating the two needs an arm that changes the access pattern at constant bytes and constant instruction count: staging A and B at swizzles or pitches that collide differently while the TMA moves the same 64 KB per K block. If bank conflicts are the term, that arm moves; if the write port is saturated, it cannot. What is established is that the quantity predicting the cost is operand bytes per flop, which is the tile's.
  • Latency from ordering in the 3.5 points still behind upstream. The feed is identical and our static issue stream is leaner, so it is neither of those; our poll body is one instruction heavier, and the sign of that is unestablished because the pre-fold spelling had upstream's poll body and was slower. The instrument that would separate a poll-count effect from an ordering one is a per-warp %globaltimer span probe, which this PR does not build — its own perturbation would have to be measured against whole first, and its coarseness is a real risk against a 276 ns K block.
  • The per-tile constants, except the large one. They are two-point fits of small differences between large numbers; issue only fits 2.4 µs a tile and no drain 0.5, which is not a ranking anyone should read. Only the drain's 2.9 is quoted, and only because a second instrument agrees.
  • The residual ~2 points against upstream. Located — the feed's interaction, not the epilogue — and not explained.
  • wide B's null from the possibility that both boxes were already free. The arm shows the instruction count does not matter; it does not show that no cheaper feed exists.

The consequence for tiling, which is somebody else's to act on

The term is the tile's operand bytes per flop, so the lever is the tile. #146 swept it and found [512, 256] at 4096³ a dead heat (0.985), because it halves the tile count and so doubles the per-tile constant each tile must amortize. This PR prices that constant at 3.4 µs a tile, of which the drain is 2.9. If the drain falls, the crossover should move below 8192 — the entry whose K loop is already at 99.3% of peak would then be the right one at 4096³ too. That is a #146 + #147 interaction, not a change here.

Composition

gemm-sol-integrated exists because #144, #145 and #146 all branched from gemm-sol and none contains another, while this work needed the instrument from #144 and the reference from #145 on top of the entries from #146. It is pushed as a shared branch rather than kept private because #147 needs the same three.

Note for whoever merges #147: its TWICE_GLOBAL/SHARED/ALL are 4/5/6 and this branch's MMA_ONLY is 4, the same discriminant on the same dial, which would silently remap arms rather than fail to build. #147 owns that resolution and the canonical explicitly-valued enumeration with a compile-time guard; nothing here touches its drain.

Validation

  • scripts/modal-run build — pass, including sm_100a codegen of all four manifests, the cublas FFI build, and ptxas on the gemm-sol-upstream bundle.
  • scripts/modal-run examples — pass. All three entries exact over every one of 1048576 BF16 outputs at 1024x1024x512 with the folded walk, worst |rel| 3.89e-3 against the fp32 reference. The fold is global_k % STAGES handed in as a const and nothing else, so identical output is the expected result and this gate is what confirms it.
  • scripts/modal-run regcount — pass, occupancy gate clean. gemm_sol_m256 censuses 16 mma / 2 ldtm / 3 tma / 2 stmatrix and gemm_sol_m512 32 / 2 / 4 / 2, identical to The epilogue is the gap, and at 4K it is only a fifth of it (#138) #144's published census and identical between the two crates, so putting two more dials on the shipped body moved no instruction in the kernels that ship.
  • scripts/modal-run bench --case sol-ablate and scripts/modal-run sol_ablate — the tables above, two containers. Every ratio is against its own run's live cuBLASLt column and no figure is mixed across containers.
  • scripts/modal-run bench --case sol-k — the secondary task.
  • cargo test, scripts/fmt --check — pass.

feitreim and others added 17 commits July 29, 2026 17:54
…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`.
… 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.
…g ladder, and one wait a band where there were two

The epilogue is the largest single term in `gemm_sol` at both shapes with a
gap. #144 measured it at 19.7% and 11.9% of the launch and left two things
fused: the drain's own cost and its failure to overlap. This separates them,
prices the chain a third at a time, and ships the one lever the split says is
worth anything.

Three new `ABLATE` arms make a doubling ladder, each repeating one more pass of
the drain per band with the extra global stores aimed at the cluster's own
first output tile so they stay in L2. An extra pass has nothing left to hide
behind, so it is paid serially by construction: `twice all - whole` is the
drain's own occupancy cost D, and `whole - no drain` is what the launch pays.

E > D at both shapes. None of the drain is hidden, and at M256 -- where the
accumulator IS double-buffered across tiles -- E is 191% of D, so the drain
also slows the phase it runs beside. The LDTM half is free: doubling
`tcgen05.ld` and its waits costs zero. What is left is the register->shared
half, at 60-70% of D.

Two drains built on that. `paired` puts a band's two LDTM issues in flight
before one wait and ships (+0.9% at 8192^3, nothing at 4096^3, two round-robin
passes each, every census column but the wait identical). `wide` puts four
behind one wait and loses.

New: `TmemTile::tile_x8_batched`, an `ldtm.wait` census column, a
`ldtm x8 batched map` device case, six ablation arms, two tables, and a
correctness gate for the arms that compute a right C.
@feitreim
feitreim merged commit 97b6406 into gemm-sol Jul 30, 2026
3 of 4 checks passed
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`.
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