Skip to content

[FlyDSL] Add packed D256 PA decode pipeline for gfx950 - #6655

Merged
coderfeli merged 3 commits into
mainfrom
fsx950223/d256-pipe-main
Oct 19, 2026
Merged

coderfeli merged 3 commits into
mainfrom
fsx950223/d256-pipe-main

Conversation

@fsx950223

@fsx950223 fsx950223 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

On gfx950, FP8 paged attention with head dimension 256 now uses a shared K/V pipeline for page sizes 16/64 and up to 32 query rows. The pipeline supports per-tensor or per-token KV scales, plain or transposed packed V, and positive sliding windows. Non-transposed 4D K caches raise NotImplementedError; gfx942 uses the generic tile path.

This is a standalone PR against main, incorporating the packed pipeline from #5949 and the extensions in #6617 through 06fa78657. It is based on main at 285579b62 and preserves the partition reducer already merged in #6619. The packed pipeline credits Sami Remes for the original implementation.

Changes

  • Stream K once per KV tile with nontemporal loads and K128 MFMA, prefetch V, and share K/V across up to two query M-tiles. Each M-tile retains private probability and softmax state.
  • Stage page IDs before the tile loop. Support page16 vector-width reads from LDS and scalar block-table fallback beyond the staged bound; use a scalar table view for page-ID staging.
  • Stage per-token scales before K prefetch, retain V-scale normalization, and scale scores before masking to preserve empty rows.
  • Bound staged pages from the visible MTP sliding-window union. Keep the 4096-page-ID limit and fallback for oversized tasks.
  • Use the existing 2×CU default plan budget for all shapes on gfx942/gfx950. Remove the D256-specific budget helper, extra CU-count tuning candidate, constant layout field and redundant architecture key; preserve native autotuning and saved configuration overrides.
  • Keep trans_k=True as the compiler default and explicitly reject non-transposed K. Reuse aiter's get_num_xcds in the existing reducer launcher and fix the tuning CLI's removed-layout reference.
  • Retain the existing PA test suite with its packed D256 coverage. Supplementary validation scripts are outside the PR.

Validation

At 6ff647358, using the pinned FlyDSL 0.4.0:

  • gfx942/MI308X full op_tests/test_flydsl_pa_decode.py: 113 passed, 4 skipped; skips are partition caps above the device's CU count.
  • gfx950/MI355X full op_tests/test_flydsl_pa_decode.py: 117 passed.
  • 320 packed D256/page16 configurations passed on gfx950 against independent FP32 attention at atol=rtol=0.005, including 32 graph-replay cases. Covers BF16/FP16 queries, both KV scale modes and packed V layouts, QL1–4 at GQA8, windows 0/1/17/257/8193, small/large budgets, single/multi-tile plans, empty/tail contexts and sinks. Maximum FP32 reference error: 0.0016555.
  • 20 supplementary gfx950 page16 boundary cases passed, including unstaged page IDs, a scheduling bound below the real context, multiple KV heads, GQA4/16/32, QL8 at GQA4, and graph replay. Random V amplitudes are scaled by 1/16 to isolate addressing and scheduling within the existing FP32 tolerance.
  • 9 unsupported-layout checks passed on each GPU, covering both V transpose modes at host, schedule, compiler, plan preparation and tuning geometry.
  • The standalone tuning CLI completed on both GPUs with D256/page16, per-token KV and plain/transposed V, saving a native autotune configuration.
  • Black, Ruff and git diff --check passed.

Validation uses AITER_AOT_IMPORT=1 and equivalent Torch reference quantizer formulas in the harness to avoid unrelated CK imports; PA kernels and independent FP32 references execute from source.

The tile implementation is byte-identical to 06fa78657. At that source revision, the prior 320-case page16 matrix (including 32 graph replays) passed with maximum FP32 error 0.0016555. A separate unscaled random GQA16/QL2/window17 input had FP32 error 0.00748747 in both the old generic path and the new pipe, with bit-identical outputs; this is an existing FP8 precision limitation.

Follow-up validation at b7a54ab96: removed test_stage_bound_covers_plan and grouped the tuning geometry dimension checks. Returns and exception types/messages match the prior implementation for dimensions 0–8. Black, Ruff and diff checks passed; pytest collected 116 remaining tests. The GPU suite results above are from 6ff647358; GPU tests were not rerun for this follow-up.

