Skip to content

Neither half of the drain has two widths, so neither is a bool - #217

Merged
feitreim merged 1 commit into
mainfrom
library/drain-widths
Aug 6, 2026
Merged

feitreim merged 1 commit into
mainfrom
library/drain-widths

Conversation

@feitreim

@feitreim feitreim commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Drain<const LDTM_X8: bool, const STMATRIX_X4: bool> shipped with #210 and the
shape is wrong twice over.

Neither axis has two rungs. The TMEM half has three instructions a drain can
issue — .x1 (tile), .x8 (tile_x8), and .x8 with the band's issues
batched behind one tcgen05.wait::ld (tile_x8_batched) — and the third
carries an ISSUES count no bool can hold. It is also the one gemm_sol
drains with, so the type could not express the drain of the kernel the repo
tunes hardest.

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, the job struct and five launch sites. That is the thing this change is
actually about: after it, a rung is an impl.

The shape

Two traits in Swizzle's and Scope's idiom — one unit struct per rung, the
instruction on the impl, and Drain::staged's walk knowing none of them:

axis trait rungs
TMEM read TmemRead X1, X8, X8Batched<ISSUES>
stmatrix write FragmentStore X2, X4
pub struct Drain<R: TmemRead, W: FragmentStore> { .. }

// the walk, entire, at any pair:
let pass = R::band::<M, N, ROWS, COLS>(accumulator, lanes, at);
W::store(chunks, 0, 0, lane, pass);

Drain::<X8, X4> is the pair that ships. An adt_const_params enum would
express the same set and is unstable; this crate takes no incomplete features,
and the traits need none.

The call sites read as what they are now. experiments' Staged job takes the
two rungs the same way, so its five launch sites say Staged::<true, X8, X2>
where they said Staged::<true, true, false> — which is the complaint
gemm_ws' own doc already makes about Ws::<STAGES, true, false, false, true>
("says nothing about which rung it is"), answered on this axis. gemm_ws' four
drain::* codes map to the four pairs directly.

What is deliberately not a rung, and why

stmatrix.m8n8.x1 is in the ISA and not in this library: four instructions
per [16, 16] block where .x2 is two and .x4 is one, at identical
addresses, in the direction #117 measured as losing. Adding it is an ldst
entry point plus an impl — the impl is the cheap half, which is the point of
the trait. Stated on FragmentStore.

TmemTile::fragments_pack16_x8 — the judgement call you flagged. It 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
ldst::store_packed_x4, which by its own doc computes a wrong C — it
exists so experiments' pack16 rung can hold every other instruction fixed
and take the cvt column to zero. Admitting it would make TmemRead's product
an associated type and bind FragmentStore to it, so the two axes would stop
being independent, for one ablation that never ships. A packed drain is its own
entry point when something needs one. Stated on TmemRead.

ldst::scatter_tile needs no judgement: it is the store direction for the
elements stmatrix cannot move, and Drain::staged's
Element<Unpacked = [f32; 2]> bound already excludes them.

gemm_sol: the axes are no longer what separates it — the walk is

Not migrated, per your instruction and my original reasoning. But the question
is now answerable rather than open, and a doctest on X8Batched compiles
Drain::<X8Batched<2>, X4>::staged, so "expressible" is checked and not
claimed. What is left is three things about the walk, none of them a rung:

  • The band and the staging tile are different widths there, on purpose. Two
    of the three shipped entries (gemm_sol_m256, gemm_sol_m256_n128) fill a
    128-wide staging tile out of two 64-wide bands, because a [32, 128] band
    is four .x8 issues and tmem's own ladder puts four at 176 registers
    against 96 — the batching wins at two and loses at four. Drain::staged ties
    the band to COLS.
  • It drains a column span of a wider accumulator, because two warpgroups
    split the tile (The warpgroup split lost to a .local depot rather than to the lanes, and both 256-wide entries take it now #197). The walk covers all N of the TmemTile it is handed
    and there is no [M, SPAN] view to hand it: columns_right shifts the base
    and keeps the width.
  • It converges twice a pass, where this walk converges once and leans on
    stmatrix.sync.aligned for the other edge.

The third entry (gemm_sol_m512, at a 64-wide staging tile where band == tile)
needs only the second of those. So the follow-up is a measurement — of a band
width parameter, of a span, and of the second convergence — rather than a
design task, which is what you asked me to establish. It is still not a
refactor: gemm_sol is the tightest register count in the repo.

Gates

Hand-run; Actions is still out. Branch is rebased onto 141db57 (the four
commits since ac79127 are README/image only, so the code tree the gates ran on
is this one).

gate result
scripts/fmt --check clean
cargo test 87 passed (86 + the X8Batched doctest)
cargo clippy --all-targets -- -D warnings (lib) clean
cargo doc --features host, RUSTDOCFLAGS=-D warnings clean
local cargo check --all-targets on all three kernel crates clean
scripts/modal-run build 0 — ap-oG3tp6FEoePpQEeEodYHYL
scripts/modal-run regcount 0 — ap-rmu7kBNgyEf03d9gwvKKRz (branch), ap-EytHGjbhdcTNPqjxa9CjRi (main, baseline)
scripts/modal-run examples 0, every case exact — ap-h9qXin3tbPqTMLnO0EIcI7
scripts/modal-run device_tests 0, 57 of 57 — ap-xCmSSn28F2KsZ49teZrVsc

The codegen claim, measured against main rather than asserted

regcount run on ac79127 and on this branch, and diffed row for row:

table rows differences
registers / spill st / spill ld / stack / smem 305 0
opcode census (mma, ldtm, ldtm.wait, tma, stmatrix, ld.sh.v4, st.g.v4, st.g.b32, cvt.bf16x2, bar.sync, bar.warp, mbar.arrive, selp) 84 0
.local depot census 143 0

Every kernel in all three crates, identical. That is the whole of what a pure
API change should read as, and it is what makes Drain::<true, true> →
Drain::<X8, X4> a rename of the same instructions.

Closes nothing on its own; it is the follow-up to #126 / #210.

`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