Repository navigation
A stopwatch on every phase of a flash backward tile visit, and what it finds (#94) - #95
Merged
Merged
Conversation
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.
Phase 1 of #94, and the instrument the rest of that front is argued from. No shipped kernel changes;
flash_forward,flash_backward_qandflash_backward_kvare untouched to the byte.Why an instrument first
The backward attention rows are 57.01 ms of a 355.82 ms step (16.0%) on a clean standalone profile of this base —
flash_kv29.80,flash_q21.33,flash_dot5.88 — which is the largest block left after #89/#92/#93. The bench puts the two kernels at 1.094 and 1.566 ms.Neither roof explains that. Per key-tile visit at [32,1024,24,128], 55 296 visits over 148 SMs at 1 CTA/SM:
Both kernels sit at ~13–14% of both roofs, so the time is in neither, and the standing candidate list (operand staging, ring depth, recompute-vs-reload, LSE handling, launch overhead) had no way to be told apart. #80's campaign settled the same question twice with a
clock64phase probe; this is that pattern ported to flash.What it is
gpu/flash-attn/src/phase_probe.rs— the two backward kernels copied and instrumented, as a child module oftcgen05(#[path]), so it sees the shared plans, the tile types and the tile contract without any of them becoming crate surface. This isgemm/src/phase_probe.rs's shape; the difference is that flash's plans are private and gemm's operands were reconstructible fromkittens.#[kernel]entry points intcgen05::kernels,flash_backward_q_probe/flash_backward_kv_probe, taking one extraclocksslice.gpu/flash-attn/src/bin/probe.rs—./run.sh flash-attn probe. Times the shipped kernel and the instrumented one back to back at three shapes and prints the per-visit budget.Tcgen05Flashlaunch methods beside the existing ones.enforce_kernel_budgetsreadsflash.kernels(), which is the three shipped kernels, so no budget moves — the probe kernels are unpinned by construction.The stopwatch costs under 1%
Probe against shipped, same container, six measurements:
Two of the six are faster than the kernel they instrument, which is the size of the noise. These are the shipped kernels' own numbers.
The budget
Ticks are the CTA's own SM clock, divided by that CTA's tile visits. Columns are the leader's role and the warpgroup's role — the same 128 threads at different times.
backward q
backward kv
Σagainst the shipped kernel's own ns/visit implies an SM clock of 1.47–1.58 GHz at the two real shapes — a plausible loaded B200 clock, and the check that says the columns are the whole visit.Three things it settles
Every wait is nearly zero.
SCORED— the warpgroup waiting the score MMAs of the tile it is about to work on — is 91 ticks, flat, at every shape in both kernels.GRAD79–98,RECYCLE42–77,SYNC52–60,FEED152–563 and falling as the stream deepens. Against a 4 300–6 800 tick visit, #75's overlap is not merely working, it has ~46× more slack than it uses. That prices operand staging and ring depth at ≤7% combined and says the GEMM campaign's six-stage lesson does not transfer — flash's feed was never short.The visit is warp 0's serial chain.
ISSUEis the leader's MMA issue, not a wait, and it is 42–49% of the visit — added to the register pass rather than overlapped with it, because the leader is one of the four pass warps. Warps 1–3 finish their pass and sit at the block barrier. The instrument reports from warp 0, which arrives last, which is why its ownSYNCreads 52 rather than ~2 100 — and the eight columns sum to 4 301 against a 4 390-tick visit, so 99% of the visit is one warp's serial chain.ISSUEscales with the MMA instruction count (kernel A issues 24tcgen05.mmaper visit, kernel B 32, ratio 1.333; measured ratio 1.247), which is what says it is the tensor core's own cadence. Per instruction ~88 ticks against a ~26-tick full-rate figure: the tensor core while busy delivers 4.4 / 4.8 TFLOP/s per SM, 29–32% of the SM's peak, which isMmaShape::M128_N64's own rate.Kernel B pays 397 ticks a visit for its statistic where kernel A pays 11. Kernel A hoists
load_row_vecto the item head; kernel B's transposed band indexes the statistic by column, soload_col_vecruns perSCORE_CHUNKinside the pass. 6.3% of kernel B.Gates
--kernel flash-attn --bin flash— green. Parity byte-identical at every gated shape (y ≤ 1.469e-3, lse ≤ 9.537e-7, dq ≤ 7.299e-4, dk ≤ 7.437e-4, dv ≤ 2.933e-3), the forced-correction shape still corrects on 100.00% of its 32 eligible visits and every other shape on 0.00%, and ptxas is 128 / 182 / 190, zero spill — the The flash forward rescales O inside its own tensor-memory segment, and the last .local frame in the module goes to zero #77 pins, unmoved, because no shipped kernel changed.--kernel flash-attn— green (the two-oracle gate).--kernel ops/--kernel modelclaim needed:gpu/modelincludesflash-attn/src/lib.rs, and the only additions are new kernels nothing on that path loads. The model gate is run on the change stacked on this one.Note
The instrument belongs in
mainon its own merits, the way #85's residency probe did — the next question about these kernels should not have to rebuild it. A stopwatch does not belong in the shipped module, and it is not in one:tcgen05.rs's three kernels carry no counter, noclock64and no extra argument.