Skip to content

Register to TMEM (STTM) - #19

Merged
feitreim merged 4 commits into
mainfrom
issue-10-sttm
Jul 27, 2026
Merged

feitreim merged 4 commits into
mainfrom
issue-10-sttm

Conversation

@feitreim

Copy link
Copy Markdown
Owner

The register → TMEM direction, mirroring TmemTile::fragment / fragment_tile
against tcgen05_st_16x256b_x1_raw — the same 16x256b shape descriptor, so
the same lane → (row, column) ownership map.

What landed

src/tmem.rs

  • TmemTile::store_fragment(row, column, low, high) — two 16x256b collective
    stores at column and column + 8.
  • TmemTile::store_fragment_tile(row, column, tile) — the same from a
    Fragment, undoing the simd-pair interleaving.
  • tmem::store_wait() — free fn over tcgen05_store_wait.

Scope is deliberately the [16, 16] block only. Composing a taller or wider
shape stays the caller's, exactly as on the drain side; there is no generic
store_tile<M, N>.

There is no _pure (f32) store form upstream — every tcgen05_st_* takes
CuSimd<u32, N> — so values go out through to_bits and the _raw form.
_unpack16 is not used: it splits 16-bit halves, and fp32 accumulator values
have to land bit-exact.

The wait asymmetry is intentional and documented. fragment waits
internally because the registers it waits on are its return value;
store_fragment* does not, because a store's registers are consumed at issue,
so a pass writing many fragments pays one store_wait at the end instead of
one per fragment. The # Safety sections say what the caller owes: all 32
lanes of the warp owning rows row..row+16 together, and the caller orders the
store against any later consumer (an MMA reading the accumulator, a later
fragment, dealloc_block) via store_wait plus whatever sync that consumer
needs.

Left explicitly open, not guessed at: whether a
tcgen05_fence_before_thread_sync / ..._after_thread_sync pair is
additionally required around such a hand-off. This crate uses neither on any
path and nothing has been established either way for the store side; the doc
comment says so rather than implying their absence is a guarantee.

Testable extraction. The simd-pair interleaving comes out of
fragment_tile into pure interleave(low, high) -> Fragment and
split(tile) -> (low, high). fragment_tile's behaviour is unchanged — the
loop body moved verbatim into interleave, both #[inline(always)] — and the
interleaving is now host-tested in both directions, retroactively covering code
that shipped hardware-validated but untestable off a GPU.

Device tests

Two cases, both passing on a B200.

sttm round trip — each thread seeds a [32, 128] band with its own dump
index at every (slot, value), stores it with store_fragment_tile,
store_waits, drains it back with fragment_tile, and dumps by thread
coordinate. The host's expectation is just "index i came back as i".

What it proves: store_fragment_tile is the exact inverse of
fragment_tile. What it does not: on its own it cannot distinguish "both use
BaseLdtm's map" from "both use the same wrong map" — any injective mismap
passes. It pins STTM to BaseLdtm only in composition with the existing
fragment map cases, which established LDTM's map against silicon. This is
stated in the kernel's doc comment.

sttm restage (32, 128) — the column-addressing case, since the round trip
holds column fixed. The existing MMA position probe seeds the accumulator,
each warp drains its band, writes it back through store_fragment_tile into
columns 128..256 of a double-width allocation, and re-drains it from there.
The values are absolute position identities the store path never computes, and
the re-drain reads at a column the fragment map cases already validated, so a
column-offset bug in the store surfaces as a value from the wrong column. It
reuses check_fragment_map unchanged — the expectation is identical.

Cost was low, so it is in: the probe's drain, store and dump loops are
extracted into drain_band / stage_band / dump_band, shared by both new
cases and all three existing layout shapes, and the restage is a const RESTAGE: bool on fragment_probe.

Verified

