Repository navigation
Composed movers: a whole [M, N] band, both memories, both directions - #43
Merged
Merged
Conversation
Every mover moved exactly one [16, 16] Fragment, so a kernel holding a RegTile<32, 128> wrote the block-composition loop itself — gemm.rs did, softmax.rs did twice, and device-tests kept its own copy in the test crate. reg.rs asserted that composition as an invariant (fragment_blocks_tile_the_bigger_shapes) while no library function implemented it. TmemTile::tile / TmemTile::store_tile and ldst::load_tile / ldst::store_tile compose the single-block movers out of one pair of placement helpers, so a band cannot mean one thing in TMEM and another in shared memory. All four land together for the same reason. The helpers live in tmem.rs and ldst.rs uses them: the composition is a property of BaseLdtm, which is the LDTM map, and ldst already documents itself as its shared-memory mirror.
drain_band/stage_band were the reference implementation this issue lifted, so deleting them in favour of TmemTile::tile/store_tile is the strongest test available: `fragment map` at (16,16), (32,32), (32,128) and `sttm restage` already validate them against silicon, and they are unchanged. The shared side had no such case — nothing in the harness monomorphized ldst::load_tile/store_tile, so they would have shipped both unmeasured by regcount and unvalidated. `band round trip` copies rows 0..32 of a [64, 128] staged tile into its rows 32..64 through both composed movers: 128 columns crosses the stacked-subtile stride and the store's row base is non-zero, which are the two things a composition loop can get wrong that a single block cannot show.
gemm's twelve-line drain and softmax's two hand-written composition loops become one call each. flash and layernorm named this API at their call sites before it existed; they now name the real one, and neither has a mover error left — flash's remaining list is #7, #11, #23, #31, layernorm's is #3, #9, #13 plus scalar broadcasts, and softmax's is exactly #9 (`tma_store`, `tma_store_commit`, `tma_store_wait`) and nothing else. It stays aspirational for that reason alone. README §"Came from writing kernels" item 2 and GAPS §2.1/2.1a updated to match.
feitreim
force-pushed
the
issue-22-composed-movers
branch
from
July 27, 2026 23:31
ea36cbd to
da5d559
Compare
This was referenced Jul 27, 2026
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.
Every mover moved exactly one
[16, 16]Fragment, so a kernel that wanted a[32, 128]band wrote the block-composition loop itself.gemm.rswrote it,softmax.rswrote it twice (once per direction), anddevice-testskeptits own copy as
drain_band/stage_band— in the test crate, so the nextkernel would have written it again.
reg.rsasserted that composition as aninvariant (
fragment_blocks_tile_the_bigger_shapes) while no library functionimplemented it.
The API
All four directions, so they cannot drift:
Generic exactly the way
RegTilealready is — theFragmentLayout<M, N>boundand no
generic_const_exprs.row/columnare the band's own origin (a warpof an
M128accumulator drainstile::<32, N>(32 * warp_id, 0)), not blockindices. The shared side takes
SwizzledChunks, likeload_fragment/store_fragment, so callers passtile.chunk_writer().Both pairs are built out of one
place_block/take_blockpair (intmem.rs,since the composition is a property of
BaseLdtm— the LDTM map — andldstalready documents itself as its shared-memory mirror). A band therefore cannot
mean one thing in TMEM and another in shared memory.
drain_band/stage_bandwere lifted, not redesigned.
Registers —
modal run modal_app.py::regcount, before and afterThe TMEM side, every kernel in
device-teststhat used the hand-written loops:fragment_map_16x16fragment_map_32x32fragment_map_32x128fragment_restage_32x128(drain and store at 128)reduction_probe(two drains, 32 and 128 wide)sttm_roundtripSpills, stack and smem are unchanged everywhere, including on
sttm_roundtrip(0 spills, 1024-byte frame in both). So the composed form is register-neutral
at both widths #5 and #6 warned about, and costs 2 registers on one probe —
which is not a case for an in-place
drain_into: the shapes where a by-valuetile has ever been expensive here (128 columns,
row_map168 → 255) areexactly the ones that did not move.
The shared side had nothing to compare against, so I measured it directly: the
new
band_roundtripkernel, once with the composed movers and once with thehand-written loops
softmax.rsused to carry (same file, same shape, onetemporary edit, not committed).
band_roundtrip,[32, 128]both directionsload_tile/store_tileComposed is cheaper by 16 registers, no spills either way. So: no in-place
form, and no regression to report other than the +2 above.
Device coverage
Rebased on
085cf3d(#9 landed mid-flight, and softmax now runs), so15 → 18 cases with #41's three; all green on a B200. The TMEM half needed no new case, which
is the point:
fragment map (16,16)/(32,32)/(32,128)andsttm restagearehardware validation of
drain_band/stage_band, and they now callTmemTile::tile/store_tileunchanged.The shared half had none — nothing in the harness monomorphized
ldst::load_tile/store_tile, so they would have shipped both unmeasured andunvalidated.
band round tripcopies rows0..32of a[64, 128]staged tileinto its rows
32..64through both composed movers. 128 columns crosses thestacked-subtile stride, and the store's row base is non-zero: the two ways a
composition loop can be wrong that a single
[16, 16]block cannot show.And, because #9 landed first, the shared pair is now exercised by a whole
kernel on hardware as well:
One host test comes with the helpers (
block_placement_is_the_composed_ coordinate): it ties the movers' storage indexing toRegTile::coordinateinboth directions, which is the invariant
reg.rsstates and nothing previouslyimplemented.
Examples
gemm— the twelve-line drain loop isaccumulator.tile(32 * warp_id, 0).Still runs.
softmax— both hand-written loops gone; the body is four calls. Itsheader no longer records the doubled loop as a cost. It was aspirational when
I started and blocked on TMA store path #9 alone; TMA store path, and softmax runs #41 landed that mid-flight, so it now
runs — and its run is the strongest available test of the shared-side
pair. Nothing is left missing here: its blocked-on column is empty.
flash_forward—scores.drain(...)→scores.tile(...),store_tile(p, ...)→store_tile(p.chunk_writer(), ...). BothWANT (#22)blocks deleted. Remaining errors are Direct global to/from register load and store #11 (
store_rows), RegTile's shape set is closed to out-of-tree kernels #23(
FragmentLayout<32, 64>), Masking and shape utilities: make_causal, tril/triu, fills, transpose #7 (make_causal_at), The map mechanism needs in-place variants: by-value costs 87 registers at 128 columns #31/Generic map mechanism and the standard elementwise op set #5 (scale,add_assign) — no mover error left.layernorm— theload_tile/store_tileit already named now resolve.Remaining: Shared vectors, and ops on shared tiles #13, Block-scope reductions: the fold four warps need, and the fp32 Element under it #3, scalar broadcasts (TMA store path #9 is gone from its list too).
examples/README.md— status table and blocked-on lists (Movers work in [16,16] blocks; every kernel rewrites the same composition loop #22 offflashand
layernorm; merged with TMA store path, and softmax runs #41's rewrite of the same rows), the intro paragraph, item 1's tail, and §"Came from writingkernels" item 2 struck through as closed with the register numbers. §9's
lane-passing bullet no longer calls
load_tile/store_tileinvented.GAPS.md§2.1 and §2.1a: the[16, 16]granularity note no longer sayscomposition is the caller's.
Verified
modal run modal_app.py::build— clippy on all three crates, host tests (47),real
cargo oxide build --arch sm_100afordevice-testsand the examples.modal run modal_app.py::regcount— four runs: before, after, thehand-written shared-band A/B, and a re-measure after the rebase (identical to
the after column).
modal run modal_app.py— 18/18 on a B200.modal run modal_app.py::examples—gemmexact,softmaxwithin 2e-3, on aB200. Two GPU runs rather than one:
softmaxbecame a running kernel underme, and this PR rewrites its inner loop.
cargo clippy --all-targets,cargo fmt --checkclean in all three crates.Closes #22