Repository navigation
The HD-wide accumulations are one N=128 band, and the dQ drain is the next item's opening move (#94) - #100
Conversation
…ASS, and time the MMA cadence (#94)
Merge orderThis PR pins ferro-kittens at
|
Re-pinned to the merged ferro
|
Remedy 2 of #94, and the forensics that retargeted it. Phase 0 is posted on the issue; this is what it licensed. Needs ferro-kittens#195 (pinned here at
1eefabb, to be re-pinned to the mergedmainrev).What phase 0 established, in one line each
issue/instr == retire/instr, soISSUEis the tensor core's retirement rate. A second issue warp is priced at exactly zero and is not in this PR.N = 64runs the tensor core at 57% ofN = 128— 55.7 against 32.0 ticks perM128_N64_K16-equivalent, withN = 256no better than 128.ISSUEis 4% TMA, 72% score MMAs, 24% gradient MMA. Barrier arms do not show.PASSis 21% TMEM read, 61% arithmetic, 18% store — not the read, which is what I expected.FILL3534 +EPI3470 +GAP1624 of a 30 108-tick item.The change
1. Every HD-wide accumulation is one
N = 128band instead of twoN = 64ones (ferro-kittens#195). An MN-majorBreaches its second stacked subtile through the descriptor's leading offset, which is howmma_atbhas always covered a 128-wide MN in one instruction;mma_abwas the last caller banding it by hand.MMA_SHAPEsplits into the two shapes that were always there:Four call sites take
OUTPUT_SHAPE: the forward'sO = P·V, kernel A'sdQ += dS·K, kernel B'sdV += Pᵀ·dYanddK += dSᵀ·Q. Each halves its instruction count and runs the tensor core at 32.1 ticks/unit instead of 48.2. Kernel A'sGMMAcolumn: 357 → 184 ticks a visit.2. The dQ drain is the next item's opening move, not this item's last.
EPIwas 3470 ticks an item, of which the wait for the last gradient MMA was 513 and the.x8drain plusstore_rowswas 2957. The wait cannot move —pipeline::runre-arms the barrier set at the item boundary — but the drain can, and one line below where it lands the pass warps were spending 3534 ticks idle atscored.wait(0)waiting out the next item's TMA fill. So the item stages its row and the next item drains it, with a flush after the persistent loop for the last one. That ispipeline::Job's own documented deferred-store shape, and the hand-off to the next item's first gradient MMA (which overwrites the accumulator) is the block barrier the pass already takes after its first tile.3.
TmemTile::fragmentissues both loads before waiting (also ferro-kittens#195).tcgen05.wait::ldretires prior loads plural, so a wait after each meant the.x1path never had more than one in flight.TREAD381 → 303.4. The instrument, which belongs in
mainon its own merits the way #95's did.phase_probegains a partition ofISSUE(TMA + SMMA + GMMA) and ofPASS(TREAD + ARITH + STORE), plusFILL,GAP,EPIandDRAINper item; andsrc/bin/probe.rsgains the MMA cadence table — one warp, one CTA, chained walks into a resident accumulator,Nthe only thing that moves. It keeps the bandedmma_abwalk locally so the comparison survives the ferro change.What it buys
./run.sh flash-attn probetimes the shipped kernels alongside the instrumented ones, so each container gives an independent same-container reading of both. Three shapes, three containers, three tree states:d6b99ea./run.sh flash-attn flash, [32,1024,24,128]:d6b99eaThe forward moves too, and it is the same one-line change: its
O = P·Vwas twoN = 64bands.The budget it leaves
[32,1024,24,128], the instrumented column,
d6b99eaagainst this PR:load_row_vecthe drain now sits in front ofISSUEsplitsTMA 61 / SMMA 1142 / GMMA 180andPASSsplitsTREAD 311 / ARITH 1247 / STORE 299.Two honest readings of that table. The item got 10% shorter and that is the result; the visit columns got longer, because moving 3.6k ticks of store into the item's head displaces work the fill used to absorb and the probe charges the residue to
STATandFEED. And kernel A is issue-bound again by a hair — 2220 against 2687 is pass-bound on paper, butIDLE336 againstSYNC38 says the pass warps are the ones with slack once the per-item terms are taken out.Where kernel A now sits:
SMMAis 1142 of a 1384-tickISSUE, all of itM128_N64at 43% off the tensor core's rate, and widening it needs a 128-key tile that shared memory forbids by 29 KiB (priced in the phase-0 comment).ARITHis 1247 ofPASS, and ~512 ticks of that isexp2against the SFU's 16 lanes/SM/cycle, which no scheduling removes. The next real lever on this kernel is neither.Gates
--kernel flash-attn --bin flash— green, and byte-identical tod6b99ea: 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 The backward's register pass splits across two warpgroups over the same TMEM lanes (#94) #98 published. The forced-correction shape corrects on 100.00% of its 32 eligible visits and every other shape on 0.00%. It is byte-identical for a reason and not by luck: the wide band issues the same products over the same K chunks in the same order into the same accumulator columns, the deferred drain is the same drain later, and the batchedtcgen05.ldpair is the same two loads.--kernel flash-attn— green (the two-oracle gate), dq ≤ 2.726e-3, dk ≤ 1.730e-3, dv ≤ 5.377e-3.--kernel ops— green.--kernel model— green, 14/14 including both MoE substitutions,aligned_tcgen05_linears, checkpoint v5 and all four overfit gates. The MoE overfit lands 2.949803 → 0.000031, the recorded value exactly.KernelBudget: forward 128 / 0 and backward q 128 / 0, both unchanged; backward kv 140 → 138 / 0, ratcheted. Zero spill everywhere. The twomma_abwalks of kernel B each held two banded operand descriptors live where they now hold one.Same-container A/B, both orders
--baseline-ref d6b99ea, and throttled containers — the full step reads 764–776 ms where a clean standalone profile of either tree reads 339–344 (2.3x, the hazard #96 named). The row deltas are the measurement, not the percentages.d6b99eaforward.attention.flashbackward.attention.flash_qbackward.attention.flash_kvbackward.attention.flash_dotOrder reversed — this branch retained and profiled first at
b1d8925,d6b99eapassed as the candidate, so the sign of every row flips and the Δ column below is still "what this PR saves":d6b99ea(candidate)forward.attention.flashbackward.attention.flash_qbackward.attention.flash_kvbackward.attention.flash_dotOrder does not change a sign:
flash_q−0.61 one way and −1.06 the other,forward−0.36 and −0.49,flash_kv−0.53 and −1.12,flash_dotflat both ways. The named rows sum to −1.51 against a −1.97 step and −2.74 against a −7.53 step; the step total is the noisier of the two at this resolution and the row is what carries the claim. As in #98, the milliseconds survive the throttle better than the percentages do — what these changes remove is instruction issue and a store, neither of which is clock-throttled the way the surrounding kernel is.Clean standalone profiles
./run.sh model profile, §13.9 shape (L=12, B=12, T=2048, D=3072, H=24, HD=128, E=8, K=2), one clean container each:d6b99eaforward.attention.flashbackward.attention.flash_qbackward.attention.flash_kvbackward.attention.flash_dotbackward attentionis 57.01 → 43.80 → 36.77 → 36.09 ms over #94's four phases, and the forward joins the ledger for the first time since #68.Training smoke
--kernel model --bin train --shard /data/wiki-train-00000.tok --steps 100— 74 040 tokens/s, 32.88% MFU over 99 measured steps, loss 11.107 → 8.114 on #98's own curve (8.280 / 8.148 / 7.878 at steps 40/50/70). Against #98's 74 663 / 33.15% that is −0.8%, inside the ~2.9% the MoE scatter atomics give this run, and it shared its GPU with two other jobs besides. This gate is "it still trains"; the rows above are what carries the claim.What this does not do
No second issue warp — the cadence prices it at zero, and that is the one thing this PR could have been about that it deliberately is not.
BACKWARD_STAGESstays 3,GRADIENT_STAGESstays 2,PASS_GROUPSstays 2,SCORE_CHUNKstays 16, and the key tile stays 64 because 128 needs 256 KiB of shared memory against 227. Kernel B keeps its own epilogue: it drains two accumulators where A drains one, itsEPIis 6347 ticks an item, and deferring it is the same change again on a kernel that is not this issue's target — worth its own increment, not this one's diff.