Skip to content

[FlyDSL] [CI] FlyDSL FMHA forward-prefill A16W16 kernel for gfx1250 (fmha_fwd_prefill_m32x8) - #5168

Merged
coderfeli merged 61 commits into
mainfrom
jruan/gfx1250_fdsl_mha_d128_bf16
Sep 4, 2026
Merged

coderfeli merged 61 commits into
mainfrom
jruan/gfx1250_fdsl_mha_d128_bf16

Conversation

@ruanjm

@ruanjm ruanjm commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

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 for qk_hdim ∈ {128, 192, 256} with v_hdim = 128.

The kernel is now the default route for qk_hdim = 128 and 192, and beats the existing D=192 production kernel on the reference shape.

What the kernel does

  • Forward prefill attention (softmax(QKᵀ·scale + mask) · V), online/streaming softmax with running max + denominator, no full score materialization.
  • Layouts: both thd (varlen / cu_seqlens) and bshd (batched) entry points (flash_attn_varlen_m32x8 / flash_attn_batch_m32x8).
  • Head dims: qk_hdim 128 / 192 / 256, v_hdim 128 (D_qk ≠ D_v supported); GQA (grouped-query) via gqa_ratio.
  • Masking / features: causal, sliding-window, attention-sink (per-head fp32 seed folded into the softmax), and optional LSE output.
  • KV-block: n_block = 64; K|V LDS slot sized max(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.

  • Identical baseline code runs 1548 → ~1016 TFLOPS (≈ 66 %) vs the healthy box.
  • HBM bandwidth 321.6 → ~234–251 TB/s (~¾); dmesg shows recurring [Hardware Error] cache level: L3/GEN, mem/io: IO.
  • Compute is full: 512 active CU (256 WGP, 8 XCD × 32) and clocks pin at 2400 MHz — the nominal config for this MI455X eng-sample, nothing fused off.

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.

Config (D_qk/D_v) Latency Throughput Notes
128 / 128 ~1420 µs ~1548 TFLOPS default route
192 / 128 ~1683 µs ~1634 TFLOPS default route; see A/B below
256 / 128 ~3.7 ms — correct but perf-dead (see below)

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/128

Speedup = sibling_us / ours_us (>1 = ours faster):

Hq/Hkv 512·1 512·2 512·4 2k·1 2k·2 2k·4 16k·1 16k·2 16k·4
64/1 1.08 1.12 1.22 1.13 1.16 1.19 1.21 1.21 1.21
128/1 1.13 1.05 1.04 1.16 1.05 1.19 1.21 1.21 1.21
32/2 1.12 1.17 1.23 1.11 1.06 1.12 1.19 1.19 1.21
64/8 1.18 1.10 1.13 1.13 1.03 1.13 1.18 1.21 1.37
32/8 1.65 1.33 1.22 1.19 1.13 1.00 1.17 1.21 1.36
64/64 1.19 1.23 1.05 0.95 0.99 0.97 1.12 1.13 1.24
96/96 1.06 1.28 1.07 0.88 0.91 0.94 1.13 1.14 1.26

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 sink

Speedup = asm_us / ours_us:

Hq/Hkv 512·1 512·2 512·4 2k·1 2k·2 2k·4 16k·1 16k·2 16k·4
64/1 0.85 1.22 0.94 1.20 1.00 1.09 0.83 0.83 0.84
128/1 1.14 1.02 1.28 1.07 1.13 1.09 0.84 0.84 0.84
32/2 1.23 1.22 1.20 1.07 1.21 0.99 0.80 0.80 0.81
64/8 1.23 1.02 1.03 1.10 0.95 1.09 0.79 0.81 0.81
32/8 1.67 1.29 1.22 1.11 1.19 1.02 0.77 0.79 0.81
64/64 1.21 1.17 1.29 0.99 0.93 0.76 0.82 0.82 0.81
96/96 1.17 1.07 1.09 1.07 0.75 0.76 0.87 0.86 0.86

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_fwd returns invalid argument on this build (no BSHD instance), so CK is THD-only here.

Hq/Hkv 512·1 512·4 2k·1 2k·4 16k·1 16k·4
64/1 † 1.76 2.62 4.29 4.41 4.33 4.36
64/8 1.91 2.55 4.06 4.13 4.32 4.48
96/96 1.68 2.95 3.11 3.44 4.86 4.80

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 gqa ratio into the M dimension, so the decisive factor is GQA vs MHA:

  • MQA / GQA configs (Hkv ≪ Hq — the modern majority): ours wins consistently ~1.0–1.4× (up to 1.99× vs ASM at small B). Packing sq·gqa rows fills tiles the per-H_q kernels leave half-empty.
  • MHA configs (Hkv = Hq, many heads — 64/64, 96/96): mixed — ours wins at small and large seqlen but dips ~10–24 % at mid-seqlen (2k) high-batch.

⚠ 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

qk_hdim default AITER_ENABLE_EXPERIMENTAL=1
128 ours* ours
192 ours d192 sibling
256 CK ours (experimental, perf-dead)

* 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.01 passing 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.
  • Comparison sweep cross-checks (this PR): vs fp32 torch ref, ours max-abs-err ~0.008–0.011 (bf16) across all shapes above; ours-vs-{sibling,CK,ASM} output agreement ≤ 0.0156 on identical inputs.

@ruanjm
ruanjm requested review from a team and a lite review from Copilot September 1, 2026 05:29
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
multigpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 5168 --add-label <label>

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to opt this PR out.

@github-actions github-actions Bot changed the title FlyDSL FMHA forward-prefill kernel for gfx1250 (fmha_fwd_prefill_m32x8) [FlyDSL] FlyDSL FMHA forward-prefill kernel for gfx1250 (fmha_fwd_prefill_m32x8) Sep 1, 2026
@github-actions github-actions Bot added the FlyDSL label Sep 1, 2026

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.

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.py and aiter/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.

Comment thread aiter/test_common.py Resolved
Comment thread op_tests/test_mha_flydsl.py Resolved
Copilot AI review requested due to automatic review settings September 1, 2026 05:41

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.

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_func claims unsupported features (including deterministic) should fall through, but the supported gate doesn’t check deterministic. 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

  • gqa is computed with floor division but there’s no validation that nheads_q is a multiple of nheads_k. If a caller ever passes an invalid head configuration, this will silently compute the wrong gqa_ratio and 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

  • gqa is computed with floor division but there’s no validation that nheads_q is a multiple of nheads_k (BSHD). If a caller passes an invalid head configuration, this will silently compute the wrong gqa_ratio and 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

Copilot AI review requested due to automatic review settings September 1, 2026 06:12

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.

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_EXPERIMENTAL is off, but flydsl_flash_attn_batch_func supports 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 supports qk_hdim in {128, 192, 256} (with v_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 supports qk_hdim in {128, 192, 256} (with v_hdim=128). Updating this avoids misleading callers.
    """Host entry — batched BSHD ``[B, S, H, D]``, qk_hdim=v_hdim=128, bf16.

Comment thread aiter/test_common.py Resolved
Comment thread op_tests/test_mha_flydsl.py Resolved
Copilot AI review requested due to automatic review settings September 1, 2026 06:19

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.

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_func computes routing based on head dims but does not validate nheads_q % nheads_k == 0 before passing sink/window through. Without a divisibility check, invalid GQA inputs could raise inside the kernel wrapper or produce incorrect results; the FlyDSL gate should return None for 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

  • mask is documented as broadcastable, but denom is computed from mask.sum() without broadcasting it to the elementwise compare shape. If mask is 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: gqa is 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_func routes based on _bqk but doesn't validate that nheads_q is divisible by nheads_k (required for GQA). Without this, invalid inputs can reach the FlyDSL batch wrapper which computes gqa via // 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

Comment thread op_tests/test_mha_flydsl.py Resolved
Comment thread op_tests/test_mha_flydsl.py Resolved
Copilot AI review requested due to automatic review settings September 1, 2026 06:29

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.

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_func may legally skip work for batches with kv_len==0 (see kv_len==0 cases in the suite). As written, o comes from an internal torch.empty allocation in the wrapper, so skipped batches can leave o containing 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 zeroed out buffer 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_gemm are 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-zeroed out buffer above, pass it into flash_attn_varlen_func so 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

Copilot AI review requested due to automatic review settings September 1, 2026 07: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.

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 in min(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()

Comment thread aiter/test_common.py Resolved
Comment thread aiter/ops/flydsl/fmha_kernels.py Resolved
Copilot AI review requested due to automatic review settings September 1, 2026 07:34

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.

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 supports qk_hdim in {128, 192, 256} (with v_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==0 batches and claims the kernel leaves output undefined, which prevents validating an important edge case. flash_attn_varlen_func documents that fully-masked rows should output zero, and the reference implementation here can handle sk==0, so the test can directly check O and LSE for kv_len==0 instead 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 supports qk_hdim in {128, 192, 256} (with v_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.

Copilot AI review requested due to automatic review settings September 1, 2026 07:41

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.

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.

Copilot AI review requested due to automatic review settings September 1, 2026 08:07

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 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 RuntimeError fallback path, the local variable mask is also used for the mismatch mask (mask = ~isClose.to('cpu')), which continues the argument-shadowing issue introduced by the new mask parameter. 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

Comment thread op_tests/test_mha_flydsl.py Resolved
Comment thread op_tests/test_mha_flydsl.py Resolved
Comment thread aiter/test_common.py Resolved
Copilot AI review requested due to automatic review settings September 2, 2026 06:11

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 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_valid is 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). If q_len - seq0 exceeds 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

Copilot AI review requested due to automatic review settings September 3, 2026 03:59

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

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 supported check can still succeed (it only looks at shape[-1]/shape[-2]), and then fail deeper inside the kernel with a harder-to-debug error. Add explicit q/k/v.dim() == 3 checks.

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. Add k.dim() == 4 / v.dim() == 4 as 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

Comment thread op_tests/test_mha_flydsl.py Resolved
Comment thread op_tests/test_mha_flydsl.py Resolved
Copilot AI review requested due to automatic review settings September 4, 2026 05:50

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.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

coderfeli and others added 2 commits September 4, 2026 08:07
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]>
Copilot AI review requested due to automatic review settings September 4, 2026 08:12

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.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@coderfeli
coderfeli merged commit 7aaebf6 into main Sep 4, 2026
79 checks passed
@coderfeli
coderfeli deleted the jruan/gfx1250_fdsl_mha_d128_bf16 branch September 4, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants