Skip to content

[FlyDSL] [FMHA][gfx1250] m32x8 prefill: d64 support, wider shape coverage, and a rewritten KV pipeline - #6355

Merged
ruanjm merged 63 commits into
mainfrom
jruan/gfx1250_fdsL_fmha_gen2
Oct 19, 2026
Merged

ruanjm merged 63 commits into
mainfrom
jruan/gfx1250_fdsL_fmha_gen2

Conversation

@ruanjm

@ruanjm ruanjm commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

1. Capability

main this PR
qk_hdim 128, 192, 256 64, 128, 192, 256
v_hdim 128 (fixed, DEFAULT_V_HDIM) 64, 128
BLOCK_M 256, fixed auto-selected 128 / 256 per launch
single-KV-tile launches general core dedicated one-barrier core
bshd + d64/64 N/A runs
thd + d64/64 falls back to CK served by FlyDSL

(64, 64) is GPT-OSS-120b's shape (GQA 64/8, sliding window 128 + sinks).

2. Robustness

Three shapes that are broken on main run correctly here:

shape main this PR
bshd, Hq=Hkv=96, d256/128, sq=128 GPU hang 68.2 us
bshd, Hq=Hkv=96, d192/128, sq=131072 GPU hang 394.5 ms
bshd, d64/64 N/A runs

3. Register pressure

The 256/128 VGPR spill is fixed: the kernel now streams K/V from LDS through a ring instead of bursting a whole tile into registers before the first wmma.

qk_hdim main VGPR / spills this PR VGPR / spills
128 440 / 0 480 / 0
192 508 / 0 416 / 0
256 512 / 220 448 / 0

4. Performance

Same sitting, same instrument, same tree with only the 4 PR files swapped. {bshd,thd} x b{1,2,4} x 18 (Hq,Hkv) x sq{16384,65536} x {const-0.25, random}, causal + sink on. warmup 3 / repeat 5. Speedup = main us / this-PR us.

vs the hand-written ASM kernel (separate B0 box)

The ASM path is off on the A0 box this PR was developed on, so a colleague ran a 4-arm sweep
(asm / main / this-PR / this-PR+bank-hint) on a B0 machine: thd, causal, d{64/64, 128/128,
192/128} x sq{16384, 65536} x {const-0.25, random} x sink{on,off}, 425 configs. The four arms
run back-to-back per config (median 17 s apart), so the per-config ratios hold even though
absolute levels drift over the 23 h sweep.

On the 132 configs where all three kernels run:

vs ASM (median) faster than ASM
main's FlyDSL 0.745x 10/132
this PR 0.983x 48/132

So the PR closes essentially the whole gap to ASM. Over all 371 asm-vs-PR pairs the median is
0.980x, i.e. within ~2% of ASM, with a wide spread (0.79x - 1.91x):

d_qk/d_v sq init n median min max
128/128 16384 const 49 0.99x 0.87x 1.91x
128/128 16384 rand 49 1.00x 0.89x 1.81x
128/128 65536 const 17 0.93x 0.90x 1.01x
128/128 65536 rand 17 0.96x 0.93x 1.07x
192/128 16384 const 51 0.96x 0.86x 1.08x
192/128 16384 rand 51 1.01x 0.89x 1.08x
64/64 16384 const 51 0.96x 0.79x 1.23x
64/64 16384 rand 51 1.01x 0.81x 1.36x
64/64 65536 const 17 0.91x 0.87x 1.12x
64/64 65536 rand 18 0.96x 0.94x 1.11x

Two axes explain most of the spread. GQA ratio is the clearest: we match ASM at MHA and
fall behind as the ratio grows, which is where ASM's K/V reuse pays off most.

GQA 1 4 8 16 32 64 128
median vs ASM 0.998x 0.990x 0.985x 0.978x 0.978x 0.970x 0.945x

Sequence length is the other: 0.993x at sq=16384 against 0.945x at 65536. The best cells are
MHA with many heads (Hq=Hkv=64/96, d128, sq=16384) at up to 1.91x; the worst are small head
counts (Hq=16, ~0.79x-0.87x) and GQA-128 at sq=65536.

Caveats: a different machine and silicon stepping from the rest of this PR's numbers; 37
configs whose arms straddled a crash/restart are excluded; main is absent from 272 configs
because main's own dispatch gate hands those shapes to ASM; and d64 at sq=65536 was skipped
after it hung the ASM kernel.

The bank-hint arm (rocdl.schedule.bank on the ring fragments) measured 1.004x against this PR
-- a wash, matching what it measured on the A0 box -- so it is not part of the claim.

vs main's FlyDSL kernel

d_qk/d_v sq init n median min max
128/128 16384 const 108 1.34x 1.17x 2.71x
128/128 16384 rand 108 1.04x 0.83x 1.47x
128/128 65536 const 108 1.28x 1.22x 1.51x
128/128 65536 rand 108 1.18x 0.90x 1.29x
192/128 16384 const 108 1.25x 1.13x 2.32x
192/128 16384 rand 108 1.16x 0.84x 1.40x
192/128 65536 const 108 1.22x 1.16x 1.43x
192/128 65536 rand 108 1.17x 0.91x 1.26x

Median 1.20x over 864 configs, faster on 769/864. All 95 regressions are random-init at sq=16384 (worst 0.83x); no const-init config regresses. Random operands throttle the clock, and the faster kernel reaches that threshold sooner.

vs CK (d64/64 — main has no FlyDSL kernel for this shape)

d_qk/d_v sq init n median
64/64 16384 const 54 7.7x
64/64 16384 rand 54 4.5x
64/64 65536 const 54 8.1x
64/64 65536 rand 54 4.6x

Testing

Correctness sampled throughout: thd causal d192 GQA4 LSE+sink sq=290; thd non-causal d128 sq=8192; bshd causal d128 window(256,0)+LSE sq=2048; bshd causal d256 LSE sq=1024; thd causal d64 varlen --rand-seqlens; thd causal d128 gqa=8 sq=777. All err 0 in bf16 and fp16.

ruanjm and others added 30 commits September 18, 2026 08:07
…nd get slightly perf gain in 128/128 and 192/128
…KV fence

Triple-buffers the K|V LDS slots (N_KV_PP = 3) and moves the prefetch to
distance 2: body t issues tile t+2 into the oldest slot, which the loop
rotates through iter_args (3-cycle left rotation of the ds-load pointer sets
and of the three i32 slot bases). Stage 3 needs V(t) and K(t+1) live at once,
so the third slot is a prerequisite for it.