Follow-up validation at 80f1394d5 (2×CU default and tuning cleanup), with pinned FlyDSL 0.4.0:

  • 19 default-plan configurations passed on each of gfx942 and gfx950, covering D256/page16/64, QL1/4, per-tensor/per-token scales, both packed V layouts, plus D128 FP8 and D128/D256 BF16. Inputs use B4, context8192 and sliding window257. With autotuning disabled and an empty cache, the public prepare_pa_decode_plan selects 2×CU (160 on gfx942; 512 on gfx950).
  • All 19 work/reduce plans and decode outputs on each GPU are bit-identical to b7a54ab96 with an explicit 2×CU budget; all 19 captured graphs replay successfully on each GPU.
  • Native autotuning and saved-result reload pass on both GPUs for D256/page16, per-token KV and transposed V.
  • Black, Ruff and git diff --check pass. The existing test module's executable AST is unchanged; this follow-up adds no in-tree tests and does not rerun the full GPU suite above.

Performance versus main

The latest commit 80f1394d5 defaults to 2×CU for all shapes. The main/PR tables below were measured at b7a54ab96, before this follow-up, when eligible gfx950 D256 shapes defaulted to 1×CU. The later direct 1×CU/2×CU comparison motivated restoring 2×CU; these historical main/PR timings are not a rerun of the latest default.

Compared main 285579b with PR b7a54ab, using pinned FlyDSL 0.4.0 on gfx950/MI355X (256 CUs) and gfx942/MI308X (80 CUs). Both variants ran in one process on the same GPU with identical query/KV inputs and separate source snapshots. The reducer source is byte-identical between revisions.

Each GPU ran 80 configurations: D256, BF16 queries, FP8 KV (OCP on gfx950, FNUZ on gfx942), 8 query heads / 1 KV head, page sizes 16/64, per-tensor/per-token KV scales, and trans_v=false/true. Ten (context, batch, QL, window) geometries per combination:

(8192,1,1,0), (8192,4,4,0), (8192,32,1,0), (8192,32,4,257), (131072,1,1,0), (131072,4,4,0), (131072,1,1,8193), (131072,4,4,8193), (524288,1,1,0), (524288,4,4,0).

Autotuning and saved tuning results were disabled. At measured revision b7a54ab96, each revision used its public prepare_pa_decode_plan default: gfx950 main used a 2×CU work budget and the PR used CU count for eligible D256 shapes; gfx942 used 2×CU on both. Plan capacity is also capped by batch × max partitions. The comparison therefore includes the default scheduling behavior at that measured revision.

  • Cold decode: a read-only 2 GiB flush precedes each captured plan-update → attention → reduce step. Reported decode time sums only attention + reduce GPU kernel durations; step time includes the plan-update kernel too. Each candidate uses 15 calls per profile, three alternating main/PR rounds, reduced by median. Flush time, graph gaps, CPU overhead and compilation are excluded.
  • Warm decode: GPU event timing of 50 decode calls per graph, five samples per round and seven alternating rounds; median of round medians. Includes GPU graph gaps and excludes plan updates.
  • GPU clocks used the existing dynamic policy, without locking. Comparisons use the same device and alternate candidates after warmup; absolute times should not be compared across the two cards.

All ratios below are main latency / PR latency; greater than 1 means the PR is faster. Geometric means use all ten geometries; the range includes every measured configuration.

gfx950 / MI355X

Page KV scales trans_v Cold decode geomean Cold range Warm decode geomean Cold step geomean
16 per-tensor false 0.993× 0.851–1.155× 0.927× 0.990×
16 per-tensor true 0.994× 0.850–1.146× 0.927× 0.994×
16 per-token false 1.120× 1.032–1.250× 1.070× 1.108×
16 per-token true 1.121× 1.028–1.254× 1.073× 1.108×
64 per-tensor false 1.086× 0.999–1.190× 1.043× 1.078×
64 per-tensor true 1.085× 1.013–1.193× 1.038× 1.075×
64 per-token false 1.143× 1.064–1.281× 1.089× 1.125×
64 per-token true 1.129× 1.047–1.276× 1.089× 1.114×

