Skip to content

The LDTM half was the wait, not the issue: .x8 is +23.6/+8.6/+3.6% and #109's 8.3 us closes to 8.07 (#117) - #117

Merged
feitreim merged 3 commits into
mainfrom
ldtm-half
Jul 29, 2026
Merged

feitreim merged 3 commits into
mainfrom
ldtm-half

Conversation

@feitreim

Copy link
Copy Markdown
Owner

#116 cut the epilogue's store half and left the LDTM half exactly as it found it. This is that half. Three levers were scoped; one does not exist, one is worth nothing, and one is worth more than any single step in §7 since the port.

.pack::16b is not a lever, and no GPU time was spent finding out

The scoping read it as folding the fp32→bf16 convert into the load. At the pin (b099f64, git rev-parse HEAD confirmed — not the stale 4514af2 in the same cargo directory), intrinsics/abi-v1.toml gives tcgen05_ld_16x256b_x8_pack16 the result type [u32; 32] — the same 32 registers as _x8_raw — and generated-reference.md validates it as ...x8.pack::16b.b32 <register-list:32>. The count does not fall, so nothing is packed two-into-one. It is the load-side twin of tcgen05.st's .unpack::16b: it moves 16-bit-typed tensor memory. Against an fp32 accumulator it is the wrong instruction, not a rounding mode.

The rounding question it was flagged for is moot twice over: check_c compares bf16 words with == and no tolerance at all.

The .x8 hazard is stale history

tcgen05.rs's note describes intrinsics that took a shared-memory pointer. Every generated variant at this pin is status = "active" with an array result, and _x8_pure/_x8_raw share one LLVM intrinsic and one validated encoding.

What no document settles is the register order. TmemTile::tile_x8 asserts repeat-major; upstream marks the intrinsic runtime: unexecuted. So it got a case — device-tests' ldtm x8 map, which is sttm round trip with one line changed. It passes: 16384 registers survived TMEM unchanged, 39 of 39 cases.

The ablation — one variable per rung, one envelope for all four

All four rungs declare the same 114 816 B, so one no drain control serves all of them — the clean ablation #116 could not have. Min ms over 30 launches, one container, every row checked element-by-element first.

shape staged staged8 staged4 staged84 8 vs 4 vs 84 vs
4096³ 0.1283 0.1038 0.1291 0.1043 +23.6% −0.6% +23.1%
8192³ 0.7164 0.6599 0.7186 0.6585 +8.6% −0.3% +8.8%
16384³ 5.3677 5.1804 5.4263 5.1061 +3.6% −1.1% +5.1%

The epilogue itself, by #114's subtraction — and #109's split closes

shape staged µs/tile staged8 staged4 staged84 best
4096³ 21.18 8.93 21.58 9.17 −57.9%
8192³ 14.96 6.89 15.27 6.68 −55.3%
16384³ 15.15 8.47 17.25 5.81 −61.7%

#109 put the LDTM half at 8.3 µs a tile at 8192³. staged − staged8 is 14.96 − 6.89 = 8.07. Two instruments, two containers, four issues apart, 2.8% apart. The epilogue after #116 was 14.96 µs and 54% of it was LDTM.

The mechanism is the wait, not the issue

TmemTile::fragment waits after each .x1 load, so the shipped drain never has two LDTM in flight: a [32,64] band is 16 loads and 16 fully exposed latencies. .x8 is 2 and 2. stmatrix.x4 halves an instruction count and is worth −0.6% to −1.1% — a null result with a consistent sign, and the same lesson #116 learned from the other half.

Registers, and why the two compose only at 16384³

ptxas -v, zero spill everywhere, frame 256 B: staged 42, staged4 40, staged8 94, staged84 80. .x8 costs +52 — the 32 f32 that arrive at once — and does not spill; 94 is far inside the 168 step, and residency is tensor-memory-bound anyway. .x4 then buys liveness rather than issue, taking the composed rung 94 → 80, which is the whole of why staged84 beats staged8 at 16384³ and is a wash elsewhere.

Counted in the PTX: ldtm 8 → 2, stmatrix 4 → 2, every other census column identical across all four.

Against cuBLASLt (1655.7 / 1768.5 / 1869.1 TF/s, same container)

shape staged staged8 staged4 staged84
4096³ 0.647 0.800 0.643 0.796
8192³ 0.868 0.942 0.865 0.944
16384³ 0.877 0.908 0.867 0.922

0.856 → 0.944 at 8192³ and 0.893 → 0.922 at 16384³.

Not shipped, on #116's own precedent

