Repository navigation
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
Conversation
…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.
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.
Bumps the pinned
ferro-kittensrevision fromf64a27b(ferro #195) to3ae07a8(#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 bareu32accumulator plus anMmaShape.They take the
TmemTilenow and read the shape off it, andtmem::alloc_block/alloc_cluster/dealloc_*take the column count as aconstparameter carryingtcgen05.alloc's power-of-two-in-[32, 512]rule.So:
gpu/flash-attn.SCORE_SHAPE/OUTPUT_SHAPEare gone —STmemis[QUERIES, TILE]and is theM128_N64,AccTmemis[QUERIES, HD]andis the
M128_N128. Their measurement prose moved onto the two aliases thatnow carry the fact.
FORWARD_TMEM_COLUMNS/BACKWARD_TMEM_COLUMNSbecomeusizeand keep only the half of their assertion that is this kernel's (thatthe allocation covers the segments laid out in it); the allocator carries the
ISA half.
gpu/gemm.mma_walk_cg2derivesM256_N256from the[128, 256]accumulator;
ACCUM_COLSbecomesusize.Two sites could not be said the new way, and neither is mechanical churn:
transpose_b_probeissued anM128over a 64-rowPanel, so accumulatorrows 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
PairedPanelnow, with the staged panel TMA'dinto both of its
TILEhalves; the drained rows 0..63 and the host's expectedvalues 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 sweepruns 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_runtimedoes, for the reason ferro gives.
The surprise: ferro #219 breaks the gemm module's driver JIT
At
41f9e57,cargo oxide run gemmfails at the firstcuModuleLoadDatawithDriverError(218, "a PTX JIT compilation failed")— before a single line of thegate prints. Offline
ptxas --gpu-name=sm_100a -O3accepts the same PTX andreports 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.ptxagainst main names the cause in oneline: the only instruction present after the bump and absent before it is
brx— four
brx.idx/.branchtargetsjump tables, all insidegemm_tcgen05_bf16_optimized.They are ferro #219's (
f4354d0, "the access ladder is a type the drains mustcover"), which turned
global::access_width's return from ausizeinto a#[repr(usize)]AccessWidthenum. That made thematchinstore_shared_rowsandaccumulate_shared_rowsexhaustive over fourdiscriminants, 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 / _chainlowered 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,541is this repo's only caller of eitherfunction, which is why
flash-attn— draining throughstore_rows, theper-value path with no ladder — is green at ferro main.
Bisected: red at
41f9e57, green at3ae07a8. Nothing inf4354d0..41f9e57is load-bearing here (#219's
src/mma.rschange is a doc, #223 isexamples/experiments, #224's
src/global.rsandsrc/ldst.rschanges aredoc-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
examples/,experiments/,device-tests/only, or additive librarysurface. No reach into this repo.
src/tmem.rsandsrc/ldst.rschangedthe 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 threeflash sites is what #207's contract now asks for, so there is no
double-fence and nothing to remove.
col_map) — a real codegen change (the operand is hoisted out of theslot loop), reaching
sub_col_assignin the key-parallel backward andColVecingpu/ops. Elementwise and order-preserving per element, and theflash parity numbers below confirm it: bit-for-bit main's.
Job::finish) — empty default, called byrunafter the loop. Thisrepo's jobs defer nothing.
StoreRingor
Warp, the onlykittens::epiloguesurface this repo uses.exp2_hw) — not adopted, and nothing to adopt: itssrc/reg.rschange is documentation only. Worth flagging separately that this repo's
shipped flash kernels already use
Exp2Hwat all three sites(
tcgen05.rs:1138, 1678, 2101), which ferro has now measured at −3.9% on itsown
flash_forward. A follow-up measurement, not this PR.Verification
cuda_cudart13.0 redist +CUDA_TOOLKIT_PATH) clean on allfour crates;
cargo fmtclean.gemm(fp32 + tcgen05 store/accumulate parity),flash-attnflash(four forward shapes, the ramped-key case firing thecorrection 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).
readings agree:
rebuilds --kernel gemm(ptxas, offline): identical at every entry —gemm_tcgen05_bf16_optimized160/0,gemm_tcgen05_f32_optimized172/0,gemm_tcgen05_f32_accumulate146/0 (allmaxntid 192), the fourregister_gemm_*56/48/56/56, both residency probes 18/16.transpose_probe.ptxis byte-identical to main's.compare_profile model main(same container, both arms): the wholebin/profiletable — 38gpu/opskernels with their blocks/SM andthreads/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/gemmand 202 / 174 / 194 with 4224 B insidegpu/model. That gap ismain's too, unchanged by this PR.)
compare_profile's timed arms: the baseline came back at 736.5460 msfull 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 msto three decimals isthe timing evidence in hand.
compiles
residency_probewithout launching it, sobin/residencywas runtoo: the full census table comes back,
cg2andcg4arms both, includingthe 128-column sweep row that is the whole reason the count is a runtime
parameter —
cg2 x 148 cl @ 256 colat 296 CTAs / 148 SMs / 2 waves,cg4 x 74 cl @ 128 colat 296 / 142 / 3, no tensor-memory leak.flashgate was run onmaintoo,and every parity number — all four forward shapes'
yandlse, everycorrection count, all three backward shapes'
dq/dk/dv, the probe — isbit-for-bit main's. The forward bench lands on main's
0.799 ms / 274.3 TFLOP/sexactly; backward kv/q sit inside run-to-run spread(872.1 / 1064.6 against main's 849.5 / 1073.6, separate containers).
main and both branch runs —
2.949841(MoE with aux loss),1.526770(AdamWand Muon),
3.105546(block linears), and the two dense overfits terminate at0.000000on both. The two terminal values that differ are nondeterministicin the code itself: the MoE aux-loss overfit reads
0.000030on main and0.000042/0.000112on two runs of this branch, and the block-linearoverfit
0.000056against0.000077/0.000093— the branch's own spreadis 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
ldst::{store_row_vec, load_row_vec}andSharedVec::slicearethe library route for a row statistic through shared memory. The flagged
candidate, and the first thing to pick up.
Exp2Hwagainst the softwareexp2_approxon thisrepo's flash forward, given ferro's −3.9% on its own.
this pin is waiting on.
Unrelated, pre-existing
gpu/flash-attn/src/main.rs:763callsnaive_module.split_group2, whichgpu/opsrenamed tosplit_group3. That bin does not compile onmaineither(
cargo oxidedoes not build it, which is why no gate has noticed), and this PRdoes not touch it.