Skip to content

[FlyDSL] [Perf] gfx1250 NVFP4 sparse prefill v3 kernel: tile rows over waves, 1.69x on M3.1 prefill - #8819

Open
fsx950223 wants to merge 6 commits into
mainfrom
fsx950223/gfx1250-pa-sparse-prefill-v3
Open

fsx950223 wants to merge 6 commits into
mainfrom
fsx950223/gfx1250-pa-sparse-prefill-v3

Conversation

@fsx950223

@fsx950223 fsx950223 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds aiter/ops/flydsl/kernels/pa_sparse_prefill_nvfp4_v3.py, v3 of the gfx1250 NVFP4 sparse prefill attention kernel for MiniMax-M3.1's prefill. It also adds NVFP4 pa_decode cases to op_tests/test_flydsl_pa_decode.py.

On the eight M3.1 prefill chunks, v3 at 8 rows a CTA runs 1.69x #8459's v2 at tile_rows 2, the current M3.1 call: geomean 972 -> 1641 TFLOPS on MI455X (1.691x over 3 rounds). On the guard shapes v3 serves (grids of 1536 v3 CTAs or more), it runs 1.40-1.63x.

Commits.

The v3 module stands alone.

Motivation

ATOM's M3.1 prefill runs pa_sparse_prefill_nvfp4 at impl="v2", tile_rows=2. That kernel splits a page's 128 tokens over the CTA's four waves, so every wave carries every row's softmax state and output, and a tile stops at two rows: 9.4 union pages a row on the M3.1 chunks. v3 takes 8 rows a CTA. Each wave owns two rows and walks every token of their pages: 3.0-3.5 union pages a row, one owner a row, no cross-wave merge.

Changes

  • aiter/ops/flydsl/kernels/pa_sparse_prefill_nvfp4_v3.py (new):
    • Tile: 8 rows (tokens) of one KV head a CTA (tile_rows 8; 4 also served). Wave w owns two rows, paired over the waves by their private pages (LPT).
    • Phase A: pages every wave selects go through a CTA-wide ring. One tensor DMA a page and wave, one barrier a page, raised wave priority. V of those pages is dequantized once a CTA.
    • Phase B: the rest go through wave-private quarter rings: no barrier, DMA descriptors built in SALU, and a K/V plane pair in one 2-D tensor DMA (tdm_fold, which the caller reads off the planes' addresses).
    • Math: QK is a scaled WMMA on the raw e2m1 K and the BF16 query split into two FP8 terms. PV uses FP16 operands with a lazy softmax rebase.
    • The tile's union: indexed from representative masks with branch-free list stores, dead chunks skipped. First entries come from hashed LDS tables, and its barriers fence LDS only.
    • Prologue and epilogue: query rows load at the kernel start, the query terms are folded, and the epilogue is spill-free.
    • Trims (last commit, bit-exact):
      • a pairwise maxnum tree for the head maximum;
      • the rare rebase, tail-mask and row-pair bodies laid out of line, with branch-likelihood hints (raw LLVM dialect: FlyDSL has no such API);
      • shorter branch chains;
      • K/V code planes padded in LDS so every 16-byte read spans all 64 banks;
      • grouped V-block reads;
      • K tiles read before a page head's barriers.
    • Walk-step trims (last commit):
      • the lazy-rebase test on the lane's own maximum;
      • each lane keeps its part of the softmax row sum, and the epilogue adds the other half once;
      • a paired A step's P computed before its rebase branches;
      • a uniform next item word;
      • A-page DMA staged without branches, its descriptor built at barrier 1.
    • Optional MXFP8 output (quant_mx) behind a constexpr: o_proj's FP8 values + E8M0 scales, bit for bit the separate group-32 quant, padded rows zero. The BF16 build does not change.
    • check_options validates the compile options; OPTIONS and TILE_ROWS name them.
    • Final ISA of the M3.1 build (tq8, nvfp4_buffers 3): 336 VGPRs, 0 spills, LDS 102,960 B, 3 CTAs a WGP. The wave-uniform reads, ballots and lane counts stay raw ROCDL, with the reason at each call: the stable forms add 33-77 instructions a tile, and FlyDSL has no stable ballot.
  • op_tests/test_flydsl_pa_decode.py: NVFP4 K/V cases for gfx1250 (see "Changed op tests"). It also passes two null MXFP8 output pointers to the reduce kernel's launch, which the carried [FlyDSL] gfx1250 PA decode: MXFP8 (E8M0 group-32) output for o_proj #8365 needs.

Performance (if applicable)

Paired A/B (sp_ab ab): 60 interleaved pairs of CUDA-graph replays after a 300 ms warm-up, on one otherwise idle GPU, FlyDSL 0.5.2.

The tables are round 1 of three. At an earlier revision, the same A/B under FlyDSL 0.5.2 and main's 0.5.3 agreed within 0.1% (1.4461x vs 1.4463x). With FlyDSL 0.5.3 (main's pin), this exact v3 file was timed in a tree with #8459 and the v3 wiring, with no other process on the GPU. It ran 1.684x on the 8 chunks (968 -> 1632 TFLOPS) and 1.295x on the guard (worst 1.084x), matching the 0.5.2 tables within 0.5%.

