Repository navigation
[FlyDSL] [Perf] pa_decode: gfx950 reducer issues all partition loads in one rung - #7701
Conversation
…in one rung On gfx950 the dual-mode reducer replaces the (1, 2, 4, 8, 16, 32) rung ladder with one 32-partition rung. LLVM hoisted the ladder's shared leading loads above the count branch, waited on them there and trickled the rest in small batches: 32 live partitions took several serial L2 round trips. One rung issues every load at once; partitions past the live count read zeros from the per-sequence buffer bound. Above 32 live partitions, each group's loads now issue before the weight barrier, as on gfx1250. Trade-off: sequences with few live partitions now pay the 32-load rung (see the PR description). gfx942 and gfx1250 are unchanged. 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: |
…nes use DPP The reducer's softmax weights reduce each row's partition max and sum across lanes with shuffle_xor. On gfx950 the 8/4/2/1-lane steps lowered to ds_swizzle, an LDS crossbar round trip with a full lgkmcnt wait each: eight serial ~44-cycle waits per reducer wave, on the critical path of every short call. Those steps now use the 16-lane DPP xor patterns (the same partner lane, so results are bit-identical); the 16/32-lane steps keep permlane swaps. Other architectures are unchanged. Paired A/B on MI355X over 87 shapes: 1.0069x, all outputs bit-exact; short calls 1-3% (MiniMax fp8/bf16 b1 decode, R1/R5b/H1 page 16), the lowest shapes within +-0.4% when re-measured alone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 |
ruff 0.16.0, the version CI pins, flags the dpp_utils import placed after tensor_shim (I001). Import order only; no behavior change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts first loads' and preload them The reducer's first load is reduce_info, whose pointer sat at byte 0x50 of the kernel arguments; on gfx950 nothing was preloaded, so every call waited on a kernarg round trip before it could fetch its partition range. gfx950 now orders the reducer's arguments as reduce_info, the statistics and partials pointers, their strides, query_rows and num_kv_heads, which are the 14 dwords that preload into user SGPRs, and enables the preload. reduce_info is then fetched at once, with the remaining arguments in the same round trip. The kernel body is shared; gfx942 and gfx1250 keep their argument order. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ngs after the weight barrier Above 32 live partitions the gfx950 reducer issued each group's partial loads before the weight barrier and held them in registers until then. With one partition group, which large batches get, that rung spans all 256 partitions: the kernel compiled to 266 VGPRs, one wave per SIMD, and every partition count ran at that occupancy. Batches of 128-256 sequences with 2-8 partitions each were 4-9% slower than main. gfx950 now issues loads ahead of the barrier only when a group's rung is at most 64 partitions; a single group keeps main's order and reuses the LDS allocated up front. That kernel drops to 51 VGPRs. Outputs are bit-identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
zhiding512
left a comment
There was a problem hiding this comment.
Advisory review: no correctness issue found; two small fixes suggested.
What I ran (MI355X / gfx950, 256 CUs, FlyDSL 0.5.0; this PR applied on main cb4ac34):
- Reducer bit-exactness: compiled
compile_pa_decode_ps_reducefor gfx950 over 184 configs (head dims 64/128/192/256/512, bf16/f16 logits, with and without sinks, NP 24-256, 1-16 partition groups,num_xcds0 and 8, NaN in every slot past the live partitions). The output is bit-identical to main in 184/184 configs (148 dual-mode, 100 multi-group, 66 withnum_xcds=8), all finite. - Latency: MiniMax-M3 TP4 shapes (Hq16 / Hkv1 / D128, page 128), ATOM call style (block table padded to 256K tokens, no
max_context_length, default plan, scratch sized fromplan.capacity, FP8 with per-tensor scale tensors), CUDA graph of 10 decodes, main and the PR in separate interleaved processes (main 4, PR 3, 30 samples each). Geomean 1.064x over 12 shapes, worst 1.006x; b1-b8 decode +10.8-11.8%, in line with your table. Withmax_context_lengthset to the real length the reducer compiles register-only (NP <= 64) and the gain drops to about 1.6-1.9%, so the headline comes from the dual-mode reducer.
Per-shape latency (us), main vs this PR
| shape | main | this PR | speedup |
|---|---|---|---|
| decode b1 ctx8K bf16 | 7.69 | 6.94 | 1.108x |
| decode b1 ctx8K fp8 | 7.32 | 6.58 | 1.112x |
| decode b4 ctx8K bf16 | 7.86 | 7.03 | 1.118x |
| decode b8 ctx8K fp8 | 7.86 | 7.03 | 1.118x |
| decode b32 ctx8K bf16 | 23.62 | 23.20 | 1.018x |
| decode b32 ctx8K fp8 | 15.65 | 15.33 | 1.021x |
| decode b4 ctx32K fp8 | 10.40 | 9.68 | 1.074x |
| decode b3 ctx225K bf16 | 65.72 | 65.33 | 1.006x |
| verify b3 q4 ctx8K bf16 | 12.50 | 11.73 | 1.066x |
| verify b3 q4 ctx8K fp8 | 11.46 | 10.71 | 1.070x |
| verify b8 q4 ctx32K bf16 | 38.63 | 37.63 | 1.027x |
| verify b8 q4 ctx32K fp8 | 24.30 | 23.35 | 1.041x |
test_pa_decode_reduce_split_groups skips unless get_gfx_runtime() == "gfx1250" (op_tests/test_flydsl_pa_decode.py L218-219) and compiles with architecture="gfx1250" (L260). On gfx950 the reducer is only covered end-to-end with tolerances, so the bit-exactness this PR relies on has no in-repo guard (the 184/184 result above is out-of-tree). Could you parametrize that test over the runtime arch (on gfx950, groups > 1 only when NP > 64) so the bitwise check runs here too?
The kernarg-preload point is inline.
Advisory review, AI-assisted; the runtime numbers come from the runs described above.
…; honor the preload env Review follow-ups: - test_pa_decode_reduce_split_groups ran only on gfx1250, so on gfx950 the reducer's bit-exactness had no in-repo guard. It now runs on gfx950 too: dual-mode CTAs (bounds above 64) with split groups must match one group bit for bit, and the dual CTA's single 32-wide rung must match the register-only ladder bit for bit up to 32 live partitions. A copy of the reducer that adds the dual rung's products in reverse order fails it. - The gfx950 reducer launch takes AITER_FLYDSL_KERNARG_PRELOAD and the count from tensor_shim (capped at 16), so AITER_FLYDSL_KERNARG_PRELOAD=0 reaches it. Defaults compile as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the review, and for the 184-config bit-exactness sweep. You're right that
Results:
The self-review and Testing sections are updated accordingly. The preload point is answered inline. |
zhiding512
left a comment
There was a problem hiding this comment.
Approving. Both points from my earlier review are addressed in a8b9f03 (the preload honors its env var; the split-group test now runs on gfx950), and outputs stay bit-identical.
…cies main now carries #7700 (at bdabd08) and #7709 (at ce737ce, including its own resolution against #7700) as squash merges, plus #7619's gfx1250 pa_decode changes. Every conflict in op_lds.py, pipeline.py, traits.py, pa_decode_kernel.py, pa_decode_plan.py, pa_decode.py and the test takes main's side, so the stack's older #7700/#7709 heads and their merge resolutions are superseded. On top of main the branch keeps only #7701 (02dc5d1, unchanged) and this PR's three commits. The STREAM_KV commit's flag rename now also renames main's named cache key fields: PaDecodeCacheKey.gfx942_busy -> busy_grid and gfx942_two_per_cu -> two_per_cu. Every consumer other than STREAM_KV stays gated on "gfx94". Two hunks of this PR's commits were already on main through #7709's resolution and drop out of this PR's diff: DUAL_GROUP's "not STREAM_KV" and the _zero_rows kv_query axis follows SPLIT_MAJOR. The merged tree is identical to main + #7701's five commits + this PR's three commits cherry-picked. Co-Authored-By: Claude Opus 5.5 <[email protected]>
main now carries #7701 at its head a8b9f03, which also honors the kernarg preload env in the gfx950 reducer. The one conflict, in pa_decode_reduce.py, takes main's version; the branch carried #7701 at 02dc5d1. Against main the branch now holds only this PR's three commits (traits.py, op_epilog.py), and the merged tree is identical to main + those three commits cherry-picked. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
On gfx950 the FlyDSL
pa_decodepartition reducer now uses one 32-partition register rung, so all of its loads issue together. Previously it used a 1-2-4-8-16-32 rung ladder. Its cross-lane max and sum within 16 lanes now use DPP instead of LDS swizzles, and its leading kernel arguments preload into SGPRs. MiniMax-M3 decode and MTP4 verify on MI355X get a geomean of 1.059x; over all 87 timed gfx950 shapes the PR is 1.030x. Two shapes with few live partitions per sequence remain slower than main, by up to -2.6%; they are tabulated below. Outputs are bitwise identical to main, and gfx942 and gfx1250 are unchanged.Motivation
Every gfx950
pa_decodecall launches the reducer after the tile kernel. On short MiniMax-M3 workloads it is 26-53% of the call (~4.1 us of 7.5-13 us).In dual mode the reducer picks a rung by the live partition count. LLVM hoists the rungs' shared leading loads above that count branch and waits on them there. It then issues the rest in small batches, so 32 live partitions took several serial L2 round trips.
With a single rung, every statistics and partial load issues at once. Partitions past the live count read zeros from the per-sequence buffer descriptor, whose size is the live count times the stride.
Above 32 live partitions, the previous revision issued each group's partial loads before the weight barrier and held them in registers. With one partition group, which large batches get, that rung spans all 256 partitions: the kernel compiled to 266 VGPRs, one wave per SIMD, and ran every partition count at that occupancy. Batches of 128-256 sequences with 2-8 partitions each were 4-9% slower than main.
Before any of those loads, the reducer fetches its partition range from
reduce_info. On gfx950 nothing was preloaded and thereduce_infopointer sat at byte 0x50 of the kernel arguments, so every call first waited on a kernel-argument round trip.Changes
dpp_xor_f32). Before, they usedds_swizzle, an LDS crossbar round trip with a fulllgkmcntwait each: eight serial ~44-cycle waits per reducer wave, on the critical path of every short call. The partner lanes are the same, so results are bit-identical; offsets 16/32 keep the permlane swaps.dual_rungs = (DUAL_REGISTER_PARTITIONS,), with asched_barrier(0)after the rung's loads._top_firstLDS rungs), when a group's rung is at most 64 partitions. A single group of up to 256 keeps main's order and reuses the LDS allocated up front, so that kernel stays at 51 VGPRs instead of 266.reduce_info, the statistics and partials pointers, their strides,query_rowsandnum_kv_headslead the kernel's arguments. These are the 14 dwords that preload into user SGPRs, and the preload is enabled, soreduce_infois fetched at once with the remaining arguments in the same round trip. The kernel body is shared (_pa_decode_reduce_body); gfx942 and gfx1250 keep their argument order, and the launch passes arguments through_reduce_args. The preload honorsAITER_FLYDSL_KERNARG_PRELOADand its count (capped at 16), like the other FlyDSL kernels.test_pa_decode_reduce_split_groups(op_tests/test_flydsl_pa_decode.py) now runs on gfx950 as well as gfx1250. On gfx950, dual-mode CTAs (bounds above 64) with split groups must match one group bit for bit, and the dual CTA's single 32-wide rung must match the register-only ladder bit for bit up to 32 live partitions.Unchanged:
The PR shares only
op_tests/test_flydsl_pa_decode.pywith #7700, in different tests; the two heads merge without conflict.Alternatives I measured and rejected, all keeping every load of a rung in one batch:
(4, 16, 32),(4, 32)and(8, 32)ladders selected by the live count. The smaller rungs' loads were issued in reverse so no two rungs share a leading load.Every variant cost the 32-partition workloads 1-4% (any count branch ahead of the 32-rung does). None recovered more than about half of the few-partition losses of the time; most of those came from the single-group register occupancy, which the last commit fixes without a branch.
Performance (if applicable)
Method:
pa_decodeare loaded side by side in one process. They run on identical inputs and plans, each captured as a CUDA graph of 10 calls. Replays alternate ABBA: 20 pairs, 10 replays per sample. The columns are per-version medians; the speedup is the median paired ratio.zhiding512/pa-benchmark(bench_pa_minimax_m3.py, not part of this PR): tables padded to 256K tokens, default plan. The 67 other shapes are 16 larger page-128 batches and 51pa_decodereview shapes.d02f9d058a.Scored MiniMax-M3 workloads, this PR vs main (geomean 1.059x):
Regressions. Every shape slower than -1.5% among the 67 other shapes:
pa_decodereview shapes (page 16, D256 page 64, MXFP4, padded tables, budget/hinted plans), geomean 1.026x.Both have few live partitions per sequence (2 and 4):
R1_fp8_d128_p16_B1H1_tbl128k_ctx1024Further shapes. 40 gfx950 shapes outside both benchmarks (head dim 64 and 256, D128 page 64, GQA 4 and 16, MTP 2-4, sliding windows, per-token FP8 page 16, batch 512,
max_partitionsand budget plans, MXFP4): 1.0043x, all 40 bit-exact. The lowest, BF16 page-16 GQA-16 B4 16K at 0.974x, reads 1.010x against the previous revision when re-measured alone (candidate first, 20 pairs).The single-group fix alone (this PR's last commit, measured on top of #7700 and the earlier commits, same method): 1.0022x over all 87 shapes, every output bit-exact; FP8 b256 4K 1.065x, BF16 b256 1.030x, FP8 and BF16 MTP4 verify b32 1.043x and 1.030x. Re-measured alone (candidate first, 20 pairs) over 36 shapes with more than 32 live partitions it reads 1.000x.
The argument preload (the previous commit, measured on top of #7700 and the earlier commits, same method): 1.0032x over all 87 shapes (scored 1.007x, larger page-128 batches 1.006x, review set 1.001x), every output bit-exact. Its short page-16 and head-256 review shapes, re-measured alone (candidate first, 24 pairs), read 0.979x-1.045x with a geomean of 1.003x.
The DPP lane exchanges alone (this PR's second commit, measured on top of #7700 and the first commit): 1.007x over all 87 shapes, every output bit-exact. Short calls gain 1-3% (MiniMax b1 decode, R1/R5b/H1 page 16). Re-measured alone, its lowest shapes are within +-0.4%.
Testing
test_pa_decode_reduce_split_groupsused to skip everywhere but gfx1250; it now also runs on gfx950 and checks the reducer bit for bit there (see the self-review). The rest ofop_tests/test_flydsl_pa_decode.pyis unchanged. MI250X is not targeted. gfx942 was tested on an MI308X (80 CU), not an MI300X.Documentation
The
compile_pa_decode_ps_reducedocstring gains a gfx950 note on the single rung, next to the comment at the rung selection. No user-facing behavior or API changes, so the guides are unchanged.Dependencies
Breaking Changes
None
PR Self-Review
Reviewed revision
a8b9f03
Behavior and intent
On gfx950 only, the PA decode reducer always runs its widest 32-partition register rung, instead of picking a rung from the live partition count. Above 32 partitions, it issues each group's loads before the weight barrier. Its cross-lane max and sum within 16 lanes use DPP instead of
ds_swizzle, whose LDS round trips sat on every short call's critical path, and the arguments its first loads need lead the kernel signature and preload into SGPRs, removing a kernel-argument round trip ahead ofreduce_info. Single-group CTAs keep main's load order above 32 partitions, because holding a 256-partition rung in registers dropped the whole kernel to one wave per SIMD. The ladder made LLVM hoist and wait on shared loads, which serialized 32-partition reductions into several L2 round trips. Results are unchanged; only timing changes, in both directions, as tabulated.Validation and unverified scope
Validation:
pytest op_tests/test_flydsl_pa_decode.py(main's file with this PR's test change, as CI merges it) passed: 361 passed, 31 skipped. The sixtest_pa_decode_reduce_split_groupscases that used to skip on gfx950 now run and pass; they pass against main's reducer too.test_pa_decode_reduce_split_groupson gfx950 (head 64, 256 and 512).d02f9d058aand with this PR (at02dc5d11b8; the last commit touches only the gfx950 preload hint and a test that skips on gfx942). All 232 compiled PA kernels have identicalgpu.binarycode.gpu.binarycode before and after it (default environment).Not verified:
architecture == "gfx950".PR-specific question
The changed test is
test_pa_decode_reduce_split_groups, the canonical reducer test. Before this PR it skipped on every arch but gfx1250, so on gfx950 nothing in the repository checked the reducer bit for bit; only end-to-end tolerances did. It now runs on gfx950 and fails if:It passes on main as well, since main's dual rungs are the same ladder, so it guards this PR's claim of unchanged results rather than reproducing an old failure. No other test compares reducer variants bitwise.
The boundary this rests on: partitions past a sequence's live count must contribute exactly zero now that the reducer always loads 32 slots. The logits buffer descriptor is sized to
part_count * stride_logits_part, so loads beyond it return hardware zeros, and the statistics are masked withlive.selectbefore the weights. All 62 benchmark workloads (2-170 live partitions) and all 87 paired shapes reproduce main's outputs bit for bit.dpp_xor_f32reaches only lanes within a 16-lane row, so it is used for offsets 8/4/2/1 on gfx950 only; each lane receives the partner valueds_swizzlegave it. The argument reorder is a positional contract between_reduce_argsand the gfx950 kernel signature; a mismatch would read wrong pointers or strides, which every pytest case and the 62-workload gate would catch.Changed op tests
op_tests/test_flydsl_pa_decode.py, onlytest_pa_decode_reduce_split_groups: it now runs on gfx950 as well as gfx1250. On gfx950 it checks split groups against one group (dual mode, bounds above 64) and the dual CTA's single 32-wide rung against the register-only ladder, both bit for bit, with NaN in every slot past the live partitions. It is not redundant: it was the only bitwise reducer check, and it skipped on gfx950.🤖 Generated with Claude Code