Skip to content

The accumulator carries the MMA shape and the column count, and the pin stops where the drains' access ladder becomes a jump table - #127

Merged
feitreim merged 1 commit into
mainfrom
ferro-bump-203
Aug 7, 2026
Merged

feitreim merged 1 commit into
mainfrom
ferro-bump-203

Conversation

@feitreim

@feitreim feitreim commented Aug 7, 2026 •

Copy link
Copy Markdown
Owner

Bumps the pinned ferro-kittens revision from f64a27b (ferro #195) to
3ae07a8 (#218), absorbing #203's accumulator typing. Behaviour is identical;
the diff is the churn that typing forces and nothing else.

The pin stops one commit short of ferro main, and that is the finding: #219
makes the gemm module fail the driver's PTX JIT. Bisected; cause named below.

What #203 changed, and what it cost here

kittens::mma's nine walks took a bare u32 accumulator plus an MmaShape.
They take the TmemTile now and read the shape off it, and
tmem::alloc_block / alloc_cluster / dealloc_* take the column count as a
const parameter carrying tcgen05.alloc's power-of-two-in-[32, 512] rule.
So:

  • gpu/flash-attn. SCORE_SHAPE / OUTPUT_SHAPE are gone — STmem is
    [QUERIES, TILE] and is the M128_N64, AccTmem is [QUERIES, HD] and
    is the M128_N128. Their measurement prose moved onto the two aliases that
    now carry the fact. FORWARD_TMEM_COLUMNS / BACKWARD_TMEM_COLUMNS become
    usize and keep only the half of their assertion that is this kernel's (that
    the allocation covers the segments laid out in it); the allocator carries the
    ISA half.
  • gpu/gemm. mma_walk_cg2 derives M256_N256 from the [128, 256]
    accumulator; ACCUM_COLS becomes usize.

Two sites could not be said the new way, and neither is mechanical churn:

  • transpose_b_probe issued an M128 over a 64-row Panel, so accumulator
    rows 64..127 read whatever followed the operand in shared memory. Harmless —
    nothing drained them — and invisible, and it is exactly the shape #203 exists
    to reject. A is the forward's PairedPanel now, with the staged panel TMA'd
    into both of its TILE halves; the drained rows 0..63 and the host's expected
    values do not move (score_mma probe max abs error 1.907e-6, main's number).
  • residency_probe's column count is a runtime kernel parameter — the sweep
    runs the four-CTA width at 256 and again at 128 — so it writes the two
    allocator bodies out by hand, exactly as ferro's own tmem_ladder_runtime
    does, for the reason ferro gives.

The surprise: ferro #219 breaks the gemm module's driver JIT

At 41f9e57, cargo oxide run gemm fails at the first cuModuleLoadData with
DriverError(218, "a PTX JIT compilation failed") — before a single line of the
gate prints. Offline ptxas --gpu-name=sm_100a -O3 accepts the same PTX and
reports register counts identical to main's (160 / 172 / 146, zero spill, zero
frame), so it is the driver's JIT and not the assembler.

A whole-module opcode diff of gemm.ptx against main names the cause in one
line: the only instruction present after the bump and absent before it is brx
— four brx.idx / .branchtargets jump tables, all inside
gemm_tcgen05_bf16_optimized.

They are ferro #219's (f4354d0, "the access ladder is a type the drains must
cover"), which turned global::access_width's return from a usize into a
#[repr(usize)] AccessWidth enum. That made the match in
store_shared_rows and accumulate_shared_rows exhaustive over four
discriminants, and LLVM lowers an exhaustive four-arm match on a repr(usize)
enum to a jump table where the old 16 / 8 / 2 if E::BYTES == 2 / _ chain
lowered to compares. The arms are unchanged — the rest of the PTX diff is those
four bodies permuted into table order.

gpu/gemm/src/optimized.rs:537,541 is this repo's only caller of either
function, which is why flash-attn — draining through store_rows, the
per-value path with no ladder — is green at ferro main.

Bisected: red at 41f9e57, green at 3ae07a8. Nothing in f4354d0..41f9e57
is load-bearing here (#219's src/mma.rs change is a doc, #223 is
examples/experiments, #224's src/global.rs and src/ldst.rs changes are
doc-only), so stopping at #218 costs this repo nothing. It wants a ferro-side
issue: a typing change that was not supposed to move codegen moved it into a
construct the driver refuses.

Also in the window, checked against the diffs rather than the titles

  • #197, #202, #204, #205, #209, #210, #223 —
    examples/, experiments/, device-tests/ only, or additive library
    surface. No reach into this repo.
  • #198 / #207 (fence contracts) — src/tmem.rs and src/ldst.rs changed
    the documentation of what a caller owes; the library emits and removes no
    fence. The store_tile→MMA proxy fence this repo already has at all three
    flash sites is what #207's contract now asks for, so there is no
    double-fence
    and nothing to remove.
  • #199 (col_map) — a real codegen change (the operand is hoisted out of the
    slot loop), reaching sub_col_assign in the key-parallel backward and
    ColVec in gpu/ops. Elementwise and order-preserving per element, and the
    flash parity numbers below confirm it: bit-for-bit main's.
  • #200 (Job::finish) — empty default, called by run after the loop. This
    repo's jobs defer nothing.
  • #206, #217, #218 — additive; nothing was removed from StoreRing
    or Warp, the only kittens::epilogue surface this repo uses.
  • #208 (exp2_hw) — not adopted, and nothing to adopt: its src/reg.rs
    change is documentation only. Worth flagging separately that this repo's
    shipped flash kernels already use Exp2Hw at all three sites
    (tcgen05.rs:1138, 1678, 2101), which ferro has now measured at −3.9% on its
    own flash_forward. A follow-up measurement, not this PR.