Hardware Workload (M3.1 prefill chunk: 4 KV heads, top-16 pages, 10% pick swaps) Before (TFLOPS) After (TFLOPS) Change
MI455X (gfx1250) 1req-32k-on-82k: 1 x 32768 new on 81920 cached 987 1666 1.695x
MI455X (gfx1250) 2req-on-53k: 21720 on 52736, 11008 on 128 (new on cached) 977 1664 1.706x
MI455X (gfx1250) 2req-short: 11456 on 11136, 21248 on 128 (new on cached) 981 1665 1.704x
MI455X (gfx1250) 5req-on-21k-206k: 1793 on 21376, 24165 on 165760, 1592 on 66560, 3073 on 23808, 2048 on 205568 (new on cached) 976 1649 1.694x
MI455X (gfx1250) hi95-5req-6.5k-on-125k: 5 x 6528 new on 124928 cached 972 1647 1.696x
MI455X (gfx1250) hi98-12req-2.7k-on-128k: 12 x 2688 new on 128000 cached 962 1623 1.683x
MI455X (gfx1250) hi95-4req-8k-on-350k: 4 x 8192 new on 349952 cached 964 1620 1.678x
MI455X (gfx1250) hi99-24req-1.3k-on-130k: 24 x 1344 new on 129920 cached 955 1596 1.662x
MI455X (gfx1250) geomean of the 8 972 1641 1.690x
Guard case (v3 grid >= 1536 CTAs) Shape Before (TFLOPS) After (TFLOPS) Change
1req-32k-on-82k-s25 25% pick swaps 909 1435 1.587x
5req-on-21k-206k-s25 25% pick swaps 901 1428 1.587x
2req-on-53k-s50 50% pick swaps 828 1235 1.493x
hi98-12req-2.7k-on-128k-rnd random picks 758 1062 1.401x
tp4-14336-on-99968 TP4, one KV head 989 1503 1.520x
tp4-32768-on-65280 TP4, one KV head 984 1596 1.625x
smallT-4k-on-100k 4K new tokens, 4 KV heads 966 1509 1.561x

Grids under about 1536 v3 CTAs should stay on v2 tile_rows 2. Measured before the two trims commits: 0.33x at 128 CTAs, 0.91-1.0x at 800-1088 CTAs, and a v3 win at every one of 110 grids from 1536 up (1.025-1.26x).

v3 rows are not bit-exact with v2, because a row's pages accumulate in a different order. The error against FP32 is no worse than v2's. These ratios were measured before the trims commits; the first trims commit leaves every output bit-identical:

  • relative L2 0.94x v2's on the large cases, at most 1.0x over all 29 checked;
  • max abs error at most 1.10x;
  • worst row at most 1.0x;
  • 0 mismatches at 3e-2.

The last commit's per-lane row sum adds each row sum's two halves in a different order, so v3 outputs move in their last BF16 bits (max relative difference 1.4e-3 to 5.3e-3 against the previous v3). On every case of the 124-check correctness gate, relative L2 and worst-row error vs FP32 are unchanged to 5 digits, and max abs error is unchanged except on one case (25% pick swaps, x1.0013). Rows that take v2 are unchanged.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

The new kernel and the new test cases are gfx1250-only; see "Validation and unverified scope".

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Stacked on #8365 (ruili / lirui927: NVFP4 PA decode + MXFP8 output, which carries #8289).

Breaking Changes

None. The v3 module is new and nothing imports it yet; the test file only gains cases.

PR Self-Review

Reviewed revision

2173680

Behavior and intent

Validation and unverified scope

MI455X (gfx1250).

This revision (2173680c7ca4):

Earlier revisions, with FlyDSL 0.5.3 (the v3 file before the trims commits):

  • python3 op_tests/test_flydsl_pa_sparse_prefill_nvfp4.py, in this PR's earlier revision 67a6173a0 ([FlyDSL] [Perf] gfx1250 NVFP4 sparse prefill attention with K/V reuse across query tokens #8459 plus the v3 wiring, with this v3 file swapped in): 75 checkAllclose passed, 0 failed. Its v3 candidates (tq8, tq4, reversed K/V plane order, no fold, ring variants, MXFP8) are compared with FP32 and pa_decode.
  • The 124-check correctness gate over 29 cases: 124/0 against FP32 and [FlyDSL] [Perf] gfx1250 NVFP4 sparse prefill attention with K/V reuse across query tokens #8459's v2. No NaN, padded rows exact, the error ratios above, determinism, CUDA-graph replay, MXFP8 bit-exact.
  • pytest op_tests/test_flydsl_pa_decode.py at e2ba80658a9e: 496 passed, 109 skipped, including the 16 new NVFP4 tests (480 passed, 109 skipped before them). The trims commits do not touch the files this test reaches.
  • A code review of v3 found no correctness bug on the M3.1 path; its fixes are in the file.

Unverified:

PR-specific question

What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?

Changed op tests

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu 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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 8819 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

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 stop the title rewrites; labels stay in sync either way.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@fsx950223 fsx950223 changed the title [FlyDSL] [Perf] gfx1250 NVFP4 sparse prefill v3: tile rows over waves, 1.38x on M3.1 prefill [FlyDSL] [Perf] gfx1250 NVFP4 sparse prefill v3: tile rows over waves, 1.45x on M3.1 prefill Nov 30, 2026
@fsx950223 fsx950223 changed the title [FlyDSL] [Perf] gfx1250 NVFP4 sparse prefill v3: tile rows over waves, 1.45x on M3.1 prefill [FlyDSL] [Perf] gfx1250 NVFP4 sparse prefill v3 kernel: tile rows over waves, 1.45x on M3.1 prefill Nov 30, 2026
@fsx950223
fsx950223 force-pushed the fsx950223/gfx1250-pa-sparse-prefill-v3 branch 2 times, most recently from c4e0b7f to 5a04258 Compare November 30, 2026 05:58
ruili and others added 3 commits November 30, 2026 05:59
NVFP4 K/V (packed e2m1, one E4M3 scale per 16 values, token-major per
(page, KV head): [128, 64] payload and [128, 8] scale bytes) for the gfx1250
FlyDSL pa_decode, selected by key/value scales of dtype float8_e4m3fn.

