Repository navigation
[FlyDSL] [CI] FlyDSL FMHA forward-prefill A16W16 kernel for gfx1250 (fmha_fwd_prefill_m32x8) - #5168
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
fmha_fwd_prefill_m32x8)fmha_fwd_prefill_m32x8)
There was a problem hiding this comment.
Pull request overview
Adds a new FlyDSL Flash-Attention forward/prefill implementation for gfx1250 (m32x8, wave32/8-waves) and updates routing so supported bf16 head-dim cases prefer the new kernel while preserving fallbacks (ASM/CK/Triton). Also consolidates and expands gfx1250 MHA test coverage (THD varlen + BSHD batched) and extends checkAllclose to support masked comparisons.
Changes:
- Introduces the gfx1250 FlyDSL FMHA forward/prefill kernel (
fmha_fwd_prefill_m32x8) plus new shared Q/K/V/O staging/buffer-manager infrastructure. - Updates dispatch/routing in
aiter/ops/mha.pyandaiter/ops/flydsl/fmha_kernels.py, including a new FlyDSL BSHD entry. - Replaces the old varlen-only test with a unified gfx1250 FlyDSL MHA test/benchmark script and adds masked-check support in
checkAllclose.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
op_tests/test_mha_flydsl.py |
New unified THD+BSHD gfx1250 FlyDSL MHA correctness/perf harness (replaces prior varlen-only test). |
op_tests/test_mha_flydsl_varlen.py |
Removes the legacy varlen-only test script. |
aiter/test_common.py |
Adds mask support to checkAllclose for selectively ignoring elements. |
aiter/ops/mha.py |
Adds FlyDSL batched routing and improves sink/window gating to avoid silent feature drops. |
aiter/ops/flydsl/kernels/fmha_gfx1250/mha_buffer_managers.py |
New/updated staging managers for Q/K/V/O (async + TDM variants) used by gfx1250 FMHA kernels. |
aiter/ops/flydsl/kernels/fmha_gfx1250/fmha_fwd_prefill_m32x8.py |
Adds the new m32x8 forward-prefill kernel implementation plus build/launch wrappers. |
aiter/ops/flydsl/fmha_kernels.py |
Updates FlyDSL varlen routing and adds FlyDSL BSHD entry routing to m32x8. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Suppressed comments (10)
Previously missed (6) — in code that hasn't changed since the last review.
aiter/ops/flydsl/fmha_kernels.py:356
flydsl_flash_attn_batch_funcclaims unsupported features (includingdeterministic) should fall through, but thesupportedgate doesn’t checkdeterministic. This can route deterministic requests into the FlyDSL kernel even though the contract says it should fall through (and it’s inconsistent with the varlen gate).
and not return_attn_probs
op_tests/test_mha_flydsl.py:906
- The sink axis is currently restricted to (128,128) based on an older “m16x8-only” assumption. The new gfx1250 m32x8 path supports sink for the supported (d_qk,d_v) pairs, so this restriction skips sink coverage for 192/128 and 256/128.
def _sink_axis(d_qk, d_v):
return (
sink_list if (d_qk, d_v) == (128, 128) else [s for s in sink_list if not s]
)
op_tests/test_mha_flydsl.py:912
- The sliding-window axis is currently restricted to (128,128) based on an older “m16x8-only” assumption. The new gfx1250 m32x8 path supports sliding window for the supported (d_qk,d_v) pairs, so this skips window coverage for 192/128 and 256/128.
def _window_axis(d_qk, d_v):
return window_list if (d_qk, d_v) == (128, 128) else [(-1, -1)]
op_tests/test_mha_flydsl.py:730
- The script currently disables the entire BSHD suite unless
AITER_ENABLE_EXPERIMENTAL=1, but BSHD 128/128 and 192/128 route to the m32x8 kernel by default (only 256/128 is experimental). This skip prevents the default-route batch path from being tested.
if not is_experimental_enabled():
if run_bshd:
print(" SKIP bshd suite: set AITER_ENABLE_EXPERIMENTAL=1")
run_bshd = False
aiter/ops/mha.py:3691
- This comment refers to an “experimental FlyDSL m16x8 kernel” owning the 128/128 path, but this PR introduces/uses the m32x8 kernel for gfx1250 routing. The logic is fine (yielding the ASM gate under experimental), but the comment is now misleading.
# Experimental FlyDSL m16x8 kernel owns the 128/128 path when enabled;
# yield so it reaches flydsl_flash_attn_varlen_func below.
if hdim_q == 128 and is_experimental_enabled():
aiter/ops/flydsl/kernels/fmha_gfx1250/fmha_fwd_prefill_m32x8.py:1860
gqais computed with floor division but there’s no validation thatnheads_qis a multiple ofnheads_k. If a caller ever passes an invalid head configuration, this will silently compute the wronggqa_ratioand can lead to incorrect indexing.
This issue also appears on line 1993 of the same file.
nheads_q = q.shape[1]
nheads_k = k.shape[1]
gqa = nheads_q // nheads_k
aiter/ops/flydsl/kernels/fmha_gfx1250/fmha_fwd_prefill_m32x8.py:1423
- The THD kernel entry docstring says “empty scaffold”, but this file contains the full compute loop + epilogue and is routed as a default path per the PR description. Please update the docstring to avoid implying the kernel is unimplemented.
"""Varlen THD entry — empty scaffold.
THD: this batch's token ranges come from cu_seqlens (batch = grid.z).
"""
aiter/ops/flydsl/kernels/fmha_gfx1250/fmha_fwd_prefill_m32x8.py:1525
- The BSHD kernel entry docstring says “empty scaffold”, but the kernel is implemented and routed by default for supported shapes. This wording is misleading and contradicts the PR description.
"""Batched BSHD entry — empty scaffold.
Uniform sequence lengths (``seq_len_q`` / ``seq_len_k``) replace
cu_seqlens — nothing transient, so this path is CUDA-graph safe.
Token base is batch_idx * seq_len (batch = grid.z).
aiter/ops/flydsl/kernels/fmha_gfx1250/fmha_fwd_prefill_m32x8.py:1595
- This NOTE says “v1 scaffold” and that launching produces no output yet, but this module is being routed as a default kernel. Leaving this note as-is makes it look like routing is enabled for an unimplemented kernel.
# NOTE: v1 scaffold. The device kernel bodies are empty, so launching produces
# no output yet — this wiring exists so the dispatch paths in fmha_kernels.py can
# route qk_hdim==128 here while the kernel is being built out.
aiter/ops/flydsl/kernels/fmha_gfx1250/fmha_fwd_prefill_m32x8.py:1996
gqais computed with floor division but there’s no validation thatnheads_qis a multiple ofnheads_k(BSHD). If a caller passes an invalid head configuration, this will silently compute the wronggqa_ratioand can lead to incorrect indexing.
batch, seq_len_q, nheads_q, _ = q.shape
seq_len_k = k.shape[1]
nheads_k = k.shape[2]
gqa = nheads_q // nheads_k
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Suppressed comments (4)
Previously missed (3) — in code that hasn't changed since the last review.
op_tests/test_mha_flydsl.py:734
- The test currently skips the entire BSHD suite when
AITER_ENABLE_EXPERIMENTALis off, butflydsl_flash_attn_batch_funcsupports D_qk in (128, 192) without the experimental gate. This means the default batched routing for 128/192 is never exercised by the test script.
if not is_experimental_enabled():
if run_bshd:
print(" SKIP bshd suite: set AITER_ENABLE_EXPERIMENTAL=1")
run_bshd = False
if run_thd:
aiter/ops/mha.py:3692
- The comment says "experimental FlyDSL m16x8" owns the 128/128 path, but the routing added in this PR uses the m32x8 kernel (
flash_attn_*_m32x8). This is confusing when reading the dispatch logic.
# Experimental FlyDSL m16x8 kernel owns the 128/128 path when enabled;
# yield so it reaches flydsl_flash_attn_varlen_func below.
if hdim_q == 128 and is_experimental_enabled():
return False
aiter/ops/flydsl/kernels/fmha_gfx1250/fmha_fwd_prefill_m32x8.py:1829
- The host-entry docstring says
qk_hdim=v_hdim=128, but this function supportsqk_hdimin{128, 192, 256}(withv_hdim=128). Updating this avoids misleading callers.
This issue also appears on line 1959 of the same file.
"""Host entry — varlen THD, qk_hdim=v_hdim=128, bf16.
aiter/ops/flydsl/kernels/fmha_gfx1250/fmha_fwd_prefill_m32x8.py:1959
- The host-entry docstring says
qk_hdim=v_hdim=128, but this function supportsqk_hdimin{128, 192, 256}(withv_hdim=128). Updating this avoids misleading callers.
"""Host entry — batched BSHD ``[B, S, H, D]``, qk_hdim=v_hdim=128, bf16.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Suppressed comments (5)
Previously missed (1) — in code that hasn't changed since the last review.
aiter/ops/flydsl/fmha_kernels.py:258
flydsl_flash_attn_varlen_funccomputes routing based on head dims but does not validatenheads_q % nheads_k == 0before passingsink/windowthrough. Without a divisibility check, invalid GQA inputs could raise inside the kernel wrapper or produce incorrect results; the FlyDSL gate should returnNonefor unsupported shapes instead of crashing.
This issue also appears on line 344 of the same file.
qk_hdim = q.shape[-1]
exp = is_experimental_enabled()
_use_wave8_mha = (
qk_hdim == 128 or (qk_hdim == 192 and not exp) or (qk_hdim == 256 and exp)
)
_use_sibling = qk_hdim == 192 and exp
# Attention sink + finite sliding window are supported only by our m32x8 path (d192 is
aiter/test_common.py:499
maskis documented as broadcastable, butdenomis computed frommask.sum()without broadcasting it to the elementwise compare shape. Ifmaskis smaller (e.g.,[tokens]masking a[tokens, H, D]tensor), the mismatch ratio will be scaled incorrectly.
if mask is not None:
isClose = isClose | ~mask
denom = int(mask.sum().item())
if denom == 0:
if printLog:
op_tests/test_mha_flydsl.py:497
- The routing-check helper refers to an "m16x8" kernel in tags/help text, but the spy is on
flash_attn_varlen_m32x8. This makes the test output and docs misleading when diagnosing routing.
def run_route_m16x8_test():
"""Routing check: with AITER_ENABLE_EXPERIMENTAL=1, a D_qk=D_v=128 varlen
call must dispatch to ``fk.flash_attn_varlen_m32x8`` (both causal and
non-causal). Spies on that entry to assert it fired exactly once per call and
that the returned output has shape ``(total_q, H, D)``. This is a routing/shape
aiter/ops/flydsl/kernels/fmha_gfx1250/fmha_fwd_prefill_m32x8.py:1988
- Same issue as THD:
gqais computed with//without checking divisibility of query heads by KV heads. This should assert (or otherwise validate) to avoid silently producing wrong results for invalid shapes.
batch, seq_len_q, nheads_q, _ = q.shape
seq_len_k = k.shape[1]
nheads_k = k.shape[2]
gqa = nheads_q // nheads_k
aiter/ops/flydsl/fmha_kernels.py:351
flydsl_flash_attn_batch_funcroutes based on_bqkbut doesn't validate thatnheads_qis divisible bynheads_k(required for GQA). Without this, invalid inputs can reach the FlyDSL batch wrapper which computesgqavia//and may mis-index.
# BSHD routes to the m32x8 kernel (no d192 sibling exists for BSHD). D_v=128. D_qk 128/192 are
# the DEFAULT; D_qk==256 needs AITER_ENABLE_EXPERIMENTAL=1 (else CK).
_bqk = q.shape[-1]
supported = (
get_gfx() == "gfx1250"
and q.dim() == 4
and (_bqk in (128, 192) or (_bqk == 256 and is_experimental_enabled()))
and v.shape[-1] == 128
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Suppressed comments (4)
Previously missed (2) — in code that hasn't changed since the last review.
op_tests/test_mha_flydsl.py:205
flash_attn_varlen_funcmay legally skip work for batches withkv_len==0(see kv_len==0 cases in the suite). As written,ocomes from an internaltorch.emptyallocation in the wrapper, so skipped batches can leaveocontaining uninitialized data, and the test masks those rows out (so it won’t catch a correctness regression). To make the behavior deterministic and enable checking the expected all-zero output, pre-allocate a zeroedoutbuffer here and pass it into the op.
This issue also appears on line 213 of the same file.
q = torch.randn(total_q, H_q, d_qk, dtype=torch.bfloat16, device=device)
k = torch.randn(total_k, H_kv, d_qk, dtype=torch.bfloat16, device=device)
v = torch.randn(total_k, H_kv, d_v, dtype=torch.bfloat16, device=device)
scale = 1.0 / math.sqrt(d_qk)
aiter/ops/flydsl/kernels/fmha_gfx1250/fmha_fwd_prefill_m32x8.py:253
- This comment says the compute stages are "EMPTY, unwired", but
_wmma_bf16,_qk_gemm,_softmax, and_pv_gemmare implemented below and are part of the main loop. Updating the comment would avoid confusion during maintenance.
# ============================================================================
# Compute stages — EMPTY, unwired. Implemented and tested one at a time; the KV
# streaming driver below lands (and is tested) first with these left inert.
# ============================================================================
op_tests/test_mha_flydsl.py:217
- The varlen call doesn’t pass an
out=buffer, so if a backend path skips writing (e.g.,kv_len==0) the returned tensor can contain uninitialized values. If you adopt a pre-zeroedoutbuffer above, pass it intoflash_attn_varlen_funcso skipped work leaves the correct all-zero result and the test can validate it.
return flash_attn_varlen_func(
q,
k,
v,
cu_seqlens_q,
op_tests/test_mha_flydsl.py:653
- The BSHD path (128/192) is routed to the FlyDSL m32x8 kernel by default (not behind the experimental gate), but the test suite disables all BSHD coverage unless
AITER_ENABLE_EXPERIMENTAL=1. This reduces coverage of the default routing behavior.
if not is_experimental_enabled():
if run_bshd:
print(" SKIP bshd suite: set AITER_ENABLE_EXPERIMENTAL=1")
run_bshd = False
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Suppressed comments (1)
aiter/test_common.py:533
- In the CPU fallback path,
num = mask.sum()is still a tensor and is used inmin(printNum, num)/ slicing. This has the same type-safety issue as the GPU path and should be converted to a Python int consistently.
mask = ~isClose.to("cpu")
num = mask.sum()
printNum = min(printNum, num)
percent = (num / denom).item()
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Suppressed comments (3)
Previously missed (2) — in code that hasn't changed since the last review.
aiter/ops/flydsl/kernels/fmha_gfx1250/fmha_fwd_prefill_a16w16_m32x8.py:1905
- The host-entry docstring says
qk_hdim=v_hdim=128, but the implementation explicitly supportsqk_hdim in {128, 192, 256}(withv_hdim=128). This can mislead callers and reviewers when debugging routing issues.
This issue also appears on line 2038 of the same file.
"""Host entry — varlen THD, qk_hdim=v_hdim=128, bf16.
op_tests/test_mha_flydsl.py:282
- The varlen test masks out
kv_len==0batches and claims the kernel leaves output undefined, which prevents validating an important edge case.flash_attn_varlen_funcdocuments that fully-masked rows should output zero, and the reference implementation here can handlesk==0, so the test can directly check O and LSE forkv_len==0instead of skipping them.
# A batch whose kv_len==0 attends to no keys: the kernel skips those work-
# groups and leaves their query-row output undefined. Mark those rows invalid
# so checkAllclose ignores them (True = compare, False = ignore).
kv_lens = [cu_k[b + 1] - cu_k[b] for b in range(B)]
o_f = o.float()
aiter/ops/flydsl/kernels/fmha_gfx1250/fmha_fwd_prefill_a16w16_m32x8.py:2038
- The host-entry docstring says
qk_hdim=v_hdim=128, but the implementation supportsqk_hdim in {128, 192, 256}(withv_hdim=128). Keeping the docstring aligned avoids confusion when this path is selected by dispatch.
"""Host entry — batched BSHD ``[B, S, H, D]``, qk_hdim=v_hdim=128, bf16.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Suppressed comments (5)
Previously missed (4) — in code that hasn't changed since the last review.
op_tests/test_mha_flydsl.py:276
- For kv_len==0 cases, the reference returns all-zero outputs, and the FlyDSL kernels in this repo also explicitly zero-fill those rows (and set LSE=-inf). Masking these rows out makes the test pass even if the kernel regresses on this edge case, despite the nearby shape list stating the output must be zeros.
# A batch whose kv_len==0 attends to no keys: the kernel skips those work-
# groups and leaves their query-row output undefined. Mark those rows invalid
# so checkAllclose ignores them (True = compare, False = ignore).
kv_lens = [cu_k[b + 1] - cu_k[b] for b in range(B)]
o_f = o.float()
op_tests/test_mha_flydsl.py:282
- The LSE check currently skips kv_len==0 batches, but those rows have a well-defined expected value (logsumexp over an empty KV set): -inf (or logsumexp(sink) if sink is enabled). Skipping reduces coverage of an important edge case.
for b in range(B):
if kv_lens[b] == 0:
continue
sq = cu_q[b + 1] - cu_q[b]
op_tests/test_mha_flydsl.py:599
- CLI help text says sink is only supported on the m16x8 path, but this test’s routing logic (_m32x8_serves_sink_window) and the PR kernel itself are m32x8. This is misleading for anyone running the test matrix.
help="Attention sink: true/false. Default runs both.\n"
"Only the m16x8 (d_qk=d_v=128) path supports sink; skipped elsewhere.\n"
"e.g.: -s true",
)
aiter/ops/flydsl/kernels/fmha_gfx1250/fmha_fwd_prefill_a16w16_m32x8.py:1905
- This docstring says qk_hdim=v_hdim=128, but the function asserts qk_hdim in {128,192,256} and v_hdim==128. Please update the docstring to match the actual supported dims.
This issue also appears on line 2038 of the same file.
"""Host entry — varlen THD, qk_hdim=v_hdim=128, bf16.
aiter/ops/flydsl/kernels/fmha_gfx1250/fmha_fwd_prefill_a16w16_m32x8.py:2038
- This docstring says qk_hdim=v_hdim=128, but the function supports qk_hdim in {128,192,256} (with v_hdim==128). Please update the docstring to avoid confusing API users.
"""Host entry — batched BSHD ``[B, S, H, D]``, qk_hdim=v_hdim=128, bf16.
3343422 to
06447e3
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The new gfx1250 FlyDSL FMHA path claims fp16 support, but the added test suite currently hardcodes bf16 and doesn’t exercise fp16 routing/correctness, risking regressions.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
aiter/test_common.py:536
- In the
RuntimeErrorfallback path, the local variablemaskis also used for the mismatch mask (mask = ~isClose.to('cpu')), which continues the argument-shadowing issue introduced by the newmaskparameter. Renaming it here as well keeps the two concepts (compare-mask vs mismatch-mask) distinct.
except RuntimeError:
a, b = a.to("cpu"), b.to("cpu")
mask = ~isClose.to("cpu")
num = int(mask.sum().item())
printNum = min(printNum, num)
percent = num / denom
- Files reviewed: 8/8 changed files
- Comments generated: 4
- Review effort level: Lite
There was a problem hiding this comment.
🟡 Changes recommended
The new TDM-based buffer manager code computes n_seq_valid extents without clamping to the view shape, which can make TDM descriptors invalid and cause out-of-bounds behavior at runtime.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
aiter/ops/flydsl/kernels/fmha_gfx1250/fmha_b16_buffer_managers.py:1664
n_seq_validis only lower-bounded by 0, but it is used as the TDM extent for a tile whose seq dimension is fixed (_WMMA_M // gqa, i.e. 16 for MHA). Ifq_len - seq0exceeds the tile height, the extent can exceed the view shape, which is generally invalid for the TDM store descriptor. Clamp the extent to the tile’s seq dimension.
rem = q_len - seq0
n_seq_valid = fx.max(rem, fx.Int32(0))
- Files reviewed: 8/8 changed files
- Comments generated: 1
- Review effort level: Lite
There was a problem hiding this comment.
🔵 Needs a closer look
It introduces a substantial new GPU kernel + routing changes that warrant careful end-to-end correctness/performance validation, and there are a couple of small but concrete gate/test issues to address first.
Review details
Suppressed comments (3)
Previously missed (2) — in code that hasn't changed since the last review.
aiter/ops/flydsl/fmha_kernels.py:282
- The FlyDSL varlen gate doesn’t validate tensor ranks. If a caller passes tensors with unexpected dimensionality, this
supportedcheck can still succeed (it only looks atshape[-1]/shape[-2]), and then fail deeper inside the kernel with a harder-to-debug error. Add explicitq/k/v.dim() == 3checks.
This issue also appears on line 373 of the same file.
op_tests/test_mha_flydsl.py:691
- The skip message is misleading: without experimental, only the causal + no-sink + no-window subset of THD 128/128 routes to the PR3039 ASM gate; other 128/128 configurations can still route to FlyDSL. Clarify the message so it doesn’t imply all 128/128 is ASM-only.
aiter/ops/flydsl/fmha_kernels.py:377
- The FlyDSL batch gate only checks
q.dim() == 4. Addk.dim() == 4/v.dim() == 4as well so the gate can’t accidentally accept unexpected tensor ranks and then crash inside the kernel.
supported = (
get_gfx() == "gfx1250"
and q.dim() == 4
and (qk_hdim in (128, 192) or (qk_hdim == 256 and is_experimental_enabled()))
and v.shape[-1] == 128
- Files reviewed: 8/8 changed files
- Comments generated: 0 new
- Review effort level: Lite
Ruff flagged SIM102 (collapsible nested if) in _flydsl_serves_thd. Naming the predicate collapses the nesting without tripping SIM103, which the plain single-if form would have. The main merge also silently broke an import: #5116 deleted aiter/ops/flydsl/utils.py, which this kernel imported get_shared_memory_per_block from. Git reported no conflict because the two sides touched different files. Switch to the replacement, get_lds_capacity_bytes("gfx1250") from aiter.jit.utils.chip_info, which is the convention the other gfx1250 kernels on main already use and returns the same 327680 bytes the old fallback did. Co-Authored-By: Claude <[email protected]>
Summary
Adds a clean-DSL Flash-Attention forward / prefill kernel for gfx1250 (MI400), written entirely on the current FlyDSL
fx.*surface. It targets wave32 / 8 waves per threadgroup (256 threads),BLOCK_M = 256, and serves bf16 and fp16 attention forqk_hdim ∈ {128, 192, 256}withv_hdim = 128.The kernel is now the default route for
qk_hdim = 128and192, and beats the existing D=192 production kernel on the reference shape.What the kernel does
softmax(QKᵀ·scale + mask) · V), online/streaming softmax with running max + denominator, no full score materialization.thd(varlen /cu_seqlens) andbshd(batched) entry points (flash_attn_varlen_m32x8/flash_attn_batch_m32x8).qk_hdim128 / 192 / 256,v_hdim128 (D_qk ≠ D_v supported); GQA (grouped-query) viagqa_ratio.n_block = 64; K|V LDS slot sizedmax(k_blk + v_blk, q_staging)so the larger-hdim Q staging fits at occupancy 1.⚠ Benchmark environment
The perf box is currently in a degraded state and absolute numbers are not trustworthy. Diagnosis: memory/IO-bandwidth fault, not a compute or code issue.
[Hardware Error] cache level: L3/GEN, mem/io: IO.All comparison tables below are RELATIVE (ours vs competitor, back-to-back on the same box at the same time).
Performance (healthy-box reference)
Reference shape:
thd, B=4, H=8/8, sq=sk=16384, causal(bf16), healthy box.Kernel comparisons (current box, relative)
speedup = competitor_time / ours_time— > 1 means ours is faster.(Hq, Hkv)head counts span the modern GQA range (MQA → GQA → MHA);B ∈ {1,2,4}, causal, THD,sq ∈ {512, 2048, 16384}. Grid: ours = ⌈sq·gqa/256⌉ M-blocks × H_kv × B; sibling/ASM = ⌈sq/128⌉ × H_q × B. Correctness: max-abs-err vs fp32 torch ~0.008–0.016; ours-vs-competitor agreement ≤ 0.0156 (except one flagged case below).Columns are
seqlen·B. Small/mid-seqlen numbers are noisy (±15–20 %) on this bandwidth-degraded box (run-to-run thermal drift); the sq=16384 columns are stable and are the load-bearing signal for long-context prefill.vs. the D=192 sibling (
flash_attn_varlen_d192_gfx1250) — d192/128Speedup = sibling_us / ours_us (>1 = ours faster):
Ours beats the sibling at every seqlen, and cleanly at 16384 (~1.1–1.37×) — including the MHA configs (64/64, 96/96) that dip at mid-seqlen. Ours is the better d192/128 kernel.
vs. ASM (PR3039
fmha_fwd_with_sink_varlen_asm) — d128/128, no sinkSpeedup = asm_us / ours_us:
ASM (the hand-tuned d128 kernel) is the real competitor: ours is ~par-to-ahead at small/mid seqlen (noisy), but ASM wins at 16384 by ~15–25 % (ours 0.77–0.87×), uniformly across configs.
vs. CK — d128/128, sink on (representative)
Speedup = ck_us / ours_us. CK's batched
mha_fwdreturnsinvalid argumenton this build (no BSHD instance), so CK is THD-only here.Ours is 1.7–4.9× faster than CK, widening with seqlen — CK is not competitive for prefill on gfx1250. † MQA+sink output disagreement flagged below (latency still valid).
Reading the results
Our grid parallelizes over H_kv (not H_q) and packs the
gqaratio into the M dimension, so the decisive factor is GQA vs MHA:sq·gqarows fills tiles the per-H_q kernels leave half-empty.⚠ Correctness flag: MQA (Hkv=1) with sink shows large ours-vs-CK disagreement (max-abs-diff 2.6–3.8, vs 0.0156 everywhere else). Non-sink MQA agrees perfectly. Our sink path was only validated to gqa≤4 — the sink + extreme-gqa (Hkv=1) corner needs investigation before claiming MQA+sink correctness (could be ours or CK).
256 / 128
Numerically correct, but has VGPR spill (512 / 216 spilled) → poor perf. Kept experimental-only (
AITER_ENABLE_EXPERIMENTAL=1); non-experimental 256 routes to CK.Routing
AITER_ENABLE_EXPERIMENTAL=1* THD caveat: a PR3039 gfx1250 ASM gate sits in front for the varlen public entry and claims d128/128 + causal + no-sink + no-window + non-experimental by default; our kernel takes 128 there only under
AITER_ENABLE_EXPERIMENTAL=1. Non-causal 128, 128-with-sink/window, and all BSHD 128 go to ours by default.bshd(no sibling): 128/192 → ours (both); 256 → CK default / ours experimental.Correctness
checkAllclose atol=0.01 rtol=0.01passing for thd d128 (causal, ±sink, ±lse), thd d192 (2-TDM-split), and bshd d128 across the same feature combos; GQA and partial-KV-tile tails covered.