Skip to content

The drains dispatch on the ladder's byte count again, and the jump tables were never this tree's (#225) - #227

Merged
feitreim merged 1 commit into
mainfrom
fix-225-brx
Aug 7, 2026
Merged

feitreim merged 1 commit into
mainfrom
fix-225-brx

Conversation

@feitreim

@feitreim feitreim commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Closes #225 — but not with the story the issue has, and the difference is worth
reading before the diff.

The fix

Both drains match access_width_bytes — three cases and a wildcard — instead of
matching AccessWidth exhaustively. AccessWidth, access_width and every
discriminant #219 introduced stay exactly as they were; AccessWidth::RUNGS
(variant_count) and a const { assert! } at each drain keep the one thing the
exhaustive match was there for: a rung added to the type is still a compile
error at both drains.

What an exhaustive match costs is not the typing, it is that it names every
rung whether or not the instantiation can reach one
. Measured on rustc's MIR,
same nightly, four spellings of the same dispatch:

dispatch MIR terminator cases
match AccessWidth, four arms (#219, main) switchInt [16, 8, 4, 2, otherwise: unreachable] 4
match AccessWidth, three arms + _ switchInt [16, 8, 2, 4, otherwise] — rustc re-adds the covered variant 4
if width == … chain over the enum three 1-case switchInts, re-merged by LLVM 4
match access_width_bytes, three arms + _ switchInt [16, 8, 2, otherwise] 3

LLVM tables a switch at four cases and branches at three
(MinimumJumpTableEntries; confirmed against llc -mtriple=nvptx64 -mcpu=sm_100a
on hand-written IR, where 4 cases → brx.idx and 3 → compares, with and without
a reachable default). So a caller whose leading dimension or column is a
compile-time constant folds a rung away and gets three — unless the match spells
the fourth back in. That is how oxide-train's gemm_tcgen05_bf16_optimized
acquired four brx.idx tables at #219. A wildcard lets the dead rung fold.

The reproduction, which failed, and what it found instead

The issue asks for a JIT-load reproducer on a B200. It does not reproduce, and
the negative results are the most useful thing here:

  1. The tables are not The accumulator note says what #203 did, and the access ladder is a type the drains must cover #219's, in this tree. regcount at 3ae07a8 (the
    commit before The accumulator note says what #203 did, and the access ladder is a type the drains must cover #219) already emits 51 jump-tabled entry functions; at
    bda3329 it emits the same 51, plus the four gemm_sol_*_early
    kernels that did not exist yet. Every count identical, no entry gained or
    lost one.
  2. They load. On a B200 on driver 580.95.05 — the driver in the report —
    device_tests (57/57), examples, kittens-experiments -- check and
    bench --case gemm-sol all run at main with those 55 tabled kernels in the
    modules they JIT-load.
  3. Four in one entry also load. device-tests' new shared_drain_quad
    calls both drains at both tile widths in a single kernel — the consumer's
    exact shape, 4 tables in one entry, against ferro's previous maximum of 2.
    Built at main, its module loads and the harness passes 57/57.
  4. The in-tree control on the threshold: the bf16 drains have four live
    rungs (16/8/4/2) and table; the fp32 drains have three, because
    access_width cannot return 2 for a 4-byte element, and never table — at any
    commit, under any of the four spellings above.

So brx is necessary in the consumer's failure — their opcode diff and bisect
are not in doubt — but it is not sufficient: whatever tips
cuModuleLoadData into DriverError(218) in their module is not the count, not
the construct alone, and is not reproducible from this repo. This fix restores
the lowering their green build had; if 218 survives it there, the remaining
variable is on their side and worth a fresh issue.

Why the guard is a census and not a gate

regcount grows a jump-table census beside the local-memory depot — brx per
entry function, the same substrate, for the same reason: ptxas never reports
it, and it is where a runtime compiler's refusal lives. It is a report,
because a gate would fail every run of a tree that works (55 of 318 at main,
and green everywhere). The thing nobody had was not a gate; it was a column to
diff. The regression downstream was one opcode class appearing in one module,
and it took a consumer's bisect to find because this repo measured registers,
opcodes and .local and never this. It arms into a gate if the shipped set ever
reads zero.

The device tier's half is shared_drain_quad: module load is whole-module, so
tier 3 exercises it by starting at all — no extra container, no extra device
time, and the only module in the tree with the consumer's shape. CI.md gains a
tier-2 section on the ptxas/JIT split that made this invisible.

Codegen and timing

regcount, main vs this branch, same arch, same container recipe:

result
register / spill st / spill ld / stack / smem 317 kernels, 0 counters differ
opcode census 88 gemm_* rows, 0 differ
jump-table census identical set, identical counts (+ the new probe)
occupancy-step gate green

bench --case gemm-sol, separate containers (the arms cannot share one across
two trees), with cuBLASLt in the same process as the control:

shape ours main ours here Δ cuBLASLt main cuBLASLt here Δ (unchanged binary)
4096³ 1457.9 1427.4 −2.1% 1709.1 1643.1 −3.9%
8192³ 2052.1 2008.2 −2.1% 2159.2 2148.3 −0.5%
16384³ 2140.5 2127.0 −0.6% 2163.5 2164.7 +0.1%

The unchanged baseline moves further than our arm does at the shape where our
arm moves most, and ours/theirs at 4096³ improves (0.853 → 0.869). With
every static counter identical, this is the container-to-container drift CI.md
prices at 2.9%, not the diff.

Gates

scripts/fmt --check, clippy --all-targets -D warnings, test (doctests
included) and doc --no-deps locally; regcount green on Modal CPU;
session --arms device-tests,bench:gemm-sol,examples green on a B200 —
57/57 harness cases, both example binaries, kittens-experiments -- check.

Follow-up

oxide-train is pinned at 3ae07a8 (#218) because of this (oxide-train #127).
Once this merges the pin can advance to ferro main — and that bump is also the
experiment that says whether the compare-chain dispatch is what their module
needed, which nothing in this repo can answer.

…bles were never this tree's (#225)

`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
feitreim merged commit b589b8a into main Aug 7, 2026
3 checks passed
feitreim added a commit that referenced this pull request Aug 7, 2026
feitreim added a commit that referenced this pull request Aug 7, 2026
…ow (#228)

* A wait on a device has a deadline, and an arm that wedges costs one row

`kittens::watchdog` polls the event behind a launch instead of blocking on it,
so a kernel that stops making progress ends the process in 30 s naming the row
the sweep last announced. Every host wait in the three kernel crates goes
through it. `session` now runs the arms after a failed one and summarizes, so
`bench --case sol-k` and `profile` -- barred from `ARMS` because a hanging
launch takes every row after it -- have arms. `wedge_demo` is the control.

Timeouts are re-derived from measured baselines with the baseline in a comment;
`device_tests` moves 1200 -> 300 against its measured 83.5 s.

* The cache volume was serving a stale build, and rustdoc is what said so

* The staging constructors synchronize too, and the demo is what found it

* CI.md carries the stale-build finding and the measurement that closes it

* The wedge belongs in front of the row's own launch, not in front of the process

* The spin says where it is, and its loop cannot be hoisted away

* The docs say two minutes because the demo does

* The coverage section names all three of the calls that synchronize

* Every wait can say how long it took, and the demo asks it to

* The spin uses clock64, because a globaltimer spin is a loop LLVM may delete

* The trace says the guard reports and the spin is absent, and both files say so

* The spin reads memory it can never be sure of, and the demo shows the PTX first

* The jump-table census reads zero from a fresh build, where #227 recorded no change

* An event cannot sit behind a call that never returns, so the row gets a thread

* The design notes carry the two deadlines and the eight runs behind them

* The deadline fired at 5.0 s and the arms after it ran, so the docs say the number
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.

#219's AccessWidth enum lowers the store ladder to brx jump tables the driver JIT refuses (DriverError 218)

1 participant