Repository navigation
[FlyDSL] [Perf] Let the consumer finish a gfx1250 PTPC split-K GEMM - #7449
Conversation
2c8902d to
3499407
Compare
9ecd054 to
546a3e8
Compare
49f0052 to
9f82222
Compare
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
…heir consumers With ROCm/aiter#7449, aiter.gemm_a8w8_bpreshuffle_splitk_deferred leaves the fp32 partials unreduced when the tuned gfx1250 PTPC GEMM splits K and M is at most max_m; the consumer claims them (aiter.splitk_partials) and reduces them as it reads the output. - LinearBase.splitk_consumer_max_m (0 = off) routes the per-token FP8 bpreshuffle GEMM through it. Not while a token graph records: its replay would run the consumer, an eager region, without the partials. - MiniMax-M3 sets it on gfx1250 to ATOM_SPLITK_CONSUMER_REDUCE_MAX_M (default 64, 0 = off) for the QKV projections whose attention impl claims the partials in rope_cache (not under Ulysses SP, whose head exchange reads qkv first) and for the dense MLP's gate/up. - PagedAttentionImpl.rope_cache hands them to triton_fused_norm_rope_cache; SparseMHAPagedAttentionImpl.rope_cache to aiter.fused_qknorm_idxrqknorm (qkv_partials, ROCm/aiter#8011) when that op takes them: the index branch runs, no fp4 cache, and an aiter with the argument. Every other path finishes qkv with the standalone reduce first. A dummy run releases them. - swiglu_oai_split_reducing, an opaque op, claims a gate/up's partials at run time and reduces them in the activation kernel. An aiter without #7449 never defers; one with #7449 but without #8011 defers and reduces in the sparse layers with the standalone kernel, as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review routing reminder: @aoli26 is the primary reviewer for the FlyDSL GEMM scope on this PR, with @coderfeli as backup. Please route the next technical review/action to the component owner; CI status remains a separate merge gate. |
…er decide Drop the aiter probes: the try-import of the deferred GEMM API and the inspect.signature check for fused_qknorm_idxrqknorm's qkv_partials. ATOM needs aiter with ROCm/aiter#7449 and #8011 (docs/environment_variables.md). Stop restating aiter's rules: the sparse rope_cache passes qkv's partials to fused_qknorm_idxrqknorm in every mode (the op reduces them itself where it cannot fuse them), and the gfx1250 gate goes: the deferred GEMM decides per call, arch included, whether it defers. Only ATOM's own Triton kernel path still reduces first. claims_splitk_partials is opt-in per class: PagedAttentionImpl and SparseMHAPagedAttentionImpl set it, a subclass does not inherit it. The model checks ATOM's own attention layer and impl by type instead of getattr defaults. The env doc names both deferred GEMMs (QKV and the dense MLP gate/up into SwiGLU-OAI). Co-Authored-By: Claude Opus 5.5 <[email protected]>
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (3)
- Make a missed claim fail loudly instead of returning the "already reduced"
None.aiter/ops/gemm_op_a8w8.pysplitk_partials(~L1053-1067) returnsNoneboth for "y holds its values" and for a still-deferredyit does not recognise: a reshaped view (y.view(m, h, d)), a column slice, a non-leading row slice, or an entry pushed out of the 64-entry table (~L1041). The consumer then reads unwritten bf16, andreduce_splitk_partials(y)returnsyunwritten too. A CPU run of the PR's own code reproduces all four cases. Fix: when the address/storage matches a live entry but the view check fails, raise. On eviction, launch the standalone reduce for the evicted entry (or raise); do not drop it silently. - Share the kernel selection with
_gemm_a8w8_bpreshuffle_intoinstead of re-deriving it in_splitk_deferrable._splitk_deferrable(~L979) re-implements the config lookup, the libtype check and the arch gate, and the deferred path also skipsgemm_a8w8_bpreshuffle's input asserts (e.g.WQ.dtype == fp8). Main has already changed that dispatch since this branch's base (INT8 bpreshuffle), so the two copies can drift and break the "bitwise equal" promise. Fix: factor one(config, kernelName)resolver and call it from both paths. - Add a CPU test of the hand-off table that CI actually runs.
op_tests/test_gemm_a8w8_splitk_deferred.pyskips everywhere except gfx1250, so CI (MI300X/MI35X) never executes any of the new logic. The table is pure host code. Fix: stub the two launchers and cover claim-once, the leading-row-slice claim, the rejected views (they should raise after item 1) and eviction.
Minor (non-blocking):
_SPLITK_DEFERRED.pop(Y.data_ptr(), None)in the non-deferred branch is dead code. A live entry holds its allocation, so a freshYcan never land on that address.- The eviction
whilecan be anif. - The comment "its address cannot be handed out again until the consumer claims it" ignores eviction.
- The test docstring says "Every check is bitwise", but the
errcolumn is an allclose check against the fp32 reference.
Reviewed at 9f82222. CI: 30 pass, 33 skipped, 0 failing (the new test skips on CI archs).
|
|
9f82222 to
6bd1332
Compare
|
@valarLip thanks, all three are addressed in 6bd1332 (rebased on current
GPU rerun at 6bd1332 on one MI455X:
|
|
@aoli26 good question. I had not tried What fits.
The blocker for the decode configs. The shared epilogue splits a tile by rows: each split reduces
These are the rows where the deferred path gains the most. Every other M3 decode row passes: the t32x128 and larger tiles, t16x128 sk4 (gate/up M 8), and the tile_n 192 rows (gate/up M 1, 4 and 48). No current
What the fused epilogue would buy. It removes the second launch, which is the deferred design's whole gain, and it also removes the deferred caveats you list (unclaimed outputs, eviction, pinned memory, eager-only hand-off). It further avoids the cost the deferred path pays in the consumer, which reads Measurement. One MI455X, the same HIP-graph harness as the PR table (16 independent GEMMs per graph, average per GEMM, median of 5 rounds), on the M3 TP4 decode shapes 2560×6144, 2304×6144 and 6144×6144 at M 1, 2, 4, 8, 16, 32, 48, 64:
Compared per layer: GEMM→qknorm for QKV, GEMM→SwiGLU for gate/up. I will post the numbers here. If (b) ≤ (c) on the decode rows, I will replace the deferred API with a PTPC |
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (2)
- Post the
_fskcomparison @aoli26 asked for, and settle the design before this public API lands. You plan to replace the deferred API with a PTPC_fskvariant if (b) ≤ (c) on the decode rows (comment of 2026-11-18). Until those numbers are in, merging would ship four top-level names (aiter.splitk_partials,aiter.reduce_splitk_partials,gemm_a8w8_bpreshuffle_splitk_deferred[_supports_arch]) plus a global hand-off table that may be deleted shortly after, and ROCm/ATOM#2988 would be built on them. Fix: post (a)/(b)/(c) per layer on the M3 shapes here. Keep this design only if the fused epilogue loses or cannot fit the t16x64 rows, and say so in the PR body. - Fix the two docstrings that contradict the code.
aiter/ops/gemm_op_a8w8.pygemm_a8w8_bpreshuffle_splitk_deferred: "Eager only" followed by "a graph must capture producer and consumer together". Graph capture of both together is the intended ATOM use, so drop "Eager only" and state that constraint instead._splitk_deferrable: says "split_k > 1", but the code defers only split_k in (2, 4, 8).
Minor (non-blocking):
splitk_partials/reduce_splitk_partialsland at top level throughimport *with names that read as generic, but they only apply to deferred bpreshuffle outputs. Consider agemm_a8w8_bpreshuffle_prefix.- The eviction reduce runs on the current stream, not the stream of the evicted GEMM. That is only a hazard for an unclaimed output produced on a side stream.
bpreshuffle_gemm_gfx1250.pyreduce_splitk_partials_gfx1250:tuple(...)around thetorch.Sizecomparison is redundant.
Re-reviewed at 6bd1332. Already fixed: a missed claim now raises for views and eviction reduces (1), the shared _bpreshuffle_config resolver (2), and the CPU test_handoff_table that main() runs on every arch (3). All four minors are done too. CI: 16 pass, 25 skipped, 1 wheel build pending; the op-test run has not happened yet at this head.
…heir consumers With ROCm/aiter#7449, aiter.gemm_a8w8_bpreshuffle_splitk_deferred leaves the fp32 partials unreduced when the tuned gfx1250 PTPC GEMM splits K and M is at most max_m; the consumer claims them (aiter.splitk_partials) and reduces them as it reads the output. - LinearBase.splitk_consumer_max_m (0 = off) routes the per-token FP8 bpreshuffle GEMM through it. Not while a token graph records: its replay would run the consumer, an eager region, without the partials. - MiniMax-M3 sets it on gfx1250 to ATOM_SPLITK_CONSUMER_REDUCE_MAX_M (default 64, 0 = off) for the QKV projections whose attention impl claims the partials in rope_cache (not under Ulysses SP, whose head exchange reads qkv first) and for the dense MLP's gate/up. - PagedAttentionImpl.rope_cache hands them to triton_fused_norm_rope_cache; SparseMHAPagedAttentionImpl.rope_cache to aiter.fused_qknorm_idxrqknorm (qkv_partials, ROCm/aiter#8011) when that op takes them: the index branch runs, no fp4 cache, and an aiter with the argument. Every other path finishes qkv with the standalone reduce first. A dummy run releases them. - swiglu_oai_split_reducing, an opaque op, claims a gate/up's partials at run time and reduces them in the activation kernel. An aiter without #7449 never defers; one with #7449 but without #8011 defers and reduces in the sparse layers with the standalone kernel, as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…er decide Drop the aiter probes: the try-import of the deferred GEMM API and the inspect.signature check for fused_qknorm_idxrqknorm's qkv_partials. ATOM needs aiter with ROCm/aiter#7449 and #8011 (docs/environment_variables.md). Stop restating aiter's rules: the sparse rope_cache passes qkv's partials to fused_qknorm_idxrqknorm in every mode (the op reduces them itself where it cannot fuse them), and the gfx1250 gate goes: the deferred GEMM decides per call, arch included, whether it defers. Only ATOM's own Triton kernel path still reduces first. claims_splitk_partials is opt-in per class: PagedAttentionImpl and SparseMHAPagedAttentionImpl set it, a subclass does not inherit it. The model checks ATOM's own attention layer and impl by type instead of getattr defaults. The env doc names both deferred GEMMs (QKV and the dense MLP gate/up into SwiGLU-OAI). Co-Authored-By: Claude Opus 5.5 <[email protected]>
6bd1332 to
b6892c5
Compare
aoli26
left a comment
There was a problem hiding this comment.
Thanks for the detailed reply and the docstring/body updates. LGTM now.
At decode sizes the tuned gfx1250 PTPC GEMM splits K (MiniMax-M3 TP4 sparse QKV, M16 x N2560 x K6144: 40 output tiles on 256 CUs, split 4), and a second kernel sums the fp32 partials into bf16. That reduce reads 0.7 MB and costs a fixed ~1.3 us per launch in a HIP graph from 46 KB to 2.9 MB (1.7 us of the GEMM + reduce pair at M16), 57 times per M3 decode step. gemm_a8w8_bpreshuffle_splitk_deferred runs the same tuned kernel but, when it splits K (split 2/4/8, M <= max_m, gfx1250), leaves the partials unreduced in the allocation of the bf16 output it returns. A consumer claims them with splitk_partials() and sums them as gemm_a8w8_splitk_reduce does (fp32, split order, one round to nearest even), writing the reduced row back, so it sees and leaves behind exactly what the two-kernel path produces. reduce_splitk_partials() finishes the output with the standalone kernel for a consumer that cannot. Every other call returns gemm_a8w8_bpreshuffle's output. run_preshuffle_gemm_a8_gfx1250 and run_gemm_a8w8_bpreshuffle_gfx1250 take a caller's partials buffer (partials=) and then skip the reduce, which reduce_splitk_partials_gfx1250 launches on its own. Without partials= they behave as before. op_tests/test_gemm_a8w8_splitk_deferred.py checks the deferred GEMM + reduce bitwise against gemm_a8w8_bpreshuffle at the M3 TP4 decode shapes, M 1..64 (sparse QKV, dense QKV, dense gate/up), and the hand-off rules. Signed-off-by: lirui927 <[email protected]> Co-authored-by: Cursor <[email protected]>
…ookup splitk_partials now looks a tensor up by its allocation, so any view of a deferred output is found: the whole output or a leading row slice claims the partials as before, and any other view (a reshape, a column slice, a later row slice) raises instead of reading as an output that already holds its values. When the 64-entry table is full, the oldest unclaimed output is finished with the standalone reduce instead of being dropped unwritten. _bpreshuffle_config is the tuned-row lookup _gemm_a8w8_bpreshuffle_into dispatches on; the deferred path uses it instead of its own copy, and only takes fp8 operands with a bf16 output, so every other call goes through gemm_a8w8_bpreshuffle and its input checks. Drop the dead table pop in the non-deferred branch. op_tests/test_gemm_a8w8_splitk_deferred.py gains a host-only test of the hand-off table with both FlyDSL launchers stubbed (claim once, leading row slice, rejected views, eviction), which runs on every arch, also as `python3 <file>`; the GPU tests stay gfx1250 only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
splitk_partials and reduce_splitk_partials apply to deferred gemm_a8w8_bpreshuffle outputs only, so they are now gemm_a8w8_bpreshuffle_splitk_partials and gemm_a8w8_bpreshuffle_splitk_reduce, next to gemm_a8w8_bpreshuffle_splitk_deferred. gemm_a8w8_bpreshuffle_splitk_deferred no longer says "Eager only": it states the graph-capture constraint instead (capture the producer and its consumer, or the reduce, in the same graph). _splitk_deferrable says split_k in (2, 4, 8), as the code checks. The table comment says that an eviction reduce runs on the stream current at the eviction. The reduce_splitk_partials_gfx1250 shape check compares torch.Size directly. An eviction during graph capture raises instead of recording a reduce into an allocation the table then drops. gemm_a8w8_bpreshuffle_splitk_partials notes that a copy of a deferred output is not recognised. test_handoff_table also checks that off gfx1250 the deferred GEMM returns gemm_a8w8_bpreshuffle's output. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t know gemm_a8w8_bpreshuffle_splitk_deferred's docstring now states: - why the partials sit behind the returned tensor instead of in a second one: whether a call defers, and with which split_k, is known only when it runs (the tuned row for this M). A caller that traces its model once for every M and runs the GEMM as an opaque op of that graph (torch.compile, as ATOM's LinearBase does) can pass on the output, whose shape follows from the input shapes; a [split_k, M, N] tensor that may not exist would need a data-dependent shape there. The explicit form stays ``partials=`` of run_gemm_a8w8_bpreshuffle_gfx1250; - the misuses nothing detects: an output read before it is claimed (uninitialised memory), a copy of an unclaimed output (clone, cast), which reads as finished, and a consumer outside the producer's graph, which claims once and after every later replay reads the values that claim left; - the memory: the output's storage is the whole allocation, about (2 + 4 * split_k) / 2 times its own size (9x at split 4), for as long as the output lives, claimed or not, and up to 64 unclaimed outputs stay listed with theirs. Docstrings only (gemm_a8w8_bpreshuffle_splitk_partials' is re-wrapped, same words); no code change. Co-Authored-By: Claude Fable 5.2 <[email protected]>
97f5332 to
ed0119b
Compare
One @benchmark function, test_gemm_a8w8_splitk_deferred(m, n, k), with a candidate loop that records us, TFLOPS, TB/s and err for each candidate and asserts both the bitwise match with gemm_a8w8_bpreshuffle and the fp32 torch reference (run_torch); one -s/--mnk sweep and one summary table. The claim and hand-off checks are plain functions that main() calls, so the file needs no pytest: CI runs it as python3 <file>, where the hand-off check runs on every arch. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
@valarLip could you take another look? Your review of 2026-11-24 left one item open, the reply to aoli26 on the API form, with approval once aoli26 was satisfied.
|
…umer main (ROCm#8678) launches the GEMM and the split-K reduce through the AOT cache launchers; _launch_splitk_reduce takes splitk_reduce_launcher the same way. Co-Authored-By: Claude Fable 5.2 <[email protected]>
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (2)
Thanks for the merge and the op-test reshape. Prior asks: all fixed at this head. That covers:
- the loud missed claim and the eviction reduce (
gemm_op_a8w8.py:1316-1331,:1293-1301); - the shared
_bpreshuffle_config(:1103,:1217); - the CI-run host test, which ran and passed at this head on MI35X shard 4;
- the
_fskcomparison and the docstrings; - the reply to @aoli26, with the misuse cases and the memory cost now in the docstring (
:1253-1278).
The merge resolution in _launch_splitk_reduce uses main's splitk_reduce_launcher.lazy, and the deferred GEMM still goes through the same run_gemm_a8w8_bpreshuffle_gfx1250 as main's AOT path.
Two small things:
- The "deferred" timing in the op test includes standalone reduces (
op_tests/test_gemm_a8w8_splitk_deferred.py:85-99).- The timed
deferredlambda leaves every output unclaimed. Once 64 outputs are listed, each call evicts the oldest one and launchesgemm_a8w8_bpreshuffle_splitk_reduce. - The table also carries 63 entries from one shape to the next. A host-only trace of the head code with stubbed launchers shows standalone reduces in 40 of 104 timed calls for the first shape and in 103 of 104 for every later shape.
- So the "deferred" us/TFLOPS/TB/s columns show roughly the GEMM + reduce cost, and the comment "The GEMM alone, as the model launches it" is wrong.
- Fix: claim inside the timed call so nothing stays listed, e.g.
y = deferred_gemm(...); return y, splitk_partials(y), then finish withsplitk_reduce(*out). The claim is a host-side pop with no launch. - Earlier rounds, mine included, missed this: the lambda was already there at b6892c5. I am raising it now because this head rewrote its comment.
- The timed
- Bring the PR description up to date with the head (it is the squash text).
- Testing still says "The head, ed0119b, is 97f5332 rebased onto main e6d2d31"; the head is 92397e7.
- "Not covered" says the GPU tests were not rerun after the rebase, while the Self-Review says MI455X at this head exits 0 on the 21 shapes.
- The "pytest 5 passed" line describes the old pytest layout, which this head no longer has.
Root cause vs patch
Root problem: at decode M, split-K pays a separate reduce launch plus an fp32 round trip. The clean fix is a consumer that takes the partials explicitly (#8011). The fused in-kernel epilogue was measured and loses on 21 of 24 rows. The address-keyed global table is the patch-like part. It exists only because ATOM's opaque torch.compile op returns one tensor, and a [split_k, M, N] output would need a data-dependent shape. It is documented, the component owner accepted it, and the explicit partials= form exists at the low level, so I see no cheap cleaner fix. Verdict: right direction with patch-like parts; not blocking.
Both items are small. I will approve once they are in.
Reviewed at 92397e7 (round 4, pass A; request_changes, so no pass B; true delta = old b6892c5 replayed onto merge base 4960107 -> head). Already fixed: missed-claim raise and eviction reduce, shared config, CI host test, _fsk comparison, docstrings, misuse-case docstring.
The timed "deferred" candidate left every output unclaimed, so once 64 were listed each call evicted the oldest and launched the standalone reduce: its us / TFLOPS / TB/s columns showed GEMM + reduce. The candidate now claims the partials as the consumer does (a host pop, no launch), so nothing stays listed; the output is still finished and checked outside the timing. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Both items of the 2026-12-01 review are in at 87a18c5 (test file only; the library files are those of 92397e7). 1. The timed
2. The description matches the head.
|
valarLip
left a comment
There was a problem hiding this comment.
✅ LGTM
Thanks. Both items from round 4 are fixed at this head. The only change since 92397e7 is the op test (op_tests/test_gemm_a8w8_splitk_deferred.py, +12/-4); the library files are the ones reviewed last round.
Prior asks (round 4):
- The "deferred" timing included standalone reduces: fixed.
claimed()(:64-66) claims inside the timed call (:95), and:107finishes the output outside the timing.- A host-only trace of the head code with both FlyDSL launchers stubbed (104 calls per candidate, as
run_perftestmakes them) shows 0 standalone reduces in the timed "deferred" calls on every shape (it was 40/104, then 103/104), and nothing left listed between shapes. - Every output form is finished correctly: split 4/8 gives
(y, partials)and one reduce; a split-1 row, gfx950, or M abovemax_mgives(y, None), andsplitk_reduce(y, None)returnsyunchanged.run_perftestpasses a tuple return through untouched. - The new comments at
:91-94and:106are true.
- PR description: fixed. Testing and Self-Review name 87a18c5 / 92397e7, the stale ed0119b / e6d2d31 and "pytest 5 passed" lines are gone, and "Not covered" now agrees with the Self-Review (no GPU sweep at this head).
Rounds 1-3 stay fixed (library unchanged). @aoli26's two questions were answered and they posted "LGTM now".
CI: the first PR run (46823068865) at this head was cancelled, so its GPU jobs show "fail" at 0 s; the rerun is still in progress. Please merge once it is green.
Root cause vs patch
Root problem: at decode M, split-K pays a separate reduce launch plus an fp32 round trip. The clean fix is a consumer that takes the partials explicitly, which this PR provides. The address-keyed hand-off table is the patch-like part, needed only because ATOM's opaque torch.compile op returns one tensor. It is documented and accepted by the component owner, and the explicit partials= form exists at the low level. Verdict: right direction with patch-like parts; not blocking.
Reviewed at 87a18c5 (round 5, passes A+B, both approve; true delta = 92397e7 -> 87a18c5, same merge base 4960107). Already fixed: missed-claim raise and eviction reduce, shared config, CI host test, _fsk comparison, docstrings, misuse-case docstring, deferred timing claim, PR description.
Conflict resolved (from #7449, PTPC split-K left to the consumer): - bpreshuffle_gemm_gfx1250: keep both of run_preshuffle_gemm_a8_gfx1250's fused_splitk and partials arguments. A caller's partials buffer is the unfused (split_k, M, N) layout, so a launch with partials runs unfused (the same fallback as an unsupported fused geometry) and skips the reduce; the fused epilogue and the reduce launch keep their own guards. Merged cleanly but needed a change: - gemm_op_a8w8._splitk_deferrable: a fused split-K row (_fsk) reduces in the kernel, its output is final, so it is not deferred and goes through gemm_a8w8_bpreshuffle.
…plit-K hand-off (#7449) - test_gemm_a8w8: a fused PTPC kernel name launched with partials= writes the unfused (split_k, M, N) partials, launches no reduce and leaves Out alone; reduce_splitk_partials_gfx1250 then gives the fused output's bytes. - test_gemm_a8w8_splitk_deferred: a fused split-K row is not deferred (host table check, and on gfx1250 the deferred call is the plain GEMM: no reduce launch, no partials, same bytes).
…15808c7, head 2026-11-19T10:14:52Z) Applied as the diff ce334d0..15808c7 (26 files) onto the rebased 1116 tree; PR state: open, author aoli26, base main. Squash-applied: #8246's branch merges main (ce334d0, this tree's base) and carries rebased copies of aoli26's #7827 (head 9d38b5c, every added line present here) and #7868 (head 570805d; 3 of its added lines are superseded by #8246's later edits), so this one diff applies the #7827 -> #7868 -> #8246 stack as #8246 has it. (cherry picked from commit f58bb7e) Rebase onto main 12-03: kept at the 15808c7 snapshot (the PR head is now c4f8a6d, see the rebase report). Main's #8678 (AOT launchers) and #7449 (deferred split-K partials) conflict with it in the two wrappers: bpreshuffle_gemm_gfx1250.py takes both fused_splitk and main's partials (a launch with partials runs unfused, main's _launch_splitk_reduce / reduce_splitk_partials_gfx1250 kept, skipped when fused); mxfp8_bpreshuffle_gemm_gfx1250.py keeps fused_splitk_ok (generic kernel included) and launches gemm_a8w8_launcher.lazy() with this PR's argument layout (arg_out, runtime cluster_m, fused_splitk). Same as the PR author's own merge of main, without the later lean_stripe_fits guard. aiter/aot/flydsl/sources.py: the gemm_a8w8_gfx1250 cache now also hashes kernels/splitk_fused_epilogue_gfx1250.py, which the kernel imports (as on the PR head). Rebase onto main 12-03: op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py counts reduce launches through splitk_reduce_launcher.lazy (main #8678 replaced _compile_splitk_reduce), as on the PR head.
#8978) * K3 TP1 a8w8 GEMM: compute N tail, underfilled tiles, aligned A-scale loads, retuned rows (#8778 @ ea7a5d8) #8778 (aoli26; base main; open) applied to k3-455-dev as its net change on its 19 files at head ea7a5d8 (2026-11-26T14:47:07Z), 3-way against the PR's main base adbb6ac. The 8 files k3-455-dev had changed (all only by #8246 @ 15808c7) take the PR's version, so all 19 files equal the PR head. It carries the newer #8246 (ccc4270), the table PRs #8579 / #8586 / #8601 and main's #8566 (its compute guard, which #8778 replaces); no other main change rides in. Validated in the K3 1P1D integration branch (aiter zejun/k3-455-dev 627e1eb) on 16 MI455X (wuhuikx/LLM-Booster#578). The PR head has moved on since (204ce9d: merges of #8246 @ 0d6cf15 and of main, which brings #8737); those can follow when #8778 lands. Co-authored-by: zejunchen-zejun <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> * Update K3 FP8 kernels to c997 and add exact-M tuning Preserve the existing dev wrappers and bucket tables. Add 162 accepted retuned exact configurations and 3 c997-default compatibility records, with CPU dispatch coverage for all 675 measured points. Backport the three kernel files from c99781c without merging main history. Integrated-head GPU validation remains outstanding. --------- Co-authored-by: aoli26 <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Zhang <[email protected]> (cherry picked from commit 1cc9d02) Rebase onto main 12-03: the 19 files keep this commit's content; only main's later changes are added: the AOT launcher factories of #8678 (mxfp8 / batched wrappers launch gemm_a8w8_launcher.lazy(), _gemm_a8w8_compute_bound_launcher.lazy(), splitk_reduce_launcher.lazy(); _lazy_import keeps _data_ptr), #7449's deferred split-K entry points and #8636's ragged-K fallback. gemm_a8w8_gfx1250.py: this commit's rank0 split-K epilogue and flush_addr (it already carries #8737's flush). gemm_op_a8w8.py: main's #8566 guard in get_mxscale_bpreshuffle_config (no padded row below a compute kernel's M tile) is removed, as on the #8778 head, because the c997 compute kernel serves underfilled tiles; test_gemm_host_dispatch_cache.py takes #8778's test_mxscale_compute_row_serves_underfilled_m_tile in place of main's two guard tests. kimik3 mxscale tuned CSV: this commit's rows (626 changed or added) replayed by key; the result equals this commit's table. Rebase onto main 12-03: main #7449 moved the bpreshuffle row lookup into _bpreshuffle_config(XQ, WQ); this commit's Kimi-K3 exact-row lookup there needs x_scale, w_scale and Y, so _bpreshuffle_config takes them (the deferred split-K path passes a meta tensor of the output's shape and dtype, so it picks the same row as gemm_a8w8_bpreshuffle). Rebase onto main 12-03: op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py counts reduce launches through splitk_reduce_launcher.lazy (main #8678 replaced _compile_splitk_reduce).
Based on
main, GEMM only, with no dependency on other PRs. The consumer side is separate: #8011 letsfused_qknorm_idxrqknormtake the partials (qkv_partials). ROCm/ATOM#2988 uses both.What this PR does
At decode sizes (M ≤ 64 per rank), the tuned gfx1250 PTPC FP8 GEMM (
gemm_a8w8_bpreshuffle, FlyDSL backend) splits K. A separategemm_a8w8_splitk_reducelaunch then sums the fp32 partials into bf16. That reduce moves very little data, so its cost is mostly the launch plus one store/reload round trip. This PR lets the kernel that reads the GEMM output do the reduction itself.gemm_a8w8_bpreshuffle_splitk_deferred(...)runs the same tuned kernel but skips the reduce. It applies when the tuned row is the gfx1250 FlyDSL kernel with split 2/4/8, the operands are fp8 with bf16 output, K is unpadded and M ≤max_m(default 64). Every other call goes throughgemm_a8w8_bpreshuffleand its input checks and returns its output.gemm_a8w8_bpreshuffle_splitk_partials(y)hands the partials to a consumer. The consumer sums them as the reduce kernel does (fp32, split order, one round to nearest even) and writes the reduced rows back, so it sees, and leaves behind, exactly what the two-kernel path produces.gemm_a8w8_bpreshuffle_splitk_reduce(y)finishesyin place with the standalone reduce kernel, for a consumer that cannot take partials.gemm_a8w8_bpreshuffle_splitk_partialsinstead of reading as finished. When the 64-entry hand-off table is full, the oldest unclaimed output is finished with the standalone reduce (on the current stream; during graph capture this raises instead).gemm_a8w8_bpreshufflepick the kernel from the same tuned-row lookup (_bpreshuffle_config).run_preshuffle_gemm_a8_gfx1250(..., partials=)(andrun_gemm_a8w8_bpreshuffle_gfx1250) accepts a caller-provided partials buffer and leaves it unreduced;reduce_splitk_partials_gfx1250launches the reduce on its own. Without that argument they behave as before.Why the partials are implicit
gemm_a8w8_bpreshuffle_splitk_deferredreturns one tensor and keeps the partials behind it (same allocation, found again by its address) instead of taking or returning a workspace. The reason is how ROCm/ATOM#2988 calls it:--level 3) and runs that graph for every batch size.LinearBase.forwardruns the GEMM in it as an opaquetorch_compile_guardop.[M, N]does. A[split_k, M, N]tensor that may not exist would have a data-dependent shape, which no op in aiter or ATOM has today.So the per-call facts (deferred or not, split count, where the partials are) travel beside the graph, keyed by the output's address, and ATOM's graph keeps carrying one tensor. An explicit form would have to carry more through that graph: partials with a data-dependent size, or a fixed-capacity workspace plus the split count. It is not part of this PR. The consumers already take the partials as an argument (
qkv_partialsin #8011), and a caller that picks the kernel itself has the explicit low-level form,run_gemm_a8w8_bpreshuffle_gfx1250(..., partials=).What the caller has to know, as the docstring now states it. Nothing detects the first three:
yread before it is claimed is uninitialised memory.y(clone(),float()) reads as finished. (A view other than the whole output or a leading row slice raises at the claim.)y. perf(minimax-m3): reduce split-K QKV and gate/up partials in their consumers ATOM#2988 does not defer while a token graph records.y's storage is the whole allocation, about (2 + 4·split_k)/2 timesy(5x, 9x, 17x at split 2, 4, 8), for as long asylives, claimed or not. Up to 64 unclaimed outputs stay listed, storage included.Benefit
One MI455X, MiniMax-M3 TP4 decode GEMMs. 16 GEMMs with independent inputs are captured in one HIP graph; the number is the average per GEMM over replays, median of 5 rounds (a benchmark script outside this PR).
The deferred GEMM followed by
gemm_a8w8_bpreshuffle_splitk_reducetakes as long asgemm_a8w8_bpreshuffle(within ±0.4 µs run to run), so the new path costs nothing by itself.What a layer saves is the last column minus what the consumer spends on summing the partials. For
fused_qknorm_idxrqknormwith #8011 that is 0.5 µs at 4 splits and 1.4–2.2 µs at 8 splits, so the MiniMax-M3 sparse attention layer saves about 1.5 µs at M 16, 0.7 µs at M 32 and 0.2 µs at M 64.Why not a fused in-kernel split-K epilogue (
_fsk)I built a PTPC
_fskvariant for the comparison (not in this PR): the split-K workgroups of a tile form one (1, 1, split_k) cluster and reduce in-kernel. Where the sharedemit_fused_splitk_epiloguecannot take the tile (t16x64 and similar rows, where a split owns fewer rows than its row loop needs), a flat-indexed copy of it reduces instead, so every M3 decode row fits. It is bitwise equal to GEMM + reduce in all 155 checked cases (11 configs incl. split 2, 4 and 8, 3 shapes, M 1–64 with tails) and for each best config below. Per layer, on one MI455X: 16 layers with independent weights per HIP graph, µs per layer, median of 9 interleaved rounds (max-min spread ≤ 0.4 µs for (a) and (b), ≤ 0.95 µs for (c); one outlier round in (b) at sparse M 32). (b) is the fastest_fskconfig per shape and M from a sweep over tile, tile_k, buffers, warps and split 2/4/8 (256 configs that fit in LDS). Consumers as in ROCm/ATOM#2988: sparse QKV →fused_qknorm_idxrqknorminsert mode (#8011), dense QKV → ATOM'striton_fused_norm_rope_cache, gate/up → ATOM'sswiglu_oai_split; the KV caches are bf16. The script is outside this PR.The deferred design is faster on 21 of 24 rows, by 0.1–1.2 µs per layer (median 0.5).
_fskwins only on dense QKV at M 1 and 4 (0.3 and 0.2 µs), and ties at sparse QKV M 64. Its in-kernel exchange (peer rows through L2 behind a cluster barrier, every split waiting for the slowest) costs more than the consumer spends summing the partials. So this PR keeps the deferred API.Testing
GPU runs on one MI455X. The library files of the head (87a18c5) are those of 92397e7, the merge of main 4960107, where
op_tests/test_gemm_a8w8_splitk_deferred.pypassed on MI455X. 87a18c5 changes only that test's timeddeferredcandidate, which now claims the partials inside the timed call; the test has not been rerun on a GPU since. Thetest_gemm_a8w8.py --no-legacysweep is from b6892c5, before the merge.op_tests/test_gemm_a8w8_splitk_deferred.py(an aiter op test run aspython3 <file>: one@benchmarksweep with a summary table of us / TFLOPS / TB/s / err per candidate): 21 GEMM cases, sparse QKV, dense QKV and gate/up at M 1–64, split 4 and 8. The deferred GEMM + reduce is bitwise equal togemm_a8w8_bpreshufflein every case, and every candidate is within 1% + 0.1 per element of an fp32 torch reference. It also checks the hand-off: the partials are handed out once, andgemm_a8w8_bpreshuffle_splitk_reduceclaims them itself and returns a finished tensor as it is. It fails if no case actually splits K.check_handoff_tablein the same file runs on every arch, also underpython3 <file>, so CI executes it: both FlyDSL launchers are stubbed and it checks claim-once, the leading-row-slice claim, that five other views raise, that eviction reduces the oldest output, and that off gfx1250 the deferred GEMM returnsgemm_a8w8_bpreshuffle's output. Passes on MI455X, and on a GPU-less host with the arch set to gfx950 (AITER_AOT_REPLAY=1 GPU_ARCHS=gfx950; other cases skipped).op_tests/test_gemm_a8w8.py --no-legacyruns every FlyDSL shape of the gfx1250 tuned bpreshuffle CSV throughgemm_a8w8_bpreshuffle, whose split-K reduce now goes through the shared launcher. All 451 shapes pass. 177 are within atol/rtol 1e-2 of the fp32 reference; 274 have up to 2.4% of elements outside it from bf16 rounding (largest absolute difference 0.094). None fails the catastrophic check.Not covered
partials=form is explicit.deferredcandidate changed, so its us / TFLOPS / TB/s columns are not re-measured.test_gemm_a8w8.py --no-legacywas last run at b6892c5, before the merge of main.PR Self-Review
Reviewed revision
87a18c5
Behavior and intent
gemm_a8w8_bpreshuffle_splitk_deferred(...): for the gfx1250 FlyDSL PTPC FP8 GEMM with split 2/4/8, fp8 operands, bf16 output, unpadded K and M <=max_m(default 64), it skips thegemm_a8w8_splitk_reducelaunch and leaves the fp32 partials for the consumer (gemm_a8w8_bpreshuffle_splitk_partials(y)), or finishes in place withgemm_a8w8_bpreshuffle_splitk_reduce(y). Every other call returnsgemm_a8w8_bpreshuffle's output._gemm_a8w8_bpreshuffle_into(_bpreshuffle_config).run_preshuffle_gemm_a8_gfx1250/run_gemm_a8w8_bpreshuffle_gfx1250accept a callerpartials=buffer; without it they behave as before.[split_k, M, N]tensor would have a data-dependent shape there. The docstring states this, the three misuses nothing detects (output read before its claim, copy of an unclaimed output, consumer outside the producer's graph) and the memory behind the output._fsk) was measured per layer on the M3 shapes and loses on 21 of 24 rows (table in the description), so the deferred API stays.Validation and unverified scope
op_tests/test_gemm_a8w8_splitk_deferred.py: the timeddeferredcandidate claims the partials inside the timed call (claimed(...), a host pop with no launch), so no output stays listed and none is evicted. Host trace with both FlyDSL launchers stubbed, 104 calls a shape over three shapes: the old candidate launched the standalone reduce in 40 of 104 calls on the first shape and 103 of 104 on the later ones, with 64 outputs left listed; the new one in 0 of 104, with none listed.check_handoff_tablepasses on the same host;black --checkandruff checkpass on the file.rocm/fw-bringup:gfx1250-minimax-m3-20261112:python3 op_tests/test_gemm_a8w8_splitk_deferred.pyexits 0; 21 shapes (sparse QKV, dense QKV, gate/up; M 1-64; split 4 or 8), three candidates each bitwise equal togemm_a8w8_bpreshuffleand err 0 against the fp32 reference; the claim check and the hand-off check pass, through main's AOT cache launchers.aiter/ops/flydsl/bpreshuffle_gemm_gfx1250.py: main's [FlyDSL] [gfx1250] Launch the GEMM and grouped-MoE kernels through the AOT cache #8678 launches the GEMM and the split-K reduce through the AOT cache launchers, so_launch_splitk_reducetakessplitk_reduce_launcher.lazy(split_k, out_dtype, "f32"), the call main's own reduce makes.AITER_AOT_REPLAY=1 GPU_ARCHS=gfx950 python3 op_tests/test_gemm_a8w8_splitk_deferred.py, aiter's native enum module stubbed): the hand-off check passes, then the sweep is skipped for the arch, exit 0; CI runs it this way on every arch.python3 op_tests/test_gemm_a8w8.py --no-legacyover all 451 FlyDSL shapes of the gfx1250 tuned CSV (reduce via the shared launcher): none fails; 177 within 1e-2, 274 with up to 2.4% of elements off by bf16 rounding (max 0.094).python3 -m pytest -q tests/model_ops/test_splitk_consumer_reduce.py tests/model_ops/test_splitk_consumer_claims.py: 21 passed.deferredcandidate's timing columns are not re-measured);test_gemm_a8w8.py --no-legacyand the ATOM tests after the merge of main; CI GPU cases (MI300X/MI35X, where the GPU cases skip); a caller-owned workspace in ATOM's compiled graph (not built; only a CPU toy of the op boundary was run).PR-specific question
What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
test_gemm_a8w8_splitk_deferred.pyis new and calls APIs added here (gemm_a8w8_bpreshuffle_splitk_deferred,gemm_a8w8_bpreshuffle_splitk_partials,gemm_a8w8_bpreshuffle_splitk_reduce), so it cannot run before this PR.test_gemm_a8w8.pychecks the finished GEMM against an fp32 reference with tolerance; it never exposes unreduced partials or the claim/hand-off contract, and it does not check bitwise equality between the deferred and two-kernel paths.Changed op tests
op_tests/test_gemm_a8w8_splitk_deferred.py(new)gemm_a8w8_bpreshuffleon MiniMax-M3 decode shapes at split 4/8; partials handed out once;gemm_a8w8_bpreshuffle_splitk_reduceclaims them itself and passes a finished tensor through unchanged; on every arch, the host-side hand-off table (rejected views raise, eviction reduces) and the off-gfx1250 fallback.test_gemm_a8w8.pyonly checks finished outputs within tolerance.