Repository navigation
The backward's MMA issue moves to a fifth warp, off the register pass's critical path (#94) - #96
Merged
Merged
Conversation
feitreim
added a commit
that referenced
this pull request
Aug 5, 2026
…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 1 of #94, stacked on #95 (the probe it is argued from and measured with). Base is
flash-bwd-probe; the diff against it istcgen05.rs,host.rs, the probe kept in step, and two pins.The finding, in one line
#95's phase budget put 99% of a backward tile visit in warp 0's serial chain: the leader issued the tile's MMAs (2 108 / 2 628 ticks, 42–49% of the visit) and then ran its share of the register pass (1 641 / 2 708), while warps 1–3 sat at the block barrier waiting for it. Every actual wait in the loop was ≤ 7% —
SCORED, the warpgroup waiting the score MMAs, was 91 ticks flat at every shape in both kernels.The change
One more warp.
FLASH_BACKWARD_BLOCKgoes 128 → 160; warp 4 issues every TMA and every MMA and runs no pass, warps 0–3 run the pass and drain the accumulator and issue nothing. Both roles runkey_tilesiterations and meet at the same singlesync_threadsper tile, so the barrier counts match whichever branch a warp is in:Every ring, every semaphore,
BACKWARD_STAGES,GRADIENT_STAGES, the shared plan, the TMEM layout and the arithmetic are untouched. The only change is which warp callsmma_*andtma_load, andleadermoving from thread 0 toISSUE_WARP * 32.This is not the warp specialization #75 deleted. That was 192 threads with a separate TMA warp and MMA warp, six barrier sets, and a per-query statistic re-staged through a shared ring because specialization had removed the block sync it hid behind. It lost because of that structure, not because a dedicated issuer is wrong — and #95's budget is what says which.
Numbers
./run.sh flash-attn flash, [32,1024,24,128], base and branch measured in clean containers:Clean standalone profile, §13.9 shape, against the base's own standalone profile:
backward.attention.flash_qbackward.attention.flash_kvbackward.attention.flash_dotforward.attention.flashBackward attention goes from 16.0% of the step to 12.6%. These are two containers, and the untouched forward drifting +0.78 is the scale of that; the same-container A/B below is the claim.
Same-container A/B,
--baseline-ref 9060469, marked=== baseline ===/=== candidate ===pair. This is a throttled container (784 ms absolute where a standalone profile of the same base reads 355.82 — 2.20×, the known hazard), so the row deltas are the measurement:backward.attention.flash_qbackward.attention.flash_kvbackward.attention.flash_dotforward.attention.flashNamed rows sum to −11.11 against a −11.93 step — they account for the whole of it. The unmarked pair the same run emits reproduces it independently:
flash_q34.7574 → 27.9273 (−6.83),flash_kv59.4506 → 56.7879 (−2.66).With the order reversed (this branch profiled first,
mainas the candidate —compare_profilealways runs the retained ref first, so the branch is passed as--baseline-ref):backward.attention.flash_qbackward.attention.flash_kvbackward.attention.flash_dotforward.attention.flashOrder does not matter: −7.49 / −3.59 one way and −7.11 / −3.23 the other, with the named rows accounting for the step delta in both (−11.11 of −11.93, and −10.34 of −9.94).
The honest claim is the ~−11 to −13 ms the named rows carry, ~3.2–3.7% of a clean step.
Why kernel A converts and kernel B mostly does not — the probe again
#95's instrument moved with the kernel (the two roles are now two warps, so it reports each warp's own wait at the shared barrier:
SYNCfor the pass warps, the newIDLEfor the issue warp). Same shape, before and after:Two things move at once, and they are the whole result:
ISSUEgets cheaper — 2 108 → 1 354 and 2 628 → 1 768. The MMA issue was contending with the register pass; alone in its own warp it runs ~35% faster.PASSgets more expensive — 1 641 → 2 329 (×1.42) and 2 708 → 5 314 (×1.96). Before, warp 0 measured a pass it largely ran alone, because warps 1–3 had finished theirs and were waiting; now all four run it together and contend.Kernel A wins because ×1.42 is much less than the serial sum it replaces. Kernel B barely wins because ×1.96 nearly eats it: its pass does two swizzled operand stores where A's does one (
PᵀanddSᵀagainstdSalone) and twosub_col_assignbroadcasts, and it parallelizes across four warps worse than A's does. Why it parallelizes worse is not established here — it is the next question, not a claim in this PR.IDLEof 946 and 4 004 says the same thing from the issue warp's side: both kernels are now pass-bound, kernel B overwhelmingly.PASSis 90.4% and 89.2% of the pass warps' column. That retargets #94's remedy list — remedy 3 (split the pass across two warpgroups) moves ahead of remedy 2, and kernel B is where it is worth the most.Gates
--kernel flash-attn --bin flash— green. Parity is byte-identical to the 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 — the same digits as the baseline run, which is the point: no arithmetic changed, only which warp issues. The forced-correction shape still corrects on 100.00% of its 32 eligible visits and every other shape on 0.00%.--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.000031 against the recorded 0.000028; the backward's arithmetic is unchanged, so that is the scatter-atomic nondeterminism and nothing else.--kernel ops— green.KernelBudget: forward 128 / 0 unchanged; backward q 182 → 189, backward kv 190 → 198, both still zero spill. Pins ratcheted to the measured numbers. The rise is.maxntid, as it was in One flash-attention backward per direction, at one block barrier a key tile (#69) #75 and The flash forward rescales O inside its own tensor-memory segment, and the last .local frame in the module goes to zero #77: the kernels declare 160 threads where they declared 128, so ptxas' budget went from65536/128to65536/160— 409 per thread against 512 — and it spent seven and eight more of a smaller allowance. Occupancy is unmoved: residency is pinned at 1 CTA/SM byBACKWARD_TMEM_COLUMNS = 512either way, and 160 threads is five warps of the SM's 64 slots.--kernel model --bin train --shard /data/wiki-train-00000.tok --steps 100— 75 553 tokens/s, 33.55% MFU over 99 measured steps, loss 11.107 → 8.010. Against the ~73k / 32.5% this front opened on that is +3.5%, which is barely outside the ~2.9% main-vs-main spread MoE atomics give this run — the row-level A/B above is what carries the claim, and this is the "it still trains" gate.What this does not do
BACKWARD_STAGESstays 3 andGRADIENT_STAGESstays 2 — #95 priced the whole feed at ≤7% of a visit and this PR does not touch it.MmaShape::M128_N64stays, so the tensor core still runs at ~30% of the SM's peak while busy; that is #94's remedy 2 and it is no longer the leading term now thatISSUEis off the critical path andIDLEis 946 / 4 004. The register pass is what is left, at ~90% of both kernels.