Skip to content

Audit the library whole: three doc claims were wrong, and the surface says scope four ways - #133

Merged
feitreim merged 3 commits into
mainfrom
audit-library-surface
Jul 29, 2026
Merged

feitreim merged 3 commits into
mainfrom
audit-library-surface

Conversation

@feitreim

Copy link
Copy Markdown
Owner

src/ is 10 156 lines and nobody had read it whole since it grew. This is that
read, against the three areas Finn picked: API coherence, missing
coverage
, docs vs reality. No API changed. Findings are issues; the only
edits here are documentation corrections, where a stale doc is the finding and
the fix.

Dead code is deliberately not the report. Library code with no caller in this
repo is not a defect — StoreRing sat uncalled from #111 until #123 turned out
to want it. Where an uncalled primitive appears below it is because its contract
is confused, never because nothing calls it.

Doc corrections in src/, and how each was established

1. reg.rs's module header said the measurement does not favour the SFU
exp2.
It said so on a register count — softmax_probe_128 going 168 → 255
with 112 B of spill — and #76 timed the same swap on the real kernel at 50 regs
/ 128 B frame / 1178 GB/s against 48 / 0 / 3153 GB/s. 2.7×, the wrong way.
Established by reading #76's table through #81, which was filed against this
exact sentence, plus examples/src/softmax.rs:162-171, where the kernel already
records the contradiction and says it is not resting there. I did not re-run
it — the numbers are attributed to #76 in the doc, not asserted fresh. The
"ex2.approx serializes where the FMA chain schedules" claim beside it had no
probe behind it and is removed rather than restated. The default does not
move
: exp2 still resolves to Exp2Approx, because that is a numerics
decision, it is #81's, and flash_forward — the other caller, twice per element
in its inner loop — has no reference to check one against.

2. tmem.rs's occupancy table said gemm allocates 128 columns and is capped
by shared memory at 3 CTAs where its columns would allow 4.
Established by
reading examples/src/gemm.rs: const BLOCK_N: usize = 256 (line 357) is what
alloc_cluster(tmem_slot, BLOCK_N as u32) (2705) and dealloc_cluster (2849)
pass since #104 promoted the pair tile. Tensor memory now admits 2, the staged
plan STAGED_SHARED_BYTES == 114_816 (627) admits 2 against the 116 736 B half
of an SM, and staged_ctas_per_sm (609) is that min — so tensor memory is
the term that binds gemm now
, which is the opposite of what the module said.

3. ldst.rs's three store contracts required "all 32 lanes of the warp owning
TMEM rows row..row+16".
Established by reading the module: nothing in
ldst.rs names a TMEM address — store_fragment takes a SwizzledChunks and a
register Fragment, and row/column are the shared tile's. The clause is
tmem.rs's, where it is correct, and it drifted onto the store side only: the
load side (load_fragment) never had it. Corrected while there:
store_fragment_x4 inherited "the 16 addresses come from lanes 0..15", which is
the .x2 fact — the .x4 takes 32.

4. Two #56 citations in reg.rs that cannot be to this repo's #56. The
sentences date from commit 6ad92f5 (2026-07-27); issue #56 was created
2026-07-28T01:53 and is about softmax's seed permutation. Replaced with what
is checkable: ex2_approx_f32 is a generated intrinsic in cuda-device's
float.rs at the pin, so it needs no libdevice call.

GAPS.md

Re-dated to 2026-07-29, and two entries removed that had gone stale inside a
day
— both landed 2026-07-28, the same day #65 re-read the entries they
falsified:

Corrected against a checkout of the pin whose HEAD I confirmed to be
b099f64c1a32869b74be99f4f88242fb68655b51 before reading anything from it
(#106's rule — there are six cuda-oxide checkouts on this machine and five are
not our pin):

And §7 is new: the coherence of the surface itself, which no comparison
against ThunderKittens finds. It is where most of the audit went.

tests/gaps.rs gains six never-instantiated generic functions naming what the
new and rewritten entries claim landed: the element-generic global movers, the
staged-drain pair, the .x8 TMEM drain, the store ring's Scope, the cluster
charge and the operand-order square, and both item sources.

Issues filed

# Finding Area
#124 Scope is in the type once (StoreRing) and spelled three other ways (Job::RANKS, block_reduce's WARPS, store_shared_rows' THREADS); Scope and RANKS are adjacent rungs of one ladder built twice with no rung in common coherence
#125 The shared plan is open-coded in bytes, twice per kernel, in all five kernels; the two GEMM walks are the same program coverage
#126 drain_staged is verbatim identical in both GEMMs and is what SHIPPED_EPILOGUE selects; epilogue.rs holds only the TMA route, which #123 measured losing to it coverage
#127 Every register-side entry point takes a lane the crate gives no way to obtain, and the proxy fence its own contracts oblige is private coherence
#128 alloc_block takes an unchecked runtime columns; the MMA takes a bare u32 where TmemTile exists coherence
#129 from_raw vs attach, the unsafe boundary, the missing load verb and the root re-exports each pick two conventions coherence
#130 RegVec cannot reach memory at all, SharedVec cannot be sliced, neither folds in place coverage
#131 The load side is stuck at ldmatrix.x2 while the store side got .x4 coverage
#132 Job has no teardown hook; nine entry points in one file remember the drain by hand coverage