_drain_barrier becomes _kv_wait(num_tensorcnt=-1, num_asynccnt=-1) plus
_kv_fence (the same wait + barrier) and _kv_drain_depths. A counter is waited
only if the caller names it -- -1 skips it entirely, which is distinct from 0
("drain it") -- so a mixed loader pair (V1 K on asynccnt + V2 V on tensorcnt)
shares one fence while a single-loader build emits no dead waits. Stage 4
partial waits plug in here.

Two deviations from the plan, both measured:

- No tail peel. Peeling the last body (fence to 0, no prefetch) cost 5.5% on
  case 10 -- a third trace of this body. Instead the prefetch tile is clamped
  to last_tile, so every body issues exactly one tile's copies. The 2 dead
  L2-resident re-loads per workgroup land in slots nobody reads again; the
  epilogue drains the live counters so they do not outlive the kernel.

- KV_PARTIAL_FENCE = False. Leaving tile t+1 in flight across the body loses
  ~1.5% (min/med 1301/1317 us vs 1281/1293 for the full drain): with 3 slots
  it puts two of them under TDM writes while a third is read. Kept as a
  compile-time knob to revisit at stage 4, where K/V producer specialization
  cuts the descriptor count.

ISA: 408/450/480 VGPR, 0 spills at hdim 128/192/256. Case 10 @ init=fixed=0.25
is neutral vs stage A (1281 min / 1293 median vs 1279.3, same sitting); the
value of this stage is the slot depth stage 3 needs.

Verified: thd nc 8192 d128; thd causal 290 kv-tail d192 GQA4 LSE+sink; bshd
causal 1024 d256; thd nc 256/64 d128; d192 causal sq=sk=64/128/100 B=3 with
LSE (num_iter 1, 2, 2+tail); bshd causal 1024 d128 windows 256,i / 64,64 /
128,0 with LSE; thd nc d128 sink+LSE window 192,i --rand-seqlens 2.

Co-Authored-By: Claude Opus 5 <[email protected]>
…carried ring head

Rotate the main loop by one tile so body u runs PV(u-1) -> QK(u) -> softmax(u),
carrying P in iter_args. That puts the two gemms back to back and lets one ring
(_pv_qk_gemm, r24/l2) drive both operand streams.

The pipeline alone costs 5%: it deletes the window where the V ring head used to
hide under the softmax VALU. Restored by issuing the NEXT body's ring head before
softmax and carrying it across the back edge -- V(u) is already resident in the
slot this body read K(u) from.

Both pipeline ends are dead bodies rather than peeled traces (an extra trace cost
5.5% in Stage 2): the leading PV multiplies the zero-seeded P, and body num_tiles'
QK/softmax sits past kv_len so everything masks to -inf.

case 10 @ init=fixed=0.25: 1291.6/1310.1 -> 1267.1/1283.0 us min/median.
VGPR 408/450/480 -> 393/438/462 at hdim 128/192/256, 0 spills.

Co-Authored-By: Claude Opus 5 <[email protected]>
The LO half now issues every K tile copy and the HI half every V tile copy, each
as a num_warps=4 TDM copy instead of a cooperative num_warps=8 one. The lowering
derives a wave's row share from wave_id % num_warps, so waves 4..7 issuing a
4-warp copy cover exactly the tile waves 0..3 would; the drain barrier still
publishes both halves to everyone.

Each wave issues half as many copy atoms (9 vs 16 tensor_load_to_lds in the h128
ISA) and its tensorcnt now tracks a single operand -- the per-half counter the
partial fence and the LO/HI anti-phase split need.

Plumbs a num_warps kwarg through _tdm_load_views and KManager16bV2/VManager16bV2
load_views (default = the manager's num_waves, so V1 and every other caller are
unchanged).

VGPR 392/430/456 at hdim 128/192/256 (was 393/438/462), 0 spills. Case 10
@ init=fixed=0.25: min/median 1277.8/1283.7 us vs a same-sitting Stage 3
baseline of 1282.7/1285.5 -- neutral, as expected for an enabler. Passes the
full 9-config correctness suite.

Co-Authored-By: Claude Opus 5 <[email protected]>
Run the two wave-halves' phases in opposite order so each barrier window has
one half in the WMMA stream and the other in the softmax VALU stream:

  LO body u:  [drain BAR] head, prefetch | gemm(u)                | BAR | softmax(u)
  HI body u:  [drain BAR] prefetch, head | softmax(u-1) + rescale | BAR | gemm(u)

The lagging half carries S(u-1) (f32) across the back edge where the leading
half carries P(u-1) (bf16) -- same slot count, so _QS and the epilogue offsets
are unchanged. Its dead leading softmax(start_tile-1) is neutralized by seeding
s_acc to -inf, which is exactly _softmax's fully-masked path (m_new = m_prev,
corr = 1, P = 0, d unchanged) -- the same path the dead trailing body already
exercised. It also needs no carried ring head: the head is issued right after
the drain and consumed after the mid-body barrier, hiding under its own
softmax, so it trades 80 VGPR of head carry for 32 VGPR of s_acc.

Because the sub-loop split points are softmax-tile indices and the lagging half
softmaxes u-1, the clean loop starts one body later when a left loop exists to
absorb it. Body and barrier counts stay identical on both halves.

VGPR 402/440/468 @ qk_hdim 128/192/256, 0 spills (was 392/430/456).
Case 10 @ init=fixed=0.25, same sitting: min 1275.3 -> 1224.9 us (-4.0%),
median 1293.3 -> 1230.1 us (-4.9%); the two arms' spreads do not overlap.

Co-Authored-By: Claude Opus 5 <[email protected]>
This is a correctness harness, but it drove run_perftest at its defaults
(101 iters / 2 warmup), so every row spent nearly all its wall clock producing
a us column that nobody reads here -- one bshd d128 window row took 12.8s, of
which 3.7s was compile + allclose.

Default the loop to 3 iters / 1 warmup and add --bench to restore 101 / 2 for
the rare case the harness's own timing column matters. Perf measurement belongs
in op_tests/perf_mha_flydsl.py either way.

Co-Authored-By: Claude Opus 5 <[email protected]>
phase barrier, pinned ring-head pairs, s_setprio around the gemm

