Repository navigation
[FlyDSL] [Perf] pa_decode: gfx950 MXFP4 KV — MTP, large groups, pages 16/64, sinks/windows, head_dim 64-512, and faster decode - #8000
zhiding512 wants to merge 4 commits into
Conversation
…4, sinks, sliding windows, head_dim 64/256 Until now the MXFP4 KV path in the shared PA tile kernel (#7056) took one query position, at most 16 query heads per KV head, 128-token pages, head_dim 128, no sinks and no sliding window. Without a work plan it ran one CTA per (sequence, KV head). This change widens what it accepts and fixes the plan-free grid. FP8 and BF16 KV are unchanged. Coverage: - MTP, query_length 1..4. Query rows take up to four 16-row M-tiles a CTA. Each M-tile's QK reuses the tile's K registers and the one bf16 widening of V. Past that, query positions split over CTAs (grid y = KV heads x splits). Two kernel fixes for MTP: the score mask also covers the tile before a sequence's last one, and the direct-output zero fill of an empty sequence covers all of its query rows. - 1..64 query heads per KV head. Rows past the group are padded in the last M-tile. - Pages of 16 and 64 tokens, besides 128. Each wave reads its own page ids from the staged window, or from the block table past it. - Attention sinks, applied in the shared reducer, and sliding windows. The window masks each query row's left edge and zeroes the widened V of tokens before the MTP window union. Plan-free tasks start at the window's first tile. - head_dim 64, 128 and 256. QK runs one scaled MFMA per 128-element K block. head_dim 64 pads its one block with zero K and a 1.0 scale. head_dim 128 compiles to the same ISA as before. Performance (MXFP4 only): - Plan-free decode splits each sequence's tiles over CTAs when at most half of the CUs would otherwise hold one CTA per (sequence, KV head). The split count is preloaded, and the shared ps reducer merges the splits. On MI355X b1/32k context: 120 us -> 9 us. - Reducer partitions are bounded by block-table tiles instead of the CU count. - PV uses 16x16x32 BF16 MFMAs (two 16-token chunks each). - The MXFP4 reducer opts into kernarg preload. - The epilogue's f32 O rows in LDS get a 16 B pad, which removes a bank conflict. Tests: op_tests/test_flydsl_pa_decode.py gains MTP, G17..64, pages 16/64, sinks, windows, head_dim 64/256, plan-free split and graph-replay cases, plus NaN/Inf rows in unowned KV at every page size. Unsupported shapes (head_dim 96, G65, page 32) are refused. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… reducer Performance work on the gfx950 PA decode. Most of it applies only to MXFP4 KV. Four changes also reach FP8/BF16 KV on gfx950: the planner, KV-head dispatch order and both reducer changes. gfx942 and gfx1250 are unchanged. Tile kernel (MXFP4): - Padded query rows are prefetched ahead of the K/V burst. - Head dims up to 128 peel the task's first tile instead of its last, so the first tile starts with no history to rescale. Splat operands of the packed f32 ops get a defined high half, so vmcnt waits no longer track them. Max reductions use a balanced v_max3 tree. - head_dim 256 widens V one 128-dim K block at a time when that lets two CTAs share a CU. - One-slot plans (capacity == batch) write final rows from the tile kernel and skip the reducer launch. Tasks of a sequence that took freed slots merge in the last-arriving CTA. - Sinks fold into the final rows wherever the tile kernel writes them. - 128-bit non-temporal K/V loads are used when independent sequence/head streams fill the CUs, or half of them for unsplit tasks. The last tile is peeled on those paths. - MTP: query positions split only for idle CUs. Past two M-tiles (276 VGPRs, one wave per SIMD) the query positions, or else a KV head's query heads, split further. The split CTAs of a task take block ids one XCD count apart, so the second K/V read hits L2. - Tasks shorter than six tiles keep one tile group. - Compact plans of at most two tiles per task use eight 32-token waves. Planner and grid (gfx950, every KV dtype): - Single-query, single-KV-head plans with the default budget take one slot per CU when the per-task tile bound stays within twice the full plan's. - When a plan leaves slots empty, CTA ids map with the KV head fastest. - Sliding-window plans whose window union touches at most two tiles get one slot per sequence. Reducer (gfx950, every KV dtype): - Dual-reducer rungs issue the statistics and all logits loads together, with no wait per ladder level. - Partition groups fill the CTA whatever the average partition count. The grid mapping lives in pa_decode.context (logical_block, logical_slots, logical_kv_heads). It covers gfx942's split-major grid (#7709) as well. Every step was A/B'ed in-process on MI355X: paired, cold KV, 30 pairs, three rounds plus one with the candidate first. MXFP4 output is bit-exact, except the eight-wave path (maxrel <= 2.6e-3, FP32 accuracy passes). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…4, long tasks, head_dim 384/512 Removes the remaining MXFP4 shape limits that the FP8 KV path does not have on gfx950: - Any query_length. Splits need not divide it: each split takes ceil(query_length / splits) positions, and the last one starts that many before the end and stores only the rows past the split before it. A split past two M-tiles splits further when that adds no M-tile. - More than 64 query heads per KV head. Such a group runs as equal sets of at most 64 query heads, each through the existing KV-head split; only K/V reads map back to the cache head. A group with no such split (a prime above 64) is still refused. - Tasks of more than 4096 pages (page-16 tasks past 64K tokens). A task stages its first 4096 page ids, and its later tiles read the block table. - head_dim 384 and 512 (multiples of 128). V is widened, and PV run, one K block at a time when the tile's staging does not fit in LDS. - A CTA takes only as many M-tiles as keep O within 128 VGPRs (four up to head_dim 128, two at 256, one past that). Two CTAs share a CU only while O stays within a quarter of the 256 registers. On MI355X head_dim 256: G64 decode -34%, MTP4 G16 -50%. Tests cover MTP 5..8 with and without plans, uneven splits, groups past 64, tasks past 4096 pages, head_dim 384/512, windows, sinks, empty rows and graph replay. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
…t string concat) Sorts the imports of pipeline.py and pa_decode.py, merges the nested planner if in traits.py, marks the const_expr/runtime if pair in the epilogue noqa: SIM102 (as attention_a2a_intranode_kernel.py does), and parenthesizes implicit string concatenations in the op test. No behavior change.
There was a problem hiding this comment.
🟡 Changes recommended
Critical regressions break gfx1250 cluster-merge tracing and valid decode plans with absent arrival counters or zero-width block tables, while balanced-plan refreshes also perform unnecessary searches and synchronization.
4 open issues
What changed in this PR
Extends the shared FlyDSL paged-attention decode kernel’s gfx950 MXFP4 support beyond the limits introduced in #7056, while optimizing scheduling, memory loads, and partition reduction.
Changes:
- Adds multi-token queries, larger query-head groups, pages of 16/64 tokens, sinks, sliding windows, and head dimensions through 512.
- Adds plan-free splitting and one-slot in-kernel merging, plus gfx950 planner and reducer optimizations shared with FP8/BF16.
- Expands tests for supported shapes, masking, empty rows, graph replay, and unsupported inputs.
| File | Description |
|---|---|
op_tests/test_flydsl_pa_decode.py |
Expands MXFP4 correctness and scheduling coverage. |
aiter/ops/flydsl/pa_decode.py |
Adds validation, split policies, scratch handling, and launch selection. |
aiter/ops/flydsl/kernels/pa_decode/traits.py |
Defines expanded shape support and resource-aware schedules. |
aiter/ops/flydsl/kernels/pa_decode/pipeline.py |
Extends MXFP4 computation and optimizes tile processing. |
aiter/ops/flydsl/kernels/pa_decode/op_softmax.py |
Adds a balanced maximum-reduction helper. |
aiter/ops/flydsl/kernels/pa_decode/op_merge.py |
Switches cluster merging to the shared block mapper. |
aiter/ops/flydsl/kernels/pa_decode/op_lds.py |
Generalizes query, page, scale, and value loading. |
aiter/ops/flydsl/kernels/pa_decode/op_gemm.py |
Supports multiple MXFP4 head-dimension blocks. |
aiter/ops/flydsl/kernels/pa_decode/op_epilog.py |
Adds sink handling and one-slot partition merging. |
aiter/ops/flydsl/kernels/pa_decode/context.py |
Centralizes block mapping and uneven query splits. |
aiter/ops/flydsl/kernels/pa_decode_reduce.py |
Adds gfx950 argument preloading and load scheduling. |
aiter/ops/flydsl/kernels/pa_decode_plan.py |
Adds compact and short-window planning policies. |
aiter/ops/flydsl/kernels/pa_decode_kernel.py |
Wires new schedules, output modes, and launch arguments. |
Review effort: Balanced
| group = max(1, 128 // (t.cluster_merge * elems)) | ||
| lane = fx.Int32(gpu.thread_id("x")) % t.WAVE | ||
| kv_query = fx.Int32(gpu.block_id("y")) | ||
| kv_query = logical_block(t)[1] |
| reduce_partitions = min( | ||
| partitions, | ||
| capacity, | ||
| -(-max_blocks_per_seq * page_size // KV_COMPUTE_BLOCK), |
| work_plan is not None | ||
| and not direct | ||
| and same_strides | ||
| and capacity == num_seqs |
| fewer = (compact >= fx.max(rows_used, 1)).select(compact, capacity) | ||
| lo_compact = tile_bound(fewer) | ||
| merge = (lo <= 2) & (lo_compact <= 2 * lo) | ||
| lo = merge.select(lo_compact, lo) |
Independent perf check on MI355X (gfx950) and MI308X (gfx942)Revision: head The MXFP4 gains reproduce. However, three of the gfx950 planner/grid changes also apply to FP8/BF16 KV, and they regress several common shapes by up to 1.5x. The worst cases are sliding-window decode (GPT-OSS-style window 128/256), MTP, and short single-KV-head FP8 decode such as MiniMax-M3 TP4. gfx942 is neutral. Method:
MXFP4: claims reproduce
Regression 1: window rule (
|
| Shape (cold KV, unaligned/varlen lengths) | main → PR (µs) | PR/main | Ablation |
|---|---|---|---|
| bf16 D64 p16 H8 G8 sinks win128 B8 ctxU 1-32K ql1 | 6.96 → 7.48 | 1.076 (4/4) | 0.993 |
| fp8 D64 p16 H8 G8 sinks win128 B8 ctxU 1-32K ql1 | 6.65 → 7.41 | 1.110 (4/4) | 1.004 |
| bf16 D64 p16 H8 G8 sinks win128 B8 ctxU 1-32K ql2 | 6.29 → 7.90 | 1.255 (4/4) | 0.997 |
| bf16 D64 p16 H8 G8 sinks win128 B8 ctxU 1-32K ql4 | 7.60 → 9.90 | 1.303 (4/4) | 1.006 |
| fp8 D64 p16 H8 G8 sinks win256 B1 ctx 4000 ql1 | 6.36 → 8.29 | 1.314 (4/4) | 0.961 |
| bf16 D64 p16 H8 G8 sinks win256 B1 ctx 4000 ql2 | 5.99 → 9.17 | 1.532 (4/4) | 1.026 |
| fp8 D128 p128 H1 G16 win128 B32 ctxU 1-32K ql1 | 6.25 → 7.70 | 1.234 (4/4) | 1.013 |
| bf16 D128 p128 H1 G16 win128 B32 ctxU 1-32K ql4 | 10.91 → 16.19 | 1.483 (4/4) | 0.999 |
| fp8 D64 p16 H8 G8 sinks win128 B64 ctxU 1-8K ql1 (capacity is already = batch) | 11.11 → 11.18 | 1.007 | 1.003 |
Regression 2: compact rule (pa_decode_plan.py L488-L503)
The rule applies to gfx950, q1, a single KV head and the default budget, for every KV dtype. It merges two-tile tasks into one slot per CU. For FP8 KV, two CTAs per CU of the shorter tasks are faster. BF16 sees a smaller version of the same regression, except at B128 with ctx 128-2K, which improves (0.935).
These are the ~128K-256K-token totals where the rule fires:
| Shape (cold KV) | main → PR (µs) | PR/main | Ablation |
|---|---|---|---|
| MiniMax-M3 TP4 fp8 (per-token) D128 p128 G16, b32 8K | 16.79 → 18.20 | 1.084 (6/6) | 1.005 |
| same, b4 32K | 12.22 → 12.97 | 1.061 (6/6) | 0.998 |
| fp8 per-token D128 p16 G8 B64 2K | 11.15 → 13.02 | 1.168 (4/4) | 0.994 |
| fp8 per-token D128 p16 G8 B4 32K | 12.62 → 14.20 | 1.125 (4/4) | 1.000 |
| fp8 per-tensor D128 p64 G8 B32 8K | 17.01 → 19.04 | 1.119 (4/4) | 1.004 |
| fp8 per-token varlen B64 ctxU 128-2K | 9.16 → 10.06 | 1.100 (6/6) | 1.003 |
| bf16 D128 p64 G8 B64 2K | 15.92 → 17.17 | 1.078 (4/4) | 1.007 |
All ablation outputs are bit-exact with main. In a 264-shape single-KV-head q1 grid, 47 shapes are more than 2% slower and 23 are more than 5% slower. The PR body's "no FP8/BF16 shape is >2.5% slower" holds for its 12-shape control set but not beyond it.
Smaller: KV-head-fastest CTA mapping (traits.py L755-L766)
On gfx950 the FP8/BF16 tile kernels are not ISA-identical to main. For H>1, or MTP with query splits, the prologue now loads gridDim from the kernarg segment and does a ~35-instruction scalar division before the work-info load can issue.
Short calls pay for it, and the plan and output are unchanged (bit-exact, ablation-insensitive):
| Shape (cold KV) | main → PR (µs) | PR/main |
|---|---|---|
| fp8 per-token D128 p128 G16 B8 ql4 4K | 10.32 → 11.17 | 1.082 (4/4) |
| fp8 per-token D128 p128 G16 B1 ql4 32K | 11.76 → 12.49 | 1.062 (4/4) |
| fp8 D128 p16 H8 G8 B4 2K | 8.56 → 8.76 | 1.023 (4/4) |
It does help elsewhere: bf16 H8 G8 p16 B1 2K is 10.11 → 8.19 µs (0.810). It is a trade-off rather than a pure loss. I attribute the slowdown to the prologue from the ISA diff; there is no knob to toggle the mapping, so this attribution is not confirmed by ablation.
Neutral
- FP8/BF16 with explicit budget or
max_partitions, padded tables, B512/B1024 short contexts, skewed varlen, and MTP without query splits: 0.96-1.00. - gfx942 (MI308X, 952 UT + grid cases, BF16 and the four FP8 variants): geomean 1.0007, all bit-exact, worst single case 1.035.
- ISA: 109 tile kernels differ from main only in one kernarg offset (
0x70→0x98). The plan kernel changes as expected.
- ISA: 109 tile kernels differ from main only in one kernarg offset (
Suggestions
- Gate the window and compact rules to MXFP4.
plan_pa_decodedoes not know the KV dtype, so one option is akv_dtypeargument. Another is to let gfx950 FP8/BF16 write final rows forcapacity == batchplans, the way MXFP4 does; the window rule would then pay off for them too. - Limit
HEADS_FASTESTto the cases where it wins, or precompute the division on the host (it divides by the grid's y dimension). - Widen the FP8/BF16 control set with varlen, unaligned windows and per-token FP8. Fixed-length, 256-aligned windows hide regression 1 for q1.
Not covered: gfx1250, end-to-end serving, and accuracy beyond an output comparison with main.
fsx950223
left a comment
There was a problem hiding this comment.
Reviewed exact head e0b7696. Three correctness regressions were independently reproduced, and existing exact-SHA performance feedback identifies substantive FP8/BF16 planner regressions. Targeted gfx942 tests passed, but gfx950 validation was unavailable because the configured login host timed out. Detailed commands and logs are preserved in validation.md.
[P1] Restore the gfx1250 cluster-merge block mapping — aiter/ops/flydsl/kernels/pa_decode/op_merge.py:286
Existing gfx1250 FP8/BF16 decodes that select cluster merging now call logical_block() with Gfx1250Traits. That type has none of the mapping fields the helper reads, starting with SPLIT_MAJOR. A minimal trace using the pinned FlyDSL 0.5.0 reproduces AttributeError before code generation. Consequently, these previously supported cluster-merge specializations cannot compile. Restore the previous y-axis lookup here, or explicitly provide a mapping compatible with Gfx1250Traits.
[P2] Require arrival counters before selecting the one-slot path — aiter/ops/flydsl/pa_decode.py:569
PADecodePlan.arrival_counters defaults to None, and validate() explicitly accepts it to retain the shared reducer. For MXFP4 with capacity equal to batch, max_partitions > 1 and matching output/query strides, this predicate nevertheless selects one_slot_plan. Pointer preparation then raises AttributeError on work_plan.arrival_counters.data_ptr(). The metadata-only reproduction fails at head and is accepted at base. Require non-null arrival counters in this predicate so valid counter-free plans use the reducer fallback.
[P2] Keep the reducer specialization bound positive for empty tables — aiter/ops/flydsl/pa_decode.py:557
A zero-width block table with zero context lengths is accepted by the input contract. For a non-direct MXFP4 planned call, such as batch 1, capacity 2 and max_partitions 2, this term makes reduce_partitions zero. compile_pa_decode_ps_reduce() then raises ValueError instead of producing zero output. The same metadata-only input is accepted at base. Clamp the specialization bound to at least one; reduce_info already records zero live partitions for the empty sequence.
[P2] Avoid applying MXFP4 planner heuristics to slower FP8/BF16 paths — aiter/ops/flydsl/kernels/pa_decode_plan.py:483
The default-budget short-window rule applies to every KV dtype, although its reducer-elimination justification holds for MXFP4. FP8/BF16 two-tile window plans still launch the reducer, so capacity=batch serializes tiles without saving that launch. Existing reviewer measurements on this exact head/base show BF16 D128, page128, H1/G16, batch32, query_length4, window128 increasing from 10.91 to 16.19 us; restoring the base budget gives a ratio of 0.999. The neighboring compact-plan rule similarly slows per-token FP8 D128/page16/G8, batch64, context2048 by 16.8%, with budget ablation restoring baseline. Gate these heuristics by KV dtype or provide equivalent final-output paths before applying them to FP8/BF16. These measurements were reviewed as existing evidence, not rerun today.
Validation:
- PASS on
local:git -C checkout rev-parse HEAD; git -C checkout merge-base 95d21128485c56fbadb37d5d158508985da5615b HEAD; git -C checkout diff --check
HEAD matched e0b7696; merge-base matched the supplied base; diff check passed. - PASS on
hjbog-srdc-39.amd.com / sixifang_dev:ssh -o BatchMode=yes -o ConnectTimeout=10 -o RequestTTY=no -o ControlMaster=no -o ControlPath=none hjbog-srdc-39.amd.com "docker exec -i sixifang_dev bash -s" < gfx942-tests.sh
Exit 0: 71 passed, 106 skipped, 661 deselected. Verified gfx942, exact remote HEAD, FlyDSL 0.5.0 and intended aiter import. Selection and output are preserved in gfx942-tests.sh and gfx942-tests.log. - PASS on
hjbog-srdc-39.amd.com / sixifang_dev:ssh -o BatchMode=yes -o ConnectTimeout=10 -o RequestTTY=no -o ControlMaster=no -o ControlPath=none hjbog-srdc-39.amd.com "docker exec -i sixifang_dev bash -s" < gfx942-regression.sh
Exit 0: 97 passed, 54 skipped, 687 deselected. Covered short-window planning and NaN/Inf masking in unowned KV rows, including FP8/BF16 and MTP. Log: gfx942-regression.log. - FAIL on
hjbog-srdc-39.amd.com / sixifang_dev:ssh -o BatchMode=yes -o ConnectTimeout=10 -o RequestTTY=no -o ControlMaster=no -o ControlPath=none hjbog-srdc-39.amd.com "docker exec -i sixifang_dev bash -s" < gfx942-repro.sh
Harness exit 0 with regression exceptions caught: missing counters raised NoneType.data_ptr AttributeError; empty table raised a zero-partition ValueError; Gfx1250Traits mapping trace raised missing-SPLIT_MAJOR AttributeError. Wrapper launches were suppressed; the tracing check used a CPU argument. Log: reproduce-retry.log. - PASS on
hjbog-srdc-39.amd.com / sixifang_dev:ssh -o BatchMode=yes -o ConnectTimeout=10 -o RequestTTY=no -o ControlMaster=no -o ControlPath=none hjbog-srdc-39.amd.com "docker exec -i sixifang_dev bash -s" < gfx942-base-repro.sh
Exit 0: the same missing-counter and empty-table inputs were accepted by the exact base wrapper with compilation and launches suppressed. Separate source and cache; log: reproduce-base.log. - SKIP on
dzm-mi355-gpu34-dev:ssh -o BatchMode=yes -o ConnectTimeout=10 -o RequestTTY=no -o ControlMaster=no -o ControlPath=none -o RemoteCommand=none dzm-mi355-gpu34-dev "squeue -h -u zhiming_ding_qle -o '%i|%N|%t'"
Allocation discovery failed with exit 255: connection to aac16.amd.com:22 timed out on both attempts. No gfx950 GPU tests ran. Logs: allocation.log and allocation-retry.log.
Remaining validation:
- gfx950 MXFP4 correctness, synchronization stress and performance could not be independently tested in this run.
- The gfx1250 finding was verified at FlyDSL tracing time; no gfx1250 GPU or ISA validation was performed.
- Base comparisons checked wrapper acceptance with launches suppressed, not numerical GPU output.
- CI checks were inspected and the op's pytest dispatch was confirmed, but individual CI test logs were unavailable.
- Existing exact-SHA performance measurements were read and traced to the changed planner rules; they were not rerun.
Automated Codex review of commit e0b769600bb7.
|
No activity for 15 days, so this is now labelled |
SGLang's aiter backend decodes with page size 1 on HIP: the cache holds one [num_kv_heads, head_dim] row per token slot and each sequence names its slots through kv_indptr/kv_indices, so aiter calls paged_attention_ragged. FlyDSL has no kernel for that layout (pa_decode_tile takes 16- or 64-token pages in the vectorized 5-D layout), which leaves the layout without a portable fast path. Add pa_decode_ragged_fast for the serving geometry: one query row per sequence, BF16 K/V/output, head_dim 256, 1..16 query heads per KV head, at most 64 sequences, and at least 16K slots per sequence on average (kv_indices.numel() >= 16384 * num_seqs; the predicate cannot read device lengths). One CTA owns one (sequence, KV head, global KV split); its four waves walk 16-token tiles and run online softmax independently, then merge once in LDS. QK runs as mfma_f32_16x16x32_bf16 with tokens on M and query heads on N, so P stays in registers for the PV MFMA; V is staged in a wave-private LDS tile, retired with s_waitcnt lgkmcnt(0), and read back transposed with ds_read_b64_tr_b16. The split count comes from the device's CU count and the batch's total slot bound. A second kernel merges the KV splits, with a single-launch path for small batches. The kernel is not wired into a page-1 entry yet: this adds the kernel and its shape/dtype/stride/device/arch acceptance predicate so a caller (or the generalized ragged kernel) can select it. The predicate refuses every non-gfx950 architecture because the kernel uses the gfx950-only ds_read_b64_tr_b16 LDS read; the entry asserts the same condition. Other shapes are refused by the predicate, so no existing path changes. MI350X, public API, symmetric A/B/B/A against production's aiter HIP paged_attention_ragged, 5 rounds x 50 calls per arm, per-call CUDA events. Two runs of the ten production decode shapes (B = 1, 2, 4, 8 or 12 sequences, 106,960 tokens each, 8 query heads, 1 KV head, head_dim 256) measure 1.543x and 1.560x geomean; combined over the two runs it is 1.552x, per-shape 1.371-1.954x. Same-arm A/A pair medians are ~1.01 in both runs. A generality sweep over 18 shapes (head_dim 128/256, group 8 with 1 and 2 KV heads, group 16 with 1 KV head, a group-17 refusal, Q 1/2/4, varlen, 64/65 sequences, 1-262,144 tokens) accepts six shapes and refuses twelve in the predicate (head_dim, Q>1, group>16, more than 64 sequences, batch-average context below 16K slots, or a non-gfx950 arch). The six accepted shapes are 1.274x geomean faster than HIP (0.977-1.547x); the exact-16K-gate shape is 0.977x in this run (a 2% loss against HIP). A mixed-length batch [65536,1,1,1] (average 16,384.75 slots/sequence) is 2.10x faster than HIP; [32768,1,1,1] (average 8,192.75) is refused, which is conservative. Correctness: 18 tests, including an fp64 reference on nine length sets with planted keys and a sparse slot pool, the 4-D cache view, non-contiguous query/output and empty-index refusals, a real 65-sequence refusal, a monkeypatched gfx942 arch refusal, group 1/16, repeated launches and the mixed-length gate. max |out - ref| / (0.01 * (|ref| + rms/2)) is 0.175-0.194 on the ten production shapes and 0.175-0.191 on the six accepted generality shapes; all finite. FlyDSL 0.5.5 passes 18/18. ISA (gfx950, production shape, 0 spills): attention 206 VGPR, 36 SGPR, 45,072 B LDS; reduce 88 VGPR, 31 SGPR, 3,072 B LDS. No new dependencies. No open FlyDSL PR adds a page-1 ragged decode kernel; ROCm#1448/ROCm#1452/ROCm#1056/ROCm#1505-1507 touch other kernels/layouts, and the aiter PA decode PRs (ROCm/aiter#8000/#7864/ #7206/#8910, draft ROCm/aiter#2919) are page-16/64/128 or HIP. Production still calls HIP today; this is an enablement change, not a serving win. Signed-off-by: Arist12 <[email protected]>


Summary
Brings the gfx950 MXFP4 KV path of the shared FlyDSL PA decode tile kernel to the shapes the FP8 KV path takes, and makes it faster. The change has three commits, and each one passes the full op test on its own. A fourth commit only applies ruff fixes.
On MI355X, the 81 MXFP4 shapes main supports run at 0.548x of main's time (geomean). Shapes that main refused now run.
Motivation
The MXFP4 path from #7056 took one query position, at most 16 query heads per KV head, 128-token pages and head_dim 128, with no sinks or windows. Any other shape raised NotImplementedError, so MTP, GQA groups above 16, sinks and windows could not use MXFP4 KV.
Without a work plan it ran one CTA per (sequence, KV head). At b1 with 32K context, one CU walked the whole context: 120 us, against 7.9 us after this PR.
Changes
Coverage (commit 1):
kernarg_preloadkey (gfx950 only).Performance (commit 2):
pa_decode/context.py(logical_block,logical_slots,logical_kv_heads). This includes gfx942's split-major grid from [FlyDSL] [Perf] pa_decode: gfx942 schedule tuning (K/V streaming, latency hiding, grid-size policies) #7709, with unchanged behavior.Remaining limits (commit 3):
Unchanged: FP8 and BF16 KV kernels, gfx942 and gfx1250. On gfx950, FP8/BF16 KV also go through the planner and reducer changes above.
Performance (if applicable)
Setup:
Bandwidth, from the same A/B run. It is the K+V bytes the context lengths read (packed FP4 plus E8M0 scales) divided by kernel time:
For reference, a read-bandwidth microbenchmark on MI355X reaches 7.1-7.3 TB/s with non-temporal loads and at least 32 KB in flight per CU, and 6.0-6.3 TB/s with ordinary loads. Nominal HBM peak is 8 TB/s. The large shapes went from 67-78% to 84-92% of the non-temporal ceiling.
Per commit (full / feature / held-out sets):
Accuracy:
Testing
op_tests/test_flydsl_pa_decode.py. MI355X: 804 passed / 34 skipped (main: 427 / 38).Documentation
compile_pa_decode_tile(split_sequences,kernarg_preload).Dependencies
Breaking Changes
None. Shapes that raised NotImplementedError now run. The MXFP4 path still refuses head_dim 96, page 32 and prime groups above 64.
PR Self-Review
Reviewed revision
e0b7696
Behavior and intent
On gfx950,
pa_decodewith MXFP4 KV now accepts these shapes, which used to raise NotImplementedError:It also runs faster on the shapes it already took. The planner and reducer changes also apply to FP8/BF16 KV on gfx950. Planner output on gfx942 is unchanged: the one-slot window rule is gated to gfx950, and
test_pa_decode_plan_short_windowchecks that.Validation and unverified scope
Commands:
python -m pytest op_tests/test_flydsl_pa_decode.pyon MI355X (gfx950) and MI308X (gfx942). Results are in Testing.The performance, accuracy and gfx942 runs used the same three patches on base edf58c6. The rebase onto 95d2112 touches none of the changed files (
git range-diffshows the patches identical).A fourth commit applies the ruff 0.16 fixes CI asked for: import order, one merged
if, and parenthesized string concatenations. It changes no behavior. On head e0b7696, MI355X runs 804 passed / 34 skipped.Not verified:
PR-specific question
pa_decoderaised NotImplementedError on every one of them.test_pa_decode_plan_short_window: on gfx950 it fails without the one-slot window rule. On gfx942 it checks that the plan is unchanged.op_tests/test_flydsl_pa_decode.pyis the canonical test for this op. Before this PR, its MXFP4 cases covered only q1, G<=16, page 128 and head_dim 128. Its FP8/BF16 cases cover similar shapes but not the MXFP4 scale, unpack and V-widening path that these changes touch.Changed op tests
op_tests/test_flydsl_pa_decode.pyadds gfx950 MXFP4 cases for:None of these shapes had MXFP4 coverage before, because the path refused them. The planner test
test_pa_decode_plan_short_windownow expects the one-slot window plan only on gfx950.Overlap: #7701 and #7864 touch the same gfx950 reducer and streaming code. Whichever lands second needs a rebase. #7923 adds MXFP4 K/V on gfx1250 in the same kernel family.