Skip to content

[FlyDSL] [QSA] Sparse prefill attention on gfx950: union and packed-direct ports, strided K/V, routing - #7556

Open
eppaneamd wants to merge 34 commits into
mainfrom
eppaneamd/flydsl-qsa-sparse-prefill-gfx950
Open

eppaneamd wants to merge 34 commits into
mainfrom
eppaneamd/flydsl-qsa-sparse-prefill-gfx950

Conversation

@eppaneamd

@eppaneamd eppaneamd commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Runs #6576's QSA sparse prefill attention (merged, gfx942 only) on gfx950 (MI355X), reads interleaved K/V caches in place on gfx950, turns on its tile routing on gfx950, and gives callers the op's own operand rules, paged-cache helpers and warm-up.

  • Union kernel on gfx950, with [FlyDSL] FlyDSL QSA indexer scorer + sparse GQA #5996's gfx950 instruction choices (16x16x32 MFMA, ds_read_b64_tr_b16 for V), 64-bank LDS swizzles and native bf16. Then K/V double-buffered in the 160 KiB LDS and 128-bit LDS DMA, each bitwise equal to its parent. One 8192-row step: 0.489 ms against [FlyDSL] Add QSA sparse prefill attention for MI308 #6576-as-written's 0.583 (both with the gather; Performance).
  • Packed direct kernel on gfx950 (K32 MFMA, v_cvt_pk_bf16_f32): 0.82-0.86× at ≤ 512 rows.
  • Strided K/V rows on gfx950: K and V may be token-row views of one pool, such as vLLM's one K|V record per token, read in place: 0.87-0.97× gather + call.
  • Routing on gfx950: each tile goes to union or direct by a measured entry, instead of forced union. A random-selection 1024-row chunk: 0.21×; 8192-row steps: 1.008× the forced-union entry.
  • Caller API: callers ask the op's rules instead of restating them (Changes, Callers). Its commits change no kernel; under kernels/ they only extract plan_query_tile from allocate_plan.
  • Main merged ([FlyDSL] [QSA] Sparse prefill follow-ups: runtime softmax scale, shared helpers, opt-in batch invariance #8148, [FlyDSL] [QSA] Add FP8 K/V to the sparse prefill #8149): gfx942 runs main's kernels (compile-only: main's ISA except K3, main's launch arguments). gfx950 runs this PR's kernels with main's runtime softmax scale and batch_invariant. FP8 K/V stay on gfx942: [FlyDSL] [QSA] Add FP8 K/V to the sparse prefill #8149's kernels are E4M3FNUZ, gfx950's FP8 is E4M3FN.
  • Since review 5799733140 (on 3a3b4a2c4): the K/V row stride bound, strided rows on gfx950 only, the op test's kernel assertions, ISA-identical cleanups, the caller API, K3's chunk-local sort key, the merge of main and the warm-up of main's batch-invariant and FP8 variants. Each commit message has the details.

Motivation

Changes

  • API: on gfx950, flydsl_qsa_sparse_prefill accepts K and V as strided views:
    • each row is dense [heads, 256];
    • rows are one stride apart: a multiple of 16 bytes, at least heads × 256, below 2**28 elements (the kernels form a four-row block's extent and offsets in 32 bits);
    • K and V share the stride and may be views of one pool;
    • byte spans are checked with the stride; workspaces and launchers are keyed by it, so each stride compiles its own kernels;
    • elsewhere strided rows are rejected: no gfx942 GPU run covers them yet.
  • Caller API (aiter/ops/qsa.py, implemented in aiter/ops/flydsl/qsa_sparse_prefill.py):
    • qsa_sparse_prefill_problem(...): the first operand rule a call breaks, as the message the op raises, or None; can_use_flydsl_qsa_sparse_prefill is the same as a bool. The op raises from the same ordered rule list, so the two cannot drift.
    • qsa_sparse_prefill_available(): whether the FlyDSL backend imports in this process.
    • qsa_paged_kv_pool(k_cache, v_cache) and qsa_paged_kv_slots(...): a paged K/V cache as the op's token pools and kv_slots.
    • qsa_sparse_prefill_warmup(run, ...): one call per kernel-variant class through the caller's own run, so the compile keys are the caller's.
  • K3 sort key (sparse_prefill_order_masks, both architectures): an order CTA breaks cost ties by the task's position in its own chunk of at most 4096 tasks instead of its global rank. Same order; the key stays below 224, so K3 needs no 64-bit-key variant and the warm-up covers layouts of any task count (before, past 221 tasks at block capacity 8224, a first call compiled one).
  • Merge of main ([FlyDSL] [QSA] Sparse prefill follow-ups: runtime softmax scale, shared helpers, opt-in batch invariance #8148: runtime softmax scale, batch_invariant; [FlyDSL] [QSA] Add FP8 K/V to the sparse prefill #8149: FP8 K/V on gfx942):
    • one rule list: main's compute, FP8 scale and batch_invariant rules beside this PR's scale, stride and row rules;
    • qsa_sparse_prefill_problem and the aiter/ops/qsa.py wrappers take batch_invariant, k_scale, v_scale and compute;
    • FP8 K/V of any FP8 dtype are rejected off gfx942, right after the device rule;
    • batch_invariant=True on gfx950: packed direct compiles the K16 loop raw direct runs, so packed and raw K/V give the same bits; the default mode keeps K32;
    • K3 compiles both of main's CHUNKED variants on a key's first compile, each with the chunk-local sort key.
  • Warm-up of main's variants: qsa_sparse_prefill_warmup also compiles the batch-invariant and FP8 kernels (K3 without routing, FP8 split and core plans, FP8 raw direct):
    • its layouts carry prefixes, so run gets K/V of each request's prefix and query tokens (before: query tokens only);
    • it returns the (query_lens, prefix_lens) that ran;
    • FP8 direct compiles packed and raw together on first compile, as BF16 direct does.
  • [FlyDSL] [QSA] qsa_sparse_prefill: public selection-width and byte-limit query #8083's support query (qsa_sparse_prefill_widths, qsa_sparse_prefill_supports_selection, flydsl_qsa_sparse_prefill_available) also answers gfx950; the op's architecture and selection rules use it.
  • Platform: new field route_all_or_none (default off). AITER_QSA_PLATFORM accepts 0 or 1 for bool fields.
  • gfx942: main's kernels. Compile-only, contiguous K/V compiles to main's ISA except K3 (chunk-local sort key, same order), and FP8 direct also compiles its other variant on first compile. Two degenerate K/V inputs are now rejected (Breaking Changes); strided rows are rejected, as before.
  • Kernels compile on first use; none is prebuilt: aiter/aot/flydsl/ has no QSA module, [FlyDSL] Add QSA sparse prefill attention for MI308 #6576's gfx942 kernels included.
Caller API: signatures and conditions
  • qsa_sparse_prefill_problem(q, k, v, indices, *, query_lens, prefix_lens, softmax_scale, out, kv_slots, batch_invariant, k_scale, v_scale, compute) returns the first operand rule the call breaks, as the message the op raises, or None. States of the process (graph capture, one GPU per process) stay in the op and are not rules.
  • Against main's wrapper on gfx942 (Rule parity): of 14,884 generated inputs the same are accepted; Breaking Changes lists two more that main accepts. Some rejections name another rule: main's dtype message is split into Q contiguity, K/V row stride and E4M3FNUZ ones, and this PR's rules run before main's later ones.
  • qsa_paged_kv_pool(k_cache, v_cache) turns a paged cache [pages, page_size, heads, 256] (arbitrary page and token strides, shared by K and V) into the op's token pools, or None. Conditions:
    • dense head vectors;
    • K and V 16-byte aligned;
    • page_size % 4 and pool rows per page % 4 (the op reads four-token blocks at four consecutive rows from a multiple of four);
    • no empty dimension.
  • qsa_paged_kv_slots(query_lens, prefix_lens, block_table, page_size, rows_per_page) returns the op's kv_slots (int32, packed token to pool row), with the host lengths copied pinned and non-blocking.
  • qsa_sparse_prefill_warmup(run, *, num_q_heads, num_kv_heads, selection_width, device) calls the caller's run(q, indices, query_lens, prefix_lens) once per kernel-variant class on synthetic Q and indices; the caller's K/V hold each request's prefix and query tokens. The layouts:
    • below the union gate;
    • at the gate, with a 4-token prefix (a request on the base union tile in both batch modes);
    • each wide tile's first rows, where the policy takes one;
    • for FP8 K/V, each union layout again with enough rows to keep its tasks whole (unsplit FP8 plans).
  • It returns the (query_lens, prefix_lens) that ran: none without FlyDSL or on an architecture without a tile policy. The tile choice is plan_query_tile, extracted verbatim from allocate_plan and used by both.
  • Without FlyDSL the names exist too: the predicate answers "QSA sparse prefill requires FlyDSL", the warm-up runs nothing, and the pool and slot helpers are plain torch.
  • gfx942 ISA: for contiguous K/V the merge base fe86c6e07 and 3f1bff21e compile every gfx942 kernel to the same ISA (compile-only, FlyDSL 0.4.0, 0.4.1 and 0.4.2: 300 kernels per version, a planted one-constant change caught). Since then kernels/qsa/ changed by extracting the host-side plan_query_tile from allocate_plan and by K3's chunk-local sort key.
  • gfx942 ISA after the merge of main: compile-only against main (FlyDSL 0.5.3, 80 CUs; 92 layouts at groups 12 / 6 / 3 / 16: BF16 and FP8 per tensor and per token, single, ragged, batch-invariant, raw-and-packed, slot-pool and top-k 1024 requests, FP8 split and core plans, 2 and 16 KV heads):
    • 137 compiles (116 distinct kernels) outside K3 give main's ISA;
    • 442 launches pass main's arguments, plus KV_STRIDE, GFX950 = false, K3's route_all_or_none = false and its chunk-position shift;
    • planted constants in the union, FP8 union and K2 kernels and a planted host change each fail the comparison;
    • the warm-up commit adds 24 FP8 direct compiles (each key's other variant, on stand-in arguments), each equal to the kernel a call with raw or packed direct forced compiles.

Callers

Performance

  • Baseline: the per-shape and end-to-end "Before" results use vLLM's Triton config from before [ROCm][Perf][Qwen4Exp] Tune sparse GQA prefill profile on gfx942 and gfx950 vllm-project/vllm#62590 (merged 2026-11-17), which retunes that kernel for gfx950; they were not re-measured with it. The kernel comparison has both configs on the real 8192-row step: 2.351 ms before, 1.540 ms since, against 0.463 ms for this branch.
  • Merge of main (gfx950, the op test's performance cases at groups 12 / 6 / 3, three alternating rounds against the pre-merge head b83688cc07 on one image): 0.999-1.041× per call, geomean 1.018×. Graph replay and kernel times are unchanged; an eager call spends about 8 µs more on the host (173 → 181 µs; main's operand rules and launch arguments).
  • Short calls over a long prefix lose: 256 rows over a 132096-token prefix take 129 µs against Triton's 110 (1.18×). A 768-row threshold on the caller's side covers every losing cell measured.
  • Per call through vLLM's QSA call site on MI355X: 0.18-0.42× Triton's time at every other shape measured, 256-8192 rows (table below).
µs per call through vLLM's QSA call site, and setup
Rows, prefix tokens Before After Change
8192, 0 2452 549 0.22×
8192, 8192 2601 779 0.30×
8192, 32768 2672 833 0.31×
8192, 132096 2651 882 0.33×
1024, 0 332 66 0.20×
1024, 132096 360 150 0.42×
768, 0 324 57 0.18×
256, 0 101 36 0.36×
256, 132096 110 129 1.18×

Against other kernels. One real 8192-row prefill step: five requests, real indexer selections, K/V in a paged pool over 4 GiB, FlyDSL 0.4.1. All rows come from one process: median of 8 alternating rounds of 100 calls, round spreads ≤ 0.4 %.

Kernel K/V ms per call
Triton, vLLM's config before vllm-project/vllm#62590 in place 2.351
#5996, FlyDSL sparse GQA at 48cdcb285 in place 1.661
Triton, vllm-project/vllm#62590's gfx950 config in place 1.540
Triton, best config we found (a row-bounded variant, not in vLLM) in place 1.265
#6576 as written gather + call 0.583
This branch gather + call 0.489
This branch in place 0.463

The two rows of this branch give bitwise-equal outputs. Attention only: #5996's indexer scorer is not compared.

Routing, FlyDSL versions, ISA identity, op-test performance suite
  • Routing: the routed call stays within 1.05× the faster of all-union and all-direct under a union plan on 90 of 91 calibration layouts (worst 1.062×, geomean 0.937×). That is the best an entry can reach: with a union plan, sparse_prefill_compact, sparse_prefill_order_masks and the union launch run even when every tile goes direct. Against all-direct with no union plan, 13 of 91 are above 1.05× (worst 1.226×, a 2048-row chunk over a 64K context; geomean 1.013×).
    • The layouts: 24 real 8192-row steps, the op test's cases at groups 12 / 6 / 3, and correlated and random chunks of 256-8192 rows at 8K-128K context.
  • FlyDSL 0.4.1 against 0.4.0: the op alone is within 0.99-1.01× in every cell above. FlyDSL 0.4.2 passes the op test, and its performance suite is within 0.4 % of 0.4.1's at group 12.
  • The review commits: every kernel compiles to the ISA of 3a3b4a2c4, the revision these tables were measured on (gfx942 and gfx950, FlyDSL 0.4.0 / 0.4.1 / 0.4.2; 382 compiles on gfx950 and 422 on gfx942 per version: a captured 8192-row step, the op test's layouts with the performance suite at groups 12 / 6 / 3, 13 strided layouts, and every K/V-reading kernel at the largest admitted stride).
  • The op test's performance suite (single-request prefills of 1024-32768 rows, against its SGLang Triton path): 0.35-0.66× at group 12, 0.25-0.65× at groups 6 / 3.

End to end in vLLM

Qwen3.8-Flash-Next MXFP4, TP2 on 2 × MI355X; prefill chunks of ≥ 768 rows go to this op, reading the KV cache in place. Before: the Triton split-K kernel with vLLM's config before vllm-project/vllm#62590.

  • Median TTFT −12.3 to −27.4 % and output tok/s +6.1 to +18.7 % at the 8 cells below (32K at c1-c32, 128K at c1 and c4, 1K at c32 and c128).
  • Median inter-token latency: within −1.3 to +2.1 % at every cell in either run, since decode steps do not call this op.
  • GSM8K (1,319 questions, 5-shot, strict match): 0.958 → 0.966 and 0.964 → 0.958 in the two runs, differences +0.0076 ± 0.0074 and −0.0068 ± 0.0075 (± standard error).
  • The caller API in vLLM: [ROCm][Perf][Qwen4Exp] Optimize QSA prefill scoring and FlyDSL attention vllm-project/vllm#67036's new seam matches its previous one at every cell measured (median TTFT within the noise floor); the new path's host cost per layer call, with the op replaced by a no-op, is 18.4 µs against 10.2 µs at 768 and 1024 rows (details).
End-to-end table, stack and protocol
Input, concurrency Median TTFT before (ms) After (ms) Change Output tok/s change Output tok/s vs 928dfc9812
32K, 1 773 654 −15.5 % +10.4 % +19.2 %
32K, 4 2086 1780 −14.7 % +12.9 % +25.3 %
32K, 16 6071 5151 −15.2 % +18.7 % +33.3 %
32K, 32 5017 3640 −27.4 % +14.2 % +29.7 %
128K, 1 3279 2834 −13.5 % +13.3 % +54.1 %
128K, 4 7857 6893 −12.3 % +14.8 % +64.0 %
1K, 32 567 492 −13.2 % +6.1 % +8.8 %
1K, 128 935 817 −12.6 % +12.4 % +13.7 %
  • 1K at concurrency 1-5: within each cell's run-to-run spread in both runs.
  • Base: [ROCm][Perf] Qwen3.8-Flash-Next specialized decode at 1-192 rows on MI355X (--monokernel) vllm-project/vllm#65188 at 3c5e29ffcd, with its --monokernel serve command and benchmark protocol (vllm bench serve, random prompts, --ignore-eos, 128 output tokens). The PR's changed files were laid over the image's vLLM (76c6f3f2a9). The 57 files that changed between that and the PR's base 6044ab0609, none of them Qwen's, stayed at the image's version in every arm.
  • After: the same stack plus the vLLM change that hands prefill chunks of ≥ 768 rows to this op. It is now on [ROCm][Perf] Qwen3.8-Flash-Next specialized decode at 1-192 rows on MI355X (--monokernel) vllm-project/vllm#65188 as f045002d57 (comment). These runs used its previous revision, which makes the same op call behind an opt-in.
  • Versions: vllm/vllm-openai-rocm nightly 76c6f3f2a95f, FlyDSL 0.4.0.
  • Runs: one server lifetime per arm and run, two runs in opposite orders; each cell is the median averaged over the two runs.
  • Last column: this op together with the head's MFMA indexer scorer (3c5e29ffcd), against the head's parent 928dfc9812. It is the product of two A/B ratios: the scorer commit's own run (same protocol, both orders, another MI355X node; +36 / +43 % at 128K c1 / c4) and this table's.
  • GSM8K: how many of its prefill steps reached the op (≥ 768 rows) was not counted. The op's accuracy evidence is the op test's oracle and the fp64 checks below.
The caller API in vLLM

vllm-project/vllm#67036 at 3ff909482f (this PR's API) against the same PR's previous head 4ce31f8c2b (vLLM's own copy of the contract, over the AITER head fddf1837d2):

  • TP2 Qwen3.8-Flash-Next MXFP4 on 2 × MI355X, vllm/vllm-openai-rocm nightly f5d93296c8 (vLLM 0.34.0rc1.dev206) with FlyDSL 0.5.0, the PR's serve command without --monokernel.
  • Five server lifetimes in the order old, new, op disabled, new, old. "Op disabled" is the new seam with its row threshold raised so that no step takes the op.
  • Median TTFT in ms: the mean of the two lifetimes for old and new, one lifetime for the op disabled. The noise floor is the larger same-class spread, at least 2 %.
Cell Old New New vs old (noise floor) Op disabled Op disabled vs new
1K, c3 189.1 189.8 +0.4 % (2.6 %) 183.4 −3.3 %
32K, c1 626.3 623.0 −0.5 % (2.0 %) 739.2 +18.7 %
128K, c1 2719.7 2701.2 −0.7 % (2.1 %) 3135.1 +16.1 %
  • The op is faster than Triton at 32K and 128K c1 and makes no measurable difference at 1K c3.
  • ITL is unchanged (6.9 / 6.0 / 6.2 ms); GSM8K strict is 0.9598 for the new against 0.9629 for the old (SE 0.0075); no log has a decline warning.
  • Host cost of the new path per layer call with the op replaced by a no-op: 18.4 µs against 10.2 µs at 768 and 1024 rows (the op takes 57 µs there).
  • Not measured: other concurrencies, TP4 / TP8, fp8 KV cache, more than one op-disabled lifetime.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

On gfx942 two degenerate K/V inputs it accepted before are now rejected:

  • K/V with no rows whose head or dim strides are not dense (torch calls any empty tensor contiguous);
  • HK ≥ 220, whose rows sit 228 elements or more apart (the stride bound, on both archs).

Otherwise none; gfx950 was refused before.

PR Self-Review

Reviewed revision

60fe14d4ca

Behavior and intent

  • gfx950 callers get the op instead of a refusal.
  • gfx950 callers with interleaved or padded K/V rows pass views instead of gathering.
  • Callers can ask qsa_sparse_prefill_problem instead of restating the operand rules, read a paged cache in place through qsa_paged_kv_pool and qsa_paged_kv_slots, and warm the kernels through their own call with qsa_sparse_prefill_warmup.
  • gfx942 callers of qsa_sparse_prefill run main's kernels, K3 with the chunk-local key; some rejections name another rule than main's (Caller API details).
  • gfx950 callers can pass batch_invariant; FP8 K/V are rejected there.

Validation and unverified scope

Validated on MI355X (details below):

  • Op test python3 op_tests/test_flydsl_qsa_sparse_prefill.py -g 12 6 3 16 without its performance suite, in its own process with empty FlyDSL caches, on FlyDSL 0.5.3 (main's pin): passed, 299 invocations, 4 min 26 s. Every error count is 0 and every invalid input is rejected; each planted fault failed an earlier revision of it (details).
  • CPU tests tests/test_qsa_sparse_prefill_support.py, tests/test_qsa_paged_kv.py, tests/test_qsa_sparse_prefill_warmup.py: 230 passed; 246 after the merge with [FlyDSL] [QSA] qsa_sparse_prefill: public selection-width and byte-limit query #8083 (its 16 support-query tests, run on gfx942 and gfx950); 249 on b83688cc07; 368 on this head.
  • K3 sort key: on 42 calls (7 layouts × groups 12/6/3, with the platform's route and with every tile forced onto union; up to 4 order CTAs and 13,120 tasks), the published task order, the union route and the output are bit-identical to the commit before, and each order holds every task once. On CPU, 16,385 tiles at 128 KV heads compile the K3 variant one tile does (test_the_task_count_compiles_no_new_order_kernel, which fails before).
  • Rule parity against main (gfx942; the support test's 122 cases alone and every ordered pair merged, 14,884 inputs):
    • the same 656 inputs accepted;
    • 9,671 with main's outcome and message;
    • 5,007 rejections with another message (main's dtype message split, the architecture list, this PR's rules ahead of main's);
    • 206 integer scales past float range rejected where main raises OverflowError.
  • Merge of main on gfx950:
    • output bits of 99 calls (11 layouts × groups 12 / 6 / 3 × the platform's route, every tile on union, raw direct) equal the pre-merge head's;
    • K1-K3 (task order, active tiles, direct flags, score masks, residual rows) equal main's prepare module on 234 calls: BF16 in both batch modes, FP8 per tensor and per token with split and core plans, past 4096 order entries;
    • the warm-up test in both batch modes (details).
  • Strided views: each of the 19 strided cases is bitwise equal to the call on gathered contiguous K/V.
  • No writes outside the op's tensors under a guard allocator, through vLLM's call site: 0 guard violations.

Unverified:

  • The op test's performance suite on this head: its cases were timed against the pre-merge head instead (Performance).
  • gfx942 on a GPU. Contiguous K/V compiles to main's ISA; strided rows are rejected there until a gfx942 run covers them. Main's FP8 suites run on gfx942 only, so they have not run on this head. The new tests have not run on gfx942 hardware: the CPU tests inject the architecture, the paged record cases are written to report the gfx950-only stride rule there, and the warm-up op test returns on any architecture but gfx950.
  • [ROCm][Perf][Qwen4Exp] Optimize QSA prefill scoring and FlyDSL attention vllm-project/vllm#67036's CI. Its pinned AITER (v0.1.29) lacks this API: the vLLM side runs against it through fakes there until the pin moves.
  • Packed union at the largest stride: compile-only (1536 rows 512 MiB apart do not fit in memory); slotted union (1536 rows over the same four pool rows), raw and packed direct run at it.
  • FP8 K/V on gfx950: rejected; gfx950's E4M3FN needs its own kernels.
  • Layouts outside the 91 calibration layouts. The gfx950 route terms were chosen on the layouts they were measured on, and they are decision terms, not phase timings.
Op test runs, route assertions and planted faults
  • Stack of the FlyDSL 0.5.3 runs: lmsysorg/sglang:v0.5.23-rocm724-mi35x (ROCm 7.2.4) with AITER main 73960daf4e built in it, FlyDSL 0.5.3, and this head's QSA files over it; the other modules on the QSA path are the same in 73960daf4e and this head.
  • Earlier revisions ran on vllm/vllm-openai-rocm nightly dd4e40142a32 with this branch's QSA files over its aiter.
  • 3f1bff21e (the same kernels; the test without the review's two additions) on FlyDSL 0.4.2 and 0.5.0 on the same GPU: 468 checks each; the op's times on 0.5.0 are 0.97-1.01× those on 0.4.2.
  • The revision before it passed on FlyDSL 0.4.1 and 0.4.2 (7 min 25 s and 7 min 41 s); its kernels compile to the same ISA.
  • Every suite but performance (twelve) ran at groups 12 / 6 / 3 / 16, the FP8 suites as their one gfx950 rejection case.
  • On gfx950 the test asserts the route:
    • union tiles for every case at or above the 1536-row gate;
    • a union plan with gated raw direct for the request at the 4 GiB − 1 MiB limit, and on that request each route forced (every tile on union; every tile on gated raw direct);
    • packed then raw (64-bit past 4 GiB) direct at the largest stride, and union tiles on a 1536-row request there.
  • Planted faults that each failed an earlier revision of it: union gated off; the stride bound at 227 and at 229; the strided-row gate inverted; the raw-direct override dropped; the union kernel without its per-request stride offset; a signed DMA row offset; the slotted union descriptor's extent halved; V's stride not compared with K's; the forced route ignored; the union kernel's softmax max scaled by 1.0000001.
Caller API validation
  • CPU tests: CPU tensors with the architecture injected; one table row per rule, in order, with hand-derived constants for the pool and slot helpers. Before the merge with [FlyDSL] [QSA] qsa_sparse_prefill: public selection-width and byte-limit query #8083: tests/test_qsa_sparse_prefill_support.py (96), tests/test_qsa_paged_kv.py (32), tests/test_qsa_sparse_prefill_warmup.py (102).
  • Rule parity: against the wrapper at fddf1837d2 (one line changed there, so that its ROCm device test can be injected): every single-rule case alone and every ordered pair of cases merged, on gfx942, gfx950 and gfx90a with the ROCm device rule injected and real, 53,016 inputs (the old wrapper rejects 51,265 and accepts 1,751). The old op, the new op and the new problem() give the same outcome, type and message on all of them.
  • Op test identity: per-case compile keys (launcher addresses normalized), plans, call counts, raised messages and 750 output hashes (231 invocations, -g 12 6 3) equal those of fddf1837d2. Recorded on an earlier revision of these commits; the bodies of _check_call and flydsl_qsa_sparse_prefill are AST-identical since, docstrings aside. K3's compile key has lost its wide constant since (K3 sort key), so its keys no longer match fddf1837d2's.
  • Paged cases (-c paged_ragged_4_pitched_pages paged_hk2_ragged_pages_apart paged_extend_64_ctx_70065_dense_pages -g 12 6 3, 9 invocations): the pools hold the packed K/V at the slots, the op over them equals the packed call bit for bit, and the slot table is built under torch.cuda.set_sync_debug_mode("error") (a prototype mode: it flags the synchronizing operations it knows).
  • Warm-up compile test (op_tests/test_flydsl_qsa_sparse_prefill_warmup.py -g 12 6 3, each mode in its own process with an empty FlyDSL cache, 116 s):
    • after the warm-up, 0 compiles in 8 served-layout calls at every group, in the default and the batch-invariant mode, counted by the kernels' _COMPILED dicts and by the .pkl files FlyDSL writes;
    • the warm-up compiled 9, 10 and 13 kernels at groups 12, 6 and 3 in either mode, and 10 with the wide cache at group 6;
    • the control without the warm-up compiled 3 kernels in its first call;
    • on CPU, the plan and launch builders record every compile key: the warm-up layouts' keys cover those of 1-20000-row layouts of 1-3 requests, with and without prefixes, and a 131,072-token context, per architecture (gfx942 at 80 CUs, gfx950 at 256 and 32), K/V dtype, batch mode, K/V pool, group and KV heads;
    • an earlier revision of the test also dropped each layout class in turn (the first call of that class then compiled 2, 1 and 1 kernels, so each layout is needed); those modes are not kept in the test.
  • Mutants: 148 rule and text mutants of the new code, 144 killed, each by a named failing test (the 4 parity-grid kills by a mismatch). 4 survive, 3 distinct, all equivalent:
    • dropping not math.isfinite(scaled) (the range check beside it rejects inf and NaN);
    • dropping n >= 2**31 from the lengths rule (a length that large fails the sum checks unless the tensors hold that many rows);
    • swapping two adjacent pool rules that both return None.
Kernel ports, strided views and writes outside the op's tensors
  • Union port and its two levers: error against fp64 equal to [FlyDSL] Add QSA sparse prefill attention for MI308 #6576's (rel_l2 1.96e-3); each lever bitwise equal to its parent; repeat calls bitwise equal, graph replay equal to eager, planted-key and union-leak tests pass.
  • Packed direct port: the op test passes. It is not bitwise equal to the gfx942-style kernel, because K32 changes the summation order.
  • Strided views: the 19 cases include a pool past 4 GiB, two KV heads, four requests on union tiles and kv_slots.
  • Compile-only (gfx942 and gfx950, FlyDSL 0.4.0 and 0.4.1, and 0.4.2 for the review commits): ISA, VGPR and LDS counts per commit, in each commit message. No VGPR spills or scratch on gfx950.
  • No writes outside the op's tensors: vLLM's call site ran the branch, reading the cache in place, under a guard allocator (guard bytes before and after every device allocation): 16 layouts of 11,265-16,408 rows with 0-24 decode rows, then 220 calls over 160 layouts. The inputs and the output rows before the op's first row are unchanged; repeat calls are bitwise equal. The guards cannot see reads.

PR-specific question

What each changed op test fails on before this PR, and why existing tests do not cover it. op_tests/test_flydsl_qsa_sparse_prefill.py is the only test of flydsl_qsa_sparse_prefill: the other QSA op tests on main cover the decode kernel (test_flydsl_qsa_sparse_decode.py), the MQA logits and the Triton QSA scorers and writers.

  • On main the op refuses gfx950 (raise ValueError("QSA sparse attention requires gfx942"), aiter/ops/flydsl/qsa_sparse_prefill.py:524-525) and the test has SUPPORTED_GFX = ["gfx942"], so main() logs "unsupported on gfx950; skipping" (test lines 125 and 2584-2588). On gfx950 main's test therefore checks nothing, and any case run there reaches that ValueError.
  • Each added gfx950 suite pins something this PR adds (Changed op tests), and the planted faults under "Validation and unverified scope" each failed an earlier revision of it.
  • Not shown: the new suites were not run on gfx942, where strided rows are rejected.

Changed op tests

  • op_tests/test_flydsl_qsa_sparse_prefill.py: gfx950 is admitted, so the file runs in AITER's MI35X PR CI: 3 min 56 s on MI355X with FlyDSL 0.5.3, default arguments and empty FlyDSL caches. Main's FP8 suites run on gfx942; on gfx950 one case checks their rejection. Its largest cases need about 28 GiB of free device memory (smaller GPUs skip them with a warning). New suites: functional layouts over the union gate, strided, route, rejection, max-stride and paged (below).
  • op_tests/test_flydsl_qsa_sparse_prefill_warmup.py (new): the warm-up compile test above, in both batch modes. It reads the GPU's architecture in its parent process and returns with a message on any but gfx950, because CI runs every op_tests/test_*.py as python3 FILE on each runner type; 116 s on MI355X.
Suites added to op_tests/test_flydsl_qsa_sparse_prefill.py
  • Functional layouts over gfx950's union gate (4 requests; one request at the 4 GiB − 1 MiB limit); one more graph case and two more kv_slots cases at 2048 rows; a constant-logit case at 2048 rows, on union tiles on gfx950 (logits near 1e11, where the softmax max decides the result); the strided suite's three layouts also run contiguous here, so --case runs them.
  • Strided (19 cases, each bitwise equal to the call on gathered contiguous K/V; rejected off gfx950), with TB/s.
  • Route (2 cases: the request at the 4 GiB − 1 MiB limit with each route forced; union tiles at or above the 1536-row gate, gated raw direct at the limit).
  • Rejection (10 cases that must raise: stride over the limit, unaligned, below heads × 256, K and V strides differing, a strided V beside a dense K, heads not dense, heads overlapping, a strided last dim, a non-contiguous Q, span over the limit).
  • Max stride (4 cases at stride 2**28 − 8, each by packed and by raw direct; one a 1536-row request on union tiles).
  • Paged (3 cases, -c paged_*): K and V in a paged cache on random pages (NaN elsewhere), as the halves of one K|V record per token with pages further apart than they are long (1568-token pages 19,992 rows apart; two KV heads, 64-token pages 96 rows apart) or as two dense buffers; on gfx942 the record cases must report the strided-rows rule.
  • The summary rows and the skip gate read the GPU's arch (get_gfx_runtime()), not the last entry of GPU_ARCHS.

This change was developed with AI assistance (Claude); I reviewed every line and ran the tests listed.

🤖 Generated with Claude Code

eppaneamd and others added 8 commits November 5, 2026 14:04
The union kernel of the QSA sparse prefill (aiter#6576) was written for
gfx942. On gfx950 it now uses:
- v_mfma_f32_16x16x32_bf16 for QK and PV (512 per union ISA, no 16x16x16);
- ds_read_b64_tr_b16 for the V operand instead of v_perm transposes;
- K and V LDS swizzles for the 64-bank LDS;
- native bf16 packing; the lgkmcnt waits capped at 15.

A ("gfx950", 256) Platform entry routes all rows to the union kernel and
the wrapper admits gfx950. The gfx942 path compiles to identical ISA for
every kernel; the direct kernels and K1-K3 are unchanged.

Compile-only (FlyDSL 0.4.1 and 0.4.0): 248 VGPR, 64 KiB LDS, no spills.

MI355X, one 8192-row prefill step of Qwen3.8-Flash-Next at TP2 (12 query
heads, 1 KV head, D 256, 2051 index columns, the indexer's real
selections, K/V gathered from a paged pool over 4 GiB), FlyDSL 0.4.1,
whole call (gather, K1-K3, union, direct), median of 8 alternating rounds:

  node / GPU         as written   this port   ratio
  MI355X node A, 0    0.583 ms     0.546 ms    0.94
  MI355X node A, 6    0.670 ms     0.562 ms    0.84
  MI355X node B, 2    0.544 ms     0.488 ms    0.90

Against fp64, the output error equals the as-written kernel's
(rel_l2 1.96e-3). Repeat calls are bitwise equal, graph replay equals
eager, and planted-key and union-leak tests pass.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
gfx950's 160 KiB LDS holds two K/V tiles. On gfx950, k_lds and v_lds
now hold two 32 KiB tiles each (tile t in stage t & 1, 128 KiB in all).
The DMA of a tile no longer overwrites a tile other waves may still be
reading, so six rendezvous keep only their compiler fences: prologue 4
and 7, phase 0, 3 and 4, epilogue 0. A race/version model of both wave
groups' streams checked each removal and every barrier kept.

Arithmetic is unchanged. The output is bitwise equal to the previous
commit in 50 eager calls and 50 graph replays. Union ISA: s_barrier
80 -> 58, LDS 64 -> 128 KiB, 248 VGPR, no spills. gfx942 keeps one stage
and every rendezvous (identical ISA).

Whole call against the previous commit (same step and method as the
port's message): 0.974, 0.974 (node A, GPU 6, two runs), 0.970 (node B).

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
On gfx950, K and V reach LDS through buffer_load_dwordx4 ... lds (1 KiB
per wave instruction) instead of buffer_load_dword ... lds (256 B). The
LDS rows become half-major (dims half h of key t at h * HALF + t * 256),
so one x4 DMA writes four keys' half rows: 4 DMA per wave per tile
instead of 16. The K and V swizzles keep every read on the bank it used
before, and the per-lane range clamp gives the same address and
in/out-of-range result as before.

Every output element keeps its operands and accumulation order; only the
MFMA instruction that computes a dim moves (n <-> n ^ 1 on odd lane
groups). The output is bitwise equal to the previous commit in 50 eager
calls and 50 graph replays. Union ISA: dword DMA 288 -> 0, x4 DMA 72,
240 VGPR, no spills. gfx942 ISA is identical.

Whole call against the previous commit: 0.989, 0.988 (node A, GPU 6,
two runs), 0.948 (node B).

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The wrapper admits gfx950 since the union kernel's gfx950 port, so the
op test runs there as well.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The packed direct kernel of the QSA sparse prefill (aiter#6576) was
written for gfx942. On gfx950 it now uses:
- v_mfma_f32_16x16x32_bf16 for QK and PV (32, no 16x16x16): a K32
  MFMA takes the operand words of two K16 MFMAs side by side, so S and
  O keep their layouts;
- v_cvt_pk_bf16_f32 for P and O, in place of the 36 packing v_perm;
- one V round trip per 32-key tile. The gfx942 loop waits for segment
  0's V (vmcnt(0)) before it requests segment 1's. The gfx950 loop
  requests V by dims half around QK and the next tile's K before PV,
  and waits vmcnt(8) for K, vmcnt(24) for half 0, vmcnt(16) for
  half 1. So that this fits the VGPRs of two waves a SIMD, Q waits in
  the epilogue's LDS between tiles, and the block-ID prefetch moves
  one tile ahead.

The gfx942 loop keeps its code; on gfx950 it runs no tile and MLIR
removes it. Its softmax moves into a helper that both loops share
(same operations, same order). The raw direct kernel is unchanged.

Compile-only, FlyDSL 0.4.1 and 0.4.0, the first calls of 12 op-test
layouts and one 8192-row step (10 packed direct kernels per arch):
- gfx942: every kernel's ISA is identical;
- gfx950: every kernel but the packed direct one is identical, the
  raw direct kernel included;
- gfx950 packed direct kernel: 242 VGPRs (was 246), two waves a SIMD
  as before, 8 KiB LDS as before, no spills or scratch.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…V caches in place)

The QSA sparse prefill (aiter#6576) took K and V only as contiguous
[tokens, heads, 256] tensors. A KV cache that stores one K|V record per
token, such as vLLM's interleaved QSA cache (1 KiB a token at one KV
head; K and V are views of one pool, 512 elements a token apart), had
to be gathered into contiguous copies before each call.

K and V may now be strided views of the same shape:
- each row holds dense [heads, 256] values (stride(2) == 1,
  stride(1) == 256);
- rows sit one stride apart: at least heads x 256 elements, a multiple
  of 8 elements (16 bytes), the same for K and V;
- K and V may be views of one pool; V is addressed from its own data
  pointer.
This holds with and without kv_slots. Q, out, indices and kv_slots
keep their rules.

Every kernel that reads K/V rows takes the row stride as a
compile-time constant: the union kernel (DMA row offsets and buffer
descriptors), the raw direct kernel (key and value offsets, and the
64-bit path for pools past 4 GiB) and the pack kernels. Rows with a
gap add its term to addresses and buffer extents; dense rows do not
compile it. The prepare kernels and the packed direct kernel read no
K/V and are unchanged.

The host bounds the strided byte spans: each request's K/V span, the
pool's span with kv_slots (which selects the 64-bit path), the pack
kernel's 32-bit reach, and out's overlap with K/V. Workspaces and
compiled launchers are keyed by the stride.

The op test adds 11 strided cases (interleaved and padded rows, with
and without kv_slots: a ragged batch, two KV heads, a pool past 4 GiB),
each bitwise equal to the call on gathered contiguous K/V, and 4
rejection cases (stride not 16-byte aligned, stride below heads x 256,
K and V strides differing, span over the limit).

Compile-only, FlyDSL 0.4.1 and 0.4.0, gfx950 and gfx942, the first
calls of 7 layouts:
- contiguous K/V: every kernel's final ISA is byte-identical to the
  gfx950 direct port's (132 compiles);
- strided K/V: only the union, raw direct and pack kernels change. No
  VGPR spills or scratch, and no kernel needs more VGPRs than with
  dense rows except the gfx942 union below. gfx950 union: +4
  instructions for interleaved rows at one KV head;
- gfx942 union at one KV head: +312 to +372 instructions (0.4.1) and
  235 VGPRs (was 228-229), with an SGPR spill as the two-KV-head and
  slotted unions already have with dense rows. Rows more than 512
  bytes apart put its DMA row step in VOFFSET, as two KV heads' dense
  rows already do.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…roughput-bound union phase

K3's route (sparse_prefill_prepare.py _route) compares its union step
limits only when the union phase is set by its longest task. When the
phase is set by throughput it keeps every tile K2 proposed, without a
cost comparison. On MI355X that keeps the union where the gated
all-direct call is 1.6-2.4x faster: long or random contexts give
4096- and 8192-row chunks wide unions, while each row's direct work
stays bounded by its own top-k.

A new Platform switch, route_all_or_none (default off), reaches K3 as
the fifth value of the plan's route_model, a compile-time constant.
With it on, a throughput-bound phase also weighs keeping every
proposed tile against none, with route_margin favouring keeping all,
as in the general comparison. AITER_QSA_PLATFORM reads a bool field
as 0 or 1 (bool("0") is True).

No entry turns the switch on in this commit.

Compile-only, FlyDSL 0.4.1 and 0.4.0, gfx942 and gfx950, the first
calls of 12 op-test layouts and one 8192-row step:
- switch off: every kernel's ISA is identical to the parent's;
- switch on (AITER_QSA_PLATFORM=route_all_or_none=1): only
  sparse_prefill_order_masks changes. FlyDSL 0.4.1: +6 instructions,
  99 VGPRs (was 98); 0.4.0: +1 instruction, 107 VGPRs (was 99). LDS,
  barriers and the 23 SGPR spills are unchanged.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d entry

The gfx950 entry held MI308X's terms with every tile forced to the union
kernel (union_ratio 1e30, route_margin 0.999999). It now routes: K3's
all-or-none comparison is on, calls below 1536 rows go direct, and the
route terms are chosen on MI355X so that K3's choices on 91 calibration
layouts stay near the faster of all-union and host-gated all-direct.

The terms are decision-tuned, not phase timings. With least-squares
phase timings (union 9.556 us + 2.228 us a step, direct 14.31 us fixed,
fitted before the packed direct port), none of 896 settings of the
other fields keeps these layouts within the limits, even with the
all-or-none switch; the worst layout reads 1.45x.

Calibration layouts (91): 24 8192-row prefill steps with real indexer
selections, the op test's cases at groups 12, 6 and 3, correlated chunks
of 256-8192 rows at 8K-128K context, and random-selection chunks.

Measured on MI355X, one GPU, routed call against the faster of
all-union and host-gated all-direct in the same process:
- 90 of 91 layouts within 1.05x, worst 1.062x, geomean 0.937x;
- the 8192-row steps stay all-union: 1.008x the forced-union entry
  (1.010x on a narrow K/V view);
- a 1024-row chunk with random selections at 31K context goes direct:
  0.21x the forced-union entry (117 us against about 505 us);
- the op test passes at groups 12, 6 and 3 with this entry.

Not covered: layouts outside the calibration set. The terms were chosen
on the same layouts they were measured on, and small changes to their
ratios lose the limits on some of them.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 6, 2026

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 7556 --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.

@johannes-graner johannes-graner 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.

Thanks for the port. The main points are the large-stride compile failure and the abstraction level of the gfx950 path, both below.

Validation on gfx950, FlyDSL 0.4.1, head 3a3b4a2: the full op test passes (144 cases, 306 checkAllclose, 0 failed). A forced-union run of the four cases that fit the union path passes (it forces routing but does not report which kernel ran). A probe of a large-stride K/V view fails at compile (first comment). FlyDSL 0.4.2, which this head pins, and gfx942 were not tested.

Main points:

  • Large K/V row strides are accepted by the wrapper but fail to compile in the raw direct kernel (stride of 357,913,952 elements or more), and the packed/slotted descriptor wraps at 4 * row_bytes == 2**32. Please bound or reject strides until both paths handle them, and add a test.
  • The gfx950 path drops to hand-written word lists, duplicated LDS swizzles, per-site stride arithmetic and unexported rocdl calls where gfx942 uses tiled MMA and layouts. No addressing bug found; see the _qk950 comment and those on the related sites.

Also: the new strided cases do not reach the gfx950 union gate, and the strided timing table has no TB/s column.

Minor / consider:

  • requirements.txt moves FlyDSL to 0.4.2 while the validation here and in the PR used 0.4.1. Unlikely to break anything, just noting it.
  • New gfx950 and stride specializations are not enrolled in PREBUILD_KERNELS, so a prebuilt wheel does not cover the first calls. Please enroll representative variants or document that QSA is JIT-only.
  • Was XCD-local task ordering compared with the current length-balanced order on MI355X? A performance question only.
  • The public qsa_sparse_prefill docstring still says gfx942-only, and Platform still describes route terms as microseconds although the new entry says they are decision weights.
  • The routing coefficients were fit on 91 calibration layouts, and that harness is not in the tree. Not required for this PR, but if you already have a QSA benchmark script ready, op_tests/op_benchmarks/flydsl/ would be a good home: CI does not run anything under op_benchmarks/, and it would keep the calibration reproducible.

eppaneamd added a commit to samremes/vllm that referenced this pull request Nov 6, 2026
…gfx950)

On gfx950, when vLLM uses AITER (VLLM_ROCM_USE_AITER=1) and the installed
AITER's FlyDSL QSA sparse prefill supports gfx950 (ROCm/aiter#7556),
prefill chunks of 768 or more rows run on that op instead of the Triton
split-K kernel. No new environment variables.

- The ROCm metadata builder describes a step's trailing prefilling
  requests with their exact host lengths (QSAPrefillLayout, from
  seq_lens_cpu_upper_bound and query_start_loc_cpu; no device read), for
  bf16 caches and steps of 768 or more tokens.
- qsa_sparse_paged_attention hands those requests' rows to the op and
  runs the rows before them on the Triton kernel, which then sizes its
  split-K launch for those rows alone. The op reads the interleaved K|V
  cache in place: K and V as token-row views one 512-element record
  apart, plus a slot per key. A cache it cannot read that way (two KV
  heads per rank, at TP1) stays on Triton.
- The kernel warmup calls the op on the QSA layer's own cache views,
  whose row pitch and pool span select the kernels: one 768-row request
  (direct kernels), one 4096-row request and two 2048-row requests (union
  tiles; AITER widens the tile for a single request at 6 or 3 query heads
  per KV head). Every key is read from the null block, the one block an
  extensible KV cache has mapped at warmup.
- 768 rows is where the op beats the Triton kernel at every measured
  prefix length at TP2 (12 query heads per KV head).

Per call on MI355X (TP2: 12 query heads, 1 KV head, D 256; Triton with
main's config -> FlyDSL, in place): 8192 rows 2.45 -> 0.55 ms without a
prefix and 2.65 -> 0.88 ms over a 132K-token prefix; 768 rows 0.32 ->
0.06 ms.

Served, Qwen3.8-Flash-Next MXFP4 at TP2 on 2 x MI355X with this PR's
serve command and benchmark protocol (two runs in opposite orders), with
the previous revision of this change (the same op call, behind an
opt-in): median TTFT -12 to -27 % at 32K c1-c32, 128K c1/c4 and 1K
c32/c128, output tok/s +6 to +19 %, median ITL -1.3 to +2.1 %; GSM8K
0.958 -> 0.966 and 0.964 -> 0.958 (differences +0.0076 and -0.0068,
standard errors 0.0074 and 0.0075).

Tests (tests/models/qwen4_exp/test_qsa_amd.py): the attention reference
test runs the op on gfx950 for two 512-row requests and for a 2048-row
request after rows left to Triton, with causal selections and padded
pages, at 2e-3; unit tests cover the host layout, the builder, the
capability and the gate, the in-place views and slots, the hook, the
owner and the warmup.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
eppaneamd and others added 11 commits November 6, 2026 09:43
Raw direct builds 3x a row's bytes as a 32-bit constant, so a K/V row
stride of 357,913,944 elements or more (the first multiple of 8 past
2**31 / 6) failed to compile (sparse_prefill_direct.py:334). The packed
and slotted paths form 4x a row's bytes as 32-bit extents and offsets
(packed direct's descriptor would wrap at 2**29). The wrapper now
rejects strides of 2**28 elements or more before any launch, which
keeps every such value below 2**31.

Op test:
- stride_over_limit: a 2**28-element row stride is rejected.
- max stride: a 4-token request read through rows 2**28 - 8 elements
  apart (packed, kv_slots, and a kv_slots pool past 4 GiB) matches the
  contiguous call bit for bit; the call also compiles the raw direct
  kernel at that stride.
- 2048-row strided, kv_slots and graph cases clear gfx950's 1536-row
  union gate. The summaries report the union tiles of each call (the
  route sparse_prefill_order_masks writes); on gfx950 those layouts
  must run some.
- The strided suite reports TB/s.

Docs: the public docstring lists gfx950; Platform's route terms are
microseconds only for timing-calibrated entries; QSA kernels compile on
first use and none is prebuilt.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…a NamedTuple read plan

Review cleanups with no change to compiled code:
- comments this PR added name sparse_prefill_order_masks instead of K3;
- the gfx950 check is get_gfx_runtime() == "gfx950" at its two call
  sites (union and packed direct launch arguments);
- LDS read plans are a NamedTuple (storage, reads, load).

Every kernel's ISA is byte-identical to the previous commit's on
gfx942 and gfx950 with FlyDSL 0.4.0, 0.4.1 and 0.4.2 (compile-only:
the F7 step, the op test's layouts, dense/interleaved/padded strided
rows and the largest admitted stride; 291 gfx950 / 323 gfx942 kernels).

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nd the readers

The union kernel's LDS DMA (_dma_chunk950, _dma_block950) and the K/V
readers (_k_lds_address950, _v_tr_bases950) now derive their addresses
from _k_swizzle950, _v_swizzle950 and _lds_row950. V's swizzle is
Swizzle<2,3,4> o Swizzle<1,5,5> over (64,(128,2)):(128,(1,8192)); K's
parity XOR has no single SwizzleType, so both stay plain functions (a
SwizzleType layout for V changed the gfx950 union kernel by up to 2
VALU instructions).

Every kernel's ISA is byte-identical to the previous commit's on
gfx942 and gfx950 with FlyDSL 0.4.0, 0.4.1 and 0.4.2.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…; list the raw rocdl ops

- The V transpose read uses rocdl.cdna4.LDSReadTrans16_64b() through
  fx.copy instead of rocdl.ds_read_tr16_b64.
- The packed direct kernel's lane broadcast uses fx.gpu.shuffle_idx
  instead of rocdl.ds_bpermute.
- One comment at the rocdl import lists the raw ops FlyDSL 0.4's
  rocdl.__all__ has no stable form of (s_setprio, sched barriers with
  VALU/TRANS masks, ballot/readlane/readfirstlane, perm_b32,
  cvt_pk_bf16_f32, exp2 as a bare v_exp_f32).

Every kernel's ISA is byte-identical to the previous commit's on
gfx942 and gfx950 with FlyDSL 0.4.0, 0.4.1 and 0.4.2.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
_qk950 is the gfx942 _qk path (make_tiled_mma over MFMA(16,16,32,BF16),
K step outer) with the K operands viewed by _k_operands950; Q is read
by _read_q_g2r. The hand-written QK word lists (QK950, _qk950_words)
go. The PV side keeps its word lists: every tiled form tried changed
register allocation, and _o_piece950's word order depends on lane
parity, which is not a static fragment layout.

Every kernel's ISA is byte-identical to the previous commit's on
gfx942 and gfx950 with FlyDSL 0.4.0, 0.4.1 and 0.4.2, MFMA issue order
included.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y atom

The gfx950 x4 K/V LDS DMA (_read_block_g2s950) uses fx.copy with
rocdl.BufferCopyLDS128b() instead of rocdl.raw_ptr_buffer_load_lds.
The atom takes a buffer pointer, so the request's K/V buffers stay
pointers (_request_buffer) and only the gfx942 path converts them to
resources for its raw 32-bit DMA, which is unchanged. The synchronous
atom keeps the compiler's vmcnt tracking, as the raw call did; the
asynchronous cdna4.BufferLoadAsyncLDS128b also compiles to the same
code, but its loads would need asyncmark/wait_asyncmark waits.

A comment names sparse_prefill_compact instead of K2.

Every kernel's ISA is byte-identical to the previous commit's on
gfx942 and gfx950 with FlyDSL 0.4.0, 0.4.1 and 0.4.2.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ernels ran

- The wrapper rejects strided K/V rows (a stride other than HK x 256) off
  gfx950: no gfx942 GPU run covers them yet. On gfx942 the row check then
  admits the contiguous K/V it admitted before this PR, except K/V with
  no rows (which torch calls contiguous whatever their strides) whose
  head or dim strides are not dense; HK >= 2**20, whose dense rows sit
  2**28 elements or more apart, is rejected on both archs by the stride
  bound. The docstrings say so, and that each row stride compiles its
  own kernels; a broken docstring reflow is fixed.
- The strided and max-stride suites check that rejection off gfx950,
  without computing their reference there.
- New layouts over gfx950's 1536-row union gate: ragged_4_rows_2986
  (four requests, also interleaved and through kv_slots) must run union
  tiles; chunk_1536_ctx_8386560 (one request at the 4 GiB - 1 MiB K/V
  limit) must build a union plan whose direct side reads the raw K/V.
  Before, every gfx950 union call had one request and packed its direct
  side.
- A route suite runs chunk_1536_ctx_8386560 with each route forced
  through AITER_QSA_PLATFORM (a test helper that sets it and drops the
  cached entry and plans): every proposed tile on union (gfx950
  proposes every tile), which must run union tiles on gfx950, and none
  proposed (every tile on gated raw direct), which must run none.
- The functional suite now reports each call's union tiles, and every
  suite that reports them also reports the direct path (packed, raw,
  raw wide); the gfx950 checks read the runtime arch (get_gfx_runtime).
- The max-stride cases run packed direct and, through
  AITER_QSA_PLATFORM, raw direct (64-bit loads for the 5.5 GiB pool),
  and check which one ran; the 4-token request always packed before. A
  1536-row case reads its blocks through kv_slots at the maximum stride
  with every tile forced onto union, and must run union tiles. The
  summary reports err and union tiles per direct path.
- Rejection cases for non-dense K/V heads, overlapping heads, a strided
  last dim, a strided V beside a dense K, and a non-contiguous Q. The
  K/V cases expect the row check's own message, so that off gfx950 the
  strided-row rejection cannot stand in for it.
- Comments of the existing layouts say which arch their route holds on.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e atom; strict platform switch

- The LDS transpose read uses rocdl.cdna4.LDSReadTrans(16, 64), the
  form in cdna4.__all__ (the same atom as LDSReadTrans16_64b).
- The list of raw rocdl ops with no stable FlyDSL form now names every
  one the sparse_prefill kernels use, including the union's
  membership-bit raw_ptr_buffer_load.
- The gfx950 routing entry's comment names its oracle (all-direct under
  a union plan); wide_tiles_per_cu is written 8 / 21 (the same value:
  BQ21 from 2048 rows, BQ42 from 4096 at 256 CUs).
- Comments and docstrings that misstated the code: the raw direct
  module (gfx942 and gfx950), the K/V DMA row offsets (VOFFSET on
  gfx950), the gfx950 union docstring and the gfx950 helpers' section
  comment (lgkmcnt waits capped at 15, some rendezvous dropped), the V
  swizzle, the limit-0 DMA read, and the gfx942 raw LDS DMA comment
  (BufferCopyLDS32b through fx.copy compiles to the same gfx942 code).
- AITER_QSA_PLATFORM accepts only 0 or 1 for a switch, with its own
  error message.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…k kernels

The byte extent of a request's K/V rows and a row's offset, rows stride
elements apart (HK x 256 values, then a gap of padding), were written out
at each site: the union kernel's request buffer, the raw direct kernel's
resources, the pack kernel's block and source extent, and the packed
direct kernel's K/V extent. They now come from two helpers in
sparse_prefill_common, _kv_extent and _kv_offset, with one gap convention;
each caller keeps its integer type.

Every kernel's ISA is byte-identical to the previous commit's on gfx942
and gfx950 with FlyDSL 0.4.0, 0.4.1 and 0.4.2 (382 compiles on gfx950 and
422 on gfx942 per version).

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
_mfma takes the depth (16 by default, 32 on gfx950) and replaces
_mfma32; the gfx950 QK and PV helpers pass 32.

Every kernel's ISA is byte-identical to the previous commit's on gfx942
and gfx950 with FlyDSL 0.4.0, 0.4.1 and 0.4.2.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…loop with fx.const_expr

The gfx950 build no longer zeroes the gfx942 loop's trip count and relies
on MLIR to delete it; each arch traces only its own loop.

Every kernel's ISA is byte-identical to the previous commit's on gfx942
and gfx950 with FlyDSL 0.4.0, 0.4.1 and 0.4.2.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@eppaneamd

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review and the reproductions. Changes: 39bcc83 (stride bound, tests, docs), five cleanups (a45a236 to 56cc2dc), and five commits from a further pass over the whole PR (dca0800 to 3f1bff2; 0009-0011 are ISA-identical refactors: one stride arithmetic, one MFMA helper, the packed kernel's loop chosen per arch). Each cleanup compiles to byte-identical ISA on gfx942 and gfx950 with FlyDSL 0.4.0, 0.4.1 and 0.4.2, for every kernel build of the compile set, so the PR's performance tables still hold. The compile set: a captured 8192-row serving step; the op test's layouts, including the performance suite at groups 12, 6 and 3 (BQ 10 to 42) and HK16; 13 strided layouts with dense, interleaved and padded rows; and every K/V-reading kernel at the largest admitted stride. That is 382 compiles on gfx950 and 422 on gfx942 per FlyDSL version.

  • Strided K/V is now gfx950 only (dca0800): no gfx942 GPU run covers it yet, so off gfx950 the wrapper rejects strided rows, as it did before this PR. The PR title already scopes it to gfx950.
  • The further pass also found test gaps on gfx950, now closed in dca0800: no union call had more than one request, none had gated raw direct, and the max-stride cases only ever packed. The new cases assert which kernels ran, and a route suite forces each route on the gated-raw-direct layout. More rejection cases cover non-dense or overlapping heads, a strided V beside a dense K, a strided last dim and a non-contiguous Q. 4463c64 corrects comments that misstated the code and uses the exported LDSReadTrans(16, 64).
  • Validation on MI355X: the op test at groups 12 / 6 / 3 passes every suite on the final head with FlyDSL 0.4.2 (468 checks, 7 min 11 s; run before a fix to the test's module docstring, the only difference). The previous revision of the series, with the same kernels' ISA and all but the route suite and the newest cases, passed on FlyDSL 0.4.1 and 0.4.2. Planted faults each fail the new checks:
    • union gated off;
    • the stride bound moved to 227 and to 229;
    • the strided-row gate inverted;
    • raw direct not forced at the largest stride;
    • the union kernel without its per-request stride offset;
    • a signed DMA row offset;
    • the slotted union descriptor's extent halved;
    • V's stride not compared with K's;
    • the forced route ignored.
  • FlyDSL 0.4.2: this PR does not touch requirements.txt or setup.py; main already pins 0.4.2 (setup.py:27). The op test passes on 0.4.2 as well, and performance matches 0.4.1 within 0.4 % at group 12.
  • PREBUILD_KERNELS: no QSA kernel is in aiter/aot/flydsl/, including [FlyDSL] Add QSA sparse prefill attention for MI308 #6576's gfx942 ones. The op's docstring now says the kernels compile on first use and none is prebuilt. The variants depend on the caller's K/V row stride and pool size (the wide path), so a prebuilt set would cover only some callers; the vLLM wiring for QSA ([ROCm][Perf] Qwen3.8-Flash-Next specialized decode at 1-192 rows on MI355X (--monokernel) vllm-project/vllm#65188) compiles them at startup on its own cache views. Enrolling a representative set can be a follow-up.
  • XCD-local ordering: not compared. It was on the candidate list after the gfx950 port's trace, but that trace showed a 91.6 % L2 hit rate on the union kernel, so it had little to recover; the K/V LDS double buffer and the 128-bit LDS DMA ranked higher, and those are in.
  • Docstrings: the public docstring lists gfx950. Platform now says its terms are microseconds only for timing-calibrated entries; the gfx950 entry's are decision weights.
  • Calibration harness: part of its 91 layouts are captured Qwen3.8 selections, which I can't put in the tree. I can port the synthetic part to op_tests/op_benchmarks/flydsl/ as a follow-up PR.

@johannes-graner johannes-graner 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.

Thanks for the updates, this looks really good now!

@eppaneamd
eppaneamd marked this pull request as ready for review November 10, 2026 09:32
@eppaneamd
eppaneamd requested review from a team and a balanced review from Copilot November 10, 2026 09:32
@github-actions github-actions Bot changed the title [FlyDSL][QSA] Sparse prefill attention on gfx950: union and packed-direct ports, strided K/V, routing [FlyDSL] [QSA] Sparse prefill attention on gfx950: union and packed-direct ports, strided K/V, routing Nov 10, 2026
Copilot AI balanced review requested due to automatic review settings November 16, 2026 16:33

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.

🟡 Changes recommended

The warmup omits K3’s wide sort-key specialization, allowing supported calls to trigger compilation during serving; both modes need warmup coverage and regression assertions for their compile keys.

1 open issue

Review effort: Balanced

Comment thread aiter/ops/flydsl/qsa_sparse_prefill.py Resolved
Conflicts with #8083 (selection-width and byte-limit query):
- flydsl_qsa_sparse_prefill_available() answers gfx942 and gfx950, the
  architectures this branch admits; _check_call's architecture rule asks it.
- _check_call's indices rule uses flydsl_qsa_sparse_prefill_supports_selection,
  as main's entry does; the message and the rule order are unchanged.
- __all__ and the FlyDSL imports in aiter.ops.qsa list both sides' names.
- tests/test_qsa_sparse_prefill_support.py holds both test sets; the support
  query's tests run on gfx942 and gfx950, and gfx950 left "other GPUs".

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 12:16

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.

🟡 Changes recommended

Warm-up misses a valid wide-sort specialization, scalar conversion can raise instead of rejecting, and overlap checks reject valid non-overlapping outputs.

3 open issues

Review effort: Balanced

Comment thread aiter/ops/flydsl/qsa_sparse_prefill.py Resolved
Comment thread aiter/ops/flydsl/qsa_sparse_prefill.py Resolved
eppaneamd and others added 2 commits November 18, 2026 21:44
float(softmax_scale) raises OverflowError for e.g. 10**400, so
_check_call raised instead of returning a _Rejected. Treat it as an
infinite scale so the range rule rejects it like 1e40. A TypeError or
ValueError from float() is rejected as a non-host-scalar TypeError.
Add a scale_int_overflow case to the rejected-call tests.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
With strided K/V rows the bounding span includes padding that neither
kernel reads, so an output placed in the gap was rejected. Test the
occupied row intervals of K and V instead, and add an ACCEPTED case
with an out in the gap between rows (stride 32768, hk 1, gfx950).

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 21: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.

🔵 Needs a closer look

Warm-up misses the wide=True order/mask kernel specialization for valid layouts, so the first served call can still trigger JIT compilation.

1 open issue
2 resolved since last review

Review effort: Balanced

eppaneamd added a commit to eppaneamd/InferenceX that referenced this pull request Nov 20, 2026
…ithin the admission

Patches 22, 23, 26 and 27; c12, c24, c48 and c80 set their two variables:
- 22-23 FP8 stage-2 route output for the target's MXFP4 MoE (ROCm/aiter#8174 in the image's
  AITER checkout, sgl-project/sglang#51198 wiring), SGLANG_AITER_MOE_STAGE2_FP8
- 26 brings patch 15 to the head of sgl-project/sglang#50863; SGLANG_USE_HIP_HC_PREFILL_TRITON
  replaces SGLANG_AMD_HC_PREFILL, which 26 no longer reads
- 27 decode FP8 quant fused into the GDN gated norm and the attention output gate
  (sgl-project/sglang#51023), no variable

cuda-graph-bs-decode at c12-c80: every size to the admission at c12 and c24, every size to 64
and every 8 to 128 at c48 and c80. c48 also sets strip-thinking-cache and
mamba-max-states-per-path 2, as c80 does. Patch 12's header names ROCm/aiter#7556's head
1c8725c7f3 and how the patch differs from it. c1 and c2 are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rony Leppänen <[email protected]>
K3 sorted each order CTA's tasks on (cost << shift) + tasks - 1 - rank,
with the rank global, and compiled a 64-bit-key variant when that could
reach 2**31: past 2**21 tasks at block capacity 8224. The warmup
compiles K3 on small layouts only, so a call that large compiled that
variant while serving.

An order CTA sorts only its own chunk of at most 4096 ranks, so the
position in the chunk breaks cost ties in the same order. Costs stay
below 2**12 for every top-k and query tile the op takes, so the key
stays below 2**24 and K3 has one variant. Drop the 64-bit variant, its
two-word LDS exchange and the Int64 lane shuffle only it used.

Test that 16385 tiles at 128 KV heads take the K3 variant one tile
does; before, they compiled a second one.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 11:24

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.

🔵 Needs a closer look

The gfx950 MFMA/LDS pipeline and shared gfx942 changes require native GPU review because current-head GPU validation and gfx942 hardware coverage are missing.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

eppaneamd and others added 2 commits November 23, 2026 14:18
Brings in #8148 (runtime softmax scale, shared QK/PV/rescale helpers,
stable FlyDSL API, batch_invariant) and #8149 (FP8 K/V on gfx942, K3
runnable-first chunks, task splits, core tiles). gfx942 runs main's
kernels; gfx950 runs this PR's kernels in main's forms (runtime
SCALE_LOG2, the prim wrappers and counted LDS ledger of
sparse_prefill_common, kernel_attrs()).

- Raw direct (_Raw) takes K/V row bytes (KV_STRIDE * 2) where main
  passed KV heads; K3's route cost reads the first three terms of the
  5-term route model (main unpacked exactly four) and _route_choice
  loops over len(limits).
- K3 keeps the Int32 chunk-local sort key under main's CHUNKED, and
  both CHUNKED variants compile on a key's first compile.
- One operand rule list (_check_call): main's compute, FP8 scale and
  batch_invariant rules beside the scale, stride and row rules;
  qsa_sparse_prefill_problem and the qsa.py wrappers take
  batch_invariant, k_scale, v_scale and compute. FP8 K/V of any FP8
  dtype are rejected off gfx942, right after the device rule: #8149's
  kernels are E4M3FNUZ, and gfx950's dtypes.fp8 is E4M3FN. With
  compute="bf16" the per-request K span rule applies with a slot table
  too: the op then runs packed BF16 copies of the FP8 K/V, so
  qsa_sparse_prefill_problem reports what that call raises.
- batch_invariant=True on gfx950: packed direct compiles the K16 loop
  raw direct runs, so packed and raw K/V give the same bits; the
  default mode keeps the K32 packed loop.
- Platform: the gfx950 entry and route_all_or_none; FP8 routes on
  gfx942 only; overrides of a switch are written 0 or 1.
- Tests: the op test is main's with this PR's suites appended (their
  layouts seeded by name; FP8 suites on gfx942, a rejection case
  elsewhere); the CPU tests cover main's rules.

The warm-up does not compile main's batch-invariant and FP8 variants
yet; the next commit extends it.

Validated with FlyDSL 0.5.3: on gfx950 the op test, the output bits
against this branch's head and K1-K3 against main's prepare module; on
gfx942 compile-only, ISA and launch arguments against main's. On gfx950
an eager call takes 10 to 15 us more host time than on the head (main's
operand rules and launch arguments); graph replay and kernel times are
unchanged.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The warmup's union layout was two requests of half the union gate's rows
each, which keeps a full prefill off the wide tiles. With
batch_invariant=True a request plans union tiles only from the gate's
rows on its own, so that layout ran direct only and the union kernel, K3
without routing and the gated direct kernels (direct rows behind a union
plan) compiled while serving. For FP8 K/V (gfx942), whether a plan
splits short prefills' tasks (fewer than min(CUs, 1024)) or keeps core
tiles (H12/H6, unsplit) changes K2, K3 and the FP8 union, pack and
direct kernels, and FP8 direct reads raw K/V past the pack budget: the
warmup's base-tile layout took split plans only, and no layout raw K/V.

- The warmup layouts are (query_lens, prefix_lens): below the union
  gate; at it with a 4-token prefix, which keeps a request off the
  wide tiles in both modes (a prefix-free request between the gate
  and the wide tiles' first rows would too, but at one KV head that
  range is empty on gfx950 parts of 192 CUs or fewer); at each wide
  tile's first rows; and, for FP8 K/V, each union layout again with
  enough rows to keep its tasks whole (prepare.whole_task_rows).
  run() is now called over K/V of each request's prefix and query
  tokens, and the warmup returns the (query_lens, prefix_lens) that
  ran.
- FP8 direct compiles its packed and raw variants together on first
  compile, as BF16 direct does.

Test, on the op's own plan and launch builders over CPU tensors with
compiles recorded, that every kernel a sweep of layouts takes (1 to
20000 rows, 1 to 3 requests, with and without prefixes, a
131072-token context) is among those the warmup layouts take, per
architecture (gfx942 at 80 CUs, gfx950 at 256 and 32), K/V dtype,
batch mode, K/V pool (contiguous, slot table, wide), group and KV
heads. The warmup op test also runs with batch_invariant=True.

Validated with FlyDSL 0.5.3: on gfx950 the op test and the warmup op
test in both batch modes (no compile after the warmup); on gfx942
compile-only, every launch of the previous commit's layouts is
unchanged, and each FP8 direct variant compiled on stand-in arguments
equals the kernel a call compiles with raw or packed direct forced.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 19:47

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.

🔵 Needs a closer look

Changes to shared MFMA/LDS scheduling and K3 behavior require hardware-aware human review because gfx942 coverage is compile-only and no head-bound GPU validation report is available.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

No deployments
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.

4 participants