Review-driven restructuring of the anti-phase loop body. Functionally
equivalent; every change is about what the ISA schedules where.

- Both halves now issue the ring head immediately before the barrier that
  precedes the gemm consuming it. LO's head moves behind the softmax to
  mirror HI, so the two halves have identical body shape for tracing.
- Call _pv_qk_gemm directly; the _gemm_phase / _pv_qk wrapper is gone.
- _phase_barrier drops gpu.barrier() for a bare s_barrier_signal/wait. It is
  a scheduling rendezvous, not a memory publication, and gpu.barrier()'s
  workgroup fence lowered to s_wait_storecnt_dscnt 0x0, retiring the ring
  head the instant it was issued.
- _kv_fence gains num_dscnt so the drain barrier can leave the carried head
  in flight (s_wait_dscnt _NH instead of 0). The gemm's last ring fragment
  already takes dscnt to 0, so the WAR wall still holds.
- _keepalive anchors the f32->bf16 P conversion in the softmax block.
  MachineSink ignores SCHED_BARRIER and had sunk all 32 v_cvt_pk_bf16_f32
  into the WMMA stream.
- _issue_head pins EVERY fragment's load pair in the head burst, at all
  three burst sites (body, loop tail, and the _HEAD_BASE seed in the
  preheader). Fragment i consumes loads 2i and 2i+1; unpinned, a partner
  load drifted 12-15 slots back and the wmma waited on most of the burst
  (s_wait_dscnt 0x9 / 0x7 / 0x11) instead of the ring's 0x12. The compiler
  takes the max over all paths into the loop, so the preheader seed mattered
  on every iteration.
- s_setprio 1/0 brackets the WMMA stream: under anti-phase the other half is
  in its softmax VALU and the gemm half must win issue arbitration.

ISA: 386 / 447 / 503 VGPR at hdim 128 / 192 / 256, 0 spills. Every
mid-stream wait in the gemm is now the ring's own s_wait_dscnt 0x12 with no
compiler-inserted wait; what remains is the ring drain tail (0x10 down to
0x2, stepping by 2, four per gemm block).

Correctness sampled clean: thd causal d192 GQA4 LSE+sink sq=sk=290; bshd
causal d256 1024; bshd causal d128 windows 256,i and 64,64 with LSE.

Perf, case 10 --fix-init, same sitting, min/median of 6:
  prior commit 1221.1 / 1225.2 us
  this commit  1273.9 / 1294   us
The head-behind-softmax placement is the regression (it gives up the LDS
latency cover under the softmax VALU); it is kept deliberately as the
structure to capture a hardware thread trace against.

Co-Authored-By: Claude Opus 5 <[email protected]>
The HI half opened each body with the drain barrier, so the loop's back-edge
bookkeeping and _addr_phase's VALU/SALU landed in front of it and were serialized
against the leading half's WMMA stream. Moving the drain to the body tail puts
that work behind the barrier instead.

Rotating it shifts HI's barrier stream by one -- the body now opens with the
phase barrier and closes with the drain -- so HI gets one filler fence before the
loop and LO its partner after, keeping phase barrier paired with phase barrier.

Co-Authored-By: Claude Opus 5 <[email protected]>
…ave dense TDM

Stage A of the 12 x 26 KB LDS redesign. K and V move into separate chunks and every
K/V tile is split 2-way along n_block into chunks 156 KB apart, so a tile's two halves
always land in different 64 KB LDS segments. K[pp][s] = chunk 2pp + 6s,
V[pp][s] = chunk 2pp + 1 + 6s; 312 KB of the 320 KB budget.

Addressing stays one carried Int32 per slot (base = chunk 2pp), so _addr_phase's
wr_slot iter-arg and the yield's left-rotation are unchanged.

Q and O stop owning private LDS and time-share KV chunks. Q sits in slot 1 at
chunk_b = (w&1) ^ ((w>>2)&1), slice = w>>1, which puts every SIMD-mate pair on
opposite sides of the 156 KB boundary. O is keyed on the loop's carried slots and
lands in the two the loop has finished with; it occupies only a chunk's K region,
clearing the V rows the trailing dead ring head still reads by 512 B (asserted).

K/V producer specialization is now unconditional: LO issues every K copy, HI every V
copy, and each producer wave copies one dense n_block/4 row band by itself
(num_warps=1) instead of taking a share of every split. One tensor_load per wave per
pow2 hdim segment. This drops the cooperative path from KManager16bV2.load_views and
VManager16bV2.load_views, so the V1 managers no longer reach feature parity -- to be
refactored separately.

Also factors the bare s_barrier_signal/wait pair into _bare_barrier(), which is NOT
interchangeable with gpu.barrier(): the latter emits s_wait_storecnt_dscnt 0x0 and
would retire the in-flight ring head. Emitted ISA is unchanged by the refactor.

case 10 --fix-init, same sitting, interleaved: min 1243.9 / median 1255.4 us vs
min 1262.0 / median 1278.6 us, ~1.5-2% better. VGPR 388/453/499 at qk_hdim
128/192/256, 0 spills.

Co-Authored-By: Claude Opus 5 <[email protected]>
WarpType gains SIMD parity: LO_EVEN/LO_ODD/HI_EVEN/HI_ODD, with is_lo and
odd_simd predicates replacing the LO_WARP/HI_WARP comparisons. Odd SIMDs take a
tile's two n_block halves in the opposite order, so the two parities never sit in
the same 64 KB LDS segment set at the same point of a gemm.

Read side only -- the producer still writes split s to chunk s. The swap permutes
the kv-tile slots by ^(NKV/2) and the contraction slots by ^(nkt/2) together, so
S, P and the PV consumption stay mutually consistent; the softmax mask is the one
consumer of the absolute index and gets kv_slots_swapped, which only renames its
per-slot compile-time constant. Verified load-bearing: dropping it while keeping
the base swap fails a windowed shape on 45.8% of elements.

Gated on KV_SPLIT_PARITY_ORDER via fx.const_expr, so the flag picks the trace
width too -- off traces only the *_EVEN roles and emits ISA byte-identical to the
previous 2-way body (388 VGPR, 5083 insns at h128). On costs a 4-way trace: 396
VGPR and 9272 insns at h128, 0 spills at 128/192/256.