Actually run, all green:

  • modal run modal_app.py::build — cargo clippy --features host --all-targets (clean), 21 host tests (all pass, 2 new), cargo clippy --all-targets in device-tests (clean), and cargo oxide build --arch sm_100a, which is real device codegen and the only thing that catches
    post-monomorphization failures.
  • cargo fmt --check clean in both crates.
  • modal run modal_app.py on a B200, once: 7 of 7 cases passed, including
    both new ones.
pass  swizzle round trip        4096 elements placed exactly
pass  fragment map (16, 16)     1024 values, all at BaseLdtm's coordinates
pass  fragment map (32, 32)     4096 values, all at BaseLdtm's coordinates
pass  fragment map (32, 128)    16384 values, all at BaseLdtm's coordinates
pass  sttm restage (32, 128)    16384 values, all at BaseLdtm's coordinates
pass  stmatrix round trip       4096 elements placed exactly
pass  sttm round trip           16384 registers survived TMEM unchanged

Changes to the plan

  • modal_app.py::build now runs clippy for both crates, replacing its
    cargo check. The constraint that device-tests be clippy-clean was
    unenforceable otherwise: that crate cannot even cargo check off a CUDA box.
    The clippy component is not in the image's rustup install and
    RUSTUP_TOOLCHAIN shadows rust-toolchain.toml, so it is added in a layer
    of its own after the expensive ones — the shared backend-build layers stay
    cached. This is not CI (CI: gate the device surface, the host feature, and the B200 harness #17); it is the existing local build path.
  • device-tests gets #![allow(clippy::missing_safety_doc)]. Five
    pre-existing kernel entry points already tripped it; a # Safety section per
    #[kernel] would restate the launch config each doc gives.
  • GAPS.md 2.1 and the device-test inventory in section 6 updated.

Everything in the plan's "upstream facts" held as written — signatures,
CuSimd construction, the absence of a _pure store, and the interleaving
inverse.

Closes #10

feitreim added 4 commits July 27, 2026 16:43
`TmemTile::store_fragment` / `store_fragment_tile` mirror `fragment` /
`fragment_tile` against `tcgen05_st_16x256b_x1_raw` — the same shape
descriptor, so the same lane -> (row, column) ownership. There is no `_pure`
store form and `_unpack16` would split 16-bit halves, so fp32 accumulator
values go out through `to_bits` and the `_raw` form.

The store side deliberately does not wait. A load must, because the registers
it waits on are its return value; a store's are consumed at issue, so a pass
writing many fragments pays one `store_wait` at the end. Whether the tcgen05
thread-sync fences are additionally needed around a hand-off is left stated as
open rather than guessed at.

The simd-pair interleaving comes out of `fragment_tile` into `interleave` /
`split`, which are pure and now host-tested in both directions — code that
shipped hardware-validated but untestable off a GPU.
Two cases. The round trip seeds every register with its own dump index,
stores the band with `store_fragment_tile`, `store_wait`s, and drains it
back — it shows STTM is the exact inverse of LDTM, and nothing more on its
own. The restage case runs the existing MMA position probe, writes the
drained band into a second column band and re-drains it there, so the values
are absolute coordinates the store path never computes and a column-offset
bug in STTM cannot hide behind a matching load.

The probe's drain, store and dump loops are extracted into `drain_band` /
`stage_band` / `dump_band` so both cases and all three layout shapes share
one composition. Kernel entry points keep clippy quiet about `# Safety`
sections crate-wide: their contract is the launch config their own docs give.
`cargo check` becomes `cargo clippy`, and the harness — which only typechecks
where cuda.h is — gets a clippy run of its own. `RUSTUP_TOOLCHAIN` shadows
rust-toolchain.toml in the image, so the component is installed in a layer of
its own after the expensive ones, leaving the shared backend build cached.
@feitreim
feitreim merged commit b96491a into main Jul 27, 2026
@feitreim
feitreim deleted the issue-10-sttm branch July 27, 2026 21:19
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.

Register to TMEM (STTM)

1 participant