Repository navigation
[FlyDSL] gfx1250 PA decode: BF16 wave-pair pipeline at D64, drop redundant D128 checks - #7384
Conversation
…or one-slot-per-sequence plans Plans whose capacity equals the batch (prefill-like and large batches) no longer launch the partition reducer on gfx1250. A sequence with a single task stores its final rows directly, the CTA indexed by an empty sequence clears its rows, and sequences that still own several tasks (slots freed by empty ones) merge them in their last-arriving CTA. The merge counts arrivals in a new zero-initialized PADecodePlan field, arrival_counters [batch, kv_heads, 32] int32 (one 128-byte line per counter), allocated once with the plan and reset by the last arrival, so CUDA-graph replays and plan refreshes keep working. Partials, statistics, the counter and the merge readback use device-scope (SCOPE_DEV) accesses; agent-scope fences would lower to a device-wide L2 writeback per CTA. The merge reproduces the register reducer's math and order, so outputs are bitwise identical. Multi-partition decode plans keep the separate reducer: merging there costs two device-scope round trips (BF16 sparse decode 64 rows: 17.7 us merged kernel vs 7.45 us tile + 2.9 us reducer). Co-authored-by: Cursor <[email protected]>
Multi-partition gfx1250 decode plans no longer launch the partition reducer when every sequence's tasks fit one workgroup cluster. The tile kernel runs P = min(partition bound, max_partitions) CTAs per (sequence, KV head) as one cluster (P in [2, 16]): CTA i runs the sequence's task i from reduce_info when it has one, stores packed partials with plain stores, and after a cluster-scope release, the cluster barrier and a cluster-scope acquire every CTA of the cluster merges 1/P of the sequence's rows with the reducer's math and partition order, so outputs stay bitwise identical. A sequence's single task stores final rows directly and empty sequences clear theirs. A cluster shares one XCC and L2, so the release/acquire lower to s_wait_storecnt 0 and global_inv SCOPE_SE without the L2 writeback that made device-scope merging slow (17.7 us tile kernel at 64 rows). The plan is unchanged; the grid becomes batch * P CTAs along x, and plans qualify when that fits the plan capacity or two CTAs per CU, so idle CTAs waiting at the barrier never displace working ones. Sinks, head_dim > 512, larger partition bounds and plans with one slot per sequence keep their paths. AITER_FLYDSL_PA_CLUSTER_MERGE=0 restores the reducer. Against origin/main, BF16 sparse decode 64 rows (CUDA graph): 11.4 -> 9.0 us; 4-32 rows save 1.9-2.4 us; FP8 sparse decode 64 rows: 11.0 -> 8.6 us. Co-authored-by: Cursor <[email protected]>
Pin sparse decode rows of up to 2048 page16 tokens (8 partitions, with graph replays) and 4096-token rows (16 partitions, the widest cluster) to the cluster-merge path on gfx1250; other architectures keep the reducer. Co-authored-by: Cursor <[email protected]>
…uster limit gfx1250 keeps at most 240 workgroup clusters resident on its 256 CUs, whatever the cluster size: sparse decode with 2 or 4 partitions per row runs at the same speed up to 240 rows and about 1.5x slower from 241 rows, when the extra clusters wait for a second wave. ATOM caps 241-256 sparse rows at 2 partitions, so those batches ran 1.34x (BF16) to 1.40x (FP8) slower than the reducer. Cluster merging now also requires sequences x KV heads <= 15 per 16 CUs; larger grids keep the reducer. Co-authored-by: Cursor <[email protected]>
…-tile pages for dense decode FP8 D128 page128 tiles with four 16-row query tiles (MTP4 at GQA 16) now give each wave its own query tile. QK reads K rows in PV's contraction order, so P stays in registers and softmax needs no cross-wave exchange: one barrier per 128-token page instead of twelve. Interior pages skip causal masks and fuse the row scale and V normalization into the exponent. Single-query-tile FP8 D128 page128 tiles (decode) now double-buffer pages with asynchronous per-token scale copies, and both FP8 pipelines issue the first page's DMA before staging Q. BF16 page128 and multi-tile FP8 pipelines drop the barrier between query tiles that the next tile's max barrier already orders. Co-authored-by: Cursor <[email protected]>
Rows 0-7 and 8-15 of each QK tile read opposite halves of their 16-token chunks, so a K operand load no longer puts both row groups on the same LDS banks. Half-wave 1 swaps its P pieces to match; scale and mask offsets follow the same mapping. Co-authored-by: Cursor <[email protected]>
…A merges One task slot per sequence with two empty rows gives the long row three tasks, so the per-wave FP8 query-tile path publishes partials and merges them in its last-arriving CTA across graph replays. Co-authored-by: Cursor <[email protected]>
BF16 D128 page128 tiles with four 16-row query tiles (MTP4 at GQA 16, the MiniMax-M3 verify step) no longer split each page's tokens across waves and exchange maxima and P through LDS (nine barriers per page). Wave pairs share two query tiles and each wave covers half of every page, so one K or V operand feeds two WMMAs. QK's accumulator rows are PV's P operand split, so P stays in registers and each page needs only its buffer barrier. A pair merges its two online-softmax states once, through the free page buffer. Interior pages skip causal masks and fuse the softmax scale into the exponent; windowed tiles mask their leading pages as well. All four output modes take the path. New BF16 cases cover direct output, last-arriver and cluster merges, 60 padded rows, two queries per tile, FP16 queries and a window spanning masked and unmasked pages. Co-authored-by: Cursor <[email protected]>
…ve ILP LLVM's iterative ILP scheduler cuts the per-wave BF16 page loop from 776 to 609 instructions, mostly VGPR bank switches (255 to 122 per page), at 414 VGPRs. Dense verify on MiniMax-M3 shapes is 1-4% faster in ABBA rounds; outputs are unchanged. Other tile kernels keep the default scheduler. Co-authored-by: Cursor <[email protected]>
Per-wave BF16 tiles now issue the second page's DMA right after the query loads, so the first page's wait leaves it in flight instead of issuing it after that wait. Masked pages also fuse a positive softmax scale into the exponent, as unmasked pages do (masked scores stay -inf), cutting the masked page loop from 901 to 802 instructions; only masked pages' rounding changes. Dense verify on MiniMax-M3 shapes: 1.0-2.9% faster in ABBA rounds. Co-authored-by: Cursor <[email protected]>
…iles and the reducer Every gfx1250 PA decode kernel started with a scalar load of its first pointer from the kernarg segment, and the tile kernel loaded its remaining arguments only after its work record arrived, so two dependent kernarg round trips preceded the page-table lookup. gfx1250 preloads kernel arguments into up to 30 user SGPRs (120 bytes). * The tile kernel's arguments are reordered so that everything the reducer-fed and direct-output specializations read fits in the preloaded bytes, and the KV head count is passed explicitly instead of being read from the hidden grid size. Cluster and last-arriver merge kernels are not preloaded: their merge-only arguments do not fit, and argument loads that a preload leaves behind made sparse cluster merges 2-6% slower. * The reducer's 108 argument bytes all preload, so its first load is reduce_info. * The BF16 page128 pipeline keeps its Q loads ahead of the first page's table lookup. Dense M3 decode (CUDA graph, 2 ABBA rounds vs 9773c35): BF16 bs1/4/8/32 8K 0.88/0.86/0.90/0.94, bs4 32K 0.92, bs3 220K 0.97; FP8 0.91/0.91/0.92/0.94, 0.91, 0.96. Verify cases 0.93-0.97, sparse cases unchanged. Outputs are bitwise identical on all 36 M3 cases and the cluster/shape suites. A new test replays dense page128 decode in a CUDA graph that refreshes its plan with new lengths, for the reducer and direct-output paths. Co-authored-by: Cursor <[email protected]>
…atistics and split 32-partition rungs Two load-issue limits dominated the gfx1250 reducer after its launch: * Above 32 live partitions, each group loaded its partials only after the weight barrier, so the reduction waited on three dependent round trips (reduce_info, statistics, partials). Groups now issue their partial loads before the barrier, in the same order and with the same arithmetic. * Up to 32 live partitions one wave issued all of a row's partial loads. A wave issuing 32 of them took about 0.6 us longer than one issuing 16. Rungs of more than 16 partitions now spread the loads and weights over up to four partition groups; group 0 adds every weighted partial in partition order, so the output matches the single-group ladder bit for bit, as the cluster and last-arriver merges assume. Register-only CTAs take up to four groups within the dual-mode CTA's wave budget. gfx942/gfx950 keep their reduction order and compile to the same ISA as before (checked offline for register-only and dual-mode specializations). Reducer device time (M3 shape, partials freshly written, bs1): 32 live partitions np32 3.44 -> 2.92 us, np256 3.60 -> 3.12 us; 128 live np256 4.28 -> 3.20 us; 256 live 4.77 -> 3.68 us. Dense M3 decode (CUDA graph, 2 ABBA rounds vs 9773c35, including the preceding kernarg preload): BF16 bs1/4/8/32 8K 0.80/0.83/0.84/0.92, bs4 32K 0.85, bs3 220K 0.94; FP8 0.84/0.85/0.86/0.92, 0.86, 0.92. Verify cases 0.88-0.95, sparse cases unchanged. Outputs are bitwise identical on all 36 M3 cases and the cluster/shape suites, and 10,000-call NaN-poisoned graph stresses of each changed path match their first call bit for bit. A new test reduces the same packed partials with one group and with split groups, register-only and dual-mode, and requires identical bits. Co-authored-by: Cursor <[email protected]>
…veraging at most 32 partitions D128 plans whose capacity averages at most 32 partitions per sequence kept a single partition group, which runs every row's 32-partition rung from one wave and leaves a sequence that does take more partitions to a one-group LDS reduction. On gfx1250 they now take the four groups that split that rung, within the same grid wave budget. Reducer at bs32, 2048-page table: 16 live partitions 3.40 -> 2.96 us, 32 live 3.97 -> 3.24 us. ATOM-style tables (no max_context_length) at bs32 8K: FP8 12.57 -> 11.36 us, BF16 15.73 -> 14.18 us against 9773c35, matching the exact-table path's outputs bit for bit. Uniform plans keep their outputs. In a mixed plan (one 220K sequence among fifteen 8K ones) the long sequence's 256 partitions now add in four blocks: 2.4e-5 relative difference from 9773c35 on that row, unchanged FP32-reference error; skipping one partition per block shows 0.13. The split-group test now also covers four-group dual-mode CTAs and checks sequences above 32 partitions against a float64 reference. Co-authored-by: Cursor <[email protected]>
…-merge-partitions Co-authored-by: Cursor <[email protected]> # Conflicts: # aiter/ops/flydsl/kernels/pa_decode_kernel.py # aiter/ops/flydsl/kernels/pa_decode_reduce.py # aiter/ops/flydsl/pa_decode.py
Keep the merge-alignment changes, but restore the fused exponent of unmasked per-token FP8 pages, which folds the query scale and log2(vnorm) into one FMA. Splitting it added two VALU operations per score: the unmasked page loop traded 32 v_pk_fma_f32 for 32 v_pk_mul_f32 and 64 v_pk_add_f32. Finite inputs with large per-token K scales or logits can again overflow or lose the V normalization. FP8 dense verify on gfx1250 (H16/KV1/D128, page 128, three requests with four causal queries, eight partitions), median of ten alternating rounds: context 007cc39 8f7fc89 this commit 8K 11.053 us 11.716 us (+6.0%) 11.046 us (-0.1%) 32K 31.763 us 34.623 us (+9.0%) 31.761 us (0.0%) The merge-alignment changes leave this shape's FP8 and BF16 tile-kernel ISA unchanged. Co-authored-by: Cursor <[email protected]>
Eligible gfx1250 PA decode plans always merge partitions within workgroup clusters. The merge-alignment test no longer disables clusters: unaligned scratch on a one-slot plan now falls back to the cluster merge, and a -inf sink keeps a reducer case with offset scratch and odd output strides. Co-authored-by: Cursor <[email protected]>
The reducer and the in-kernel merges take their per-call partition bound from max_context_length, so a bound below the real context drops partitions instead of covering them from the block table. With one 1024-token sequence and four partitions, bounds of 512 and 256 return 0.25 and 0.0 where full attention gives 1.5. Co-authored-by: Cursor <[email protected]>
…-merge-partitions # Conflicts: # aiter/ops/flydsl/kernels/pa_decode_kernel.py # aiter/ops/flydsl/pa_decode.py
…-merge-partitions Resolve pa_decode_kernel.py and pa_decode.py by keeping this branch's multi-partition direct output with main's gfx1250-strict arch check (#6767).
…w checks Main's #6767 routes gfx1250-strict through every compiled-path gfx1250 comparison, including compile_pa_decode_tile, which now hands it the tile kernel that takes the merge arguments. Spell this branch's reducer, cluster-merge and merge-argument checks the same way so the host and the kernels agree on strict. pa_decode() still rejects gfx1250-strict at entry, so no reachable path changes.
bf16_wave_query_tiles also required head_dim == 128. Packed page128 already bounds D256 to 32 query rows, so four query tiles leave only D64 and D128: keep bf16_page128_packed and m_tiles == NWARP, as suggested in the #7079 review. The wave-pair pipeline assumed D128's 2048-byte chunk spacing for both operands. Packed K keeps it (eight dims over a 128-token page), but transposed V spaces its eight-token chunks 16 * head_dim bytes apart. Pass the spacing to the operand loader so D64 reads the right V chunks; D128 keeps the same offsets and its ISA is unchanged. Add D64 variants of the four-tile BF16 page128 cases: direct, cluster, last-arriver merge, sliding window, and padded MTP5 GQA12.
…ry_tiles fp8_multi_tile requires D128 or D256 and m_tiles * head_dim <= 512, so four query tiles already imply D128. Selection is unchanged (checked on 15120 shapes) and all 48 FP8 page128 tile kernels keep byte-identical ISA. The FP8 wave pipeline's QK is one K128 WMMA per query tile, so it now asserts D128 rather than relying on the selection silently.
964b5d4 to
2d89be0
Compare
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
…-bf16-wave-d64 Keep the D64 wave-pair chunk spacing and the dropped head_dim checks, and take main's checkAllclose assertion in the split-group reducer test. Co-authored-by: Cursor <[email protected]>
6042fb6 to
0dcd7f2
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
The gfx1250 D64 wave-pair changes require target-GPU correctness, synchronization, and latency validation that this environment cannot reproduce, despite passing static address checks.
No open issues 🎉
What changed in this PR
Extends the gfx1250 BF16 paged-attention decode wave-pair pipeline to D64, building on the partition-merge work in #7079 while preserving the existing D128 path.
Changes:
- Uses separate K and V chunk spacing to support D64 operand loads.
- Removes redundant head-dimension checks from pipeline selection and adds an explicit D128 assertion to the FP8 wave pipeline.
- Adds five D64 cases covering direct output, cluster merge, last-arriver merge, sliding windows, and padded MTP5 queries.
| File | Description |
|---|---|
op_tests/test_flydsl_pa_decode.py |
Adds D64 wave-pair pipeline test cases. |
aiter/ops/flydsl/kernels/pa_decode/traits.py |
Enables D64 BF16 wave-pair selection and simplifies FP8 selection. |
aiter/ops/flydsl/kernels/pa_decode/pipeline.py |
Adjusts operand spacing for D64 and asserts the FP8 D128 requirement. |
Review effort: Balanced
0dcd7f2 to
b6f77a4
Compare
Conflicts in traits.py and test_flydsl_pa_decode.py: main's ROCm#7384 (gfx1250 BF16 wave-pair pipeline at D64) dropped head_dim == 128 from wave_query_tiles and bf16_wave_query_tiles, where this PR adds causal_rows. Kept main's conditions and comments plus causal_rows, so non-causal blocks of more than one token also stay off the per-wave tiles at D64. The test file keeps this PR's noncausal-head512-mtp-split2 case and main's D64/D128 comment. ROCm#7384's pipeline.py changes touch only the per-wave pipelines and merged cleanly. Checked the gfx1250 dispatch in Python (no GPU) over 16200 shapes: causal ones select main's pipeline, and non-causal blocks of more than one token select the shared tiles, as at 6572a4c. Signed-off-by: Rebecca Lee <[email protected]> Co-authored-by: Cursor <[email protected]>
Resolve conflicts with the gfx1250 in-kernel partition merges (#7079), MXFP4 K/V (#7056) and the D64 BF16 wave-pair pipeline (#7384): - Gfx1250Traits keeps context_partition_size alongside merge_partitions and cluster_merge; the per-wave FP8 and BF16 pipelines from main size their token ranges by the plan's partition, not KV_COMPUTE_BLOCK. - Batched FP8 softmax now covers two or three query tiles; four tiles take main's per-wave pipeline, which is 7-20% faster on gfx1250 (D128/page128/MTP4/GQA16, CUDA graphs). BF16 four-tile plain-V caches likewise take main's wave-pair pipeline (20-45% faster than the packed pipeline). - PADecodePlan keeps arrival_counters and context_partition_size, passed by keyword; gfx1250-strict supports the same partition sizes as gfx1250. - pa_decode bounds in-kernel merges and the reducer by the plan's partition size; MXFP4 accepts only 256-token partitions. - Tests take main's new merge, split-group and MXFP4 cases; the plan test stays removed as on main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ndant D128 checks (ROCm#7384)
Summary
Stacked on #7079 (base branch
zhiding512/gfx1250-pa-merge-partitions). It follows @fsx950223's review comment ontraits.py:950("Only keep self.m_tiles == self.NWARP?"). GitHub should retarget this PR tomainonce #7079 merges and its branch is deleted.Gfx1250Traits.bf16_wave_query_tilesno longer requireshead_dim == 128.bf16_page128_packedalready limits D256 to 32 query rows, so a four-tile shape can only be D64 or D128.Gfx1250Bf16WavePipelineused 2048-byte chunk spacing for both operands. That holds for packed K, where each chunk is eight dims over a 128-token page, at every head size. Transposed V spaces its eight-token chunks16 * head_dimbytes apart, so the spacing is 1 KiB at D64. The operand loader now takes the spacing for each operand. If only the condition is relaxed, all five new D64 cases fail with 47-67% of elements mismatched.wave_query_tilesalso drops itshead_dim == 128check, which was redundant:fp8_multi_tilerequires D128 or D256 andm_tiles * head_dim <= 512, so four tiles already imply D128. A grid of 15120 shapes selects the same kernels as before. The FP8 wave pipeline computes QK with a single K128 WMMA per query tile, so it now asserts D128 instead of relying on the selection silently.Tests (MI450, gfx1250)
op_tests/test_flydsl_pa_decode.pyrun: 216 passed, 77 skipped.Performance (D64)
Setup: BF16 KV, page128,
plan_pa_decodedefaults. The table gives the median end-to-endpa_decodetime in us per call, measured over CUDA-graph replays of 20 calls. Every case matches the FP32 reference.Across all 20 measured shapes (batch 1-128, KV heads 1/8), the speedup ranges from 1.21x to 2.01x, with a geomean of 1.61x.