Repository navigation
The flash forward rescales O inside its own tensor-memory segment, and the last .local frame in the module goes to zero - #77
Conversation
…d the last .local frame in the module goes to zero A PTX census after the ferro c648c67 pin (#76) found exactly one LLVM depot left in tcgen05.rs: `flash_forward`, 560 B and 405 `ld/st.local`, with neither backward kernel carrying one at all. ferro #180 unrolled the library's mover walks and that was the whole of the backwards' 528 B; the forward's was its own, and it was `out_acc` — the 128-register output accumulator the conditional correction carried from the first key tile to the epilogue, address-taken because `online_rescale` and `merge_output_tile` both wrote it through `&mut`. Nothing about it was hot: the correction fires on 0.00% of tile visits at every gated shape. What cost was the two unconditional touches, the tile-0 rescale and the epilogue merge, each walking 128 depot slots once per work item. `tcgen05.st` was absent when that correction scheme was designed and is `TmemTile::store_tile` now, so the rescale happens where the accumulator lives: a correction drains the O segment, scales it, stores it back and leaves `enable_d` on, instead of restarting the segment and keeping the running output in registers. The epilogue drains once. Forward 1.212 -> 0.832 ms at [32,1024,24,128] on B200, 180.8 -> 263.2 TFLOP/s, 128 regs / 0 B frame against 193 / 560, with parity identical to the digit at all five gated shapes — the rescale is the same arithmetic in the same order, applied to the accumulator rather than to a copy of it. The width is the lesson, and it is ferro #181's. Three formulations were measured in the same container before the fourth: the resident `&mut` accumulator, 560 B and 1.212 ms; the segment drained whole into a short-lived `&mut` band, 1072 B and 0.996 — the frame grew and the time fell 18%, because what costs is the traffic in the loop and not the bytes in the depot; that band by value, where the drain and the rescaled result are live together, 253 registers and over the ptxas pin. Only 64 columns at a time is both zero-frame and fastest. A 128-register fp32 band cannot be transformed on the way out of tensor memory whichever way it is spelled — and both backward kernels drain the full 128 into `store_rows` at 0 B, so it is the transform in between and not the width by itself. All three ptxas pins ratchet to the measured numbers: forward 128/0, backward q 182/0, backward kv 190/0. Every frame in the module is now zero.
…d a negative control proving the case can fail Every forward parity shape reports 0.00% corrections, which is the number the old scheme's checklist reported and read as good news. It is also the reason the byte-identical parity in the previous commit is genuine for the epilogue drain and vacuous for the correction: not one of the five shapes executes the mid-stream path at all, so nothing gated the segment being drained, scaled, `tcgen05.st` back and accumulated onto with `enable_d` still on. Uniform operands cannot climb CORRECTION_THRESHOLD; a gate has to make them. `CORRECTION_KEY_GAIN` scales key `p`'s staged row by `1 + 7*(p / FLASH_TILE)`. A score is linear in K, so that multiplies the score by the same factor and a tile's row max is its gain times the unramped one — the climb per key tile is ~7.7 base-2, just above the threshold, which is the side of it worth testing: the correction fires on every eligible visit and the output mass accumulated before each one is the largest the threshold permits. Q and V stay uniform, and the ramp is applied before staging so the CPU reference — which reads the staged operands — needs no ramp of its own. At [1,512,2] it corrects on 32 of 32 eligible visits (100.00%) with y <= 1.156e-3 and lse <= 2.842e-4 against tolerances left exactly where they were, and the count is asserted nonzero so a ramp that stopped tripping the threshold fails loudly instead of going quiet. The gate was then checked against a negative control, because a test that cannot fail is the same hole wearing a different shape. With the two `rescale_half` calls deleted and the vote, the counter, `store_wait` and `enable_d` all left standing, the five uniform shapes pass byte-identical and the ramped one fails on y by 0.114 against a 0.0062 tolerance. Only y catches it: lse is unmoved, because `running_sum` is rescaled in registers either way and it is only the O segment that goes stale.
The mid-stream rescale now has a gate, and the gate has a negative controlYou were right, and it was worse than "untested": the five uniform shapes correct on 0.00% of eligible visits, so all of them together gated the epilogue drain and none of them entered the mid-stream path. Pushed The case
Result at
The negative controlA gate that cannot fail is the same hole in a new shape, so I ran one: the two
0.114 against 0.0062 is 18× over. That is the direct measurement of what the old suite was missing. One detail worth keeping: only Full suiteOne The timed numbers stand (0.832 / 0.833 across two runs). SPEC's #77 entry records the gate, the 100% rate and the negative control. |
Closes out the flash half of the
.localattribution the rewrite wave (#74/#75) opened and the ferro pin bump (#76) half-answered.The census
modal run modal_app.py::main --kernel flash-attn --ptxat ferroc648c67, sm_100a. Depots inflash.ptx, plus what ptxas reports:flash_backward_qflash_backward_kvflash_forward__local_depot2[560], 405ld/st.localferro #180 did all of the backwards' frames and none of the forward's — their 528 B was the
pipeline::Jobstruct reached through the library's mover walks, and unrolling those took it whole. That is why the pin bump realized 15.7% and 22.0% on the two backwards and only 9.8% on the forward.The forward's 560 B was
out_acc: theRegTile<32, 128, BaseLdtm>output accumulator the conditional correction carried from the first key tile to the epilogue, address-taken becausereg::online_rescaleand the localmerge_output_tileboth wrote it through&mut. Nothing about it was hot — the correction fires on 0.00% of tile visits at every gated shape, including 49152 eligible ones at the bench shape. What cost was the two unconditional touches, the tile-0 rescale and the epilogue merge, each walking 128 depot slots once per work item.The fix
tcgen05.stwas absent when the correction scheme was designed and isTmemTile::store_tilenow, so the rescale happens where the accumulator lives. A correction drains the O segment, scales it, stores it back and leavesenable_don; the segment keeps accumulating instead of restarting, and the epilogue drains it once, 64 columns at a time.merge_output_tileis gone.Same arithmetic in the same order, applied to the accumulator rather than to a copy of it — so parity is unchanged to the digit.
Numbers
B200, [32,1024,24,128],
mainand this branch measured back to back.ptxas: forward 128 regs / 0 B against 193 / 560. Occupancy is unchanged — the forward plan is 114836 B and still 2 CTA/SM.
Parity is byte-identical to the
mainrun at every gated shape: y ≤ 1.469e-3, lse ≤ 9.537e-7, dq ≤ 7.299e-4, dk ≤ 7.437e-4, dv ≤ 2.933e-3, corrections 0.00% everywhere.All three pins ratchet to the measured numbers (128/0, 182/0, 190/0), so the gate is exact and every frame in the module is now zero.
The width is the lesson
Four formulations, one container, same shape:
&mutaccumulator (main)&mutbandTwo things that a frame census alone would have got wrong:
&mutit is address-taken; by value the drain and the result are live together and ptxas allocates 253. Only the 64-wide form is both zero-frame and fastest — ferro #181's streaming fix, one axis over from whatSCORE_CHUNKalready found on the score band.The width by itself is not the problem: both backward kernels drain the full
[32, 128]intostore_rowsand carry 0 B. It is the transform in between.Findings posted to ferro-kittens#166 (the standing
.localumbrella). No ferro change is required —TmemTile::store_tile+store_waitsupplied the whole fix, and its device-tested round trip is what made it writable without a probe of my own.