Repository navigation
The TMEM column count and the MMA shape are the accumulator's, and the types say so now (#128) - #203
Merged
Merged
Conversation
…e types say so now (#128) `tmem::alloc_block` / `alloc_cluster` took a runtime `columns: u32` straight to an instruction operand, so `tcgen05.alloc`'s power-of-two-in-`[32, 512]` rule had nothing in a position to see it and `flash_forward` asked for 192 from the day it was written. They take `const COLUMNS: usize` and assert the rule in a `const` block, which fires at codegen — tier 2's job. `dealloc_*` takes the same parameter, so the pair that has to agree is type-checked. All nine MMA entry points took a bare `u32` accumulator plus an `MmaShape`, where `TmemTile<R, C>` already knew that shape. They take the tile. `mma::shape` reads the instruction off `[M, N]` and `mma::pair_shape` off one rank's, and both **reject**: the set is the ISA's, `M ∈ {32, 64, 128}` by `N ∈ {64, 128, 256}` at `cta_group::1` and 128 rows a rank by the same `N` at `cta_group::2`, so a `[128, 192]` is a codegen error rather than an `M128_N256` writing 64 columns of whatever is after it. `cta_group::2` is a second lookup and not `shape(2 * m, n)` because a 32-row rank tile doubles to `M64`, legal for one CTA and no shape at all for a pair. Three kernel-side `const fn`s from a tile width to a shape, each with a `panic!` for its default arm, are gone with it. The four typed walks gain no parameter — the accumulator is `[AR, BR]`, `[AR, N]` or `[M, N]` in const parameters they already had, which is one more thing the operands and the accumulator now have to agree about. `mma_walk_cg2` erases its operands' types, so its `M` and `N` are new and its callers write `::<Bf16, CHUNKS, _, _>`. No runtime escape hatch. The one caller with genuinely no constant is `device-tests`' `tmem_ladder_runtime`, whose whole point is a column count `ptxas` cannot record; it writes `alloc_block`'s body out by hand, as `tmem_ladder_none` already writes it with the allocator removed. `gemm_sol`'s `small_body` gains `ACCUM_COLUMNS` and `fragment_probe` gains `HELD`, both for the reason `HALF_N` sits beside `BLOCK_N`: a const argument cannot be arithmetic on a const parameter, and each is held to its `N` by an assert. Not done here, deliberately: the accumulator has no element type, so fp32 accumulate stays hardcoded in `descriptor`. The point is that the type is now in a position to carry one.
… to see 192 is the allocator's now
feitreim
added a commit
that referenced
this pull request
Aug 6, 2026
…are (#204) #198 and #203 each merged green and composed into a build error: the STTM probe was written against the untyped MMA surface (#198), which #203 removed. The probe now speaks the typed one — alloc_block::<COLUMNS>, the two [128, 64] halves via split_columns/columns_right, and the shape argument gone because the tile is the shape. Same instructions, same launch, no semantic change.
feitreim
added a commit
that referenced
this pull request
Aug 6, 2026
…ype the drains must cover (#219) Two finds from the compressed-API audit, neither of which changes what any kernel emits. `mma::descriptor`'s note read as though a typed accumulator were waiting on #128. It is not: #203 closed #128 by typing the walks' accumulator *address* and deliberately stopping there, so an accumulator element type is owned by nothing and asked for by nobody. The note now says that. `access_width` returned a `usize` and both drains ended in `_ =>`, so a fifth rung would have arrived at the 4-byte arm instead of failing to compile. It returns `AccessWidth` now, a `#[repr(usize)]` enum whose discriminants are the byte counts, and `store_shared_rows`/`accumulate_shared_rows` name every rung.
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.
Closes #128.
Both halves of §7.5: the two places the TMEM surface was untyped are the two
places being untyped had already cost something.
1. The column count is a
constparameteralloc_block/alloc_cluster/dealloc_block/dealloc_clustertakeconst COLUMNS: usizeand asserttcgen05.alloc's rule — a power of two in[32, 512]— in aconstblock, which fires at codegen.dealloc_*takesthe same parameter, so the pair that has to agree is type-checked rather than
remembered.
flash_forwardsheds the rule it was carrying by hand and keeps only the halfthat is its own (
TMEM_COLUMNS >= KEYS + HEAD). The doc example onTmemTile::split_columnswas itself allocating the illegal 192 and now says whyit cannot.
No runtime escape hatch. The one caller in the tree with genuinely no
constant is
device-tests'tmem_ladder_runtime, whose entire purpose is acolumn count
ptxascannot record — "only the first can see a constant, andthis rung has none to see". It writes
alloc_block's body out by hand, exactlyas its sibling
tmem_ladder_nonealready writes it with the allocator removed.An escape hatch on the library entry point would be a hole in the assert for the
sake of one probe whose point is to be illegible to it.
2. The walks take the accumulator, and derive the shape
All nine entry points take
TmemTile<M, N>instead ofu32, and none takes anMmaShape.The derivation, and what it rejects. Two lookups, both
const fn, both insrc/mma.rs:MNmma::shape(m, n)—cta_group::1mma::pair_shape(m, n)—cta_group::2, one rank's tileAnything else
panic!s in aconstblock, i.e. fails at codegen. Nothingrounds: a
[128, 192]accumulator rounded up toM128_N256would write 64columns of whatever segment sits after it, which is #175's failure arriving from
a different direction.
cta_group::2is a second lookup and notshape(2 * m, n)becauseM256isthe pair's only class: a 32-row rank tile doubles to
M64, which is a legalshape for one CTA and no shape at all for a pair. That case is a unit test.
The four typed walks gain no generic parameter. The accumulator is
TmemTile<AR, BR>formma_abt,TmemTile<AR, N>formma_abandTmemTile<M, N>formma_atb/mma_atbt— const parameters those signaturesalready had. So the operands' shape and the accumulator's are now one thing the
type checker holds together, on top of losing the shape argument.
mma_walk_cg2/mm_walk_cg2erase their operands intoOperandWalk, so theirMandNare new. A const parameter cannot be elided from a turbofish thatnames any other, so callers write
mma_walk_cg2::<Bf16, CHUNKS, _, _>— the two_are read off the tile, and writing them out would be the caller restatingwhat the argument already says.
Three
pair_shapelookups deleted, not one:examples/src/gemm.rs,examples/src/gemm_sol.rs(asmma_shape) andexperiments/src/gemm.rseachhad a
const fnfrom a tile width to a shape with apanic!for its defaultarm. That was the only thing in the repo checking an accumulator against the ISA.
Every shape in the tree is unchanged by the derivation — checked one call site at
a time before the first Modal run, and confirmed by the device cases.
Two call sites gained a const parameter, and why
generic_const_exprsis not on, so a const argument cannot be arithmetic on aconst parameter. Two bodies allocate a multiple of a generic width:
gemm_sol::small_bodygainsACCUM_COLUMNS(was2 * N as u32)device-tests'fragment_probegainsHELD(wasif RESTAGE { 2 * COLUMNS })Each is held to its own
Nby aconst { assert!(..) }, which is the patternexperiments/src/gemm.rsalready uses and documents forHALF_NbesideBLOCK_N. The 22small_body::<..>instantiations acrosssol_ablateandsol_watchare the mechanical part of the diff.Explicitly not done
No accumulator element type. fp32 accumulate stays hardcoded in
descriptor;fp16 accumulate is a
.kind::f16-only mode with no caller. The point is thatTmemTileis now in a position to carry one.Gates
cargo test(host, 199 incl. doctests)scripts/fmt --checkscripts/modal-run buildcargo doc --features host,cargo oxide build --arch sm_100aof all three kernel crates, thecublasFFI link, the vendored upstream buildscripts/modal-run regcountflash_forwardat 690st.local, the figuremodal_app.pyalready recordsscripts/modal-run device_testsmma A·Bᵀ,mma A·B,mma Aᵀ·B,mma Aᵀ·Bᵀ,mma transpose control— plusfragment map×3,tmem occupancy ladder(6 rungs, allocations balanced),tmem residency census,repeated launchscripts/modal-run examplesThe tier-2 build is the load-bearing one here: a post-monomorphization
const { assert!(..) }is invisible tocargo check, and this change adds sixof them.