Repository navigation
Description
Found by the 2026-07-29 library audit (GAPS.md §7). Two halves of one thing:
the TMEM surface is typed everywhere except at the two points where being untyped
has already cost something.
1. alloc_block/alloc_cluster take a runtime columns: u32 and check nothing
pub unsafe fn alloc_block(slot: *mut u32, columns: u32) -> u32
pub unsafe fn alloc_cluster(slot: *mut u32, columns: u32) -> u32tcgen05.alloc requires a power of two in [32, 512]. Nothing in these
signatures can see the argument, so flash_forward asked for 192 from the day
it was written and nothing caught it — no launcher, no codegen assert, no
runtime check. It now carries the rule itself
(examples/src/flash_forward.rs:203-209) and says why in its own doc at
191-196: "the column count is an argument to an instruction, so no type and no
const assertion was ever in a position to see it."
A const COLUMNS: u32 parameter puts it in a position to see it. A
post-monomorphization const { assert!(..) } fires at codegen, which is exactly
the class of failure tier 2 exists to catch (CI.md), and every caller in the
repo passes a constant already: TMEM_COLUMNS (flash_forward.rs:202),
BLOCK_N as u32 (gemm.rs:2707), ACCUM_COLUMNS (gemm_ws.rs:1121).
While there: the columns are also passed a second time to dealloc_*, where
they must match, and nothing checks that either. A const parameter makes the
pair type-checkable.
2. Every MMA entry point takes a bare u32 where a TmemTile exists
mma::mma_abt, mma_ab, mma_atb, mma_atbt, mma_walk_cg2 and their four
mm_* twins all take tmem: u32. TmemTile<R, C> is the crate's type for
exactly that address, it knows R and C, and the MMA is the only thing that
writes it. src/mma.rs:84-88 says so itself:
The accumulator stays fp32 because a walk names TMEM by a bare
u32and has
no accumulator type to read one off; fp16 accumulation is a.kind::f16-only
mode no kernel here uses, and threading a typed accumulator through belongs
with whatever gives the walks acrate::tmemtile instead of an address.
Three things that costs today:
MmaShapeis a fourth argument the accumulator already implies.
examples/src/gemm.rs:545-551is aconst fn pair_shape(block_n) -> MmaShape
thatpanic!s on an unmatched width — a lookup from a tile's columns to a
shape, written in a kernel, because the type that knows the columns is not in
the call.mma_abaccumulates intotmem + band * 64(src/mma.rs:187), i.e. it
doesTmemTile::columns_right's arithmetic on a raw integer.- fp32 accumulate is hardcoded in
descriptor, and cannot be otherwise while
there is no accumulator type to read it off.
Scope
alloc_block::<COLUMNS>/alloc_cluster::<COLUMNS>with the legality assert
in aconstblock, anddealloc_*taking the same parameter. Keep a runtime
escape hatch only if something needs it — nothing in tree does.- Let the MMA walks take
TmemTile<M, N>instead ofu32, derivingMmaShape
from(M, N)where a legal shape exists and rejecting at codegen where it does
not. This subsumespair_shape. - Do not thread an accumulator element type in this issue. fp16 accumulate
is a separate ask with no caller; the point here is that the type becomes
possible, not that it lands.
Estimate
Part 1 is ~30 lines and a mechanical sweep of five call sites. Part 2 is ~80
lines in src/mma.rs, and the risk is the MmaShape derivation: the shape set
is the ISA's and not every (M, N) has one, so the mapping has to reject rather
than round. device-tests' five mma A·Bᵀ … mma transpose control cases are
the existing check.
Related: #124 (the allocators' scope is also implicit), #16 (fp8, which touches
MmaElement but not this), #12 (which closed the operand-order square and left
the accumulator untyped).
Activity
feitreim commentedon Jul 29, 2026
Upgrade note (
20a5616): cuda-oxide adds helpers for the conventionalmma.m16n8k16accumulator layout in5c428ed, extended with logical-extent masks in13fab63.This does not directly type tcgen05 TMEM accumulators: it maps per-lane register fragments for the older warp MMA shape, while this issue is about
TmemTile<M, N>and tcgen05 addresses. It is still worth using as an API/design reference for coordinate decoding, validity masks and rejecting impossible extents rather than silently rounding them.mma_ab's shape is the band's, and the two callers that read it as the…
The TMEM column count and the MMA shape are the accumulator's, and th…
The accumulator note says what #203 did, and the access ladder is a t…