Repository navigation
Conversation
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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
johannes-graner
left a comment
There was a problem hiding this comment.
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
_qk950comment 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.txtmoves 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_prefilldocstring still says gfx942-only, andPlatformstill 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 underop_benchmarks/, and it would keep the calibration reproducible.
…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]>
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]>
|
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.
|
johannes-graner
left a comment
There was a problem hiding this comment.
Thanks for the updates, this looks really good now!
There was a problem hiding this comment.
🟡 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
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]>
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]>
…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]>
There was a problem hiding this comment.
🔵 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
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]>

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.
ds_read_b64_tr_b16for 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).v_cvt_pk_bf16_f32): 0.82-0.86× at ≤ 512 rows.kernels/they only extractplan_query_tilefromallocate_plan.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.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
flydsl_qsa_sparse_prefillaccepts K and V as strided views:[heads, 256];heads × 256, below 2**28 elements (the kernels form a four-row block's extent and offsets in 32 bits);aiter/ops/qsa.py, implemented inaiter/ops/flydsl/qsa_sparse_prefill.py):qsa_sparse_prefill_problem(...): the first operand rule a call breaks, as the message the op raises, orNone;can_use_flydsl_qsa_sparse_prefillis 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)andqsa_paged_kv_slots(...): a paged K/V cache as the op's token pools andkv_slots.qsa_sparse_prefill_warmup(run, ...): one call per kernel-variant class through the caller's ownrun, so the compile keys are the caller's.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).batch_invariant; [FlyDSL] [QSA] Add FP8 K/V to the sparse prefill #8149: FP8 K/V on gfx942):compute, FP8 scale andbatch_invariantrules beside this PR's scale, stride and row rules;qsa_sparse_prefill_problemand theaiter/ops/qsa.pywrappers takebatch_invariant,k_scale,v_scaleandcompute;batch_invariant=Trueon 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;CHUNKEDvariants on a key's first compile, each with the chunk-local sort key.qsa_sparse_prefill_warmupalso compiles the batch-invariant and FP8 kernels (K3 without routing, FP8 split and core plans, FP8 raw direct):rungets K/V of each request's prefix and query tokens (before: query tokens only);(query_lens, prefix_lens)that ran;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.route_all_or_none(default off).AITER_QSA_PLATFORMaccepts 0 or 1 for bool fields.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, orNone. States of the process (graph capture, one GPU per process) stay in the op and are not rules.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, orNone. Conditions:page_size % 4and pool rows per page% 4(the op reads four-token blocks at four consecutive rows from a multiple of four);qsa_paged_kv_slots(query_lens, prefix_lens, block_table, page_size, rows_per_page)returns the op'skv_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'srun(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:(query_lens, prefix_lens)that ran: none without FlyDSL or on an architecture without a tile policy. The tile choice isplan_query_tile, extracted verbatim fromallocate_planand used by both.fe86c6e07and3f1bff21ecompile 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 thenkernels/qsa/changed by extracting the host-sideplan_query_tilefromallocate_planand by K3's chunk-local sort key.KV_STRIDE,GFX950 = false, K3'sroute_all_or_none = falseand its chunk-position shift;Callers
3ff909482f) calls these functions throughrocm_aiter_ops. Its gate booleans, pool geometry check, slot formula, read ofsparse_prefill_common.PLATFORMSand list of warm-up layouts are replaced by the calls above. It stays inert on an AITER without them, such as the v0.1.29 its CI pins.qsa_sparse_prefill_problem,qsa_sparse_prefillandqsa_sparse_prefill_warmupfrom SGLang's QSA extend attention on gfx950; calls the op refuses stay on Triton.runbuilds slots for each request's prefix and query tokens already; [Perf] [AMD] qsa: Run extend attention on AITER's FlyDSL sparse prefill sgl-project/sglang#51179's sizes K by query rows and needs K for both.Performance
b83688cc07on 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).µs per call through vLLM's QSA call site, and setup
vllm/vllm-openai-rocmnightly76c6f3f2a95f.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 %.
48cdcb285The 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
sparse_prefill_compact,sparse_prefill_order_masksand 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×).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).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.
End-to-end table, stack and protocol
928dfc98123c5e29ffcd, with its--monokernelserve 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 base6044ab0609, none of them Qwen's, stayed at the image's version in every arm.f045002d57(comment). These runs used its previous revision, which makes the same op call behind an opt-in.vllm/vllm-openai-rocmnightly76c6f3f2a95f, FlyDSL 0.4.0.3c5e29ffcd), against the head's parent928dfc9812. 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.The caller API in vLLM
vllm-project/vllm#67036 at
3ff909482f(this PR's API) against the same PR's previous head4ce31f8c2b(vLLM's own copy of the contract, over the AITER headfddf1837d2):vllm/vllm-openai-rocmnightlyf5d93296c8(vLLM 0.34.0rc1.dev206) with FlyDSL 0.5.0, the PR's serve command without--monokernel.Testing
Documentation
Dependencies
Breaking Changes
On gfx942 two degenerate K/V inputs it accepted before are now rejected:
Otherwise none; gfx950 was refused before.
PR Self-Review
Reviewed revision
60fe14d4caBehavior and intent
qsa_sparse_prefill_probleminstead of restating the operand rules, read a paged cache in place throughqsa_paged_kv_poolandqsa_paged_kv_slots, and warm the kernels through their own call withqsa_sparse_prefill_warmup.qsa_sparse_prefillrun main's kernels, K3 with the chunk-local key; some rejections name another rule than main's (Caller API details).batch_invariant; FP8 K/V are rejected there.Validation and unverified scope
Validated on MI355X (details below):
python3 op_tests/test_flydsl_qsa_sparse_prefill.py -g 12 6 3 16without 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).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 onb83688cc07; 368 on this head.test_the_task_count_compiles_no_new_order_kernel, which fails before).OverflowError.Unverified:
Op test runs, route assertions and planted faults
lmsysorg/sglang:v0.5.23-rocm724-mi35x(ROCm 7.2.4) with AITER main73960daf4ebuilt in it, FlyDSL 0.5.3, and this head's QSA files over it; the other modules on the QSA path are the same in73960daf4eand this head.vllm/vllm-openai-rocmnightlydd4e40142a32with 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.Caller API validation
tests/test_qsa_sparse_prefill_support.py(96),tests/test_qsa_paged_kv.py(32),tests/test_qsa_sparse_prefill_warmup.py(102).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 newproblem()give the same outcome, type and message on all of them.-g 12 6 3) equal those offddf1837d2. Recorded on an earlier revision of these commits; the bodies of_check_callandflydsl_qsa_sparse_prefillare AST-identical since, docstrings aside. K3's compile key has lost itswideconstant since (K3 sort key), so its keys no longer matchfddf1837d2's.-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 undertorch.cuda.set_sync_debug_mode("error")(a prototype mode: it flags the synchronizing operations it knows).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):_COMPILEDdicts and by the.pklfiles FlyDSL writes;not math.isfinite(scaled)(the range check beside it rejects inf and NaN);n >= 2**31from the lengths rule (a length that large fails the sum checks unless the tensors hold that many rows);None.Kernel ports, strided views and writes outside the op's tensors
kv_slots.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.pyis the only test offlydsl_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.raise ValueError("QSA sparse attention requires gfx942"),aiter/ops/flydsl/qsa_sparse_prefill.py:524-525) and the test hasSUPPORTED_GFX = ["gfx942"], somain()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 thatValueError.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 everyop_tests/test_*.pyaspython3 FILEon each runner type; 116 s on MI355X.Suites added to op_tests/test_flydsl_qsa_sparse_prefill.py
--caseruns them.TB/s.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).-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.get_gfx_runtime()), not the last entry ofGPU_ARCHS.This change was developed with AI assistance (Claude); I reviewed every line and ran the tests listed.
🤖 Generated with Claude Code