Per-token KV improves with both V layouts: 1.120–1.143× geometric-mean cold speedup, with every measured per-token case above 1×. Page64/per-tensor improves by about 1.085×. Page16/per-tensor is mixed and includes a regression: at context 524288, B4, QL4, window 0, trans_v=true, main takes 204.52 µs and the PR takes 240.61 µs (0.850×, 17.6% higher latency). This PR does not have a blanket no-regression claim.

Representative cold decode times at context=131072, B4, QL4, window=0:

Page KV scales trans_v main (µs) PR (µs) Speedup
16 per-tensor false 65.24 66.87 0.976×
16 per-tensor true 65.00 66.58 0.976×
16 per-token false 70.95 56.76 1.250×
16 per-token true 70.94 56.59 1.254×
64 per-tensor false 64.39 54.12 1.190×
64 per-tensor true 62.61 52.46 1.193×
64 per-token false 70.71 55.45 1.275×
64 per-token true 68.74 53.86 1.276×

gfx942 / MI308X

Page KV scales trans_v Cold decode geomean Cold range Warm decode geomean Cold step geomean
16 per-tensor false 1.000× 0.996–1.003× 0.999× 1.002×
16 per-tensor true 1.000× 0.997–1.004× 1.000× 1.000×
16 per-token false 1.000× 0.997–1.003× 0.998× 1.001×
16 per-token true 1.000× 0.997–1.003× 0.999× 1.000×
64 per-tensor false 0.999× 0.994–1.004× 0.999× 0.998×
64 per-tensor true 1.001× 0.996–1.009× 0.999× 1.001×
64 per-token false 1.000× 0.998–1.004× 1.000× 1.000×
64 per-token true 1.000× 0.997–1.005× 1.000× 1.000×

The gfx942 path shows no material movement in this sweep: group geometric means are 0.999–1.001× and individual cold ratios are 0.994–1.009×. All 80 main/PR outputs are bit-identical; the gfx950 pipe is not selected.

Correctness and regression follow-up

Every main and PR output in the 160 configuration comparisons passed the independent, chunked FP32 causal/sliding-window reference with atol=rtol=0.005 and zero tolerance mismatches. Per-token scales vary by page/token and K/V use separate scales. Maximum FP32 absolute error: 0.00283734 on gfx950 and 0.00232045 on gfx942. gfx950 has 52/80 bit-identical outputs; maximum main/PR difference is 0.000442505, consistent with different partition plans.

The page16 regression was retested in 24 additional paired comparisons: three geometries (8192,32,1,0), (524288,1,1,0), (524288,4,4,0) × both scale modes × both V layouts × default/equal work budgets. This repeat reversed candidate order and used 30 calls per profile. All reference checks passed. At context 524288/B4/QL4 with trans_v=true, the default repeat is 205.96 → 240.77 µs; equal 512 work budgets give 205.19 → 245.07 µs (0.837×). Equal budgets do not eliminate the page16/per-tensor regression, so it cannot be attributed solely to the default budget change.

Serving throughput and CPU/host overhead were not measured. The raw results, per-kernel samples, source hashes and harness are retained outside the PR in /aiter/pr6655_main_perf_20261018/.

Larger batch/context: direct 1×CU versus 2×CU

PR revision b7a54ab was tested directly with workgroup budgets 256 (1×CU) and 512 (2×CU) on the same gfx950/MI355X, using FlyDSL 0.4.0. This isolates the budget comparison within the PR; these numbers are separate from the main/PR speedups above.

144 configurations cover D256, BF16 queries, FP8 KV, GQA8, QL1/4, page16/64, both KV scale modes and trans_v=false/true, with window=0. The (context, batch) pairs are (131072,64/128/256/512), (524288,32/128), (1048576,32/128) and (2097152,32). The largest independent K+V allocation is 64 GiB. Inputs use independently addressed physical pages, seeded random block tables, deterministic FP8 values and separate varying per-token K/V scales; both budgets share the same input allocations.

