Skip to content

The epilogue's stores were the wrong shape, and stmatrix fixes 20% of them (#15) - #116

Merged
feitreim merged 1 commit into
mainfrom
staged-epilogue
Jul 29, 2026
Merged

feitreim merged 1 commit into
mainfrom
staged-epilogue

Conversation

@feitreim

Copy link
Copy Markdown
Owner

Closes #15 (the store-shape half of it).

#114 left exactly one lever and priced it: the epilogue is the whole of the item boundary, it is exposed rather than hidden (whole − no drain = 20.43 µs/tile at 8192³ against #108's 21.4 µs measured serially by an unrelated route, ratio 1.01), and the epilogue-free kernel measures 1850 TFLOP/s against cuBLASLt's 1808 in the same container — so the epilogue is 111% of the entire gap to the library.

This adds Epilogue::Staged: Tile::drain_staged moves the band TMEM → registers → stmatrix into a per-warp [32, 64] bf16 tile → plain 16-byte stores, beside the register drain rather than instead of it. Both compute the GEMM, both are on the correctness gate, and the shipped default is unchanged, so every number in examples/README.md §7 stays quotable against one kernel.

Nothing in src/ moved — kittens::ldst::store_tile and kittens::global::store_shared_rows (#113) already existed.

The headline

Min ms over 30 timed launches, static schedule, GROUP = 8, one container, every row checked element-by-element against the CPU reference before it was timed.

shape lcf TFLOP/s staged TFLOP/s vs lcf lcf/theirs staged/theirs
4096³ 972.8 1050.9 +8.0% 0.594 0.642
8192³ 1494.9 1558.0 +4.2% 0.822 0.856
16384³ 1661.3 1692.7 +1.9% 0.877 0.893

Measured on the epilogue, not on the launch it amortizes into

gemm_cg2_staged_no_drain declares the staged envelope and deletes the drain, so #114's own subtraction runs in each arm with everything but the drain held:

shape lcf µs/tile staged µs/tile change share of the launch
4096³ 26.82 21.73 −19.0% 38.0% → 33.2%
8192³ 20.14 16.20 −19.6% 19.2% → 16.1%
16384³ 21.60 16.34 −24.4% 11.4% → 8.8%

The lcf arm at 8192³ reproduces #114's 20.43 µs at 20.14, in a different container. That is the control saying the instrument is the instrument.

The scoping arithmetic was wrong, and that is the first result

Per warp band of [32, 256] bf16, per thread:

store_rows staged
st.global 128 × 4 B, 8 discontiguous 16 B runs 32 × 16 B, 4 contiguous 128 B runs
stmatrix 0 64
ld.shared 0 32
cvt.rn.bf16x2.f32 128 128
total memory issue 128 128

The issue was scoped from a table reading 96, which got there by leaving out the ld.shared half of store_shared_rows' chunk copy — that mover is deliberately a load and a store rather than one opaque snippet, and both are instructions. Total issue does not fall. The entire hypothesis is the shape of the global write: 4× fewer store instructions, each on full 128-byte lines instead of eight half-filled 32-byte sectors — 1024 half-full sector transactions become 512 full ones.

So: was the ~6.2% met? No — 4.2% of it was. 6.2% is half the store half (13.1 µs → 6.55 µs against a 105 µs tile). The measured saving is 3.94 µs: 60% of that ceiling, 30% of the whole store half. The shortfall is exactly the correction above — the ceiling assumed the stores halved, and only the global half moved.

What it does not cost

Registers: 166 → 42, zero spill, 528 B → 256 B frame. The band never has to exist — TmemTile::tile and ldst::store_tile both walk [16, 16] blocks, so the compiler fuses them and one 8-value Fragment is live at a time, where store_rows walks the band slot-major and forces all 128 fp32 into registers. The occupancy-step hazard went the other way; gemm_cg2_staged is now on GATED_KERNELS regardless.

Residency: unmoved. 114 816 B against 98 392 (the shipped plan rounded to a tile base, plus 4 × 4096 B), inside the 116 736 an SM gives at 2 CTAs. device-tests' tmem residency census gains a rung and counts 2 there, the same integer it counts at 98 392 — the tensor-memory term of min(512 / columns, shared per SM / plan) binds at 256 accumulator columns. And the envelope control, staged no drain against no drain, two kernels differing in 16 424 untouched bytes: −0.4% / −0.4% / +1.0%.

STAGES was never available to buy bytes — §7's [256,256] s2 row is −11.8% / −7.3% at unchanged residency.

Why it wins — the gemm_ws control

The obvious reading is that the epilogue was simply in the way. gemm_ws separates that: its epilogue is already deferred one item and already on warps of its own. If staging won only because the drain was blocking, it should be worth nothing there.

shape ws ms ws staged ms staged TFLOP/s vs ws
4096³ 0.1375 0.1321 1040.4 +4.1%
8192³ 0.7902 0.7713 1425.5 +2.5%
16384³ 5.8878 5.7144 1539.3 +3.0%

It survives. The win is the store's shape, not its placement. Registers 168 → 44; residency could not move (512 accumulator columns fixed it at 1 CTA/SM before shared memory was consulted).

Design notes

  • Per warp, not per CTA — so the barrier count is zero. stmatrix is .sync.aligned and therefore a convergence point for its own warp, and store_shared_rows is cooperative rather than collective, so a warp writing and reading back its own 4096 B needs no bar.sync. Only the bar.warp.sync separating one pass's read from the next pass's write, which bar.warp.sync's own memory-ordering guarantee covers. A row-subrange of a swizzled tile is a swizzled tile (8-row period, XOR over the row index), which is what lets four be carved out of one 16 384 B run.
  • No fence.proxy.async.shared::cta, deliberately. That fence orders a generic-proxy write against an async-proxy read. Both ends here are generic. This is documented at the call site because a reader will assume it is a bug.
  • epilogue::StoreRing was the wrong tool, and it is worth saying why: its commit issues a TMA store and its acquire waits on a bulk-copy read group. This path needs neither.
  • STAGE_N = 64 is forced from both sides. SharedTile::WIDTH_OK wants a whole swizzle subtile, so 64 is the narrowest bf16 tile Swizzle128B admits; 4 warps × [32, 128] is 32 768 B against 18 344 of headroom, so it is also the widest that fits.

Also in here

regcount grows a per-entry-function PTX opcode census. #114 ran one by hand and reported it in prose; it is CPU-only and cheap, so it is a standing check now. It says gemm_cg2_staged is the only gemm_* kernel carrying stmatrix, ld.shared.v4 or st.global.v4, and that gemm_cg2_staged_no_drain is opcode-identical to gemm_cg2_no_drain — zero LDTM, zero stores, zero cvt, all four tcgen05.mma present.

Verified

  • scripts/modal-run build — clean, including the codegen-time const { assert!(..) } on the two envelopes.
  • scripts/modal-run regcount — 42 / 44 registers, zero spill, occupancy gate green, census above.
  • scripts/modal-run examples — staged exact at 512x256x256 and 4096x4096x256, all three GROUP widths, both kernels.
  • scripts/modal-run device_tests — 38/38, census counts 2 at 114 816 B.
  • scripts/modal-run bench --case staged and scripts/modal-run ws_bench — the tables above.
  • scripts/fmt --check.

Not done

The default is still the register drain at both entry points. On this evidence it is the rung to ship, but flipping it moves every baseline in §7 and belongs in a change of its own rather than folded into the measurement that motivates it.

The LDTM half — 8.3 µs of the 21.4 µs serial epilogue, 39% of it — is untouched by this and not addressable this way.

… them (#15)

#114 left one lever: the epilogue is the whole item boundary, it is exposed
rather than hidden, and the epilogue-free kernel already beats cuBLASLt. So
`Tile::drain_staged` — TMEM -> registers -> `stmatrix` into a per-warp [32, 64]
bf16 tile -> 16-byte stores — beside `Tile::drain`, as `Epilogue::Staged`.

Both kernels compute the GEMM and both are on the correctness gate; the shipped
default is unchanged, so every number in §7 stays quotable against one kernel.

**+8.0% / +4.2% / +1.9%** at 4096³ / 8192³ / 16384³, to 0.856 and 0.893 of
cuBLASLt. On the epilogue itself, by #114's own `whole - no drain` subtraction
at a fixed envelope: **-19.0% / -19.6% / -24.4%**, with the `lcf` arm
reproducing #114's 20.43 µs a tile at 20.14.

**The arithmetic the issue was scoped from is wrong** and the corrected table
is in `Tile::drain_staged`: total memory issue is 128 instructions a thread in
*both* arms, because `store_shared_rows`' chunk copy is a `ld.shared` and a
`st.global`. The gain is entirely that global stores fall 4x and land on full
128-byte lines. The ~6.2% ceiling assumed the stores halved; 4.2% arrived.

**It costs -124 registers** (166 -> 42, no spill): a block-at-a-time
LDTM -> `stmatrix` never materializes the band `store_rows`' slot-major walk
forces live. Residency is unmoved — 114 816 B is still 2 CTAs an SM, counted by
a new census rung and controlled for by `gemm_cg2_staged_no_drain`, which
differs from `gemm_cg2_no_drain` in 16 424 untouched bytes and 0.4%.

`gemm_ws` carries the same epilogue and gains **2.5-4.1%**, which is the control
that says the win is the store's shape and not its placement: that kernel's
epilogue was already deferred and already on warps of its own.

`regcount` grows a per-entry-function PTX opcode census, so #114's dead-code
defence is a standing check rather than a paragraph.
@feitreim
feitreim merged commit df12689 into main Jul 29, 2026
3 checks passed
feitreim added a commit that referenced this pull request Jul 29, 2026
…#109's 8.3 us closes to 8.07 (#117) (#117)

* The LDTM half at .x8 and stmatrix at .x4, ablated against #116's staged epilogue (#117)

* Measure it: .x8 is +23.6/+8.6/+3.6%, .x4 alone is nothing, and #109's 8.3 us of LDTM closes to 8.07

* const assert uses is_multiple_of, which clippy requires and WIDTH_OK already used
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 3, 2026
…) (#171)

* A staged tile can be folded into memory, not only written over it (#169)

`global` had `store_shared_rows` and no `+=` twin, so `C += A·Bᵀ` — every
backward pass — had no library route and every caller hand-rolled a
read-modify-write. That drops off the access ladder: `oxide-train`'s tcgen05
GEMM measures 1113.8 TFLOP/s storing and 536.2 accumulating at 4096³ on one
compute pipeline, so the fold costs more than the whole rest of the kernel. It
is not bandwidth — re-reading a 4096² bf16 `C` is 33.5 MB against a 133 µs
difference — it is the shape, which is #116's finding one level up: 4-byte
scattered accesses where the store path issues 16-byte contiguous ones.

`accumulate_shared_rows` is `store_shared_rows` with the copy replaced by a load
of both sides, an `Element::add_packed` and a store: same signature, same chunk
split, same `access_width` ladder, so the fold costs the read and nothing else.

The addition is the element's. A bf16 `C += x` has to widen both sides, add in
fp32 and round the sum **once** — the addend arrived already rounded, and
rounding again after the add is an error the accumulator did not have to carry.
That belongs beside `Element::pack`, so it is a required trait method rather
than a snippet at each epilogue: three impls, each `unpack`, `+`, `pack`.

Held by `shared accumulate` and `shared accumulate wide` on a B200 — the two
`shared drain` cases with the rectangle seeded with its own identities instead
of poison, so the answer is every identity doubled. Doubling a bf16 moves the
exponent and leaves the mantissa alone, so the comparison stays on bit patterns
with no tolerance: a fold that rounded twice, or dropped the read, lands on a
different pattern rather than a nearby one. The margins are still poison and
still checked, so the geometry the store cases prove is proved again here.

GAPS.md §2.6 records it, and two entries beside it that this work falsified or
found:

- §1.2 read "`Bf16` is still the only *operand* impl", and had not been true
  since `F16` landed eight lines above `impl MmaElement for Bf16` in the same
  file. The section's usual failure and not a slow rot. tf32 and fp8 are the
  genuinely absent ones — and `oxide-train` #67 was filed believing its fp32
  GEMM needed tf32, when that kernel's operands are bf16 and only its `C` is
  fp32.
- §2.6 now names the reason an **fp32** epilogue is still on the register route:
  `store_shared_rows` would take an `F32` tile, but nothing can fill one, since
  `ldst::store_tile*` are `stmatrix` and bound `Unpacked = [f32; 2]`. So an fp32
  `C` pays the 20.43 µs/tile scattered drain against the staged route's 6.68.
  Filed nowhere; a plain non-`stmatrix` `store_tile` over `SwizzledChunks` is
  what it wants.

* GAPS.md §2.6: the fp32 staging hole is #174, with the two entry points' ratios
feitreim added a commit that referenced this pull request Aug 4, 2026
oxide-train's fp32 GEMM converted to the staged drain goes from 120 registers
and a 512 B .local frame to 96 and none -- the frame was a band that did not
fit, and staging removes it twice over, since a pass narrows and the fold moves
into accumulate_shared_rows. Against three baseline runs on a B200 the store arm
is ~5% faster at 4096 cubed and a wash above it, and the accumulate arm is 15%
slower at 4096 and 8192 cubed.

The cause is the tile's height and it bounds when this route is right: four
bytes an element buys half the rows in the same shared bytes, so an fp32 band is
eight passes where bf16 is four, and a pass is a serial scatter, ld.shared,
global, bar.warp.sync chain. #116's -19% was measured with a tile wide enough to
amortize the pass; that kernel's operand rings do not leave one. The conversion
was not shipped.
feitreim added a commit that referenced this pull request Aug 4, 2026
…an stmatrix (#174) (#183)

* An fp32 band reaches a shared staging tile, because a scatter is not an stmatrix (#174)

`store_shared_rows` and `accumulate_shared_rows` were already generic over
their element and would take a `SharedTile<F32, ...>`; nothing could fill one.
`ldst::store_tile` and `store_tile_x4` bound `Element<Unpacked = [f32; 2]>`
because they are `stmatrix`, which moves b16 matrices and nothing else — so an
fp32 accumulator band reached memory only through `store_rows`' per-value
global stores, the shape #116 measured at 20.43 us/tile against the staged
route's 6.68.

`ldst::scatter_tile` is that missing fill, and it is deliberately not a new
instruction: a store into shared memory at any element is an ordinary
`st.shared`, so this is `global::store_rows`' own loop with a
`SwizzledChunks::element` where the `GlobalRows::at` was. It is generic in the
layout as well as the element, where `store_tile` is `BaseLdtm`-only, because
nothing about a scatter is an `ldmatrix` shape.

`SwizzledChunks::element` is the shared-side twin of `GlobalRows::at`: a column
splits into the chunk holding it and the byte offset inside that chunk, and the
swizzle stays `at`'s. Two host tests carry the addressing —
`every_column_owns_its_own_bytes_of_the_chunk_holding_it` and
`a_warps_scatter_covers_the_band_exactly_once`.

`device-tests` gains `scatter drain` and `scatter drain wide` against
`register drain` and `register drain wide`: the same rectangle at 32 and at 128
fp32 columns, written through the staging tile and straight out of the
registers. One host check holds all four, so a difference between them is the
staging tile's alone -- and the pair is the register-pressure A/B `regcount`
reads as well as the correctness one.

* The drain probes' band fill unrolls, so its own depot stops sitting in every regcount row

Every one of the four fp32 probes and both bf16 ones read 272 stack bytes and
identical .local traffic, because the identity fill was a rolled walk over a
RegTile -- ferro #166's depot, the fill's and not the drain's. Unrolling it the
way every mover in the library is unrolled leaves the drains comparable to each
other, which is the whole reason the scatter and register rows are a pair.

* A scatter's adjacent pair is one shared access, which is where its instruction count was going

The first cut issued one st.shared per value: a [16, 64] fp32 band is 64 a
thread against the eight stmatrix the same band costs at bf16, and that gap is
the whole risk in trading a global scatter for a shared one. Element gains
write_pair_shared and scatter_tile a pair rung over ColLayout's
CONTIGUOUS_VALUES, halving it -- st.shared.v2.f32 at fp32, and at bf16 not a
vector instruction at all, since two adjacent bf16 are one 32-bit word and the
pair is one pack and one store.

The alignment is structural rather than tested, which is the difference from
store_rows: a chunk is 16-byte aligned, a pair starts at a multiple of
CONTIGUOUS_VALUES by that constant's contract, and 2 * E::BYTES divides 16 at
both element widths. So the rung is a const and neither path carries a branch.
The band-coverage test now walks at the pair stride and asserts both claims the
rung rests on.

* The route landed and the milliseconds did not, so both go in the file

oxide-train's fp32 GEMM converted to the staged drain goes from 120 registers
and a 512 B .local frame to 96 and none -- the frame was a band that did not
fit, and staging removes it twice over, since a pass narrows and the fold moves
into accumulate_shared_rows. Against three baseline runs on a B200 the store arm
is ~5% faster at 4096 cubed and a wash above it, and the accumulate arm is 15%
slower at 4096 and 8192 cubed.

The cause is the tile's height and it bounds when this route is right: four
bytes an element buys half the rows in the same shared bytes, so an fp32 band is
eight passes where bf16 is four, and a pass is a serial scatter, ld.shared,
global, bar.warp.sync chain. #116's -19% was measured with a tile wide enough to
amortize the pass; that kernel's operand rings do not leave one. The conversion
was not shipped.
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.
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.

lcsf and the rest of the prototype layer

1 participant