Repository navigation
The backward's register pass splits across two warpgroups over the same TMEM lanes (#94) - #98
Merged
Merged
Conversation
…me TMEM lanes (#94) Remedy 3 of #94. `FLASH_BACKWARD_BLOCK` goes 160 -> 288: where warps 0-3 ran the whole register pass over the accumulator's 128 TMEM lanes, warps 0-7 now run it over the *same* 128 lanes with the score band's columns split between the two warpgroups. Warp 8 still issues every TMA and every MMA and runs no pass, as #96 left it. Every ring, every semaphore, `BACKWARD_STAGES`, `GRADIENT_STAGES`, the shared plan, the TMEM layout and the arithmetic are untouched. The contract is ferro-kittens#193's: a warp addresses the 32 TMEM lanes at `warp_id() % 4` and its warpgroup does not matter. It is spelled `tmem::warp_lanes()` and never `32 * warp_id`, because from warpgroup 1 the latter names a lane past the 128 that exist and reaching past the bound does not fault -- it silently reads the reader's own quadrant at the same offset. The accumulator drain splits with the pass, so `OutBand` is gone and `OutHalf` is the widest fp32 value in the module. `backward kv` -27 to -28% across four containers, `backward q` flat: A spends its pass saving on issue slack and lands on `MmaShape::M128_N64`'s roof, which is #94's remedy 2 arriving. B's pass halves cleanly, which answers #96's open question -- it was latency-bound, not throughput-bound. Registers fall 192 -> 128 and 200 -> 140 at zero spill. Parity is byte-identical: the column split changes no summation order.
This was referenced Aug 5, 2026
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.
Remedy 3 of #94, stacked on #97 (the ferro
e26c75cpin bump it needs and is measured against). Base isflash-bwd-pin-bump; the diff against it istcgen05.rs, the probe kept in step, onehost.rsdoc line and two pins.The change
FLASH_BACKWARD_BLOCK160 → 288. Where warps 0–3 ran the whole register pass over the accumulator's 128 TMEM lanes, warps 0–7 now run it over the same 128 lanes, split by column:PASS_GROUPS = 2warpgroups,PASS_COLUMNS = TILE / 2of the score band each. Warp 8 still issues every TMA and every MMA and runs no pass, exactly as #96 left it.The whole of it rests on ferro-kittens#193: a warp addresses the 32 TMEM lanes at
warp_id() % 4, its warpgroup does not matter, and it addresses no others. That was measured on a B200 at these kernels' own shapes — the[32, 16]chunk this pass reads, the[32, 128]band it drained, the[32, 64]half it drains now.It is spelled
tmem::warp_lanes(), never32 * warp_id. From warpgroup 1 the latter names a lane past the 128 that exist, and crossing that bound does not fault: it silently reads the lane at the same offset inside the reader's own quadrant. #193's table is where that is established and itsconst { assert!(M <= 32) }guards are what make the taller spelling of the same mistake a compile error.No new fence and no new barrier. The pass warps write dS (and P) through the generic proxy into shared memory and meet the issue warp at the one
sync_threadsa tile that #75 left there; nothing here stores to tensor memory, sostore_waithas nothing to cover that it did not already cover in the forward.The drain splits with the pass: each warpgroup takes
DRAIN_COLUMNS = HD / 2of its accumulator band rather than allHD, soOutBandis gone andOutHalf— the[32, 64]the forward already used — is the widest fp32 value in the module.What it buys
./run.sh flash-attn flash, [32,1024,24,128]. Two independent container pairs, becausebackward kvhas a ±3.5% spread across containers and one pair could not tell −27% from it:Kernel A does not move and kernel B does. That is the opposite of what #96 predicted from
IDLEalone, and the probe says exactly why.The probe — and #96's open question, answered
#95's instrument moved with the kernel. Same shape,
PASS_GROUPS1 against 2, both against the #97 base:backward q
backward kv
1. Why kernel B's pass parallelized worse — the question #96 left open
#96 measured B's pass growing ×1.96 when the four pass warps started running concurrently against kernel A's ×1.42, and said "why it parallelizes worse is not established here". The natural reading was that B's pass had saturated a per-SM port: it does two swizzled
store_tiles where A does one, and shared-memory store throughput is shared across the whole SM. That reading predicts the split buys B nothing — the same total work over the same saturated port takes the same time however many warps carry it.It is wrong, and the split is the experiment that says so. B's
PASSfalls ×0.57 against an ideal ×0.50. Its pass was never throughput-bound; it was latency-bound, with a long dependent chain per chunk — two TMEM reads, twosub_colbroadcasts, anexp2, two swizzled stores — and four warps on four sub-partitions could not cover it. Halving each warp's chain covers it, and 43% of the pass goes away.The ×1.96 re-reads as its converse: B's per-warp chain was long enough that four of them collided on issue slots at all, where A's shorter one mostly did not. It was a symptom of the same thing the split fixes, not of a wall.
Kernel A's is the pass with a floor: ×0.73 for twice the warps, so roughly 900 of its 1 993 ticks do not scale with warp count at all. Whatever that is, it is A's and not B's, and it is now the smaller question of the two.
2. Why kernel A is flat anyway — remedy 2 arrives
A converted its pass saving into slack and had nowhere to spend it. Before, the pass warps' visit was 2 646 against the issue warp's 2 143 — pass-bound by ~500 ticks,
IDLE299. After, it is 2 132 against 2 210,IDLE154: the two roles are level and the issue warp is now marginally the longer one.ISSUEitself rose ×1.14 (1 498 → 1 706), which is the price of the ninth warp — nine warps over four sub-partitions puts warps 0, 4 and 8 on sub-partition 0, so the issuer shares its scheduler with two pass warps where it shared with one.So kernel A is now MMA-issue bound, at
MmaShape::M128_N64's own ~30%-of-SM-peak issue rate. That is #94's remedy 2, exactly where #94 said it would surface once remedy 1 tookISSUEoff the pass's critical path. Kernel A is not slower and it is not faster; it is now sitting on a different roof, and the next increment on it is a wider MMA rather than more warps.3. Kernel B's statistic is half-paid by the same change
STAT400 → 299. B'sload_col_vecis indexed by column, so a warpgroup that runs half the chunks makes half the loads. #94's remedy 4 was a separate item; remedy 3 pays a quarter of it as a side effect, and what is left is the fixed part.Four warpgroups is not the answer, measured
B is still pass-bound after this PR (
PASS2 985 againstISSUE2 012,IDLE1 350), soPASS_GROUPS = 4is the obvious next question. It was built and run rather than argued about:PASS_GROUPS = 2PASS_GROUPS = 4Seventeen warps is 544 threads, so ptxas' allowance is
65536 / 544, it allocated 96 and spilled both kernels. B gains another 6% and A loses 12%, and the two cancel. Two warpgroups is the number, and the branch is kept for the record atflash-bwd-pass-split-4wg. (tile_x8also requiresN % 64, so the drain can only ever split two ways however wide the pass split goes — at four groups two of the warpgroups drain and two do not.)Gates
--kernel flash-attn --bin flash— green. Parity is byte-identical to the All four gpu/* ferro-kittens pins to e26c75c, and the one thing in that range that is not additive (#94) #97 base at every gated shape: dq 7.299e-4 / 5.203e-4 / 6.458e-4, dk 7.322e-4 / 7.437e-4 / 7.084e-4, dv 2.933e-3 / 2.717e-3 / 2.911e-3, y ≤ 1.469e-3, lse ≤ 9.537e-7. That is the gate this change deserves and it holds for a reason: the column split changes no summation order. Every chunk is the same arithmetic on the same inputs into the same dS columns; only the warp that runs it changed, and every reduction — theexp2, thedP − Dproduct, the gradient MMAs — is per-element or per-MMA and indifferent to it. The forced-correction shape still corrects on 100.00% of its 32 eligible visits and every other shape on 0.00%. (The four-warpgroup branch above reproduces the same digits a third time, at a third width.)--kernel flash-attn— green (the two-oracle gate).--kernel model— green, all 14 checks including both MoE substitutions,aligned_tcgen05_linears, checkpoint v5 and all four overfit gates. The MoE overfit lands 2.949803 → 0.000036 against the base run's 0.000031 and the recorded 0.000028 — the scatter-atomic nondeterminism, unchanged arithmetic.--kernel ops— green.--kernel gemm— 134 / 168 / 146 at All four gpu/* ferro-kittens pins to e26c75c, and the one thing in that range that is not additive (#94) #97, untouched here.KernelBudget: forward 128 / 0 unchanged; backward q 192 → 128, backward kv 200 → 140, both zero spill, at.maxntid 288. Pins ratcheted down. This is the first.maxntidrise in this file that gave registers back, and it is liveness rather than budget: ptxas' allowance did fall, from65536/160= 409 to65536/288= 227, and the allocation fell a hundred below it because a pass warp now runsPASS_COLUMNSof chunks where it ranTILE, and the epilogue drains[32, 64]where it drained[32, 128]— the one place either kernel held 128 fp32 registers at once. Residency is unmoved:BACKWARD_TMEM_COLUMNS = 512pins 1 CTA/SM either way, and nine warps is nine of the SM's 64 slots.Same-container A/B, both orders
--baseline-ref 0897acd— the pin-bump commit, so nothing below includes #97's effects.compare_profilealways profiles the retained ref first, so the reversed run passes this branch as--baseline-refinstead.Throttled containers, and stated as such: the full step reads 767–779 ms where a clean standalone profile of either tree reads 334–335 (2.3×, the hazard #96 named). The row deltas are the measurement.
forward.attention.flashbackward.attention.flash_qbackward.attention.flash_kvbackward.attention.flash_dotWith the order reversed (this branch retained and profiled first, #97 as the candidate) — at tag
ab-ref-flash-bwd-pass-split, which is this branch's tree before the last commit reworded twoconstassert messages and added the four-warpgroup note; no generated code differs:forward.attention.flashbackward.attention.flash_qbackward.attention.flash_kvbackward.attention.flash_dotOrder does not matter:
flash_kv−6.41 one way and −7.79 the other,flash_q+0.20 and +0.07 — flat, as the bench says. The unmarked pair each run also emits reproduces it independently: −6.13 and −6.27 onflash_kv. Named rows sum to −6.13 against a −3.93 step and −7.76 against a −10.44 step; the step total is the noisier of the two at this resolution and the row is what carries the claim.Clean standalone profiles
./run.sh model profile, §13.9 shape, one clean container each:forward.attention.flashbackward.attention.flash_qbackward.attention.flash_kvbackward.attention.flash_dotThe
flash_kvrow's −26.8% is the bench's −28% and the probe's −27%, a third instrument agreeing. Two things in this table are container drift and not results, and saying so is the point of showing it:flash_qmoves +1.05 where the same-container A/B and three bench pairs all put it flat, and the step total moves the wrong way because the non-attention remainder is 277.03 against 283.65 — 2.4% apart between two containers, which is more than the 5.6 ms the attention rows gave back. Two standalone containers are not a ±7 ms instrument for the step; the same-container A/B and the bench are.Worth one note across the two kinds of container:
flash_kvgives back 6.4, 6.8 and 7.8 ms whether the row reads 55 ms throttled or 25 ms clean. What the split removes is not itself clock-throttled, which is why the percentage looks so different in the two settings and the milliseconds do not.Training smoke
--kernel model --bin train --shard /data/wiki-train-00000.tok --steps 100— 74 663 tokens/s, 33.15% MFU over 99 measured steps, loss 11.107 → 8.088 on the same curve #96 ran (9.002 / 8.467 / 8.258 at steps 10/20/30). Against #96's 75 553 / 33.55% that is −1.2%, well inside the ~2.9% main-vs-main spread the MoE atomics give this run, and this gate is "it still trains" — the row-level A/B above is what carries the claim.An instrument fix that came with it
phase_probe.rsstill hadleader: threadIdx_x() == 0where #96 moved the shipped kernels' toISSUE_WARP * 32. The probe therefore had a pass warp doing each item's head — its TMA loads and its first score MMA — and charged the wait to a warp whose column is never published. Per item rather than per visit, which is why it stayed inside the probe's 1% overhead band and why #95's conclusions are unaffected; still not what ships. Both probe kernels are corrected, soFEEDandISSUEabove include the item head where #96's published figures did not — the before column in the tables was re-measured with the corrected probe so that both columns are the same instrument.What this does not do
BACKWARD_STAGESstays 3 andGRADIENT_STAGESstays 2 — #95 priced the whole feed at ≤7% of a visit and nothing here touches it.MmaShape::M128_N64stays, and it is now kernel A's binding roof rather than a term in a sum. The forward is untouched: it launches one warpgroup, and32 * warp_id()andwarp_lanes()are the same number there, so re-spelling it would move its schedule for no reason.