Cold measurements sum attention+reduce GPU durations after a 2 GiB read-only flush; step timing also includes the plan-update kernel. Each budget uses ten calls per profile and three alternating rounds. Warm measurements time five decode calls per graph, three samples per round and five alternating rounds. Compilation, FP32 reference computation and flush time are excluded. Clocks use the existing dynamic policy. Runtime device identity is recorded as PCI 0000:85:00.0.

The ratios in this section are 2×CU latency / 1×CU latency: above 1 favors 1×CU; below 1 favors 2×CU. Each row aggregates 18 context/batch/QL geometries.

Page KV scales trans_v Cold geomean Cold range Warm geomean Step geomean
16 per-tensor false 0.998× 0.955–1.020× 0.998× 0.998×
16 per-tensor true 0.999× 0.954–1.018× 0.999× 0.999×
16 per-token false 0.982× 0.937–1.009× 0.986× 0.982×
16 per-token true 0.982× 0.934–1.007× 0.983× 0.982×
64 per-tensor false 0.998× 0.954–1.010× 0.998× 0.998×
64 per-tensor true 0.999× 0.977–1.008× 1.000× 0.999×
64 per-token false 1.000× 0.984–1.014× 1.001× 1.001×
64 per-token true 0.995× 0.952–1.004× 0.997× 0.995×

At these larger shapes, 1×CU has no consistent advantage. Page16/per-token favors 2×CU by about 1.8% in geometric-mean cold latency. The largest observed difference is at context=524288, B128, QL1, page16, per-token, trans_v=true: 5536.94 µs (1×CU) → 5172.81 µs (2×CU), a 6.6% latency reduction with 2×CU. Page64 is mostly close; individual configurations favor either budget.

Representative direct cold timings:

Context Batch QL Page KV scales trans_v 1×CU (µs) 2×CU (µs) 2×/1× latency
524288 128 1 16 per-token false 5523.40 5173.34 0.937×
524288 128 1 16 per-token true 5536.94 5172.81 0.934×
524288 128 4 64 per-token true 5339.37 5080.87 0.952×
2097152 32 4 64 per-token true 5268.85 5173.61 0.982×
131072 512 4 64 per-token true 5088.48 5079.16 0.998×
131072 256 1 16 per-tensor false 3791.73 3866.87 1.020×

For batch≤256, the budgets produce 256 versus 512 active tasks. At batch=512, both produce 512 active tasks, so the plans are equivalent and timings agree within about 0.2%. Page-ID staging can also change with budget because the maximum tiles per task changes; recorded staging/partition data is retained with each result.

A separate fresh-process repeat at context=524288/B128 covered 16 configurations, doubled calls per cold profile to 20, and reproduced the page16/per-token/QL1 difference: trans_v=false 5524.94 → 5173.34 µs, trans_v=true 5530.13 → 5174.55 µs (about 6.4% lower latency with 2×CU).

All 144 primary + 16 repeat comparisons passed the independent batched/chunked FP32 reference with atol=rtol=0.005, zero tolerance mismatches, and maximum primary FP32 absolute error 0.000137745. Based on this comparison, follow-up 80f1394d5 restores the existing 2×CU default for all shapes and removes the special-case selection code. Native autotuning and saved configuration overrides remain available. Serving throughput and positive sliding windows were not measured in this expanded sweep.

Raw latency, TFLOPS/TB/s, sample data, source hashes and device identity are retained outside the PR in /aiter/pr6655_large_budget_20261018/.

Historical comparison against the pre-main integration source

Previous validation of 06fa78657 against 7072a730e covered 48 gfx950 and 24 gfx942 D256/page64 configurations; all outputs were bit-identical and no material regression was observed (largest measured slowdown below 0.5%). Those measurements used the previous partition reducer. These historical numbers are separate from the current-main measurements above.

Port the packed D256 pipeline from 06fa786 to current main, preserving its partition reducer. Support page16/page64, per-token KV, both packed V layouts and sliding windows; reject non-transposed K. Fix the tuning CLI output and use the shared XCD helper.

Co-authored-by: Sami Remes <[email protected]>
@fsx950223
fsx950223 requested review from a team and a balanced review from Copilot October 18, 2026 05:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 6655 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@fsx950223
fsx950223 requested a review from samremes October 18, 2026 05:56
Copilot AI balanced review requested due to automatic review settings October 18, 2026 06:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 18, 2026 13:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants