Skip to content

The accumulator note says what #203 did, and the access ladder is a type the drains must cover - #219

Merged
feitreim merged 1 commit into
mainfrom
fix/compressed-api-audit
Aug 6, 2026
Merged

feitreim merged 1 commit into
mainfrom
fix/compressed-api-audit

Conversation

@feitreim

@feitreim feitreim commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Two finds from today's compressed-API audit. Neither changes what any kernel
emits; one is prose and one is a match shape.

1. mma::descriptor's note pointed at an issue that closed

The hardcoded Tcgen05AccumulatorType::F32 was explained as waiting on
"whatever gives TmemTile an element (#128 deliberately did not)", which reads
as a future home that #128 was next to. It is not: #203 closed #128 by typing
the walks' accumulator address — TmemTile<M, N> in place of a u32, and
MmaShape derived off it — and explicitly stopped there ("No accumulator
element type. fp32 accumulate stays hardcoded in descriptor").

So the true statement is that fp16 accumulate is a .kind::f16-only mode with
no caller, TmemTile carries no element type, and threading one through is
owned by nothing and asked for by nobody. The note says that now, citing
#128/#203 as what happened. No new issue filed — there is no ask to record.

docs/library/mma.md states the same fact and already reads as past tense
(#128 gave the walks the tile and deliberately stopped there), so it is
untouched.

2. access_width's rung set is a type, and the drains cover it

The 16/8/4/2 ladder was correct, but access_width returned a usize and both
consumers ended in _ =>. A fifth rung added to the ladder would have arrived
silently at the 4-byte arm of store_shared_rows and accumulate_shared_rows —
a wrong-width access at a cursor that does not admit it, which is a fault or
worse, and nothing would have failed to compile.

The shape: a #[repr(usize)] enum, public, discriminants equal to the byte
counts.

pub enum AccessWidth { Bytes16 = CHUNK_BYTES, Bytes8 = 8, Bytes4 = 4, Bytes2 = 2 }

Exhaustiveness over usize is not a thing Rust can check, so a match that
fails to compile on a new rung has to be a match on a closed set. The
alternatives and why not:

  • usize return plus a const assert at the arms — an assert can only fire
    at codegen for a width the ladder returns at runtime, which is a panic in a
    kernel rather than a compile error, and it is not the ask.
  • A private enum behind an unchanged pub fn access_width(..) -> usize —
    zero churn outside global.rs, but it leaves the same hole one level up: a
    public function whose whole point is that the rung set is closed, handing back
    an integer that says otherwise. Two names for one thing to avoid touching
    three call sites is the wrong trade.

AccessWidth::bytes() reads the count back for a caller doing arithmetic. Call
sites stay clean: the drains match four named arms, and the ladder's own tests
name the rung instead of an integer.

The E::BYTES == 2 guard is preserved, as an if inside the named arm:

AccessWidth::Bytes2 => {
    if E::BYTES == 2 {
        drain_in_accesses::<2, E, R, C, S, THREADS>(dest, row, column, thread, tile)
    }
}

Const-false at a 4-byte element, which is what kept the 2-byte drain from being
emitted for one and still does. The old guard fell through to the _ => 4-byte
arm when false; this arm does nothing instead. Both are dead code —
access_width cannot return Bytes2 at fp32, which is what
a_four_byte_element_never_descends_below_its_own_width pins.

Callers touched: the doctest, the two ladder tests (>= 4 became
assert_ne!(.., AccessWidth::Bytes2), which is the claim that test's prose
actually makes), and tests/gaps.rs' §2.2 record. No kernel crate calls
access_width directly.

Gates

GitHub Actions is in an outage, so tier 1 was run by hand rather than read off a
check. Everything below is a local or Modal run:

scripts/fmt --check clean, all four manifests
cargo test (root, device-only) 204 pass — 117 unit, 1 gaps, 86 doctests
cargo clippy --all-targets -- -D warnings (root) clean
cargo clippy --features host --all-targets clean (local cuda_cudart redist via CUDA_TOOLKIT_PATH)
RUSTDOCFLAGS=-D warnings cargo doc --no-deps --features host clean — the only gate on intra-doc links, and this diff adds three
cargo clippy --all-targets ×3 kernel crates clean against the changed library, same local route
scripts/modal-run build pass — clippy ×4, host tests, cargo doc --features host, cargo oxide build --arch sm_100a of all three kernel crates, the cublas FFI link, the vendored upstream build
scripts/modal-run regcount pass — occupancy steps held, census unmoved: 1 of 15 shipped kernels carries local memory, examples/flash_forward at 690 st.local / 383, the figure modal_app.py already records

regcount is here rather than skipped because Fix 2 restructures a match in two
shipped drains, and "the generated code is identical" is a claim worth a census
rather than an argument. It is.

device_tests and examples were not run: nothing in this diff changes an
instruction, a width, or a shape.

…ype the drains must cover

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.
@feitreim
feitreim merged commit f4354d0 into main Aug 6, 2026
feitreim added a commit that referenced this pull request Aug 7, 2026
…bles were never this tree's (#225) (#227)

`store_shared_rows` and `accumulate_shared_rows` match `access_width_bytes` —
three cases and a wildcard — instead of matching `AccessWidth` exhaustively. The
enum stays exactly what #219 made it, and `AccessWidth::RUNGS` keeps the
guarantee the exhaustive match was there for: a rung added to the type is a
compile error at both drains.

The reason is what an exhaustive match spells. Four arms lower to
`switchInt(.., [16, 8, 4, 2, otherwise: unreachable])`, so a rung a caller has
constant-folded away — a compile-time leading dimension, a known column — is
materialised back into a live switch case, and LLVM tables a switch at four
cases where it branches at three. That is how oxide-train's
`gemm_tcgen05_bf16_optimized` acquired four `brx.idx` tables at #219 and lost
its module to `DriverError(218)` at `cuModuleLoadData` (#225, oxide-train #127).
A wildcard lets the dead rung fold.

**The tables were not new here, and that is measured.** At 3ae07a8 — the commit
before #219 — this tree's PTX already carried 51 of them, and at bda3329 it
carries the same 51 plus the four kernels that did not exist yet. Every count
identical. They load: `device_tests`, `examples`, `kittens-experiments -- check`
and `bench --case gemm-sol` all run on a B200 on driver 580.95.05, the driver in
the report. ferro's four-rung bf16 drains table; its three-rung fp32 drains
never do, which is the in-tree control on where the threshold is.

So `regcount` grows a **jump-table census** rather than a gate — `brx` per entry
function, beside the local-memory depot, on the substrate `ptxas` never reports
and a runtime compiler can refuse. A gate would fail every run of a tree that
works; what was missing was a column to diff, which is exactly what the consumer
had to run in their own repo to find this.

`device-tests` grows `shared_drain_quad`: every drain in one entry, the
consumer's shape, in a module the harness JIT-loads on every run at no extra
container and no extra device time. It loads here — four tables in one entry are
not what a JIT refuses — and it is the standing check for a driver that changes
its mind.

Codegen unmoved: 317 kernels, every register, spill, stack and smem counter
identical to main, and no kernel gains or loses a table.
feitreim added a commit that referenced this pull request Aug 7, 2026
…is a gate (#225) (#229)

* The jump tables were #219's after all, and the census that missed it is a gate (#225)

Three readings of `regcount`'s jump-table census, each from a build that
`_freshen` (#228) forced and whose four crates are seen to recompile in the
container log, same image and same pinned nightly:

    3ae07a8   #218, before the access ladder        0 of 309
    bda3329   after #219, before #227              55 of 318   (9 shipped)
    09beda9   main, after #227                      0 of 319

#219 introduced every `brx` in this tree and #227 removed every one of them,
which is the consumer's bisect exactly. #227 reported the opposite -- 51 already
present at 3ae07a8, identical counts across its own fix -- from a comparison
taken across the warm cache volume #228 later found serving stale builds. Both
numbers are superseded. 3ae07a8 has no `AccessWidth` to match on at all, so
zero is the only count that tree can produce.

Half of #225's "necessary but not sufficient" survives and half does not. No GPU
entry point mounts the cache volume (#226), so #227's B200 runs at then-main
really were runs of the 55-table tree and those modules really did load.
`shared_drain_quad` is the half that goes: it was added on the fix branch, after
the fix had put both drains back on a three-case dispatch, so it has never
carried a table and it is inside main's 0 of 319. Its doc said it demonstrated a
JIT taking four of them; it demonstrated nothing of the kind, and now says so.

So the census arms on the condition it set for itself. A kernel in the shipped
set -- `examples/` plus `GATED_KERNELS` -- carrying a `brx` fails the run;
probes are printed and do not, the way the local-memory depot's are. The table
stays as the diagnostic.

Watched in both directions: green at this branch (0 of 319) and red at bda3329's
sources under the same armed `modal_app.py`, naming the nine shipped kernels.

* The access ladder's note carries the in-tree numbers, not only the consumer's
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.

TMEM columns are an unchecked u32 and the MMA takes a raw address, not the TmemTile that exists

1 participant