staged84 is a rung beside staged; every number above is an A/B and flipping the default is a change worth making on its own. On this evidence it is the rung to ship. gemm_ws is untried and carries twice the LDTM (16 against 8).

Gates: build green, regcount green (gated kernels inside their step), device_tests 39/39, bench --case widths is the table above.

@feitreim
feitreim merged commit a5d9e85 into main Jul 29, 2026
4 checks passed
feitreim added a commit that referenced this pull request Jul 29, 2026
…and the epilogue was never gemm_ws's problem (#118) (#119)

`.x8` LDTM and `stmatrix.x4` on `gemm_ws`, plus the two `no drain` controls the
ladder is subtracted from, and the result is a lever that pays and a hypothesis
that dies.

The levers. Against #116's `staged`, `.x8` is +15.7% / +6.2% / +3.0% at
4096/8192/16384 cubed and `.x4` is +1.2% / +0.0% / +0.1% — the same clean null
it was on `gemm_cg2`. They do not compose here: `staged8` and `staged84` are
within 1.1% and trade places between sessions, and the register column said so
in advance, `.x4` recovering 2 registers (94 -> 92) where on `gemm_cg2` it
recovered 14 (94 -> 80) and that recovery *was* the composition gain. Best rung
is +19.4% / +9.5% / +5.2% over the shipped register epilogue, 0.615 -> 0.726,
0.782 -> 0.856, 0.810 -> 0.852 of cuBLASLt. Zero spill in every rung; 94 is the
largest count in the file against a reachable 255.

#117's mechanism predicted the shortfall and got it. `.x8` removes a latency
the drain never overlaps; this kernel already overlaps it, so `.x8` is worth
67%, 72% and 83% of what it was worth on `gemm_cg2`. By `whole - no drain` the
same epilogue is exposed at 8.62 us a tile here against #114's 20.43, and its
LDTM half at 3.20 against #117's 8.07 — 40-47%, which is what warp
specialization and the accumulator ping-pong buy, stated as a number for the
first time.

"Twice the LDTM (16 against 8)" is true of the PTX and false of the work. Every
census column doubles, not just LDTM, because `gemm_ws` emits its epilogue at
two call sites (`Ws::work` and `Ws::finish`) where the fused job has one. The
bands are `RegTile<32, 64>` in both files.

The floor is the finding. `gemm_ws_no_drain` — the shipped kernel with the
epilogue deleted, the probe that put `gemm_cg2` at 1850 TF/s against the
library's 1808 — reaches 0.829 / 0.923 / 0.888 of cuBLASLt, and at 8192 and
16384 cubed it is *slower than `gemm`'s complete `staged84` launch*. Best
against best is -9.7% / -9.4% / -6.9%; deleting the epilogue outright recovers
12.7 / 7.2 / 3.9 of those points. So no, `gemm_ws` does not beat `gemm`, and it
could not have: #112's 7.3% closes to 6.9% after both kernels spent everything
#116 and #117 found. The deficit is the multiply and the operand stream at one
CTA an SM. #112 blamed the peer CTA and #114 refuted it; `gemm_ws.rs` blamed the
missing peer CTA and this refutes that, by deleting the epilogue and losing
anyway. The stale paragraph is corrected in place rather than removed.