Gfx1250Nvfp4WavePipeline serves tiles of one query tile (<= 16 rows, M3.1 TP4
decode, MTP and prefill rows): each wave owns 32 tokens of every page and DMAs
them itself, QK is v_wmma_scale16_f32_16x16x128_f8f6f4 straight from the raw K
rows and their E4M3 scales (the query split into FP8 terms exact to 2^-21 of a
16-dim block's maximum), V is dequantized and transposed by the same
instruction with a constant selector, and softmax and P stay in registers, so
the page loop has no CTA barrier. Direct, last-arriver, cluster and reducer
outputs and the FP8 output epilogue are supported.

v_wmma_scale16 misreads 64-bit scale operands that come from an inline
constant or an SGPR pair on gfx1250; every selector scale is ORed with a
lane-varying zero so it stays in a VGPR pair.

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

(Carried in #8819 without op_tests/test_flydsl_pa_decode_nvfp4.py; that test is in #8365.)
…t_scale)

MiniMax-M3.1's MXFP4 checkpoint runs o_proj as a native MXFP8 GEMM
(gemm_a8w8_mx32: E4M3 activations, one E8M0 scale per 32 along K). Each of
the 57 sparse layers stored the PA's BF16 output and quantized it in a
separate kernel (ATOM quantize_fp8: 2.4 us decode, 7.2 us prefill a layer).
The per-token quantized_output (one FP32 descale a token) does not fit it.

An E8M0 output_scale [rows, H * D / 32] (dtypes.fp8_e8m0 or uint8) now
selects that output in pa_decode: FP8 bytes in the output's layout and
row-major scales, bit for bit the BF16/FP16 output of the same call
quantized as the split path did: code = ceil_pow2(max(amax, 1e-10) / 448)
(emit_mx_e8m0_scale RoundUp), values e4m3(clamp(x * 2^(127 - code), +-448))
after rounding to the output dtype. Padded bucket rows are FP8 zeros with
E8M0 1.0. A float32 [rows, 1] scale keeps the per-token output unchanged.

A 32-element group lies in one head row, so its maximum takes lane shuffles
only (kernels/pa_decode/op_mxfp8.py), no LDS, CTA or cluster exchange, and
the plan's split is kept in every output mode:

- NVFP4 wave tile: under the MXFP8 output each wave merges output tiles
  2 w, 2 w + 1 instead of w, w + 4 (dims 32 w + [0, 32)), so a group is a
  lane pair; direct rows, single-task rows of merging plans, empty and padded
  rows (Gfx1250OutputMxQuant);
- cluster merges of any size, clusters shared by several sequences, and the
  last-arriver merge: 8 lanes a group, no extra cluster barrier;
- the reducer (pa_decode_reduce_kernel_*_mxfp8[only]): 16 lanes a group with
  pairs; its FP8 / scale pointers take the unused sink slot so every
  argument still preloads, and it runs the XCD-contiguous grid: a token's
  64-byte scale row written by 16 CTAs spread over the XCDs cost 2.7 us at
  512 rows, nothing with the token's CTAs on one XCD.

Other tiles (FP8, BF16) take the reducer path and its epilogue. Padded rows
of plans whose kernel has no padding CTAs (last-arriver merge, shared
clusters, reducer) are filled after the launch. No sinks.

gfx1250 compile, no spills, no extra LDS: wave direct 212 VGPR, cluster
2/4/8 and merges 210, reducer np3/8/32 9/14/53 (as BF16). The existing tile
and reducer kernels (NVFP4 wave direct, cluster2 shared, cluster8, merge,
reducer-fed; per-token quant direct/cluster8; FP8 page16 direct and
cluster8 quant; reducer np3/8/32) compile to byte-identical ISA.

op_tests/test_flydsl_pa_decode_nvfp4.py: test_pa_decode_nvfp4_mxfp8_output
(direct prefill/decode, cluster8 c4/c24, cluster4, shared clusters 2 x4,
3 x4 and 8 x2, last-arriver merge, reducer np8; bf16/fp16; kept or skipped BF16 store;
padded and empty rows) against a torch reference and a copy of the split
quant kernel, and a __main__ benchmark (fused vs split vs BF16).

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

(Carried in #8819 without op_tests/test_flydsl_pa_decode_nvfp4.py; that test is in #8365.)
Adds pa_sparse_prefill_nvfp4_v3, a gfx1250 NVFP4 sparse-prefill attention kernel for MiniMax-M3.1's block-sparse prefill (16 query heads a KV head, head_dim 128, 128-token NVFP4 pages, top-16 pages a token), next to #8459's v1/v2.

v2 splits a page's 128 tokens over a CTA's four waves, so every wave holds every row's softmax state and output, and a tile stops at two rows. v3 takes 8 consecutive rows of one KV head per CTA, and each wave owns two of them, walking every token of its rows' pages. The tile's union of pages is built once; per row that is 3.0-3.5 union pages instead of v2's 8.8-9.4.

Pages go to one of two phases:
- Phase A: pages all waves select. They go through a CTA ring, with one tensor DMA a page and wave and one barrier a page. V is dequantized once a CTA into a shared buffer.
- Phase B: the rest. They go through wave-private quarter rings: no barrier, DMA descriptors built in SALU, and a K/V plane pair in one 2-D tensor DMA.

The rest of the design:
- Rows are paired over the waves by their phase-B pages.
- Walk metadata is read a step ahead.
- PV takes FP16 operands, with a lazy softmax rebase.
- The union is built from hashed first-entry tables, representative masks and branch-free list stores. Dead chunks are skipped, and its barriers fence LDS only.
- Query rows load at the kernel start, and the epilogue is spill-free.
- An optional MXFP8 output (o_proj's input, bit for bit the separate group-32 quant) sits behind a constexpr.

The M3.1 build (tq8, nvfp4_buffers 3): 336 VGPRs, 0 spills, LDS 99,888 B, 3 CTAs a WGP.

The module stands alone. It imports only pa_decode's NVFP4 modules and utils, and carries its own copies of the v1/v2 geometry constants and page-step helpers. Callers use compile_pa_sparse_prefill_nvfp4_v3 directly; its launch takes #8459's compile_pa_sparse_prefill_nvfp4 arguments (listed in its docstring). It needs #8365's pa_decode NVFP4 modules and nothing from #8459. On MI455X it wins from about 1536 v3 CTAs up, and smaller grids should stay on v2 at tile_rows 2.

MI455X, FlyDSL 0.5.3, vs #8459's v2 at tile_rows 2 (the current M3.1 call): the 8 M3.1 prefill chunks run at a geomean of 1.446x (982 -> 1419 TFLOPS), and the guard shapes v3 serves (pick swaps, TP4 one KV head, 4K-token small T) run 1.28-1.39x. Error vs FP32 is no worse than v2's: relative L2 0.94x on the large cases, max abs error at most 1.10x, MXFP8 bit-exact.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fsx950223
fsx950223 force-pushed the fsx950223/gfx1250-pa-sparse-prefill-v3 branch from 5a04258 to 1d0fe13 Compare November 30, 2026 06:00
The NVFP4 PA decode carried from #8365 has its tests in
op_tests/test_flydsl_pa_decode_nvfp4.py, which this PR leaves to #8365. Some of
those cases move here so the NVFP4 path still runs in this PR's tests:

- test_pa_decode_nvfp4: M3.1 TP4 rows over compacted top-16 tables with
  NaN-poisoned tail bytes, against an FP32 reference and through the
  recorded-launch path. Cases: decode c4, MTP8 c64 cluster8, one-partition
  direct, last-arriver merge, reducer, FP16 query, two KV heads (GQA 8), and
  the fp4x2 payload view.
- test_pa_decode_nvfp4_mxfp8_output: the fused MXFP8 output equals the group-32
  quant of the same call's BF16 output. Modes: direct, cluster8, merge and the
  reducer, each with the BF16 store and quant-only. Padded rows are FP8 zeros
  with E8M0 1.0 scales.

The helpers are copied from #8365's test with an _nvfp4_ prefix. The cases run
on gfx1250 only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fsx950223
fsx950223 marked this pull request as ready for review November 30, 2026 06:15
@fsx950223
fsx950223 requested review from a team and a balanced review from Copilot November 30, 2026 06:15

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 has insufficient remaining quota. Try requesting a review at a lower effort level.

@aiter-bot

aiter-bot commented Nov 30, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 2173680c7ca4 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

- **The new kernel.** v3 is a sparse-prefill attention kernel for MiniMax-M3.1. It takes eight rows a CTA with one wave owning each row, a CTA-shared ring for the pages all waves read, and private rings for the rest. That cuts union page reads a row from 9.4 to about 3.3, and the M3.1 chunks run 1.69x faster than v2 at two rows a CTA.
- **Existing code.** This PR's own commits change no existing code path: a new module, plus test cases. The carried #8365 commits change `pa_decode`; they are #8365's, gated to gfx1250 NVFP4.

Validation and unverified scope

MI455X (gfx1250).

This revision (`2173680c7ca4`):
- **Kernel identity, compile-only** (aiter's AOT dry run, no GPU needed):
  - The v3 file compiles to byte-identical final ISA with the measured kernel on all 23 production builds, through the same wrapper. The builds cover tq8 and tq4, the four K/V fold orders, BF16 and MXFP8, and one and four KV heads.
  - The measured kernel is commit `5fec542f2` of the development tree, which imports its helpers from #8459's v2 instead of copying them.
- **On this branch** (`main` + #8365 + this PR, no #8459), the module imports and compiles: tq8 and tq4, each fold order, BF16 and MXFP8. LDS is 102,960 B.
- **The trims commits' kernels**, on the development tree:
  - The first trims commit is bit-identical to the v3 before it on every scored, guard and small-T output, and the 124-check gate's records are equal.
  - The second passes the 124-check gate with the error figures above (L2 and worst row unchanged, one max abs x1.0013).
  - Both: 336 VGPRs, 0 spills.
- `ruff check` (0.16.0) and `black --check` are clean on the changed files.

Earlier revisions, with FlyDSL 0.5.3 (the v3 file before the trims commits):
- `python3 op_tests/test_flydsl_pa_sparse_prefill_nvfp4.py`, in this PR's earlier revision `67a6173a0` (#8459 plus the v3 wiring, with this v3 file swapped in): 75 `checkAllclose` passed, 0 failed. Its v3 candidates (tq8, tq4, reversed K/V plane order, no fold, ring variants, MXFP8) are compared with FP32 and `pa_decode`.
- The 124-check correctness gate over 29 cases: 124/0 against FP32 and #8459's v2. No NaN, padded rows exact, the error ratios above, determinism, CUDA-graph replay, MXFP8 bit-exact.
- `pytest op_tests/test_flydsl_pa_decode.py` at `e2ba80658a9e`: 496 passed, 109 skipped, including the 16 new NVFP4 tests (480 passed, 109 skipped before them). The trims commits do not touch the files this test reaches.
- A code review of v3 found no correctness bug on the M3.1 path; its fixes are in the file.

Unverified:
- **No test in this PR runs v3**, and nothing routes to it. The checks above ran v3 through the earlier revision's wrapper and test (#8459 plus the v3 wiring), which this PR no longer carries.
- No GPU run of this exact revision. Its kernel is the measured one by final-ISA identity.
- FlyDSL 0.5.3 performance of this revision (pending, see Performance).
- gfx942 and gfx950. The new cases skip there, and the carried #8365 paths are gated to gfx1250 NVFP4.

PR-specific question

What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
- **`op_tests/test_flydsl_pa_decode.py`'s NVFP4 cases** fail on any error in the NVFP4 K/V decode path the carried #8365 adds:
  - the e2m1 dequant or the E4M3 block scales;
  - a read of the NaN-poisoned unwritten tail bytes;
  - the cluster8, direct, last-arriver-merge or reducer output modes;
  - the FP16 query, the GQA-8 two-KV-head layout, or the fp4x2 view;
  - and, for the MXFP8 output, any FP8 byte or E8M0 scale that differs from the group-32 quant of the same call's BF16 output, including padded rows.

  No other test in this PR reaches that path, because #8365's own NVFP4 test is not carried.
- **The two added reduce-kernel arguments** keep the existing split-group test launching after #8365 adds the MXFP8 pointers. Without them that test fails at launch.

Changed op tests

- `op_tests/test_flydsl_pa_decode.py`:
  - NVFP4 K/V cases (gfx1250), moved from #8365's `test_flydsl_pa_decode_nvfp4.py` with `_nvfp4_`-prefixed helpers:
    - `test_pa_decode_nvfp4`: M3.1 TP4 rows over compacted top-16 tables with NaN-poisoned tail bytes, against an FP32 reference and through the recorded-launch path. Cases: decode c4, MTP8 c64 cluster8, one-partition direct, last-arriver merge, reducer, FP16 query, two KV heads (GQA 8), and the fp4x2 payload view.
    - `test_pa_decode_nvfp4_mxfp8_output`: direct, cluster8, merge and reducer modes, with the BF16 store and quant-only.
  - Two null MXFP8 output pointers for the reduce kernel's launch, as the carried #8365 needs.
  - Not redundant: see the PR-specific question.
- `op_tests/test_flydsl_pa_decode_nvfp4.py` (#8365's full NVFP4 decode test) is not part of this PR.
- No test of the v3 kernel (see "Validation and unverified scope").

🤖 Generated with [Claude Code](https://claude.com/claude-code)

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • FAIL — an active Copilot finding has no substantive reply from the PR author
  • FAIL — an active Copilot finding has no substantive reply from the PR author
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • FAIL — Aiter Test Gate: failed
  • Required CI failed; fix it before requesting human review.

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

Copilot AI balanced review requested due to automatic review settings November 30, 2026 06:16

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 has insufficient remaining quota. Try requesting a review at a lower effort level.

lirui927 pushed a commit that referenced this pull request Nov 30, 2026
…s) and v2 TDM ring, from #8819

Port of #8819 at a3ddace (the commits from "test: M3.1 sparse PA
UT" on) onto the MiniMax-M3.1 image branch, keeping its P2 (MXFP8 output with
more than one KV head, 8ccf673) and P3 (v2 opt-in pipe / prefetch / lean /
rsplit walks, a889381 + 155f94f):

* kernels/pa_sparse_prefill_nvfp4_v3.py (new, as in #8819): a CTA takes 8
  consecutive rows of one KV head, each wave owns 2 of them; pages most waves
  select go through a CTA ring (V dequantized once a CTA), the rest through
  wave-private quarter rings; FP16 PV operands with a lazy softmax rebase.
  BF16 output only.
* v2 (bit for bit the same output): the page DMA descriptors built in SALU
  from operands prepared once a CTA, an always-full tensor DMA ring (one
  unconditional wait a page step), and the opt-in tdm_fold (a K/V pair of
  planes with one 2-D tensor DMA). The v2 helpers v3 shares moved to module
  level.
* pa_sparse_prefill.py: impl="v3" with its v3= options, M31_PREFILL_CALL =
  {"impl": "v3", "tile_rows": 8}; "v3" runs v2 (tile_rows 2, tdm_fold) on one
  KV head, for the MXFP8 output and on grids under V3_MIN_CTAS (4096) CTAs.
* op test: #8819's simplified test with the M3.1 chunks (bench_m31_prefill)
  and the v3 cases.

The image branch held an older #8459 revision (9c3f0ef); after black it
differs from #8819's base (ff9ddf6) only in lint comments and the null MXFP8
pointers, so the image's changes since were merged onto #8819's head:

* P3 on the always-full ring: pipe orders a page's DMAs K, K scales, V, V
  scales and waits (nb - 2) * 4 + 2 before QK and (nb - 1) * 4 before the V
  rows (the ring is full, so no bound checks), prefetch hints from both
  prologues and every page step; pipe and tdm_fold exclude each other (a
  folded DMA moves K and V together). lean's selector / tail mask live in the
  module-level helpers (_selector_operand(zero), _bound_mask(lean)). rsplit
  implies cta_dma, so it keeps its own staging.
* P2: the MXFP8 output with several KV heads (padding in whole tokens, the
  bucket passed in tokens, pad row token * kv_heads + kv_head) in v1 and v2;
  the null pointers without the MXFP8 output from #8819. The op test runs
  the MXFP8 check with 1 and 4 KV heads (v2, v2 tdm_fold, v1) and P3's walks
  (lean / pipe / prefetch bit for bit vs the default v2, rsplit vs FP32).

Host compile-only, gfx1250, FlyDSL 0.5.0 (the image's pin; same with 0.5.3),
VGPRs / insts: v2 tq2 334 / 2808 (was 336 / 2935), MXFP8 334 / 3069, tdm_fold
334 / 2771, lean 244 / 2646, pipe 324, pipe + prefetch 2 330, lean + pipe
244, rsplit tq4 190, tq8 ring 2 250, v1 unchanged (580 / 3559): no spills.
v3 tq8: 336 VGPRs, 2 spilled (one store in the prologue, reloaded in the
epilogue only, not in the walks); #8819's head compiles the same. v3 tq4 201.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
lirui927 pushed a commit to ROCm/ATOM that referenced this pull request Nov 30, 2026
…REUSE_IMPL=v3

aiter's pa_sparse_prefill (with ROCm/aiter#8819) has impl="v3": a CTA takes 8
consecutive tokens of one KV head, each wave owns 2. M3.1's P (PP4 x TP1, 4 KV
heads a GPU) runs it with ATOM_M3_SPARSE_PREFILL_REUSE_IMPL=v3
ATOM_M3_SPARSE_PREFILL_REUSE_TQ=8 (MI455X, 32K-token chunks: 1.31x v2 tq2).
aiter itself runs v2 on one KV head, small grids and, by default, the MXFP8
output (ATOM_MINIMAX_M3_PA_MXFP8_OUT=1).

ATOM_M3_SPARSE_PREFILL_REUSE_OPTS now goes to the chosen implementation's
option dict (aiter's v2= or v3=), so OPTS=mxfp8=1 with IMPL=v3 lets v3 write
o_proj's MXFP8 input itself (aiter's opt-in). v2's OPTS behave as before.
Values stay integers: tdm_fold (a bool in aiter) is not settable from here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
lirui927 pushed a commit that referenced this pull request Nov 30, 2026
Replace the older v3 port (f487a42, MXFP8 store 54dbda6) with #8819's
standalone pa_sparse_prefill_nvfp4_v3.py (1d0fe13): CTA-wide phase-A ring,
wave-private phase-B quarter rings, hashed union index, lazy rebase, built-in
MXFP8 output behind quant_mx. v2's TDM ring changes stay.

Fix on top of the PR file: a padded-bucket row of the MXFP8 output is
flattened row token * kv_heads + kv_head (the PR stored token, which with
4 KV heads zeroes live rows and leaves heads 1-3 of the bucket unwritten).

Wrapper: impl="v3" with v3={"mxfp8": True} maps to quant_mx (ATOM's
interface unchanged); v3 serves grids of 1536 v3 CTAs or more (PR), one KV
head included; smaller grids run v2 tile_rows 2. Op test: parametrize
test_pa_sparse_prefill_nvfp4 (benchmark() applied in main) so pytest runs
it: 8 passed on MI455X.

MI455X, 8 M3.1 chunks, 4 KV heads, tq8 (geomean us, same GPU and session):
v2 tq2 1842.3; old v3 1486.9 / +MXFP8 1530.5; new v3 1420.8 / +MXFP8 1437.1
(1.297x / 1.282x v2). MXFP8 bit for bit the group-32 quant of the BF16 rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zufayu
zufayu requested review from coderfeli and yadaish December 1, 2026 04:41
Seven bit-exact changes from round 4 of the kdev sp-prefill campaign (checkpoint 4):

- the per-head maximum is a pairwise maxnum tree (nnan): 23 fewer instructions a
  walk step;
- the lazy rebase and tail-mask bodies, and the uncommon row-pair bodies, are laid
  out of line with llvm.intr.expect.with.probability (raw LLVM dialect: FlyDSL
  has no branch-likelihood API), so the common walk step falls through (A walk
  9,060 -> 3,220 B, B walk 9,516 -> 4,184 B of final ISA);
- shorter branch-condition chains in the A walk step;
- the K/V code planes are padded in LDS (16 B every 4 token rows), so every
  16-byte operand read spans all 64 banks (LDS 99,888 -> 102,960 B, still 3 CTAs
  a WGP);
- a paired step's late V blocks are read in one group;
- a page head step's K tiles are read before its barriers.

Measured on MI455X (FlyDSL 0.5.2, sp_ab paired A/B, 60 pairs):
- vs the previous v3: the 8 M3.1 prefill chunks run 1.101x warm, 1.099x with the
  arms swapped and 1.091x cold. Every scored, guard and small-T output is
  bit-identical.
- vs #8459's v2 at tile_rows 2: 1.577x (988 -> 1558 TFLOPS, 3 rounds).

The final ISA is 336 VGPRs with 0 spills. This self-contained copy compiles to the
same final ISA as the campaign's kernel on all 23 production builds (checked
compile-only).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fsx950223 fsx950223 changed the title [FlyDSL] [Perf] gfx1250 NVFP4 sparse prefill v3 kernel: tile rows over waves, 1.45x on M3.1 prefill [FlyDSL] [Perf] gfx1250 NVFP4 sparse prefill v3 kernel: tile rows over waves, 1.57x on M3.1 prefill Dec 2, 2026
Copilot AI balanced review requested due to automatic review settings December 2, 2026 05:39

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

A critical missing KV-head offset leaves the second head’s FP8 values and scales uncleared, and the new v3 kernel lacks reproducible regression coverage.

2 open issues

Review effort: Balanced

Comment on lines +749 to +770
offset = (
fx.Int64(token + row // g) * stride_row
+ (row % g) * stride_head
+ index % t.head_dim
)
target = fx.recast_iter(
fx.PointerType.get(fx.Int32.ir_type, fx.AddressSpace.Global, 4),
fx.add_offset(self.groups.quantized, offset),
)
if const_expr(size % (t.BLOCK_THREADS * 16)):
_store_word(target, zeros, index < size)
else:
fx.ptr_store(zeros, target)
code = (fx.Float32(scale) == fx.Float32(0.0)).select(
group_code(fx.Float32(0.0)), fx.Int32(E8M0_ONE)
)
byte = fx.Vector.from_elements([code.to(fx.Int8)])
groups = size // GROUP
first = fx.Int64(token) * stride_row // GROUP
for i in range_constexpr(-(-groups // t.BLOCK_THREADS)):
index = i * t.BLOCK_THREADS + tid
target = fx.add_offset(self.groups.scales, first + fx.Int64(index))
return tq, nb_a, nb_b, share_min, waves_per_eu, dbg, tdm_fold


def compile_pa_sparse_prefill_nvfp4_v3(
Five changes from round 5 of the kdev sp-prefill campaign (checkpoint 5):

- the lazy-rebase test reads the lane's own maximum, in the B walk as in the A
  walk;
- each lane keeps its part of the softmax row sum, and the epilogue adds the
  lane ^ 16 half once, so the per-quarter v_permlanex16 + add goes away;
- a paired A step computes P before its rebase branches; the rare rebase body
  re-reads K from the ring slot and redoes QK and P;
- the A walk's next item word is uniform in the step body;
- an A page's DMA is staged without branches, with its descriptor built at
  barrier 1.

Numerics: every change is bit-exact except the row-sum one. That one adds the
two lane halves of each row sum in a different order, so v3 outputs move in
their last BF16 bits (max relative difference 1.4e-3 to 5.3e-3 against the
previous v3). On every case of the 124-check correctness gate, relative L2 and
worst-row error vs FP32 equal the previous v3's to 5 digits, and max abs error
is equal except on one case (25% pick swaps, x1.0013). Rows that take v2 are
unchanged.

Measured on MI455X (FlyDSL 0.5.2, sp_ab paired A/B, 60 pairs):
- vs the previous v3: the 8 M3.1 prefill chunks run 1.077x warm, 1.077x with
  the arms swapped and 1.065x cold.
- vs #8459's v2 at tile_rows 2: 1.691x (979 -> 1653 TFLOPS, 3 rounds).

The final ISA is 336 VGPRs with 0 spills on all 23 builds. This self-contained
copy compiles to the same final ISA as the campaign's kernel on all 23
production builds (checked compile-only).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fsx950223 fsx950223 changed the title [FlyDSL] [Perf] gfx1250 NVFP4 sparse prefill v3 kernel: tile rows over waves, 1.57x on M3.1 prefill [FlyDSL] [Perf] gfx1250 NVFP4 sparse prefill v3 kernel: tile rows over waves, 1.69x on M3.1 prefill Dec 4, 2026
Copilot AI balanced review requested due to automatic review settings December 4, 2026 05:55

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

Multi-KV-head MXFP8 empty and padded rows leave values and scales uncleared, and the new v3 kernel lacks committed runnable correctness tests.

3 open issues

Review effort: Balanced

Comment on lines +3696 to +3701
err = (output.float() - expected).abs()
tol = 2e-2 + 2e-2 * expected.abs()
assert (err <= tol).all(), (
f"max abs err {err.max().item():.4g} at "
f"{torch.nonzero(err > tol)[:4].tolist()}"
)

@zhiding512 zhiding512 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.

FlyDSL PA review (automated harness), round 1

Verdict: changes needed. The v3 kernel reproduces its speed and passes your v3 test on hardware, and the carried pa_decode changes leave every existing kernel ISA- and bit-identical on gfx942, gfx950 and gfx1250. But the carried #8365 copy predates #8365's fix for the MXFP8 output with more than one KV head, which I reproduced on gfx1250, and no test in this PR runs v3. · head 2173680c7c · base = merge-base f70ac7f90a · FlyDSL 0.5.3 on both sides

What this PR touches, by arch

  • v3 sparse prefill (pa_sparse_prefill_nvfp4_v3.py): gfx1250 only, and nothing routes to it. This is outside the harness's pa_decode scope, so I checked it with your own test and an extra A/B (below).
  • The two carried #8365 commits: they change the shared pa_decode host code, the main and reduce kernels, op_merge.py and traits.py for every arch. So I ran the pa_decode base/head A/B on all three archs.

pa_decode: base vs head

arch (GPU) prod unit grid outputs ISA pytest (base → head)
gfx942 (MI308X, 80 CUs) 0.999 1.001 1.000 2056 / 2056 bit-identical 236 / 236 unit kernels identical 414 → 414 passed; the 16 new NVFP4 tests skip
gfx950 (MI355X, 256 CUs) 0.999 0.998 1.001 2212 / 2212 bit-identical 263 / 263 unit kernels identical 510 → 510 passed; the 16 new tests skip
gfx1250 (256 CUs) 0.998 0.995 0.998 2501 / 2501 bit-identical 495 / 495 unit + prod kernels identical 480 → 496 passed; the 16 new NVFP4 tests pass
  • Each column is the geomean of head/base time; below 1 = head faster. Method: paired ABBA CUDA-graph replays, 3 memory layouts per case, ATOM-style launches. The A/A noise band is 2.5-2.6%.
  • Flagged cases. The first pass put cases above the band on every arch: 24 on gfx942, 27 on gfx950 and 62 on gfx1250, most of them under 15 µs. Every one of them is bit-identical, with the same plan. Re-measured at 30 pairs, plus a second run with base and head swapped, 0 of 24, 0 of 27 and 0 of 63 stay slower in both orders (the 63 are the 62 plus the crashed prod case below). Geomeans: 1.000 / 0.999 on gfx942, 1.009 / 1.016 on gfx950, 0.999 / 1.005 on gfx1250. So there is no regression on any arch.
  • New arch-neutral code is inert on existing paths.
    • The reduce kernel's launch gains two MXFP8 pointers, passed as null.
    • The op_merge.py MXFP8 branches are const_expr.
    • output_scale accepts E8M0 only on gfx1250.
    • The ISA and bit identity above confirm this.
  • Side note: prod|qwen3-235b-tp4|q4|b128|c16384|atom crashed its worker on gfx1250 on both sides. It is not caused by this PR. It ran cleanly on both sides in the re-measure, so it was a one-off worker failure.

v3 sparse prefill on gfx1250 (your claims)

How I tested it. This branch has no v3 wrapper or test, so I used the earlier revision 67a6173a0 of this PR (#8459 + the v3 wiring + test_flydsl_pa_sparse_prefill_nvfp4.py) and swapped in this head's v3 file.

Correctness:

  • test_flydsl_pa_sparse_prefill_nvfp4.py passes with this head's v3 (main, no M3.1 bench). That covers:
    • every v3 candidate: tq8, tq4, nb2, bb3, reversed K/V planes, no fold;
    • the MXFP8 bitwise checks, including padded rows;
    • the spread-scores test.
  • On the 8 M3.1 chunks: 0 mismatches at 3e-2 against FP32 and no NaN. Relative L2 is 0.00167 vs v2's 0.00177 (0.94x, as you report).
  • The outputs differ from the pre-trims v3 (67a6173a0) only in last BF16 bits, as the description says.

Speed. Your 8 M3.1 chunks (4 KV heads, 10% pick swaps):

  • Paired, interleaved rounds: 40 rounds × 5 calls, the four kernels in rotating order on one idle GPU.
  • Before = impl="v2", tile_rows=2 of 67a6173a0; after = this head's v3 at tq8.
chunk v2 TFLOPS (yours → here) v3 TFLOPS (yours → here) speedup (yours → here)
1req-32k-on-82k 987 → 1046 1666 → 1663 1.695x → 1.583x
2req-on-53k 977 → 1039 1664 → 1668 1.706x → 1.606x
2req-short 981 → 1040 1665 → 1671 1.704x → 1.605x
5req-on-21k-206k 976 → 1034 1649 → 1649 1.694x → 1.597x
hi95-5req-6.5k-on-125k 972 → 1032 1647 → 1640 1.696x → 1.591x
hi98-12req-2.7k-on-128k 962 → 1021 1623 → 1619 1.683x → 1.583x
hi95-4req-8k-on-350k 964 → 1021 1620 → 1617 1.678x → 1.585x
hi99-24req-1.3k-on-130k 955 → 1015 1596 → 1591 1.662x → 1.572x
geomean 972 → 1031 1641 → 1640 1.690x → 1.590x
  • v3 reproduces: its absolute TFLOPS are within 0.5% of yours on every chunk.
  • The speedup is 6% lower here because 67a6173a0's v2 is about 6% faster than your baseline (#8459 at f4763f221). That is within the ±10% rule, so I count the claim as reproduced.
  • With v2's two-plane fold (v2={"tdm_fold": True}), the geomean is 1.545x.
  • The two trims commits: this head's v3 vs 67a6173a0's v3 is 1.178x geomean (1.170-1.183 per chunk). You claim 1.10 × 1.08 = 1.19x.

Findings

  1. Major (reproduced on gfx1250): the MXFP8 output leaves empty and padded rows partly unwritten with more than one KV head.

    • Where: Gfx1250OutputMxQuant.store_empty (op_merge.py:749-770) has no KV-head offset. The FP8 store covers heads 0..g-1, and the scale run starts at the token's first byte. pa_decode does not limit the MXFP8 output to one KV head.
    • Reproduction: NVFP4 K/V, 2 KV heads × GQA 8, poisoned buffers (0x7F / 0xFF), empty rows from _nvfp4_rows, 5 padded rows.
      • direct, cluster8 and merge: heads 8-15 and scale bytes 32-63 of every empty row keep the poison (3072 / 1024 / 1024 FP8 bytes).
      • direct and cluster8 also get half of the padded rows wrong (5120 FP8 bytes and 160 scale bytes).
      • The reducer path is clean, and every mode is clean with 1 KV head. Live rows are exact in every case.
    • Already fixed in #8365: its current head b5f687d7 has the fix (head0 = block_id.y // query_splits * g, plus per-token scale offsets). The carried copy is older. It also lacks #8365's later NVFP4 sliding-window support. This copy's host code still refuses windows for NVFP4, so that part is consistent.
    • Ask: re-carry #8365 at its current head, or rebase once it lands. A 2-KV-head case in test_pa_decode_nvfp4_mxfp8_output would have caught this: every MXFP8 case there uses one KV head.
  2. Major: no test in this PR runs v3. I agree with the open Copilot thread. The check above needed 67a6173a0's wrapper and test.

    • If v3 lands before its wiring, please carry a gfx1250-gated test that compiles and launches compile_pa_sparse_prefill_nvfp4_v3 against the FP32 reference.
    • Your old test's v3 candidates and MXFP8 checks are a good base. They passed here with this head's file.
  3. Minor: two NVFP4 test cases run a different mode than their names say. On a 256-CU gfx1250:

    • "reducer" compiles cluster8x2;
    • "mtp8-c64-cluster8" compiles the last-arriver merge.

    So test_pa_decode_nvfp4 never compares the NVFP4 reducer path with FP32. The MXFP8 test's reducer-np8 does run the reducer, but it only compares against the same call's BF16. Asserting the mode for every case, as you already do for 3 of the 8, would pin this down.

  4. Minor: the NVFP4 test uses a local tolerance instead of checkAllclose. Agreed with the Copilot thread.

  5. Minor: v3's launch contract, for whoever wires it. The launch takes raw pointers. These rules are only in the docstring:

    • MXFP8 needs one KV head. pad_row(row) (line 2234) indexes padded rows by token, while real rows use row * kv_heads + kvh. 67a6173a0's wrapper enforces this; check_options / the compile could too.
    • softmax_scale must be positive. With 0 or a negative scale, every row with a partial last page comes out NaN. I checked this on hardware. v2 behaves the same, so it is not new in v3, but the eventual wrapper should reject non-positive scales.
    • tdm_fold has to match the planes' address order.
  6. Nit: AITER_FLYDSL_NVFP4_PA_BUFFERS is validated when pa_decode_kernel.py is imported (pa_decode_kernel.py:179). A bad value breaks pa_decode on every arch, not only the NVFP4 path.

Notes

  • Merge order: the PR must merge after #8365, which is still a draft. Its carried commits should match #8365's final version.
  • Not covered by the harness: the v3 kernel's design. I read its union, ring and barrier logic and found no correctness issue on the M3.1 path. The hardware checks above are what back that up.
  • Environments:
    • gfx942: torch 2.9.1, ROCm 7.2.0.
    • gfx950: torch 2.10.0, ROCm 7.2.4.
    • gfx1250: torch 2.11, ROCm 10.1.

row = index // t.head_dim
offset = (
fx.Int64(token + row // g) * stride_row
+ (row % g) * stride_head

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.

Major, reproduced on gfx1250: store_empty has no KV-head offset here (and the scale run at line 767 starts at the token's first byte), so with 2 KV heads (GQA 8) and an E8M0 output_scale both CTAs write heads 0-7 of an empty token and heads 8-15 / scale bytes 32-63 keep whatever was in the buffer. With 0x7F/0xFF-poisoned buffers: direct, cluster8 and last-arriver merge leave heads 8-15 of every empty row poisoned (3072 / 1024 / 1024 FP8 bytes), and direct and cluster8 also get half of the padded rows wrong (5120 FP8 bytes, 160 scale bytes); the reducer and all 1-KV-head cases are clean. #8365's current head b5f687d7 already fixes this (head0 = block_id.y // query_splits * g plus per-token scale offsets); this carried copy predates it. Re-carrying #8365 at its head and adding a 2-KV-head case to test_pa_decode_nvfp4_mxfp8_output would close it.

"merge",
torch.uint8,
),
"reducer": (

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.

Minor: on a 256-CU gfx1250 this case compiles cluster8x2, not the reducer, and mtp8-c64-cluster8 (line 3605) compiles the last-arriver merge (checked with the same spy). So test_pa_decode_nvfp4 never compares the NVFP4 reducer with FP32. Could every case assert its mode, as the three named ones do, with plan kwargs that reach the reducer and cluster8?

if row < rows:
mx_row(row * kv_heads + kvh, inv, final[r * 10 + 2 : r * 10 + 10])
elif row < quant_rows:
pad_row(row)

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.

Minor (launch contract): padded MXFP8 rows are indexed by token here, while real rows use row * kv_heads + kvh (line 2232). With quant_mx and kv_heads > 1 the pad stores would land on real rows of other heads. The docstring says one KV head and 67a6173a0's wrapper enforces it; since compile_pa_sparse_prefill_nvfp4_v3 is the public entry here, rejecting it there (or in check_options) would keep a future caller safe.

# Page slots in each wave's DMA ring of the NVFP4 wave pipeline (2-4; 3 measured
# within noise of 4 at less LDS and fewer VGPRs).
NVFP4_BUFFERS = int(os.environ.get("AITER_FLYDSL_NVFP4_PA_BUFFERS", "3"))
if NVFP4_BUFFERS not in (2, 3, 4):

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.

Nit: this check runs when pa_decode_kernel.py is imported, so a bad AITER_FLYDSL_NVFP4_PA_BUFFERS breaks pa_decode on every arch, not only NVFP4 calls. Validating it where the NVFP4 tile is compiled would keep it local.

This branch has not been deployed

No deployments
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.

6 participants