Plus comments on #14 (ATOM_BYTES is also the walk step, which is why
gemm re-wraps subtiles to walk a BLOCK_K = 128 stage — and the multi-atom
OperandWalk half is separable from the swizzle work) and #42 (prefetch,
above). Nothing filed against #16, #49, #81, #85 or #105, which already cover
what the audit found in their areas.

If we did three things to this library next

1. #125, the shared plan. The largest single thing every kernel writes for
itself, and almost all of it is arithmetic over kittens objects whose sizes
kittens already knows. It is also the cause of three of the four intrinsic
leaks in #127 — DynamicSharedArray::get_raw, the *mut Barrier cast, and the
8 bytes alloc_cluster makes the caller find and align. ~150-250 lines, and the
regression suite already exists as five literals (98_392, 114_816 and three
smaller). The design risk is real and worth naming: the total has to be usable
in a #[launch_contract] literal, so the arithmetic must be const fn over the
same parameters the handles are.

2. #126, the epilogue. Second-largest duplication, and the sharpest
statement that the library is one step behind its kernels: src/epilogue.rs
opens with "the shared→global half of an epilogue", holds one type, and that
type drives the route #123 measured losing. The route that ships is 30 lines
written twice. Every instruction in it is already a library call — what is
missing is the loop and one Scope::converge. ~160 lines including the
single-shot TMA store softmax and layernorm open-code as a third shape, and
the correctness bar needs nothing new: both GEMMs check C element-exact.

3. #127, the lane and the fence. By far the best value per line in the
audit, ~40 lines. flash_forward.rs:133 claims "Nothing in this file reaches
past the library any more" and the claim is false in the kernel's first three
lines, in every kernel, because there is no kittens::lane(). Worth doing
alongside either of the above rather than as a session of its own.

Runner-up on a different axis: #128's first half (alloc_block::<COLUMNS>
with the ISA rule in a const block) is ~30 lines and is the one finding where
the absence has already let something through — flash_forward asked for an
illegal 192 columns from the day it was written, and its own doc says why
nothing was in a position to notice.

What I could not establish

One thing this PR cannot fix and that now openly contradicts it:
examples/src/flash_forward.rs carries the refuted "a CTA is charged the SM's
whole tensor memory" reasoning in three places (96-102, 104-107, 198-201), which
src/tmem.rs has said is wrong since #84 and says more pointedly now. #85
already records the housekeeping; examples/ belongs to the concurrent
restructure.

Gates

Tier 1: scripts/fmt --check, clippy --all-targets -- -D warnings,
cargo test (94 + doctests), cargo doc under RUSTDOCFLAGS=-D warnings — all
green locally.

Tier 2: scripts/modal-run build green — 104 host tests, the --features host doc gate clean under -D warnings, and cargo oxide build --arch sm_100a
of both kernel crates. Expect a rebase: examples/ is being restructured
concurrently and this branch reads it but does not touch it.

feitreim added 2 commits July 29, 2026 12:59
… says scope four ways

`src/` is 10 156 lines and nobody had read it whole since it grew. This is that
read, against Finn's three areas: API coherence, missing coverage, docs vs
reality. No API changes -- findings are issues, and the only edits here are
documentation corrections, where a stale doc is the finding and the fix.

Corrected in `src/`:

- `reg.rs`'s module header said "the measurement does not favour" the SFU
  `exp2`, on a register count. Timed on `softmax`, it is 2.7x the other way
  (#76/#81). The "ex2.approx serializes" claim had no probe and is removed, not
  restated. The default does not move: that is #81's call and `flash_forward`
  has no reference to check one against.
- `tmem.rs`'s occupancy table said `gemm` allocates 128 columns and is capped by
  shared memory at 3 CTAs. Since #104 it asks for `BLOCK_N = 256` and tensor
  memory is the resource that binds it.
- `ldst.rs`'s store contracts required "all 32 lanes of the warp owning TMEM
  rows row..row+16". Nothing in `ldst` touches tensor memory; the clause was
  `tmem.rs`'s, where it is correct, and the load side never had it.
- Two dangling `#56` citations in `reg.rs`, predating this repo's issue #56 by a
  day and unresolvable against it.

`GAPS.md` gains a section 7 -- the coherence of the surface itself, which no
comparison against ThunderKittens finds -- and loses two entries that had gone
stale inside a day: 2.2 said `GlobalRows` was fp32-only after #108 gave it an
element, and 4 said the pipeline scaffold had no caller after `gemm` had been
running on it since #83. Both are now named in `tests/gaps.rs`, along with the
`.x8` drain, the `.x4` store, the store ring's `Scope`, the cluster charge and
the operand-order square.

Nine issues filed (#124-#132) and two comments on #14 and #42.
@feitreim
feitreim merged commit bd74bee into main Jul 29, 2026
4 checks passed
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.

1 participant