Measured on case 10 at fix-init the 4-way trace costs -3.6%, and a same-code-size
control (4-way trace, swap off) is indistinguishable from swap on -- the de-
conflict itself buys nothing here, because ds_load_ptrs builds its address with
no warp_idx term, so all four waves of a half issue byte-identical K/V ds_loads.
Kept behind the flag rather than deleted.

Co-Authored-By: Claude Opus 5 <[email protected]>
…rologue

K and V had asymmetric latency cover: the K written in body u was read in
body u+1 while V had two bodies, and the K ring wasted a slot on the already
dead K(u-1). LO now writes K(u+2) into slot_of[0] -- a chunk whose K half died
at body u-1 and whose V half this body reads out of a different chunk under the
12-chunk layout -- so K gets the same two bodies. WAR holds because LO's drain
barrier pairs with HI's previous one, i.e. behind HI's gemm(u-1).

That buys the partial s_wait_tensorcnt, but only on LO: HI's carried ring head
reads V one body before the PV gemm does, and the first rendezvous behind HI's
retirement is LO's D(u+2), so HI keeps the full drain. Steady state is now
tensorcnt 0x1 (0x2 at qk_hdim 192) on the four LO bodies.

LO also exits with two K copies in flight, one of them on an O chunk, so the
epilogue drain gains a rendezvous behind it -- a wave only retires its own
copies and O's chunk halves are shared across a wave pair.

Separately, _PSLOT maps logical slots onto physical chunks so the first tile
lands in the one slot Q never covers. Its copies, and HI's dead-PV filler, are
issued before Q is read and load_q_to_vgpr_part2 takes a skip_tensorcnt so it
drains Q alone -- one global-load latency of the prologue now overlaps Q's.

Measured neutral on case 10 at fixed init (compute bound in the main loop); the
partial fence is insurance against mclk and global-load variance. 396/442/498
VGPR at hdim 128/192/256, 0 spills, unchanged.
load_q_to_vgpr_part2 drained tensorcnt to skip_tensorcnt and never touched
asynccnt, which was right only because part1 issues TDM copies alone. A caller
that wants Q's global loads overlapped by async work needs to name asynccnt too,
and one that names neither should not pay a wait on a counter part1 never used.

Both counters now take a skip count whose -1 default means "not named": the wait
is then emitted at 0 for the counters part1 itself uses, listed in
_PART1_COUNTERS, and omitted for the rest. A named count is honoured either way,
so the existing skip_tensorcnt call site is unchanged.

ISA-equivalent to the previous commit at hdim 128/192/256.
Softmax is the long side of the anti-phase body -- wave i's softmax runs against
wave i+1's gemm, so the loop costs max(softmax, gemm) and anything removed from
softmax shows up until it falls under the gemm. Every exp was exp2(s*scale*log2e
- m*log2e), i.e. two constant multiplies per element on the critical side.

