Repository navigation
Register to TMEM (STTM) - #19
Merged
Merged
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The register → TMEM direction, mirroring
TmemTile::fragment/fragment_tileagainst
tcgen05_st_16x256b_x1_raw— the same16x256bshape descriptor, sothe same lane →
(row, column)ownership map.What landed
src/tmem.rsTmemTile::store_fragment(row, column, low, high)— two16x256bcollectivestores at
columnandcolumn + 8.TmemTile::store_fragment_tile(row, column, tile)— the same from aFragment, undoing the simd-pair interleaving.tmem::store_wait()— free fn overtcgen05_store_wait.Scope is deliberately the
[16, 16]block only. Composing a taller or widershape 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 — everytcgen05_st_*takesCuSimd<u32, N>— so values go out throughto_bitsand the_rawform._unpack16is not used: it splits 16-bit halves, and fp32 accumulator valueshave to land bit-exact.
The wait asymmetry is intentional and documented.
fragmentwaitsinternally 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_waitat the end instead ofone per fragment. The
# Safetysections say what the caller owes: all 32lanes of the warp owning rows
row..row+16together, and the caller orders thestore against any later consumer (an MMA reading the accumulator, a later
fragment,dealloc_block) viastore_waitplus whatever sync that consumerneeds.
Left explicitly open, not guessed at: whether a
tcgen05_fence_before_thread_sync/..._after_thread_syncpair isadditionally 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_tileinto pureinterleave(low, high) -> Fragmentandsplit(tile) -> (low, high).fragment_tile's behaviour is unchanged — theloop body moved verbatim into
interleave, both#[inline(always)]— and theinterleaving 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 dumpindex at every
(slot, value), stores it withstore_fragment_tile,store_waits, drains it back withfragment_tile, and dumps by threadcoordinate. The host's expectation is just "index
icame back asi".What it proves:
store_fragment_tileis the exact inverse offragment_tile. What it does not: on its own it cannot distinguish "both useBaseLdtm's map" from "both use the same wrong map" — any injective mismappasses. It pins STTM to
BaseLdtmonly in composition with the existingfragment mapcases, which established LDTM's map against silicon. This isstated in the kernel's doc comment.
sttm restage (32, 128)— the column-addressing case, since the round tripholds
columnfixed. The existing MMA position probe seeds the accumulator,each warp drains its band, writes it back through
store_fragment_tileintocolumns
128..256of 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 mapcases already validated, so acolumn-offset bug in the store surfaces as a value from the wrong column. It
reuses
check_fragment_mapunchanged — 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 newcases and all three existing layout shapes, and the restage is a
const RESTAGE: boolonfragment_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-targetsindevice-tests(clean), andcargo oxide build --arch sm_100a, which is real device codegen and the only thing that catchespost-monomorphization failures.
cargo fmt --checkclean in both crates.modal run modal_app.pyon a B200, once: 7 of 7 cases passed, includingboth new ones.
Changes to the plan
modal_app.py::buildnow runs clippy for both crates, replacing itscargo check. The constraint thatdevice-testsbe clippy-clean wasunenforceable otherwise: that crate cannot even
cargo checkoff a CUDA box.The clippy component is not in the image's
rustupinstall andRUSTUP_TOOLCHAINshadowsrust-toolchain.toml, so it is added in a layerof 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-testsgets#![allow(clippy::missing_safety_doc)]. Fivepre-existing kernel entry points already tripped it; a
# Safetysection per#[kernel]would restate the launch config each doc gives.GAPS.md2.1 and the device-test inventory in section 6 updated.Everything in the plan's "upstream facts" held as written — signatures,
CuSimdconstruction, the absence of a_purestore, and the interleavinginverse.
Closes #10