Residency counted, not queried (#77): two new census rungs at this kernel's own
131 176 B and 147 584 B read 1 resident, 1 holding at both, closing the gap the
`cg2 512` rung left at a 32 B plan (1 holding, 2 resident, 100.9 us parked in a
blocking alloc; 0.9 us here).

No default moved. `staged8` is the rung to ship on `gemm_ws` — `.x4` is a null
here alone and in composition — and that is a change worth making on its own.
feitreim added a commit that referenced this pull request Jul 29, 2026
…ce (#119) (#120)

`gemm`'s default epilogue becomes `staged84` and `gemm_ws`'s becomes `staged8`.
#116, #117 and #118 each ended by saying the rung was worth shipping and that
shipping it belonged in its own change; this is that change and it is the whole
of it. No rung added, none deleted, nothing retuned — every entry point still
launches and is still on the correctness gate.

The two differ on purpose. `.x8` costs +52 and +50 registers identically; what
differs is what `.x4` hands back — 14 on `gemm_cg2` (94 -> 80) and 2 on
`gemm_ws` (94 -> 92) — and that recovery IS the composition gain. There the
pair is +5.1% at 16384^3 against `.x8` alone's +3.6%; here `staged8` and
`staged84` land inside 1.1% and trade places between sessions, so the tie goes
to the rung with less surface.

Confirmed in one container with cuBLASLt re-measured in it (#109's lesson):
`gemm` 0.1432 -> 0.1044, 0.7584 -> 0.6684 and 5.5157 -> 5.0132 ms, which is
+37.2% / +13.5% / +10.0% and 0.583 -> 0.801, 0.827 -> 0.939 and 0.871 -> 0.958
of the library. `gemm_ws` +19.6% / +8.7% / +6.3% and 0.599 -> 0.717,
0.790 -> 0.858, 0.812 -> 0.863. Both reproduce their published ratios; the
16384^3 rows moved because the denominator did.

The constants that describe the shipped launch moved with it: `main.rs` reports
114 816 B and 147 584 B, and `CTAS_PER_SM` does not move on either kernel
because the tensor-memory term of `min(512 / columns, shared per SM / plan)`
binds at both envelopes. `regcount`'s occupancy gate gained
`gemm_cg2_staged_x8x4` and reads 166 / 42 / 80 against a ceiling of 255.

Deliberately unmoved: the ablation cube, `bench --case epilogue` and
`bench --case staged` stay built at `lcf`, and `ws_bench` table 1 now NAMES
`lcf` on both sides rather than taking `gemm`'s default, so its one variable is
still where the overlap comes from.
feitreim added a commit that referenced this pull request Jul 29, 2026
#121)

* The 1.02 ceiling is an 8192-cubed fact, and the residual is stmatrix's

Nothing measured. Everything re-measured. `bench residual` re-runs #114's ceiling,
the shipped rung and cuBLASLt beside each other in one container, twice, and then
opens the residual epilogue with a doubling ladder that deletes nothing.

**The framing survives at 8192^3 and only there.** `no drain / cuBLASLt` is
1.024 and 1.018 in two fresh containers, so #114's 1.02 reproduces after both of
the changes that could have invalidated it, and the epilogue is 127-136% of the
6.5% gap. At 16384^3 the same ratio is 0.993 and 0.984 -- the epilogue-free
kernel LOSES -- so 10-23% of that gap is not epilogue. At 4096^3 it is
0.955/0.988 and the rest is the wave, which is a different mechanism and is
reported as one. Below 2048^3 cuBLASLt's own MINIMUM moves 23-26% between two
calls in one session, so no ratio there is a measurement.

**What is inside the ~7.3 us/tile, at 8192^3, both sessions:**

| | us/tile | share | lever |
| --- | ---: | ---: | --- |
| `cvt` + `stmatrix` | 3.8-4.1 | 55-64% | **none identified** |
| `ld.shared` + `st.global` | 2.0-2.3 | 31-36% | a TMA store, ~+2.7% |
| LDTM after `.x8` | 0.09 / -0.04 | 0% | spent by #117 |
| unattributed | 0.8-1.5 | 9-20% | -- |

The instrument is `Tile::drain_staged_twice`, which ADDS one link of the chain
per rung rather than removing one, because an epilogue nobody observes is one
the compiler may delete. The census says every rung stepped by exactly one pass
and that the second `.x8` LDTM survived CSE despite being spelled `_pure`.

**Two negative results, each retiring a lever.** `s84 hot` deletes the
epilogue's entire HBM traffic and is worth -2.3% to +1.8%: the stores are not
bandwidth-bound, so #15's "hand the write to a TMA engine so it stops pressing
on memory" has no pressure to relieve -- what is left to buy is the issue, and
that is a smaller and different claim. And `.x8` on the REGISTER drain
(`gemm_cg2_lcf8`, new, on the correctness gate, 166 registers byte-identical to
`gemm_cg2`) is a clean null at -1.1% to +5.8%, against +23.6/+8.6/+3.6% on the
staged path -- the scattered stores were already covering the LDTM latency.

**One positive one.** That null is the arm #116's A/B never had, and it re-prices
the shared round trip at #117's LDTM width: `staged8` beats `lcf8` by
**+12.6%/+12.8%** at 8192^3 where #116 measured +4.2% at `.x1`. The hop is worth
three times what it was measured at, because recoalescing only gets paid once
the drain has stopped waiting sixteen times a band.

**And a control this file has never taken.** Table 6 takes the same
`whole - no drain` subtraction twice in one container: it reproduces to 1-5% at
8192^3, 0.4-7% at 4096^3, and **39-46% at 16384^3**. Every 16384^3 epilogue
figure above it -- #116's 16.34, #117's 5.81, #118's 2.91 -- is inside that band
and none of them carries it. It is also why `staged8` and `staged84` trading
places here does not contradict #117 so much as locate it: that +1.5-point
composition gain was a 16384^3 row.

New: `Tile::drain_staged_twice`, `Tile::drain::<WIDE>`, five entry points
(`lcf8`, `s84 hot`, `s84 2g/2m/2x`), `bench --case residual`, six tables. No
default, constant or shipped kernel moved; `lcf8` is on the correctness gate and
the four probes say UNCHECKED in their own labels. `build`, `regcount`
(occupancy gate green, 80/87/125/102 and 166) and `examples` all pass.

* and the cvt travels with the stmatrix, so the column says so
feitreim added a commit that referenced this pull request Jul 29, 2026
#122) (#122)

#121 took the first reproducibility control on `whole - no drain` and it came back
39-46% at 16384^3 against 1-5% at 8192^3, with #116's 16.34 us/tile, #117's 5.81
and #118's 2.91 all inside the band. This is what the band is.

**It is error propagation, and the arithmetic reaches backwards with nothing
measured.** A difference carries its arms' error divided by its own share of them.
Reconstructed from #121's own printed table 6: share 17.9% / 7.8% / 5.3% at
4096/8192/16384^3, so 1/s of 5.6 / 12.9 / 19.0, and against arms that repeat to
0.86+0.58% / 0.15+0.10% / 0.45+2.11% that predicts 8.1% / 3.2% / **49%** against
#121's observed 7% / 1% / **46%**. The launches were never the problem -- they
repeat to 0.1-2.1% everywhere. The epilogue is per output tile and the launch is
per tile times K, so the share falls as 1/K by construction. **The instrument did
not degrade at 16384^3; it never worked there.**

Three things it is not, each checked: sampling (`min` of 30 is the same estimator
at every size and the arms repeat to 0.10% at 8192^3), the wave (8192^2 and
16384^2 are both 98.8% full and every comparison holds the grid fixed between its
arms), and -- against the hypothesis -- **adding rather than deleting**.
`drain_staged_twice` retires the dead-code hazard, which is real and different,
but one added link is a *smaller* share than the whole epilogue, so the ladder is
more amplified. #121's own 16384^3 ladder row is +4.01 and -2.69 for one quantity.

**And a second term nobody could see, because `bench` sorted the order away.**
`Timings` now keeps launch order; `drift` is the second fifteen launches over the
first. At 16384^3 and nowhere in the sweep, all six arms over two containers, the
device is **+6.85 to +11.33% slower by the end of a call** -- essentially the whole
of its 18-23% in-call spread -- where every other size drifts *negative*. Not the
problem size: `16384^2 x k1024` has the same tiles, items, C and wave and drifts
-1.0 to +0.6%. It is the duration, 154 ms of continuous 1.1 PFLOP/s against 16.
A 16384^3 `min` is a boost-clock reading from a call whose last launches run 10%
slower, which is also the mechanism under cuBLASLt's 1.15-1.19 max/min there.

**The fix is `bench repro`: same output geometry, shorter reduction.** K is the one
axis the epilogue's cost does not sit on, so shortening it holds the tiles, the
waves, the items, the C traffic and the epilogue total and moves only the launch
it is a fraction of. Four whole measurements per arm, round-robin so every pair is
adjacent in time, and the spread the amplification *predicts* printed beside the
one it got. One `ld.shared` + `st.global.v4` pass, two containers:

| shape | us/tile | s | observed | predicted | session to session |
| --- | ---: | ---: | ---: | ---: | ---: |
| 8192^2 x k1024 | **2.34 / 2.34** | 10.8% | 17 / 17% | 16 / 18% | **0.0%** |
| 8192^3 | 2.07 / 2.29 | 2.2% | 33 / 18% | 41 / 30% | 10.6% |
| 16384^2 x k1024 | **2.11 / 2.12** | 10.8% | 5 / 8% | 12 / 13% | **0.5%** |
| 16384^3 | 3.01 / 3.82 | 1.6% | **167 / 111%** | 235 / 177% | **26.9%** |

`predicted` tracks `observed` across a twentyfold range and bounds it above in
nine rows of ten. The 16384^2 number nobody could measure is **2.11 us/tile**,
reproduced to 0.5%; #121's ladder put it at 0.45 and 4.22. The us/tile is flat in
K (2.34/2.42/2.07 and 2.34/2.61/2.29 over an eightfold range), which is what makes
the substitution legal and is the design's own check.

**`staged8` and `staged84` are not tied, and the sign is the geometry's.** At
8192^2 `staged8` leads by 1.4-2.4% in four cells, no range reaching 1.000; at
16384^2 `staged84` leads by 0.4-1.0%, same sign both containers. The full-depth
rows do not merely fail to order them -- 16384^3 centres on `staged8` ahead by
1.4-2.3 us/tile where the shortened row says `staged84` ahead by 0.07-0.20, and
both its ranges straddle. **So #120's default is right for a reason its own row
could not carry**, and #121's advice to break the tie at 8192^3 would have broken
it the other way. Not a request to move the default.

New: `Timings::spread` / `Timings::drift` and the launch order behind them, `bench
repro`, rule 5 in the module docs, a section in README §7. Nothing measured is
inherited; no default, constant or kernel moved; `gemm.rs` untouched. `build` green
twice, `bench --case repro` run in two containers at 96 s of GPU each.
feitreim added a commit that referenced this pull request Aug 6, 2026
…re the store side's was not (#131) (#206)

`store_fragment_x4` has had a `.x4` since #116 and `load_fragment` was still
two `ldmatrix_x2` a block. `load_fragment_x4` and `load_tile_x4` close that,
on the address derivation the store side already had — `ldmatrix.m8n8.x4`
takes its 32 addresses exactly as `stmatrix.m8n8.x4` does, so one restacking
test serves both — and the `ldmatrix x4 map` / `ldmatrix x4 map wide` device
cases hold the four destination registers to the same host expectation the
narrow pair answers to.

`.x2` still ships, and that is the point of the issue. #116's `.x4` and #117's
`.x8` paid by removing waits; an `ldmatrix` has none, so the gain is issue
slots and the cost is liveness. On `softmax` — three passes, every one a
`load_tile` — the wide form is unordered at 64 and 512 blocks and 1.1% slower
at 8192, on 40 registers a thread against 32 at the same 6 CTAs an SM.
feitreim added a commit that referenced this pull request Aug 6, 2026
`Drain<const LDTM_X8: bool, const STMATRIX_X4: bool>` shipped with #126 and the
shape is wrong twice over. The TMEM axis has three instructions a drain can
issue and not two — `.x1`, `.x8`, and `.x8` with the band's issues batched
behind one `tcgen05.wait::ld` — and the third carries an `ISSUES` count no
`bool` can hold. And a `bool` puts the rung in the *walk*: each arm is an `if`
inside the loop and a position in every dial that reaches it, so a fourth rung
edits the epilogue and five launch sites rather than adding an impl.

So the axes are traits, in `Swizzle`'s and `Scope`'s idiom: `TmemRead` with
`X1`, `X8` and `X8Batched<ISSUES>`, `FragmentStore` with `X2` and `X4`, one unit
struct per rung with the instruction on the impl. `Drain::<X8, X4>` is the pair
that ships and it says which pair at the launch site where `Drain::<true, true>`
said only where in a table it sat — which is the complaint `gemm_ws`' own doc
makes about `Ws::<STAGES, true, false, false, true>`, answered on this axis.
`experiments`' `Staged` job takes the two rungs the same way, so its five
entry points read `Staged::<true, X8, X2>` instead of `Staged::<true, true,
false>`.

An `adt_const_params` enum would express the same set; it is unstable and this
crate takes no incomplete features. The traits need none.

Two things are deliberately not rungs, and the docs say why for both.
`stmatrix.m8n8.x1` is in the ISA and not in the library: four instructions per
block where `.x2` is two and `.x4` is one, at identical addresses, in the
direction #117 measured as losing — it is an `ldst` entry point plus an impl
whenever someone wants it priced. `TmemTile::fragments_pack16_x8` returns packed
b16 words rather than an fp32 `RegTile`, so it is not a width of the read axis
but a different route: the only thing that can store its product is
`store_packed_x4`, which by its own doc computes a wrong `C`. Admitting it would
make the read's product an associated type and bind the write axis to it — the
two axes would stop being independent, for an ablation that never ships.

`X8Batched` is the rung `gemm_sol`'s drain reads with, and a doctest compiles
`Drain::<X8Batched<2>, X4>::staged` so that is checked rather than claimed. It
is not enough to migrate that kernel and the axes are no longer what separates
them — the walk is. It fills a 128-wide staging tile out of two 64-wide bands on
purpose, because four `.x8` issues behind one wait is 176 registers against 96;
it drains a column *span* of a wider accumulator because two warpgroups split
the tile (#197); and it converges twice a pass. Those are three parameters on
the walk, and `gemm_sol` is the tightest register count in the repo, so the
migration is a measurement and not a refactor.

No instruction moves: this is a pure API change and `regcount`'s opcode census,
registers, spills and frames are identical on every kernel.
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