S now arrives already in log2 units, S' = S*softmax_scale*LOG2E, so the inner
loop is a bare exp2(S' - m) and m, corr and LSE live in the log2 domain. d is
domain-free: exp2 of a log2 difference is exp of the natural one. Only the
m-domain consumers move -- the sink seed gains a *LOG2E, LSE becomes
(m + log2 d)/LOG2E via the HW v_log_f32, and RESCALE_THRESHOLD compares against
8.0*LOG2E so the constant keeps its documented meaning in natural logits.

FOLD_SCALE_INTO_Q picks where the constant goes. True folds it into the bf16
multiply the Q loader already does: free, but rounded to bf16's 8 mantissa bits.
False passes scale=None to load_q_to_vgpr_part2, leaving Q raw, and the caller
applies _scale_s to the f32 QK accumulators instead -- exact, at R*NKV*8 VALU per
tile, and paid on the gemm side of the body, which is the shorter one. Expect to
key this off return_lse once training wants the precision.

Case 10 at fixed init: 1293.9 -> 1183.4 us mean, -8.5%; the exact path is
-6.6%. The win is larger than the op count suggests because the removed
v_fmamk_f32 carries a 32-bit literal and barely dual-issues, while the v_sub_f32
replacing it packs into VOPD -- 410 issue slots for 513 ops becomes 368 for 548.
396/442/498 VGPR at hdim 128/192/256, 0 spills, unchanged.
_kv_valid computed min(max(kv_len_wg - blk_row0, 0), n_block) from two uniform
scalars. AMDGPU has no s_med3_i32, so ISel folded the min/max pair into
V_MED3_I32 and the uniformity pass pulled the result back with
v_readfirstlane_b32 -- a VALU round trip on a value that was in an SGPR both
before and after, once per body per half, feeding nothing but the TDM
descriptor's valid-rows field.

Keyed on the tile index instead, the answer is n_block for every tile but the
last and a loop-invariant tail for that one, so the body is left with an s_cmp
and an s_cselect. Equivalent on every edge, including tiles past last_tile
(both saturate, matching _tile_row0) and empty KV.

All 10 v_readfirstlane_b32 and 10 of 12 v_med3_i32 are gone; VALU 5371 -> 5344.
The 2 remaining med3s are the epilogue's clamp(x,0,31), which has a real vector
consumer. Case 10 at fixed init: 1185.4 -> 1135.8 us mean, -4.2%, winning 5 of
5 interleaved rounds. 396/442/498 VGPR, 0 spills, unchanged.
The deferred-rescale gate over the wide `o_acc *= corr` multiply was emitted
once per q-row, so R=2 meant two wave-uniform branches back to back in the
softmax hot path. Neither row moves its running max in the steady state, so
both were almost always not-taken -- two s_cbranch_vccz to skip nothing.

_softmax now ORs the two rows' raw ballot masks (one s_or_b32) and returns a
single rescale_any; _softmax_phase gates all R*d_tiles vectors behind it.
Staleness stays per-row -- each row's m_new still tests its own ballot -- so
deferral is not weakened, and the taken path is exact because a row that stayed
stale has m_new == m_prev, hence corr == 1 and its multiply is the identity.

s_cbranch_vccz 11 -> 3. The larger effect is second-order: with the rows no
longer split across separate scf.if regions their m_new values land in a
consecutive VGPR pair, so LLVM packs the whole S - m_new exp-chain subtraction
two rows at a time -- v_pk_add_f32 96 -> 232, v_sub_f32 184 -> 72,
v_dual_sub_f32 182 -> 101. VALU 5344 -> 5286, SALU 3086 -> 3025, instructions
9131 -> 9012, s_delay_alu 355 -> 293.

Case 10 at fixed init: 1149.5 -> 1117.9 us mean, -2.7%, winning 5 of 5
interleaved rounds. 400/441/497 VGPR at h128/192/256, 0 spills.
_softmax narrowed P^T to the wmma element type on its way out, so every body
opened with a 32-instruction v_cvt_pk_bf16_f32 batch and only then issued the
next gemm's ring head. Nothing in the head depends on P -- it is ds_loads off
resident, already-fenced LDS -- so the head sat behind the conversion for no
reason.

The narrowing moves into a _p_to_elem helper that the caller places AFTER the
head, on both halves. _softmax now returns f32 P. In the ISA 20 ds_load_tr16
issue ahead of the cvt batch in all 8 traced bodies, where before it was 0.

Perf is a wash (1115.4 -> 1124.6 us mean over 11 runs, +0.8%, inside the ~2%
band): the whole +152 SALU is s_set_vgpr_msb 1123 -> 1242 and s_wait_alu
199 -> 216, mostly depctr_va_vdst(4) -- bank-switch and VALU-dest-to-ds_load
hazard padding around the moved loads, not the reorder itself. Kept because the
schedule is the one we want; the msb traffic is a separate problem.

398/441/506 VGPR at h128/192/256, 0 spills (506 vs 497 is P's wider f32 live
range across the head).
The deferred-rescale gate was computed inside _softmax, right where the row
maxes are: v_cmp against the threshold, then s_cmp_eq / s_cselect to broadcast
the ballot back to the lanes for m_new's select, then the s_or fold. That put a
VALU->SALU->VALU turnaround between the max tree and the exp chain, ~230
instructions ahead of the s_cbranch that actually consumes it.

Two changes. _softmax returns the R raw ballots instead of a folded condition,
and _softmax_phase ORs them at the use site -- which lets the != 0 test collapse
into s_or_b32's own SCC side-effect, so the branch reads SCC straight from the
OR. And m_new selects on the per-lane `need` rather than on the ballot: every
lane owns its own q row (the l<->l^16 pair shares one and agrees after the peer
reduce), so staleness is a per-lane decision and the ballot was only ever the
branch condition. With m_new off it, the fold has no other consumer and sinks on
its own.

Staleness is per-lane now, not wave-uniform -- a lane below threshold keeps its
own m even when another lane crossed. That is tighter, not looser, and the gate
stays exact: a lane with corr == 1 is the identity inside the taken branch.

At the compare site the scalar cluster is gone (v_cmp feeds v_cndmask directly)
and the fold is a lone s_or_b32 18 instructions ahead of the branch. VALU
5312 -> 5286, SALU 3174 -> 3120, instructions 9134 -> 9054.

Perf is even -- 10 order-balanced pairs at fixed init split 5-5, pooled 1111.0
vs 1108.2 us mean, inside the drift between sittings. Taken for the -80
instructions and the placement. This supersedes an earlier rejection of the same
per-lane select, which measured +1.7% slower before the one-branch commit
repacked this region.

404/441/506 VGPR at h128/192/256, 0 spills.
…128 at h128

KV_SPLIT_PARITY_ORDER split WarpType four ways, and the four copies run
concurrently on one CU's four SIMDs, so the I$ working set was their sum --
95 KB at n_block=128 against a 64 KB SQC I$. Carry the parity off warp_idx
instead: the split bases are built once in the prologue and live in iter_args,
so the only in-loop cost is one extra mask base. 50 KB at h128, and the wide
tile now pays: -6.6% on case 10, -18% on thd d128 sq=4096.

Cap the widening at qk_hdim 128 -- h192 spills 49 VGPRs at n_block=128.
The ~170 v_nop in the kernel were the backend interleaving pass 2's subs with
its exps: a TRANS coexecution hazard is TRANS followed by a non-TRANS VALU, so
an interleaved stream needs a pad after almost every exp. Emit both q-rows'
subs before any exp and the exp run is pure TRANS, which needs none of them --
and the bunched subs, all reading their row's shared m_new, pair up into
v_dual_sub_f32 (gfx12+ allows an identical src register in both VOPD halves).

h128: v_nop 170 -> 12, v_dual_sub_f32 148 -> 252, v_sub_f32 236 -> 32,
7669 -> 7223 instructions, 476 VGPR / 0 spills unchanged. -1.8% on case 10
over 9 interleaved pairs.
The rebase onto main carried over main's import-block cleanup but left the
bodies on the old API. Finish the migration, keeping this branch's algorithm:

  rocdl_dialect.*          -> rocdl.*        (flydsl.expr, not _mlir.dialects)
  buffer_ops.create_llvm_ptr -> create_llvm_ptr (..kernels_common)
  ir.F32Type.get()         -> T.f32
  scf_if_dispatch(...)     -> local @flyc.jit helper with a Python `if`
  scf.for_ + scf.yield_    -> `for ... in range(..., init=state)` + yield

The deferred-rescale gate keeps its single folded condition over all R rows
(one s_or_b32 / one not-taken branch), now expressed as a @flyc.jit helper
over the flattened o/corr lists rather than scf_if_dispatch's result_names
plumbing. Restores the tdm_ops import main moved into the top import group.

Also applies black (CI runs psf/black@stable); the branch's own code was not
stable-clean and would have failed pre-checks.

Co-Authored-By: Claude Opus 5 <[email protected]>
flash_attn_varlen_m32x8 returned LSE as [total_q, nheads_q], the transpose
of what every other varlen backend returns: CK mha_varlen_fwd and the
gfx1250 ASM fmha_fwd_with_sink_varlen_asm both emit [nheads_q, total_q],
which is also what flash_attn_varlen_func documents. The public entry
therefore handed back a different LSE layout depending on which backend
the router picked -- visible today only at qk_hdim=192/v_hdim=128 with no
sink, the one varlen config the ASM pre-screen claims.

The kernel writes LSE through generic stride_lse_seq/stride_lse_head, so
the layout change is confined to the wrapper's allocation and strides.

lse_num_records_bytes has to move with it. It bounded the buffer resource
by the seq axis alone, which is exact when seq is the major axis and
collapses to a few bytes when it is the minor one -- the resource would
have dropped nearly every LSE write. Bound it by the last element the
batch can touch over both axes instead; that is exactly numel*4 for a
contiguous LSE on the last batch under either layout.

Co-Authored-By: Claude Opus 5 <[email protected]>
The LDS->VGPR ring is built so a refill's registers were last read
lag*R wmma ago -- 4 for the pvqk ring. The hazard pass should therefore
cover every ring refill with s_wait_alu depctr_va_vdst(4) and nothing
tighter. It did not: the ISA carried va_vdst(0), (1), (2) and (3).

Two causes, both verified in the dump rather than inferred.

The (1)s came from registers the ring does not own. A P^T bf16 B operand
is reused by every d-tile and dies on the final d-tile row -- exactly
where the V->K transition's refills land -- so regalloc handed the
refill a pair freed one VALU earlier instead of one freed by a
_keepalive. _ring_drive grows a `dies` hook that names those values on
the fragment that last reads them, routing them through the same
release queue as the ring pairs so a refill sees a single distance.

The rest came from the scheduler. The hazard pass measures a refill
from where the release actually sits, so any ds_load the scheduler
slides above a keepalive, or wmma it slides across a ds_load, detaches
the emitted distance from the geometry the ring was built for. Fence
every ring wmma, every ring ds_load (prefetch burst included) and both
sides of the release point with sched_barrier(0).

bshd bf16 B=1 S=512 H=8 D=128 non-causal, after-keepalive waits:
2x(0) 3x(1) 1x(2) 1x(3) 106x(4) -> 2x(0) 85x(4), rest looser.
The residual (0)s are each ring's first release at ramp-in, where the
free pool is empty and regalloc hands back the pair the adjacent
keepalive just dropped; the (6)/(8)/(10) values are weaker waits at the
V->K boundary, not stalls.

Fencing also lowered pressure: bshd 500 -> 484 VGPRs. A 22-config sweep
(3 hdim pairs x causal x {bshd,thd}, plus lse/sink/window/GQA) spills on
none. Perf neutral across cases 3/10/12/13/17 (+-1%); bshd correctness
suite clean.

Co-Authored-By: Claude Opus 5 <[email protected]>
Each ANTI_PHASE body executed two s_barriers: the drain barrier, which is
followed by tensor_load_to_lds and gates the TDM overwrite of an LDS chunk
against its readers, and the anti-phase wall, which is a pure scheduling
device -- _bare_barrier emits no memory fence, and LDS publication is already
covered by _kv_fence's tensorcnt wait + gpu.barrier. Only the first is
required.

Gate the wall on a compile-time constant so both warp-specialized halves
always agree on the barrier count, and drop it everywhere it measured as a
win: 2 barriers per body -> 1 for qk_hdim 128/192, and for window-masked
qk_hdim 256. Keep it for non-window-masked qk_hdim 256, which runs n_block 64
with twice the QK fragments per body and regresses ~4% without it.

Measured against HEAD, 6 runs per side with the JIT disk cache wiped on every
variant switch:

  thd  d128 2048 window(256,256)  146.93 -> 126.38 us  -13.99%  t=-4.4
  bshd d192 2048 window(128,0)     53.80 ->  49.67 us   -7.66%  t=-11.9
  thd  d256 2048 window(256,256)   72.41 ->  68.65 us   -5.20%  t=-11.1
  bshd d128 32769 causal         1211.91 ->1187.32 us   -2.03%  t=-6.7
  bshd d192 32769 causal         1481.48 ->1452.66 us   -1.94%  t=-5.0
  thd  d128 16384 causal         1235.26 ->1214.88 us   -1.65%  t=-3.5
  thd  d256 16384 causal (kept)  1648.43 ->1644.56 us   -0.23%  t=-0.4
  bshd d256 4095 causal  (kept)    95.97 ->  95.47 us   -0.52%  t=-1.2

The two kept configs are null controls and come out flat; under unconditional
removal they were +4.2% and +4.3%.

Whole-kernel barrier totals: 16->12 (d128/d192 causal), 20->14 (d128 window),
20->16 (d256 window), 16->16 where kept. VGPR and spill counts unchanged.
Correctness: 30 configs across both layouts, all three hdims and every mask
mode pass against a torch f32 reference, max element-wise error 0.0185.

Details in /jruan/temps/20260918_perf_diff_fmha_asm_fdsl/phase_barrier_removal.md.

Co-Authored-By: Claude Opus 5 <[email protected]>
Under anti-phase, LO and HI alternate between the WMMA stream and the softmax
VALU, and SIMD-mates arbitrate for issue. Both halves used to rest at priority 0
and raise to 1 only inside _pv_qk_gemm, which leaves the half that is behind
competing on equal terms with the mate that is ahead.

Give the gemm stream one more level (1 -> 2) so it still outranks a mate that is
resting raised, and park HI at 1 rather than 0 from the first barrier both halves
reach: before that point the two are still in the symmetric Q/KV prologue, so
there is no lagging half to favour. _pv_qk_gemm's exit restores the same resting
level after every gemm, which is why it now takes warp_type.

LO is unchanged -- it keeps resting at 0, and at equal priority the lower wave id
wins arbitration anyway. warp_type is a Python-level compile-time constant, so LO
traces no instruction for any of this.

Co-Authored-By: Claude Opus 5 <[email protected]>
The two K/V manager families differed only in how a tile reaches LDS --
V1 cluster_load_async_to_lds, V2 TDM -- yet each carried its own LDS
layout, fragment reads and call-site protocol. Give V1 the padded
row-major layout V2 already used and the split collapses: one class per
operand, plus a transport mixin. V2 now subclasses V1 and overrides
nothing but the transport.

Adopting the padded layout also deletes V1's second, round-robin address
path. In row-major LDS the column step is the same on both sides of the
copy, so the async op's compile-time immediate -- which hits source and
destination in lockstep -- IS the column stride, and an 8-row block costs
one pointer pair with the columns walked by the immediate.

global_load_ptrs (a tuple of pointer lists) and load_views (TDM views)
become one load_descriptor returning a BufferOpDescriptor: built pure so
its address VALU can sink into an unrelated load's shadow, issued later
with async_load(), and self-describing on how many of this wave's copies
land on asynccnt and on tensorcnt. Callers say "fill this tile" and never
branch on the loader family; USE_TDM_LOADER now only picks a class pair.

With that, V1 takes the LO-K/HI-V producer split, and K-ahead stops being
V2-only: s_wait_asynccnt takes a depth just as tensor_wait does and both
retire in issue order, so LO's steady-state fence skips its whole K band
(16 copies at d128/n_block 128) instead of draining to 0.

Q V1's LDS reads still used fx.ptr_load, which the post-rebase FlyDSL
rejects for addrspace 3; they now use the same llvm load the K manager
does. That path had not compiled since the API migration.

V2's ISA is byte-identical at qk_hdim 128 and 192. V1 is correct at both
hdims x n_block 64 and 128, with and without K-ahead. V1 at d128/n_block
128 spills 11 VGPRs, entirely in the prologue -- the per-lane address
VGPRs the TDM transport exists to avoid; V2 and every other V1 config are
spill-free.

Co-Authored-By: Claude Opus 5 <[email protected]>
The gfx1250 prefill ASM gate in flash_attn_varlen_func sits ahead of the
FlyDSL dispatch and yields to it for d128 when experimental is on, but not
for d192. The bshd router has no such gate at all -- flash_attn_func tries
FlyDSL first -- so the two layouts disagreed: bshd d192 reached the m32x8
kernel, thd d192 never did, and every d192 varlen shape was silently served
by ASM instead.

Widen the yield to 192. d64 keeps ASM (there is no FlyDSL d64 kernel, so
yielding would drop it to CK) and d256 was never claimed by this gate.

Co-Authored-By: Claude Opus 5 <[email protected]>
Move the ad-hoc perf script to op_tests/op_benchmarks/flydsl/bench_mha_fwd.py,
next to the existing bench_mha_bwd.py, and put it under version control.

It drives the same public wrappers as test_mha_flydsl.py but computes no
reference: it forces AITER_ENABLE_EXPERIMENTAL=1 before importing aiter and
spies on the m32x8 dispatch entry, so a silent fallthrough to CK or to the
prefill ASM kernel fails loudly instead of quietly mis-measuring.

Also correct three strings that still described the coverage as 128/128 --
the case table replays each shape at 128/128, 192/128 and 256/128 -- and
point test_mha_flydsl.py's perf note at the new path.

Co-Authored-By: Claude Opus 5 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Routing can claim unsupported GQA ratios, and caller-provided output buffers can cause out-of-bounds writes for mixed dimensions.

1 open finding
Previously missed (3)

In code that hasn't changed since last review

Medium severity Reject unsupported GQA ratios before JIT compilation

aiter/​ops/​flydsl/​fmha_kernels.py:374

This router claims every divisible head ratio, but the selected TDM Q/O managers require the GQA ratio to divide or be a multiple of the packed rows (16 or 32). For example, Hq/Hkv=6/1 passes the supported predicate and then asserts during JIT compilation instead of returning None for fallback. Gate the route using the packing invariant for the actual num_q_tiles_per_wave, or make the managers support arbitrary divisible ratios.

This issue also appears on line 490 of the same file.

Low severity Correct m32x8 dispatch description

op_tests/​op_benchmarks/​flydsl/​bench_mha_fwd.py:90

This dispatch description contradicts the router added in this PR: m32x8 accepts all supported bf16/fp16 dimension pairs without an experimental gate; the environment variable only makes the competing THD ASM path yield the shapes it claims. Keeping the old 128/128-only wording makes failures in this benchmark misleading.

This issue also appears in the following locations of the same file:

  • line 205
  • line 574
  • line 581
  • line 637
Low severity Document nheads_kv sweep behavior when omitted

op_tests/​test_mha_flydsl.py:675

This new defaulting behavior conflicts with the existing --nheads_kv help, which says omission defaults to --nheads. With -nh alone the code now sweeps all built-in KV-head values, so the CLI documentation needs to describe that GQA/MQA cross product.

🧠 Review effort: Balanced

Comment thread aiter/ops/flydsl/fmha_kernels.py Resolved
@zufayu

zufayu commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Where that review came from — I ran the bot on your PR to show what it does. It is not an automatic hook; nothing reviews your PR unless somebody asks.

Any reviewer on the aiter allowlist can ask for one, on any PR including their own. The trigger is a comment containing the words below — shown quoted here, because quoted lines deliberately do not trigger it:

@aiter-bot review

  • Reviews the PR at its current head. Comment again after pushing fixes for a fresh pass; a repeat on the same commit is deduped.
  • One review runs at a time on one box, roughly 20 minutes. If work is ahead of you the bot replies with your place in the queue, and if the runner is down it says so rather than leaving you waiting for a review that will never start.
  • The card is advisory. It never blocks a merge, 🔴 included — it is there to be argued with.

Feedback on the review itself is welcome; it is how the rules get better.

ruanjm and others added 3 commits October 13, 2026 10:04
A wave owns WMMA_M * num_q_tiles contiguous packed (seq, head) rows and
Q/O describe that tile with one rectangular TDM box, so a head group
must never straddle a wave boundary. Ratios like 6 or 24 do straddle,
and the routers passed them through to a kernel assert.

Gate both routers on supports_gqa_ratio(), defined in the kernel beside
the geometry it derives from, and have the test import the same rule
instead of restating it. Unsupported ratios now fall through to CK.

ISA byte-identical at qk_hdim 128; the helper is host-side only.

Co-Authored-By: Claude Opus 5 <[email protected]>
supports_gqa_ratio required the ratio to pack for every num_q_tiles
choice, but _pick_num_q_tiles only picks one. gqa 48 straddles a wave
at rows_per_warp 32 yet sits inside a head group at 16, so it was
declined for no reason.

Restrict the picker to the choices that pack and accept a ratio when
that set is non-empty, sharing one predicate between the two so they
cannot disagree. This adds 48, 80, 112, ... (odd multiples of 16) and
leaves every already-served ratio on the same choice set, so the ISA is
byte-identical. gqa 48 is pinned to num_q_tiles=1.

Co-Authored-By: Claude Opus 5 <[email protected]>
Only the out=None path was fixed to size from v_hdim; a caller's buffer
went through unchecked. The kernel writes v_hdim values per row using
out's own strides, so at the routed (64,128) pair a q-shaped buffer was
written past its end.

Check dtype, device, contiguous last dimension and exact shape, the
same set common_mha_fwd_fake_tensors checks, and raise on a mismatch.
No backend can serve a malformed out, so failing here names the problem
rather than deferring it. The check runs only for requests m32x8 would
serve.

Co-Authored-By: Claude Opus 5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 13, 2026 10:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The new sweep can materialize millions of cases, and omitted KV-head arguments no longer follow the documented CLI behavior.

0 open findings

1 resolved since last review
Previously missed (2)

In code that hasn't changed since last review

Medium severity Preserve query-head fallback when KV heads are unspecified

op_tests/​test_mha_flydsl.py:674

When -nh is provided without -nhkv, this now uses every built-in KV-head value rather than defaulting KV heads to the requested query-head values as the CLI help promises. For example, -nh 96 will not test the intended Hq=Hkv=96 shape at all. Preserve the documented fallback when query heads are explicitly supplied.

Medium severity Apply max-cases before materializing the full Cartesian product

op_tests/​test_mha_flydsl.py:919

--max-cases is applied only after this list has materialized the full Cartesian product, so it does not actually bound the sweep's memory cost. With the new partial-axis defaults, a representative partial invocation can build about 4.8 million case tuples per layout before retaining 256, causing substantial transient memory and startup overhead. Please sample lazily (for example, bounded reservoir sampling) or sample product indices before constructing the selected cases.

🧠 Review effort: Balanced

-nhkv unset lost the plain-MHA fallback the flag documents, so -nh 96
tested gqa 96/48/32/24/12 and never Hq=Hkv=96. Restore the precedence
-nhkv -> -nh -> built-ins.

--max-cases filtered a materialized product, so a partial invocation
built every tuple before keeping a few hundred -- 4.5M tuples, 476 MB
and 4.5s for -b 1 --rand-seqlens 4. Sample product indices instead and
decode them: 0.04 MB, 1 ms. The hdim filter is applied to its axis up
front so the index space stays exact.

Co-Authored-By: Claude Opus 5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 07:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The widened router can silently ignore soft-capping and physical-padding semantics for newly claimed varlen shapes.

2 open findings
Previously missed (3)

In code that hasn't changed since last review

Low severity Update dispatch-verification docstring for widened routing

op_tests/​op_benchmarks/​flydsl/​bench_mha_fwd.py:90

The dispatch-verification docstring still describes the old 128/128 bf16-only gate, while this PR routes all supported QK/V pairs in bf16 and fp16. This is the benchmark's explanation of what the spy protects, so it should match the widened router.

Low severity Update help text with supported Q/K dimensions

op_tests/​op_benchmarks/​flydsl/​bench_mha_fwd.py:574

This help text contradicts the benchmark's supported Q/K dimensions and rejects none of them; detailed mode accepts 64, 128, 192, and 256. Update the advertised values so users can discover and benchmark the newly added paths.

Low severity Update help text to advertise V dimensions 64 and 128

op_tests/​op_benchmarks/​flydsl/​bench_mha_fwd.py:581

This help text is stale: the benchmark and router now support V dimensions 64 and 128. As written, --help hides the newly added d64 path.

🧠 Review effort: Balanced

Comment thread aiter/ops/flydsl/fmha_kernels.py Resolved
Comment thread aiter/ops/flydsl/fmha_kernels.py Resolved
flash_attn_varlen_func accepts both and CK honours them, but the FlyDSL
screen checked neither, so m32x8 served them under the wrong contract
and returned plausible-looking numbers: a soft-capped request matched
the UNCAPPED reference (err 0.05 vs 1.65 against the capped one), and a
padded multi-batch request shifted every sequence after the first
(max err 2.71 on batch 1).

Screen both off the FlyDSL path next to the existing descale and
sink-size screens. Add check_routing_declines(), which asserts the
dispatch itself -- a numeric sweep cannot see an option that is silently
ignored. Verified it fails without the screen.

Co-Authored-By: Claude Opus 5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 08:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Dispatch can still silently ignore unsupported options or misread non-packed Q/K/V tensors.

2 open findings
2 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Low severity Document all supported detailed-mode Q/K dimensions

op_tests/​op_benchmarks/​flydsl/​bench_mha_fwd.py:574

This help text contradicts the benchmark's documented and routed Q/K dimensions, which are 64, 128, 192, and 256. As written, it hides the newly supported detailed-mode values from users.

This issue also appears on line 581 of the same file.

🧠 Review effort: Balanced

Comment thread aiter/ops/flydsl/fmha_kernels.py Resolved
Comment thread aiter/ops/mha.py Resolved
Copilot AI balanced review requested due to automatic review settings October 16, 2026 06:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Expanded dispatch bypasses autograd for newly supported training inputs, and zero-length THD benchmarks fail before dispatch.

3 open findings
2 resolved since last review

🧠 Review effort: Balanced

Comment thread aiter/ops/flydsl/fmha_kernels.py Resolved
Comment thread aiter/ops/flydsl/fmha_kernels.py Resolved
Copilot AI balanced review requested due to automatic review settings October 16, 2026 06:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The benchmark timing includes host-side launch gaps, compromising kernel latency comparisons.

0 open findings

3 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Benchmark timing includes Python overhead instead of device execution

op_tests/​op_benchmarks/​flydsl/​bench_mha_fwd.py:80

Recording the start event before the full Python attention wrapper measures more than kernel execution: the GPU can process that event while Python is still routing, allocating outputs, and preparing the launch. Those idle gaps can dominate the tiny single-tile cases and distort the reported latency and TFLOPS. Use the profiler-backed run_perftest to sum device execution time, converting its microsecond result to milliseconds. Set num_rotate_args=1 because this closure has no explicit tensor arguments to rotate.

🧠 Review effort: Balanced

@coderfeli coderfeli left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ruanjm
ruanjm merged commit 8f2715a into main Oct 19, 2026
@ruanjm
ruanjm deleted the jruan/gfx1250_fdsL_fmha_gen2 branch October 19, 2026 02:49
yuychang added a commit to yuychang/aiter that referenced this pull request Oct 19, 2026
…m#6355 and ROCm#6616

- fmha_kernels.py: keep main's new _check_out and this branch's _fp8_gfx950_reject_reason rename.
- mha.py: keep the try_flydsl descale routing and gate the FlyDSL route on ck_only_feature is None.
- That keeps main's exclusion of padded cu_seqlens and logits soft-cap for every varlen call, not only descaled ones.
shay-li77 added a commit that referenced this pull request Oct 27, 2026
Conflict in aiter/ops/mha.py, can_try_gfx1250_fmha_fwd_with_sink_varlen_asm:
#6355 widened the experimental FlyDSL m32x8 yield to hdim 64/128/192 on the
line right after this branch's D192x128 stride check. Keep both: the stride
check first, then main's yield.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants