Repository navigation
[FlyDSL] [Perf] pa_decode: gfx942 schedule tuning (K/V streaming, latency hiding, grid-size policies) - #7709
Conversation
… gfx942 On gfx942 the D1024 FP8/BF16 and BF16 D512 MTP tile kernels hold the whole next-tile K prefetch and the tile's whole V gather in registers. They hit 512 VGPRs and spill 350-2000 registers to scratch. Where a lane's K row reaches 384 bytes (BF16 D192+, FP8 D512+; with several M-tiles, 1 KiB), the tile now carries only page ids. K is streamed in pieces of four head groups (two in flight) and V in head chunks (four in flight), with a scheduling fence after each chunk. M-tiles pack P into private slots behind one barrier and share every K/V chunk. Spills drop to zero. gfx950 and gfx1250 binaries are unchanged. Paired in-process A/B vs main on MI308X (gfx942, 80 CU): - 70 D1024 cases: 1.87-6.14x, all bit-exact - BF16 D512 MTP4: 2.30-4.18x, same fp32-reference error - BF16 D256 page16: 1.28-1.41x at batch >= 16, 0.81-0.94x at batch 1 - BF16 D192 page64: 1.21-1.27x at batch >= 16 107 cases: geomean 2.48x. 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: |
The gfx9 tile issues a single M-tile's V loads only after the P barrier, and PV consumes them right away. The load latency therefore sits on every tile's critical path. ATT on MI308X showed the PV MFMAs waiting on vmcnt one V load at a time. gfx950 already prefetches V at the tile start for its tuned FP8 shapes; gfx942 never did. On gfx942, single-M-tile FP8 (up to D256, any page size) and BF16 page16 D128 now take the existing prefetch_v schedule. V is loaded at the tile start and overlaps QK and softmax. BF16 page128 and BF16 D64 measured neutral and are left as they were; BF16 D192+ streams instead. gfx950 binaries are unchanged. Paired in-process A/B vs c52a931 on MI308X (gfx942, 80 CU): - 135 single-M-tile grid cases: geomean 1.052x - FP8 page16 D128: 1.02-1.42x - BF16 page16 D128: 1.04-1.21x - FP8 page128 vectorized V at batch 1: 0.98-0.99x - 111 unit-test cases: geomean 1.024x, worst 0.96x Per-token outputs move by at most 1e-6 relative; the max error against the fp32 reference is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rids When more CTAs than CUs hold work, occupancy matters more than one CTA's latency. When fewer do, the reverse holds. The schedule now records whether the host-bounded busy-CTA count (the existing split_workgroups bound times query splits) exceeds the CU count, and uses that on gfx942: - FP8 D128 MTP tiles (2-4 M-tiles) need 260-272 VGPRs, i.e. one wave per SIMD. On busy grids they compile with waves_per_eu=2. That caps them at 256 VGPRs at the cost of about ten spills, and two CTAs share each CU. - Single M-tile K/V streaming between 384-byte and 1 KiB K rows (BF16 D192/D256) now runs only on busy grids. On small grids the K prefetch it gives up was the latency that mattered: BF16 D256 batch 1 was 0.81x vs main. From 1 KiB rows, kernels always stream, because the unstreamed kernels spill. gfx950 and gfx1250 binaries are unchanged. Paired in-process A/B vs a5a617e on MI308X (gfx942, 80 CU), 310 cases: geomean 1.077x. - FP8 D128 MTP4/5/8 at batch >= 16 (or batch 64 ctx1K): 1.13-1.40x - BF16 D256 page16 batch 1 ctx 1K/8K: 1.23x, back to 1.0x vs main - Small grids: 0.97-1.00x. The worst is a long-row UT case (mtp4-g16-page128-varied), which is busy by the host bound. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The gfx9 prologue issued a CTA's Q loads after the first tile's page-table and K loads. Q staging (quantize, LDS write, barrier) therefore waited on the in-order vmcnt chain for every K load: ATT on MI308X showed a 1056-cycle wait in a 9500-cycle single-tile task. gfx942 now issues Q loads first, as gfx950 already does for MTP4-fused and MXFP4 kernels. Padding rows of a partial last M-tile load the last real row (clamped index) and staging still zero-fills them. Streamed kernels start with K pieces and keep their order. gfx950 binaries are unchanged. Paired in-process A/B vs 9428a09 on MI308X (gfx942), 111 unit-test cases: geomean 1.016x (FP8 1.01-1.05x, BF16 1.00-1.03x, streamed D1024 0.98-0.99x before excluding them). Co-Authored-By: Claude Opus 5.5 <[email protected]>
… gfx942 Tiles that load V at the tile start (V prefetch, MTP M-tiles) issued the next tile's block-table read only later, behind those V loads. Its pin-to-context select then waited on vmcnt(0), i.e. for all of V; ATT on MI308X showed about 1000 cycles of a 4400-cycle FP8 page16 tile spent there. The page-table read now issues before the V loads, fenced so the scheduler keeps that order, and the pin happens at the use. The wait drops to vmcnt(8). Applied on gfx942 to FP8 per-tensor single M-tiles and to MTP tiles, except BF16 with two M-tiles. gfx950 binaries are unchanged. Paired in-process A/B vs the previous head on MI308X (gfx942): - FP8 per-tensor single M-tile: up to 1.18x (page128 plain V); page16 1.03-1.07x at batch 64 - MTP M-tiles: 1.00-1.12x - Excluded: FP8 per-token and BF16 page16 single tiles (0.95-0.98x) and BF16 two-M-tile MTP (0.95-0.98x) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…busy gfx942 grids V prefetch at the tile start keeps the V registers live through QK and softmax. For FP8 per-tensor page128 with a vectorized V cache, that cost more than the hidden latency on small grids: 0.955-0.967x on the latency-bound unit-test shapes. It still gains 1.11-1.15x on busy grids. Such tiles now prefetch only when more CTAs than CUs hold work. Per-token, plain-V and page16 tiles are unchanged. Paired in-process A/B on MI308X (gfx942): small_query/probability_tail page128 UT cases 1.04x, busy grids unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…D256 on gfx942 A streamed BF16 D256 page16 tile needs just over 256 VGPRs, so it ran one wave per SIMD. Capped at 256 with waves_per_eu=2 (254 VGPRs, no spills), two CTAs share each CU. That only matters on busy grids, where this path is selected. Paired in-process A/B on MI308X (gfx942): BF16 D256 page16 B64 ctx32K 1.38x (main 0.94x before, now 1.30x vs main); other sizes unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… grids MTP tiles with two M-tiles and K rows of 256 bytes or more need 272-324 VGPRs (FP8 D256 GQA8 MTP4, BF16 D128 GQA8 MTP4). That leaves one wave per SIMD. On busy grids they now take the streamed multi-M-tile schedule from c52a931: K and V stream per chunk and both M-tiles share every chunk. That frees the registers held by the next-tile K prefetch and the tile's V gather, and two CTAs fit per CU. Small grids keep the prefetching schedule. Paired in-process A/B on MI308X (gfx942), busy sizes (batch >= 16, or batch 1 with a 32K context): - FP8 D256 page128 GQA8 MTP4 (2 KV heads): 1.18-1.28x - FP8 D256 page64 GQA8 MTP4 per-token: 1.23-1.52x - BF16 D128 page64 GQA8 MTP4: 1.17-1.20x Max error against the fp32 reference is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A CTA runs all query positions of an MTP row together. On small grids (few sequences, short contexts, sliding windows) most CUs are idle, and the CTA's serial latency (four M-tiles of QK, softmax and PV per tile) is the decode time. On gfx942 the schedule now splits the query positions over more CTAs when they fit; each re-reads the row's K/V, mostly from L2: - FP8 up to D128: one M-tile per CTA (4-way) while 4x the host-bounded busy CTAs fit about three per CU, else 2-way while two per CU fit. - BF16: 2-way while one per CU fits. Busy grids keep the unsplit occupancy schedules. Outputs and their fp32- reference error are unchanged, since rows are independent. Paired in-process A/B vs 9428a09 on MI308X (gfx942): - 111 unit-test cases: geomean 1.19x (MTP4/8 UT cases 1.4-2.4x) - 180 MTP grid cases: geomean 1.056x (batch 1 up to 1.45x; busy grids 1.00x) FP8 D256 (0.93-1.05x) is excluded. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…page64 on gfx942 FP8 per-token D256 page64 single tiles with V prefetch take the per-token M1 schedule, which was tuned on gfx950. On busy gfx942 grids it was 0.88-0.93x vs main (B16 ctx32K, B64 ctx8K/32K). On small grids it gains 1.01-1.07x. Busy grids keep the unprefetched schedule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The tile grid is (plan capacity, KV heads x query splits). Dispatch walks x first, so split 1 of task 0 dispatches only after every slot of split 0, padding slots included. On small grids, where the plan has many more slots than tasks, the splits ran in sequential waves of mostly empty CTAs. On large grids a task's splits ran far apart, each re-reading the task's K/V from HBM. On gfx942, split kernels now launch (KV heads x query splits, capacity), so a task's splits dispatch together. They run concurrently and share the K/V they re-read. The cache key records the choice. BF16 splits forced by the LDS limit at large head dims only use it when tasks own at least four tiles; with fewer, the split-major grid measured 0.93-0.97x. Paired in-process A/B vs 8f9fe39 on MI308X (gfx942): - 180 MTP grid cases: geomean 1.092x - FP8 MTP4/8 batch 1: 1.04-1.45x - FP8 sliding-window MTP4 batch 1/16: 1.28-1.63x - BF16 D1024 MTP batch >= 16 with ctx >= 8K: 1.10-1.26x - 111 unit-test cases: geomean 1.018x (MTP4/8 and window cases 1.16-1.20x) gfx950 binaries are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…or on small grids The same dispatch-order effect as query splits: with grid (capacity, KV heads), a second KV head's tasks dispatch only after every slot of the first head, including the plan's empty padding slots. On small gfx942 grids the planned capacity far exceeds the tasks, so heads now launch head-major there. Busy grids keep the slot-major order, which measured slightly better for them (0.93-0.98x head-major). Paired in-process A/B vs ece6342 on MI308X (gfx942), two-KV-head geometries: batch 1 ctx 1K/8K 1.11-1.29x (FP8 D64 MTP3, FP8 D256 page16, BF16 D64 MTP4); other grid sizes and the unit-test cases unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rids A sliding window bounds every MTP task to a few KV tiles. The task's serial latency therefore stays the decode time even on grids the idle-CU rule counts as busy. Windowed MTP tiles on gfx942 now split FP8 into single-M-tile CTAs on any grid, and BF16 two-way while four split CTAs fit per CU. Unwindowed rows keep the idle-CU thresholds. Paired in-process A/B vs db5c85c on MI308X (gfx942), 70 windowed MTP4 cases: geomean 1.045x (grid 1.050x) - BF16 window 257 batch 16: 1.32-1.34x - BF16 window 700 batch 64: 1.12-1.18x - FP8 per-tensor vectorized V batch 64: 1.18-1.20x Unit-test cases unchanged. The max error against the fp32 reference is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
BF16 D64 rows are 128 bytes, the same as FP8 D128, and their split CTAs stay small. BF16 D64 MTP rows now split two-way while the unsplit busy CTAs fit one per CU, as FP8 does, rather than only while the split ones do. Paired in-process A/B vs 922fde0 on MI308X (gfx942), BF16 D64 MTP geometries: - UT mtp4-g16-page128-cluster-d64: 1.38x - B1 ctx32K and B16 ctx1K: 1.12-1.13x - everything else 0.99-1.01x 41 cases: geomean 1.017x. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… per CU on gfx942 waves_per_eu=2 trades spills (FP8 D128 MTP) or nothing (streamed BF16 D256) for a second resident CTA per CU. That only pays when the host-bounded busy CTAs fill two per CU. Between one and two per CU it only costs spills: the long-row UT case mtp4-g16-page128-varied (6 rows up to 4100 tokens) ran at 0.94-0.97x vs main. The cache key gains the two-per-CU flag (before D256_PIPE). Paired in-process A/B vs 26f6401 on MI308X (gfx942): mtp4-g16-page128-varied 1.01-1.10x; grid MTP and BF16 D256 cases unchanged (0.99-1.01x). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Four BF16 D128 M-tiles per CTA hold 360 VGPRs: one wave per SIMD. With split-major launches (ece6342) a two-way split no longer re-reads K/V from HBM, since a task's two CTAs dispatch together and share it. Each CTA then holds two M-tiles and, on busy grids, takes the streamed two-M-tile schedule at two CTAs per CU. Busy BF16 D128 MTP rows with at least four M-tiles now split two-way. D192 (0.76-0.83x) and two-M-tile rows (0.85-0.96x) measured slower and keep their schedules. Paired in-process A/B vs df92172 on MI308X (gfx942): BF16 D128 MTP4/MTP8 page128 at batch >= 16: 1.03-1.10x; other BF16 MTP cases unchanged. 92 cases: geomean 1.020x. Max error against the fp32 reference is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
zhiding512
left a comment
There was a problem hiding this comment.
Advisory review. I only have gfx950 here (MI355X): with this PR applied on main cb4ac34, op_tests/test_flydsl_pa_decode.py gives 355 passed / 37 skipped, the same as main, so gfx950 is unaffected, but none of the gfx942 changes were exercised. The points below come from reading the code.
ci:mi300x; this PR has no labels and, as a draft, skipped even the MI35X standard tests. Please add ci:mi300x before marking it ready.
split_workgroups * query_splits > CU) and the split rules (for example 4 * busy <= 3 * CU) scale with the CU count, but 304-CU MI300X / MI325X weren't measured (as you note). A small MI300X subset would help before merge.
op_lds.py, pipeline.py, traits.py and pa_decode_kernel.py. Both insert cache-key fields ahead of D256_PIPE (and the positional unpack in create()), and in the launch block #7700 needs block=(traits.CTA_THREADS, 1, 1) for its dual-group CTAs where this PR keeps traits.BLOCK_THREADS. Please agree an order with #7700 and keep CTA_THREADS when rebasing.
Inline: how max_context_length=None callers interact with the busy-grid flag, and the gfx942 gating predicate.
Advisory review, AI-assisted; the runtime numbers come from the runs described above.
…re restaging STREAM_KV tiles stage the next tile's page ids in LDS at the start of the tile, so the page-table wait does not drain the K stream. The first tile's ids are staged in the prologue and read back by every wave after its barrier, but nothing ordered that read before the first tile's restaging: a fast wave could overwrite the ids while a slow wave had yet to read them, and the slow wave then gathered the first tile's V from the second tile's pages. Later tiles are ordered by the tile barriers. Streamed tasks now take one barrier after the read. The race showed as run-to-run output differences of up to 1e-3 on FP8 per-tensor D256 MTP4 two-head busy grids (1-2 of 40 runs on gfx942; 8-16 of 20 on gfx950 with streaming enabled). After the fix, every streamed case repeats bit-exactly; the cost is 1.0005x geomean over 161 streamed gfx942 cases. 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 |
…split-major on gfx950 (#7858) * [FlyDSL] [Perf] pa_decode: stream K/V for long head rows on gfx950 gfx950 pa_decode has the same register problem #7709 solved on gfx942: a lane holding a whole next-tile K prefetch plus the tile's V gather spills once its K row reaches 1 KiB (BF16 D512+, FP8 D1024), and single or paired M-tiles with 384/256-byte rows drop to one wave per SIMD on busy grids. Let STREAM_KV select on gfx950 too, outside the fused BF16 MTP and head-256 pipes, which keep their own schedules; streamed tiles skip the dual-group CTA. The busy-grid flags it reads are now arch-neutral (renamed busy_grid / two_per_cu); every other consumer stays gfx942-only. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [FlyDSL] [Perf] pa_decode: split MTP query rows over idle gfx950 CUs #7709's gfx942 query split also pays on gfx950: when few CTAs hold work, per-CTA latency dominates, and splitting the MTP query positions over more CTAs (re-reading K/V from L2) shortens the critical path. Apply it on gfx950 with two differences found by measurement: - per-token FP8 keeps its fused MTP4 tiles (splitting them ran 0.75x); - gfx950 MTP plans fix capacity at one or two slots per CU regardless of load, so a capacity bound no longer means idle CUs. The FP8 split also requires at most eight KV tiles per CU (tile_demand, the uncapped sequence x head x tile count); B64/32K per-tensor ran 0.87x without it. The BF16 D128 split for busy grids stays gfx942-only (0.6-0.9x on gfx950). Co-Authored-By: Claude Opus 5.5 <[email protected]> * [FlyDSL] [Perf] pa_decode: launch sparse gfx950 grids split-major #7709 launches gfx942 query splits and multi-head grids split-major, so a slot's splits (or a small grid's heads) dispatch together instead of queueing behind every empty plan slot of the previous split. On gfx950 the order only pays while at most a quarter of the CUs hold work; on fuller grids slot-major order measured up to 1.25x faster, so gfx950 takes it only below that bound, for FP8 and for BF16 up to D128 (LDS-forced BF16 D192/D256 splits ran 0.91-0.93x). MXFP4 keeps slot-major. Two gfx950-only paths assumed the slot-major axes and now follow the grid: the BF16 D128 planned output's slot count (grid_dim.x; with a split-major grid it read heads x splits and stored partials at wrong offsets) and the one-partition plan's empty-row zero fill (block_id("y") as the KV head). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Union of #7700 and this branch in the pa_decode tile kernel: this branch's policies stay gfx942-only and #7700's paths keep their conditions. - traits: STREAM_KV, WAVES_PER_EU_2, PAGES_EARLY, GFX942_Q_EARLY and the gfx942 V-prefetch rule sit beside #7700's gfx950 flags; the busy, two-per-CU and split-major fields join the named PaDecodeCacheKey ahead of D256_PIPE, so tests still read (D256_PIPE, stage_pages) last; P_BUFFERS covers MTP4_FUSED, D256_PIPE, BF16_MTP_FUSED and STREAM_KV; dual-group CTAs exclude streamed tiles. - pipeline: the streamed prologue barrier precedes #7700's Q-operand selection; tile() issues both next-page lookaheads; single_query_tile takes the STREAM_KV branch, else #7700's late-scale / V-after-QK path with PAGES_EARLY ahead of REUSE_KV_PAGES. - op_lds: early Q covers MTP4_FUSED, DECODE_Q_EARLY, GFX942_Q_EARLY and MXFP4, with #7700's padded-row clamp. - launch: split-major grid with CTA_THREADS blocks, #7700's gfx950 kernarg preload, waves_per_eu=2 for FP8_MTP4_LEAN or WAVES_PER_EU_2. - #7700 now runs one-partition plans on gfx942, whose empty-row zero fill read the KV head from block_id("y"); it follows the split-major grid. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…l tile groups #7700 now runs gfx942 one-partition D128 decode on sparse grids as two tile groups per CTA. There, this branch's BF16 page16 V prefetch measured 0.97x against main (UT decode, small_query and probability_tail page16 GQA8), so the rule now skips those tasks. The selection mirrors the dual-group preconditions known before the layout: gfx942, one partition, at most one CTA per CU, one query row, no window, D128, no single-tile plan. FP8 page16 keeps its V prefetch there (1.03-1.15x vs main). Co-Authored-By: Claude Opus 5.5 <[email protected]>
zhiding512
left a comment
There was a problem hiding this comment.
Approving. Checked on gfx942 (MI308X, FlyDSL 0.5.0): pa_decode pytest 285 passed / 107 skipped on both this PR and main; a 40-case A/B is bit-exact vs main; geomean 1.16x with real context lengths and 1.08x (worst 0.996x) ATOM-style without max_context_length, so no regressions.
Non-blocking follow-ups:
- The busy/split decisions use plan capacity rather than actual lengths, so most of the MTP short-context gain goes away when max_context_length is not passed (e.g. FP8 MTP4 b4 1K 1.72x -> 1.00x).
- Gate the gfx942 paths on is_gfx942 instead of
not is_gfx950. - Consider adding the ci:mi300x label so the gfx942 code is exercised in CI.
…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]>
Resolve conflicts with #7619 (gfx1250 wide steps, shared clusters, MTP4) and #7709 (gfx942 schedule tuning). - gfx1250_tile_traits also selects MXFP4 tiles: direct_output becomes plan_free, per_token_kv is off, query splits default to mxfp4_gfx1250_query_splits, and latency_grid stays off (no page16 stages). compile_gfx1250_pa_decode(t) validates the MXFP4 limits on the traits and refuses cluster_steps/cluster_runs/cluster_seqs for MXFP4. - Gfx1250Traits keeps plan_free/fuse_tasks after the new fields, which the selection passes positionally. - Kernel: the fuse_tasks branch is unchanged; its else holds main's task selection plus the plan-free tasks and the MXFP4 pipeline. - Host: cluster kernels now read work as context lengths and take run_tiles, so MXFP4 cluster launches pass context_lengths and 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e CTAs per CU #7709 streams K/V for single M-tiles with 384-1023 B rows and paired M-tiles with 256-1023 B rows once more CTAs than CUs hold work. On gfx942 a sliding window bounds every task to a few tiles, and there streaming only pays on much fuller grids: on MI308X (80 CUs) BF16 MTP4 G16 D128 windows (w257, w700) at 1.2-2.4 CTAs per CU ran 0.83-0.91x with streaming, and from 3.6 CTAs per CU 1.15-1.27x. Windowed gfx942 rows now take the busy-grid streaming arms only above three CTAs per CU (new cache-key field stream_busy). Unwindowed rows, every other busy_grid consumer and every gfx950/gfx1250 selection are unchanged. MI308X, paired in-process ABBA, 20 pairs: the 13 changed cases run 1.128x faster with cold KV (512 MB rotation; 1.095-1.221x) and 1.101x warm, all bit-exact. Of 3726 schedule-checked cases (UT matrix, off-grid probes, prod sweep) only these 13 change. gfx950 and gfx1250 binaries are identical to the previous head; pytest op_tests/test_flydsl_pa_decode.py on gfx942: 357 passed / 108 skipped, the same as main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Speeds up the FlyDSL
pa_decodetile kernel on gfx942 (MI300-series) by fixing register spills, hiding load latency and picking schedules by grid size. gfx950 and gfx1250 kernels are bit-for-bit unchanged.On all 786 cases of the unit-test-geometry matrix described below, against current main (which now includes #7700): geomean 1.34x (unit-test cases 1.39x, grid cases 1.33x). Six cases are below 0.995x, the lowest at 0.97x; see "Known regressions".
Commit 17 fixes a first-tile LDS race in the streamed path (commit 1), found while porting streaming to gfx950.
After #7700 landed, this branch merged main (
71af0c22ba). #7700 extends four gfx950 paths to gfx942. The merge keeps both sides, and commit 18 (ce737ce698) resolves the one interaction that cost speed.Motivation
The gfx9 schedule was tuned on gfx950. On gfx942 it has four problems.
Changes
The changes are all in
aiter/ops/flydsl/kernels/pa_decode/{traits,pipeline,op_lds}.pyandpa_decode_kernel.py. They are gfx942-only, selected by"gfx94" in archornot is_gfx950. One commit each:c52a931dfbK/V streaming (STREAM_KV).sched_barrier(0)per chunk.a5a617efccV prefetch for single M-tiles: FP8 up to D256 and BF16 page16 D128. This reuses gfx950'sprefetch_vschedule.9428a0946dBusy-grid flaggfx942_busy(host-bounded busy CTAs above the CU count). It is a cache-key field placed beforeD256_PIPE. On busy grids:waves_per_eu=2;2fa4680059Q loads before the first K tile. Padding rows are clamped to the last real row and still zero-filled when staged.20ee766cfbThe next tile's page-table read before this tile's V loads, fenced. The pin to the context runs at the use.b499cb7234FP8 per-tensor page128 vectorized-V prefetch only on busy grids.64a9ea306awaves_per_eu=2for busy streamed BF16 D256 (254 VGPRs, no spills).1df843bf23Streaming for two-M-tile MTP from 256-byte rows on busy grids (FP8 D256 and BF16 D128 GQA8 MTP4).d5691dd522Idle-CU query split for MTP rows. Each split CTA re-reads K/V, mostly from L2.4 * busy CTAs <= 3 * CU, else 2-way whilebusy CTAs <= CU.2 * busy CTAs <= CU.8f9fe39e4dNo V prefetch for busy FP8 per-token D256 page64 (that gfx950-tuned schedule was 0.88-0.93x there).ece634218bSplit-major grid(KV heads x query splits, capacity)for query-split kernels.db5c85c726Head-major grid for several KV heads on small grids, for the same reason.922fde04d7Windowed MTP splits on busier grids. A sliding window bounds each task to a few tiles, so:26f640138eBF16 D64 MTP splits like FP8: 128-byte rows, as with FP8 D128.df92172a41waves_per_eu=2only when the host-bounded busy CTAs fill two per CU (cache-key fieldgfx942_two_per_cu). Below that it only cost spills: the long-row UT casemtp4-g16-page128-variedwas 0.94x.8274dfbc42Busy BF16 D128 MTP4 rows split two-way.65eed8399b[Bugfix] Streamed tasks read the first tile's page ids before restaging them.71af0c22baMerge of main ([FlyDSL] [Perf] pa_decode: gfx950 fused BF16 MTP4 verify tile, decode load scheduling and lean FP8 MTP4; four paths extended to gfx942 #7700). Union of both sides; this branch's policies stay gfx942-only.PaDecodeCacheKey, ahead ofD256_PIPE.block_id("y"), which a split-major grid moves to x, so it now follows the grid.ce737ce698No BF16 page16 V prefetch under gfx942 dual tile groups.Not changed:
plan_pa_decodeand its 2CU default budget (a 3CU budget measured 0.956x on the tuned head);Performance (if applicable)
Measured on an 80-CU MI308X (gfx942) with FlyDSL 0.5.0. Before = main
769ba404ba(with #7700), after =ce737ce698.max_partitions= CU, budget 2*CU, with [FlyDSL] [Perf] pa_decode: gfx950 fused BF16 MTP4 verify tile, decode load scheduling and lean FP8 MTP4; four paths extended to gfx942 #7700's min-max task balancing on gfx942).op_tests/test_flydsl_pa_decode.py, each at its own UT lengths plus batch {1,16,64} × uniform context {1K,8K,32K}.mtp4-g16-page128-direct(FP8 per-token)The end-to-end run covers every case on an idle GPU. Commit 18 changes only the three cases it targets, and their numbers above are its re-measurement. Outputs:
Per-commit A/B for commits 13-16, measured against the pre-#7700 main:
mtp4-g16-page128-cluster-d641.38x)mtp4-g16-page128-variedUT caseCommit 17 (the race fix) against
8274dfbc42, on all 161 streamed matrix cases: geomean 1.0005x (clean MI308X run). The end-to-end numbers above are from8274dfbc42; the fix only adds one barrier per streamed task.Known regressions against main with #7700. They were none below 0.99x before #7700; the attribution comes from an A/B of early Q on/off over all 786 cases:
Early Q still gains 0.9% over the whole matrix, so it stays on. A shape-specific rule is left to a follow-up tuning pass.
Testing
op_tests/test_flydsl_pa_decode.pypasses in full on MI308X (gfx942) at every commit, including the merge andce737ce698: 285 passed, 107 skipped (MXFP4 is gfx950-only). On MI355X (gfx950) the merged branch passes 355, with 37 skipped. The existing cases cover:head1024(FP8 and BF16),head1024-mtp-split3/4,head512-mtp-split2,head192-*,head256(BF16);decode,small_query/probability_tailpage16/page128,cluster8/16,head256,d256-*,mtp, in per-tensor, per-token, plain-V and vectorized-V variants;-direct/-merge/-probability_tailcases,window,head192-mtp,graph-workspace.Documentation
The API, the plan, and the selection of supported shapes are unchanged; the change is internal to the gfx942 tile schedule.
Dependencies
Breaking Changes
None
PR Self-Review
Reviewed revision
ce737ce
Behavior and intent
On gfx942 the pa_decode tile schedule now follows its register budget and grid size. gfx950 and gfx1250 compile to identical binaries.
Each removes an in-order vmcnt wait that ATT showed on the critical path.
The old schedule was tuned on gfx950 and left these on the table on MI300.
Commit 17 also orders the streamed prologue's page-id read before the first tile restages those ids. Without it, streamed outputs could differ between identical runs.
The merge with main keeps #7700's new gfx942 paths: one-partition direct output, the min-max planner, dual-group CTAs and packed Q absmax. This branch's policies are layered on top of them. Commit 18 keeps BF16 page16 V prefetch out of dual-group tasks, where it lost.
Validation and unverified scope
Evidence:
pytest op_tests/test_flydsl_pa_decode.pyon MI308X (gfx942, FlyDSL 0.5.0) at every commit: 285 passed, 107 skipped.exp(N(0,1))before per-token FP8 quantization, main and 8274dfb have identical relative max error against the fp32 reference on every changed per-token path (page16/page128 decode, D256 page64, MTP4, window, D1024).COMPILE_ONLY=1, main (with [FlyDSL] [Perf] pa_decode: gfx950 fused BF16 MTP4 verify tile, decode load scheduling and lean FP8 MTP4; four paths extended to gfx942 #7700) vs ce737ce: gfx950 148/148 and gfx1250 166/166 binaries identical.det_check.py): 8274dfb differs in 2/200 runs on two of them (up to 1.4e-3); 65eed83 repeats bit-exactly in 200/200 everywhere.Unverified:
max_context_lengthuse the block-table capacity as the bound. They therefore see busy-grid schedules and no query split.PR-specific question
There are three boundaries.
The gfx942-only selectors (
"gfx94" in archinselect,not is_gfx950increate) must never change gfx950 or gfx1250:The new cache-key fields (
gfx942_busy,gfx942_two_per_cu,split_major) must keep the test'scache_key[-2:]= (D256_PIPE,stage_pages):PaDecodeCacheKeythey sit beforeD256_PIPE, andcreate()reads them by name.Split-major grids must not misplace one-partition output on gfx942. #7700 brought direct one-partition output to gfx942. Its empty-row zero fill now takes the KV head from the grid axis that
SPLIT_MAJORselects. With that fix reverted on gfx950 (where #7858 opens split-major), 9 unit tests fail; with it they pass.Query splits must keep every query row's math unchanged:
query_splitspath that BF16 LDS splitting already uses.partial_slotstayskv_head * capacity + slot, so the reducer's partial layout is unchanged.query_splits in (1, 2, 4)andquery_length % query_splits == 0asserts stay.Changed op tests
None. The existing
test_pa_decodecases already exercise every streamed, prefetched, query-split andwaves_per_eu=2specialization and pass. The MTP4/8 cases reach the split path, and the-variedlong-row case reaches the busy-grid path.🤖 Generated with Claude Code