Repository navigation
[FlyDSL] [Perf] gfx1250 NVFP4 sparse prefill attention with K/V reuse across query tokens - #8459
XiaobingSuper wants to merge 7 commits into
Conversation
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]>
…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]>
…rries ROCm#8289) into main Unchanged; the sparse prefill kernels below reuse its NVFP4 wave-tile and MXFP8-output helpers.
… across query tokens aiter.ops.flydsl.pa_sparse_prefill.pa_sparse_prefill_nvfp4: the prefill counterpart of pa_decode's NVFP4 wave tile, for MiniMax-M3.1's block-sparse attention: 16 query heads per KV head, head_dim 128, 128-token NVFP4 pages, top-16 pages per token. It takes the compacted page table and lengths that pa_decode's NVFP4 sparse path takes. Instead of one CTA per token gathering its own 16 pages, a CTA takes tile_rows consecutive tokens and walks the union of their selected pages once. Each page is DMAed and dequantized once, and every token that selected it runs its own QK / softmax / PV step. - impl="v1" (kernels/pa_sparse_prefill_nvfp4.py): tile_rows 2, 3, 4, 6 or 8. - impl="v2" (kernels/pa_sparse_prefill_nvfp4_v2.py): the tile's rows run in one basic block per page against a lazily re-based softmax reference. Compile options are passed through `v2` (rebase_log2, waves_per_eu, all_rows, v_valu, q_regs, v_hoist, fence, v_wide); tile_rows 2, 4, 6 or 8. - quantized_output / output_scale: o_proj's MXFP8 input (E4M3 + E8M0 per 32), bit for bit the group-32 quant of the BF16 rows, padded rows included. With one KV head, as ROCm#8365's decode output. The result equals pa_decode's to rounding: each row's pages accumulate in the tile's union order. MI455X, one MiniMax-M3.1 TP4 rank, 14336 new tokens on 99968 cached, real top-k picks: v2 at tile_rows 2 takes 248-271 us a layer against 307-312 for the paged decode one token a CTA (v1: 276-325). 16000 prose tokens on 98304: 271 vs 346 us. An AgentX-shaped 32768 on 65280: 634 vs 700 us. op_tests/test_flydsl_pa_sparse_prefill_nvfp4.py checks both impls against an FP32 attention over the dequantized pages and against pa_decode (the error must not exceed pa_decode's by more than rounding). It covers synthetic pick patterns from shared to random, padding rows and the MXFP8 output. `python op_tests/test_flydsl_pa_sparse_prefill_nvfp4.py` benchmarks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
…el (opt-in) ATOM_M3_SPARSE_PREFILL_REUSE=1 (default off). On gfx1250 with NVFP4 sparse K/V, a prefill of at least ATOM_M3_SPARSE_PREFILL_REUSE_MIN_ROWS tokens (default 256) runs aiter's pa_sparse_prefill_nvfp4 (ROCm/aiter#8459) where its predicate serves the shape. A CTA walks the union of ATOM_M3_SPARSE_PREFILL_REUSE_TQ consecutive tokens' selected pages once, DMAs and dequantizes each page once, and runs every token that selected it. Today the paged decode gives each token its own CTA gathering its 16 pages. - Covers the BF16 output and o_proj's MXFP8 input (ROCm#3634). Decode rows and shorter prefills keep the paged decode. - ATOM_M3_SPARSE_PREFILL_REUSE_IMPL selects v1 (default) or v2, the tile's rows in one basic block per page with a lazily re-based softmax reference. ATOM_M3_SPARSE_PREFILL_REUSE_OPTS passes v2's compile options; the validated configuration is v2 with TQ 2. - The prefill caller marks its rows (`prefill=True`). MI455X, one TP4 rank, real top-k picks, 14336 new tokens on 99968 cached: 248-271 us per layer with v2 against 307-312 for the paged decode (v1: 276-325). 16000 prose tokens on 98304: 271 vs 346. 32768 on 65280: 634 vs 700. Same result to rounding. tests/test_minimax_m3_nvfp4_fused_paths.py (CPU): long prefills take the kernel with the tile rows; decode rows, short prefills and the flag off keep the paged decode; v2's options and the MXFP8 output reach the kernel. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With NVFP4 sparse K/V, a prefill of at least 256 tokens runs aiter's pa_sparse_prefill_nvfp4 (ROCm/aiter#8459) where its predicate serves the shape (gfx1250, 16 query heads, head_dim 128, 128-token pages, top-16). A CTA walks the union of two consecutive tokens' selected pages once, DMAs and dequantizes each page once and runs every token that selected it, instead of a CTA a token gathering its own 16 pages. It uses the validated configuration (v2: the tile's rows in one basic block per page with a lazily re-based softmax reference) and covers the BF16 output and o_proj's MXFP8 input (ROCm#3634). Decode rows and shorter prefills keep the paged decode. MI455X, one TP4 rank, real top-k picks, 14336 new tokens on 99968 cached: 248-271 us per layer against 307-312 for the paged decode. 16000 prose tokens on 98304: 271 vs 346. 32768 on 65280: 634 vs 700. Same result to rounding. Co-Authored-By: Claude Opus 5.5 <[email protected]>
One op test: pa_decode (the path it replaces), the reuse kernel (v1 default and ATOM's v2 two-row tile) against the FP32 torch reference on three request layouts with zero-length rows and poisoned page tails, plus the MXFP8 output bitwise against the group-32 quant of the BF16 rows; one CPU check of pa_sparse_prefill_nvfp4_supported. The reference runs on the CPU. Drops the variant sweep, the dump loader, the union statistics and the graph benchmark. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… variant knobs Keep only the measured best variant (the former v2 at tile_rows 2: 3 waves a SIMD, query in registers, a 3-page prefetch ring) and drop v1, tile_rows 4 / 6 / 8 and the v2= compile options; the wrapper loses impl / tile_rows. Outputs (BF16 and MXFP8) are bit-identical to the former v2 tile_rows 2. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e KV head The flattened rows are (token, KV head) pairs, so the MXFP8 output viewed as [tokens, kv_heads * 16 * 128] is o_proj's row-major activation; only the padded bucket rows were indexed by token. quantized_pad_rows stays in flattened rows (a multiple of kv_heads), the kernel gets the bucket in tokens and pads the flattened row of its (token, KV head). BF16 kernel unchanged; the MXFP8 kernel only changes in its pad branch. The op test checks the MXFP8 bytes with 1 and 4 KV heads (a PP x TP1 MiniMax-M3.1 rank has 4). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Pushed 817863f on top of 9556c58 (fast-forward): the MXFP8 output now works with more than one KV head.
|
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 compile_pa_sparse_prefill_nvfp4's arguments. 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]>
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]>
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]>
…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]>
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]>
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]>
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]>
What
aiter.ops.flydsl.pa_sparse_prefill.pa_sparse_prefill_nvfp4: gfx1250 block-sparse prefill attention over NVFP4 pages (head_dim 128, 128-token pages, top-16 pages per token, 16 query heads per KV head), the prefill counterpart ofpa_decode's NVFP4 wave tile (#8289). It takes the same compacted page table and per-row lengths aspa_decode's NVFP4 sparse path.pa_decoderuns one CTA per token, which gathers and dequantizes its own pages. Here a CTA takes two consecutive tokens and walks the union of their selected pages once; every token that selected a page runs its own QK / softmax / PV step on it.quantized_output/output_scalewrite o_proj's MXFP8 input (E4M3 + E8M0 per 32), bit for bit the group-32 quant of the BF16 rows.When it pays off
MI455X, one GPU, us per layer, cached prefix 128K (32K-200K changes results by 3% or less). Cells are this kernel's time over
pa_decode's:pa_decodeneeds a second round of CTAs; below that it is 4-30% slower, so callers should keeppa_decodefor fewer tokens.Correctness
Results equal
pa_decode's to rounding (each row's pages accumulate in the tile's union order).op_tests/test_flydsl_pa_sparse_prefill_nvfp4.pychecks the kernel against an FP32 attention over the dequantized pages and againstpa_decode, including padding rows and the MXFP8 output byte for byte; it passes on MI455X at this head.Status: draft
sparse_pa_nvfp4_prefill(gfx950-only). Serving main's layout on gfx1250 means a gfx1250 backend ofsparse_pa_nvfp4_prefill; Fix fp8 sparse MLA folded batch mapping #3310's dim-major V does not fit this kernel's fast V dequant, so that port waits for the gfx1250 page layout (decode included) to be settled.🤖 Generated with Claude Code