Repository navigation
Description
Surfaced by #47, which made it visible rather than fixing it — the occupancy query it added to examples/src/main.rs now prints this for every kernel.
The numbers
| kernel | registers | occupancy | note |
|---|---|---|---|
softmax_rows |
66 / 256 B frame | 6 blocks, 24 warps per SM | after #47 |
layernorm_rows |
255 + spills | 2 blocks per SM | at near-identical shared memory |
Same shared-memory footprint, three times fewer blocks resident. The occupancy query is register-sensitive, so this is registers doing it, not shared memory.
Why it is worth its own issue
It is the mirror image of the defect #47 just fixed, and the pair makes a nice statement of the real rule. softmax_rows was 39 registers on a 1024-byte frame — too few registers, band spilled to local memory, 2.6x slower than it needed to be. layernorm_rows is 255 with spills — too many, and the cost lands on occupancy instead of on memory traffic. Both are "the band is the wrong shape for the register file"; they just fail in opposite directions.
That also means the fix is probably the same one-constant change: softmax_rows went from [32, 128] to a [32, 32] chunk walk carrying its running statistics across chunks, and layernorm_rows has the same structure — a per-row statistic over a [32, COLUMNS] band. Check the ladder before assuming, though: #60 found [64,64] and [32,128] are both 128 fp32/thread yet differ by 220 registers, so the row extent is not interchangeable with the column extent and M*N predicts nothing.
Acceptance
- Diagnose before optimizing, and say which hypothesis the evidence supports. softmax is latency-bound, not bandwidth-bound: 362 GB/s ceiling and a flat 51us floor #47 ruled out occupancy, work-in-flight, launch overhead, barrier serialization and instruction issue, each with a measurement that would have moved if it were the cause. Registers-cap-occupancy is the hypothesis here, not the finding — confirm it with the occupancy query rather than inferring it from 255.
layernorm_rowshas no timing harness entry — it compiles and runs but is not inbench.rs. Adding it is probably step one, and it is a prerequisite for claiming any improvement. It also has no CPU reference check the waygemmandsoftmaxdo, so "faster" cannot currently be distinguished from "wrong faster". Fix that first, with the gemm's exact check cannot catch a wrong K index: b_value ignores its depth argument #48/gemm: make the reference B vary along K, so the exact check covers the K walk #55/softmax's seed has a blind row axis: 37*128 = 0 mod 128, so the check cannot see a whole-band row error #56 discipline: a seed whose every coordinate the reference genuinely depends on, plus a positive control showing the check fails against a deliberately broken kernel.- Keep
groupnorm_tile(landed in Block-scope reductions: the fold four warps need, and the fp32 Element under it #3) working — it shares the file and theSharedVecstaging. - Report before/after registers, frame size, occupancy and throughput.
ptxas -vreports what was allocated, never what it cost (Is a streamed local-memory band actually slower? ptxas cannot say, and the ladder now makes the question concrete #63).
Note on reading the numbers
Do not treat "fewer registers" as the goal. That heuristic is what hid #47 for as long as it hid — 39 registers looked like the cheapest kernel in the repo. The goal is the band living in registers with the frame at zero, and occupancy high enough to hide what remains.
Related: #47 (the same defect, opposite sign), #60 (the ladder and the frame table), #63 (whether streaming actually costs anything).
Activity
layernorm: the band was never in registers either, and the ladder's r…
The pin moves to 20a5616, and two doc claims did not survive the audit
The pin moves to 20a5616, and two doc claims did not survive the audit
A staged tile can be folded into memory, not only written over it (#169…