Repository navigation
Audit the library whole: three doc claims were wrong, and the surface says scope four ways - #133
Merged
Merged
Conversation
… 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.
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.
src/is 10 156 lines and nobody had read it whole since it grew. This is thatread, 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 —
StoreRingsat uncalled from #111 until #123 turned outto 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 established1.
reg.rs's module header said the measurement does not favour the SFUexp2. It said so on a register count —softmax_probe_128going 168 → 255with 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 alreadyrecords 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.approxserializes where the FMA chain schedules" claim beside it had noprobe behind it and is removed rather than restated. The default does not
move:
exp2still resolves toExp2Approx, because that is a numericsdecision, it is #81's, and
flash_forward— the other caller, twice per elementin its inner loop — has no reference to check one against.
2.
tmem.rs's occupancy table saidgemmallocates 128 columns and is cappedby 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 whatalloc_cluster(tmem_slot, BLOCK_N as u32)(2705) anddealloc_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 halfof an SM, and
staged_ctas_per_sm(609) is thatmin— so tensor memory isthe term that binds
gemmnow, which is the opposite of what the module said.3.
ldst.rs's three store contracts required "all 32 lanes of the warp owningTMEM rows
row..row+16". Established by reading the module: nothing inldst.rsnames a TMEM address —store_fragmenttakes aSwizzledChunksand aregister
Fragment, androw/columnare the shared tile's. The clause istmem.rs's, where it is correct, and it drifted onto the store side only: theload side (
load_fragment) never had it. Corrected while there:store_fragment_x4inherited "the 16 addresses come from lanes 0..15", which isthe
.x2fact — the.x4takes 32.4. Two
#56citations inreg.rsthat cannot be to this repo's #56. Thesentences date from commit
6ad92f5(2026-07-27); issue #56 was created2026-07-28T01:53 and is about
softmax's seed permutation. Replaced with whatis checkable:
ex2_approx_f32is a generated intrinsic incuda-device'sfloat.rsat the pin, so it needs no libdevice call.GAPS.mdRe-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:
GlobalRowsis fp32 only. It has carried anElementsinceC should be bf16, the accumulator should not, and the cuBLASLt baseline has to move with it #108. This is the section's own failure mode and the worst find in the audit,
made worse by the paragraph having been written as the reason a bf16
Cwasout of reach — so it read as an argument and nothing prompted a re-read.
pipeline::runis uncalled by anything inexamples/.gemmhasrun on it since The cap was the whole story: gemm adopts pipeline::run at a dead heat (#51) #83. §4 also predated
run_stealing,groupedand lcsf and the rest of the prototype layer #15'sclosure, all of which it now carries.
Corrected against a checkout of the pin whose
HEADI confirmed to beb099f64c1a32869b74be99f4f88242fb68655b51before reading anything from it(#106's rule — there are six cuda-oxide checkouts on this machine and five are
not our pin):
int_nvvm_cp_async_bulk_prefetch_L2and the tensor forms are inintrinsics/imported.jsonat the pin, with their PTX; only the generated Rustwrapper is missing.
cp.reduce.async.bulk.tensoris absent from the intrinsicdatabase entirely. Recorded on Reduction TMA stores (cp.reduce.async.bulk.tensor): upstream to cuda-oxide rather than ptx_asm! locally #42.
stmatrix"we usex2only" — we use both since The epilogue's stores were the wrong shape, and stmatrix fixes 20% of them (#15) #116.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.rsgains six never-instantiated generic functions naming what thenew and rewritten entries claim landed: the element-generic global movers, the
staged-drain pair, the
.x8TMEM drain, the store ring'sScope, the clustercharge and the operand-order square, and both item sources.
Issues filed
StoreRing) and spelled three other ways (Job::RANKS,block_reduce'sWARPS,store_shared_rows'THREADS);ScopeandRANKSare adjacent rungs of one ladder built twice with no rung in commondrain_stagedis verbatim identical in both GEMMs and is whatSHIPPED_EPILOGUEselects;epilogue.rsholds only the TMA route, which #123 measured losing to itlanethe crate gives no way to obtain, and the proxy fence its own contracts oblige is privatealloc_blocktakes an unchecked runtimecolumns; the MMA takes a bareu32whereTmemTileexistsfrom_rawvsattach, theunsafeboundary, the missing load verb and the root re-exports each pick two conventionsRegVeccannot reach memory at all,SharedVeccannot be sliced, neither folds in placeldmatrix.x2while the store side got.x4Jobhas no teardown hook; nine entry points in one file remember the drain by handPlus comments on #14 (
ATOM_BYTESis also the walk step, which is whygemmre-wraps subtiles to walk aBLOCK_K = 128stage — and the multi-atomOperandWalkhalf 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
kittensobjects whose sizeskittensalready knows. It is also the cause of three of the four intrinsicleaks in #127 —
DynamicSharedArray::get_raw, the*mut Barriercast, and the8 bytes
alloc_clustermakes the caller find and align. ~150-250 lines, and theregression suite already exists as five literals (
98_392,114_816and threesmaller). The design risk is real and worth naming: the total has to be usable
in a
#[launch_contract]literal, so the arithmetic must beconst fnover thesame 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.rsopens 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 thesingle-shot TMA store
softmaxandlayernormopen-code as a third shape, andthe correctness bar needs nothing new: both GEMMs check
Celement-exact.3. #127, the lane and the fence. By far the best value per line in the
audit, ~40 lines.
flash_forward.rs:133claims "Nothing in this file reachespast 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 doingalongside 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
constblock) is ~30 lines and is the one finding wherethe absence has already let something through —
flash_forwardasked for anillegal 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
attributed to the run that produced it (softmax is now the slow kernel by 5.8x, and its CHUNK rung is only a quarter of it #76, The LDTM half was the wait, not the issue: .x8 is +23.6/+8.6/+3.6% and #109's 8.3 us closes to 8.07 (#117) #117, The TMA store loses, and the CTA-wide ring is the better of the two (#123) #123) and none was re-taken.
The
reg.rscorrection changes what the doc says the measurement was, notwhat the measurement is.
ldmatrix.x4wins (The shared to register load side is stuck at ldmatrix.x2 while the store side got .x4 #131). The addressing transfers from the storeside for free; the liveness cost does not, and
.x8's 23.6% came from removingwaits that a shared-memory load does not have. Filed as a measurement, not a
transcription.
stmatrixdeclarations really fail to resolve forsm_100a, whichldst.rsgives as the reason both stores go through localptx_asm!. I confirmed the functions exist at the pin; confirming the loweringfailure needs a build that calls them, which I did not attempt.
lib.rs's claim that libdevice math is legal beside tcgen05 in one pure-PTXartifact at
b099f64. A codegen fact; I built no kernel that mixes them.TmemTile::from_rawbeing safe is a decision or an oversight. Icould not find a rule that separates it from
SharedTile::from_raw, so Handle constructors, the unsafe boundary, the load/store verbs and the root re-exports each pick two conventions #129asks for the rule rather than asserting an answer.
RegVec's missing bridge has ever blocked a kernel. No kernelasked for it; the finding is the asymmetry against
ColVec, not a report froma caller.
epilogue.rs's "until The 16384-cubed instrument was never valid, and the fix is a shorter K (#122) #122". TheScopetrait landed in PR The TMA store loses, and the CTA-wide ring is the better of the two (#123) #123 — theonly commit that touches it — but "until The 16384-cubed instrument was never valid, and the fix is a shorter K (#122) #122" is a defensible reading of "up
to and including The 16384-cubed instrument was never valid, and the fix is a shorter K (#122) #122". Left alone rather than counted as an error.
One thing this PR cannot fix and that now openly contradicts it:
examples/src/flash_forward.rscarries the refuted "a CTA is charged the SM'swhole tensor memory" reasoning in three places (96-102, 104-107, 198-201), which
src/tmem.rshas said is wrong since #84 and says more pointedly now. #85already records the housekeeping;
examples/belongs to the concurrentrestructure.
Gates
Tier 1:
scripts/fmt --check,clippy --all-targets -- -D warnings,cargo test(94 + doctests),cargo docunderRUSTDOCFLAGS=-D warnings— allgreen locally.
Tier 2:
scripts/modal-run buildgreen — 104 host tests, the--features hostdoc gate clean under-D warnings, andcargo oxide build --arch sm_100aof both kernel crates. Expect a rebase:
examples/is being restructuredconcurrently and this branch reads it but does not touch it.