Verification

  • Local typecheck (cuda_cudart 13.0 redist + CUDA_TOOLKIT_PATH) clean on all
    four crates; cargo fmt clean.
  • All four gates green: gemm (fp32 + tcgen05 store/accumulate parity),
    flash-attn flash (four forward shapes, the ramped-key case firing the
    correction on 100% of visits, three backward shapes, the rewritten
    transpose_b_probe), ops (fifteen forward/backward checks), model
    (fifteen checks including the tcgen05 MoE and block-linear ladders).
  • Registers and blocks/SM, before and after, do not move. Two independent
    readings agree:
    • rebuilds --kernel gemm (ptxas, offline): identical at every entry —
      gemm_tcgen05_bf16_optimized 160/0, gemm_tcgen05_f32_optimized 172/0,
      gemm_tcgen05_f32_accumulate 146/0 (all maxntid 192), the four
      register_gemm_* 56/48/56/56, both residency probes 18/16.
      transpose_probe.ptx is byte-identical to main's.
    • compare_profile model main (same container, both arms): the whole
      bin/profile table — 38 gpu/ops kernels with their blocks/SM and
      threads/SM, and the three tcgen05 GEMMs at 202 / 174 / 194 regs, 4224 spill,
      1 CTA/SM — diffs to nothing but the build time. (Note the crate
      composition: the same three GEMMs are 160 / 172 / 146 with no spill inside
      gpu/gemm and 202 / 174 / 194 with 4224 B inside gpu/model. That gap is
      main's too, unchanged by this PR.)
    • compare_profile's timed arms: the baseline came back at 736.5460 ms
      full step / 734.7826 ms in kernels (99.76%)
      ; the candidate arm was still
      in its warmup when this was written, so the pair is not quoted here. The
      register and occupancy halves above are the ones a library bump moves, and
      flash's own forward bench landing on main's 0.799 ms to three decimals is
      the timing evidence in hand.
  • The hand-rolled allocators were run, not just compiled. The gemm gate
    compiles residency_probe without launching it, so bin/residency was run
    too: the full census table comes back, cg2 and cg4 arms both, including
    the 128-column sweep row that is the whole reason the count is a runtime
    parameter — cg2 x 148 cl @ 256 col at 296 CTAs / 148 SMs / 2 waves,
    cg4 x 74 cl @ 128 col at 296 / 142 / 3, no tensor-memory leak.
  • Flash behaviour is bit-identical. The flash gate was run on main too,
    and every parity number — all four forward shapes' y and lse, every
    correction count, all three backward shapes' dq/dk/dv, the probe — is
    bit-for-bit main's. The forward bench lands on main's 0.799 ms / 274.3 TFLOP/s exactly; backward kv/q sit inside run-to-run spread
    (872.1 / 1064.6 against main's 849.5 / 1073.6, separate containers).
  • Model losses. Every initial loss is identical to six decimals across
    main and both branch runs — 2.949841 (MoE with aux loss), 1.526770 (AdamW
    and Muon), 3.105546 (block linears), and the two dense overfits terminate at
    0.000000 on both. The two terminal values that differ are nondeterministic
    in the code itself: the MoE aux-loss overfit reads 0.000030 on main and
    0.000042 / 0.000112 on two runs of this branch, and the block-linear
    overfit 0.000056 against 0.000077 / 0.000093 — the branch's own spread
    is wider than its distance from main, so this is the MoE scatter's atomics and
    not a numerics change.

Unlocked follow-ups, not taken here

  1. #201 — ldst::{store_row_vec, load_row_vec} and SharedVec::slice are
    the library route for a row statistic through shared memory. The flagged
    candidate, and the first thing to pick up.
  2. #208 re-measure — Exp2Hw against the software exp2_approx on this
    repo's flash forward, given ferro's −3.9% on its own.
  3. #219 upstream, then ferro main — the jump-table regression above is what
    this pin is waiting on.

Unrelated, pre-existing

gpu/flash-attn/src/main.rs:763 calls naive_module.split_group2, which
gpu/ops renamed to split_group3. That bin does not compile on main either
(cargo oxide does not build it, which is why no gate has noticed), and this PR
does not touch it.

…in stops where the drains' access ladder becomes a jump table

Bumps `ferro-kittens` from `f64a27b` (#195) to `3ae07a8` (#218), whose breaking
change is #203: `kittens::mma`'s nine walks take the `TmemTile` instead of a
bare `u32` plus an `MmaShape` and read the shape off it, and `tmem`'s
allocators take the column count as a `const` parameter carrying
`tcgen05.alloc`'s power-of-two-in-`[32, 512]` rule.

So flash's `SCORE_SHAPE`/`OUTPUT_SHAPE` are gone: `STmem` is `[QUERIES, TILE]`
and *is* the `M128_N64`, `AccTmem` is `[QUERIES, HD]` and *is* the `M128_N128`,
and the two constants' measurement prose moves onto the aliases that now carry
the fact. `FORWARD_TMEM_COLUMNS`/`BACKWARD_TMEM_COLUMNS` keep only the half of
their assertion that is this kernel's. gemm's `mma_walk_cg2` derives `M256_N256`
from its `[128, 256]` accumulator.

Two sites could not be said the new way, and neither is mechanical:

`transpose_b_probe` issued an `M128` over a 64-row `Panel`, so accumulator rows
64..127 read whatever followed the operand in shared memory — harmless, because
nothing drained them, and exactly the shape #203 exists to reject. A is the
forward's `PairedPanel` now, with the staged panel TMA'd into both `TILE`
halves; the drained rows and the host's expected values do not move.

`residency_probe`'s column count is a runtime kernel parameter — the sweep runs
the four-CTA width at 256 and again at 128 — so it writes the two allocator
bodies out by hand, as ferro's own `tmem_ladder_runtime` does for the reason.

**The pin stops one commit short of ferro main.** At `41f9e57` the gemm module
dies at the first `cuModuleLoadData` with `DriverError(218)`, before a line of
the gate prints, while offline `ptxas --gpu-name=sm_100a -O3` accepts the same
PTX at register counts identical to main's. A whole-module opcode diff names it:
`brx` is the only instruction present after the bump and absent before it — four
`brx.idx`/`.branchtargets` tables in `gemm_tcgen05_bf16_optimized`. They are
#219's, whose `#[repr(usize)]` `AccessWidth` made `store_shared_rows`'s and
`accumulate_shared_rows`' match exhaustive over four discriminants, which LLVM
lowers to a jump table where the old chain lowered to compares. gemm is this
repo's only caller of either, which is why flash-attn — draining through
`store_rows`, no ladder — is green at ferro main. Bisected: red at `41f9e57`,
green at `3ae07a8`, and nothing in between is load-bearing here.

Gates green: gemm, flash-attn, ops, model. Behaviour identical — every flash
parity number is bit-for-bit main's and the gemm ptxas register/frame table is
unchanged at every entry.
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