Skip to content

[HIP] [FlyDSL] [gfx1250] Optimize native MXFP8 GEMM across M regimes - #8273

Open
XiaobingSuper wants to merge 16 commits into
ROCm:mainfrom
XiaobingSuper:xiaobingsuper/gfx1250-mxscale-fp8-kernel-20261119
Open

XiaobingSuper wants to merge 16 commits into
ROCm:mainfrom
XiaobingSuper:xiaobingsuper/gfx1250-mxscale-fp8-kernel-20261119

Conversation

@XiaobingSuper

@XiaobingSuper XiaobingSuper commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What

gfx1250 FlyDSL kernels for the native E4M3 / E8M0 1x32 MXFP8 GEMM, a tuner that picks one per shape, and the tuned rows. A tuned row names its kernel; shapes without a row keep main's heuristic.

Kernel File M Idea
Streaming gemm_a8w8_mx32_stream_gfx1250.py <= 16 weights straight into VGPRs, wave partials summed in wave order
Decode mxfp8_decode_gemm_gfx1250.py <= 128 weights into VGPRs, activation in LDS by TDM, K split over K-waves
Balanced decode (skdec) mxfp8_skdec_gemm_gfx1250.py <= 32 only the weight stream on the vector path; activation and scales by TDM (optional cluster multicast); a cluster splits K evenly; outputs stored after the last weight load
Full-M (fullm) mxfp8_fullm_gemm_gfx1250.py 48-128 one workgroup holds every row, each weight byte read once; a cluster splits K and shares the activation by multicast
Direct gemm_a8w8_gfx1250.py any cluster-fused split-K summed in split order; LDS reads two K steps ahead (_pd2); non-temporal weight loads when one M tile covers M
Compute gemm_a8w8_256x256_gfx1250.py >= 256 tiles 128x192, 192x192, 256x192 (fill 256 CUs where 256-wide tiles leave CUs idle) and 256x384 (128x192 per wave, fewer LDS bytes per WMMA); cluster-fused split-K on the 192-wide tiles; early A / B merge, ragged last N tile, L2 prefetch (_pf)

Compute-kernel options, each a tuner candidate with the default kernel unchanged: split pipeline fence (_sf, two TDM loads in flight on two-slot pipelines), one wave order (_wo1 / _wo2), N-major cluster numbering (_nm).

  • Tuner (gemm_a8w8_mxfp8_bpreshuffle_tune.py): times every legal kernel of a shape in a CUDA graph with events; each launch reads its own weight copy (about 1.2 GB in total, so weights are not cache-resident, as in a model) while the activation and the output stay hot. A candidate replaces the current row only if it wins every paired round and the median by --min-gain-pct (2%). run_perftest is unchanged.
  • Dispatch: rows naming a streaming, decode, skdec or fullm kernel run through the B = 1 batched runner, in both gemm_a8w8_blockscale(isBpreshuffled=True) (kernelId=bmm) and gemm_a8w8_mxfp8_bpreshuffle. The 1x32 lookup skips a row whose kernel cannot launch at the real M.
  • Rows: 315 gfx1250 rows in minimax_m3_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv and 36 in dsv4_a8w8_mxfp8_bpreshuffle_tuned_gemm.csv; no gfx950 row changes.
  • AOT: every kernel above launches through the FlyDSL AOT cache: the direct, compute and split-K reduce launches through main's launcher factories ([FlyDSL] [gfx1250] Launch the GEMM and grouped-MoE kernels through the AOT cache #8678), with the new constexprs coerced to one type, and the streaming, decode, skdec and fullm launches through four new aot_factory caches (keyed on the torch.device, so one entry serves every GPU). aiter/aot/flydsl/sources.py declares their sources, including the fused split-K epilogue the direct kernel imports.
  • Fix: the per-token gfx1250 GEMM passes the new arg_out runtime argument like the other callers.

The C-tile LDS read-back is not here; #8486 carries it.

Results

MI455X, ROCm 10.3.0, torch 2.13, FlyDSL 0.5.3, production entry with 1x32 scales, us per call in a CUDA graph, weights not cache-resident.

This revision's kernels and tables against the previous revision (f3767ec), all 351 gfx1250 rows, old and new processes alternating, 4 rounds (measured before the rebase onto main, which changes no kernel; since then 3 MiniMax rows that used an eight-wave option, dropped as too narrow, were retuned, 0.9-5.1% slower each, +0.5 us in total):

M rows total us, before -> after speedup (total) geomean
<= 16 77 405.7 -> 366.6 1.107 1.104
17-47 27 190.1 -> 168.8 1.126 1.129
48-128 56 423.6 -> 375.8 1.127 1.121
160-192 14 184.8 -> 178.8 1.034 1.043
256-2048 109 2644.1 -> 2486.2 1.063 1.053
>= 4096 68 18577.2 -> 17028.9 1.091 1.134
all 351 22425.5 -> 20605.0 1.088 1.095

250 rows name another kernel (1.096 total, 1.132 geomean); the other 101 are unchanged (1.007). Outputs are bit-identical to the previous revision on 232 rows; the 119 others changed kernel and differ by at most 1.7e-3 relative. The previous revision was 1.046 (total) over the first one.

After the rebase onto main (AOT launch path of #8678), 41 rows across all M segments against the pre-rebase head, 2 rounds: 1.000 total, 0.996 geomean; two small-M direct rows (10x9856x6144, 20x24576x6144) measured 3-6% slower. Their kernel binaries, launch arguments, allocations and outputs are identical; the same kernel runs at one of two discrete speeds set by host-side process history unrelated to the GEMM (replaying the graph on another stream, importing another module first or a single hardware queue flips it either way), and the new launch path, which imports only the kernel module it launches, lands on the slow one more often in this harness.

Against main, measured at the first revision (5b674a1) and not re-measured since; main has no gfx1250 rows for these shapes:

M N K main first revision speedup
1 2560 6144 7.65 3.24 2.36x
16 6144 6144 8.13 5.23 1.55x
64 2304 6144 7.85 5.39 1.46x
1024 2304 6144 18.41 13.19 1.40x
4096 2944 6144 46.00 28.38 1.62x
32768 2560 6144 215.35 157.91 1.36x

Reviewed revision

ff556f4

Behavior and intent

On gfx1250, a 1x32 MXFP8 shape with a tuned row runs the kernel the row names; shapes without a row keep main's heuristic. gfx950 and 128x128 paths are unchanged. There is no separate entry point for the small-M kernels: they run exactly where a tuned row selects them. Split-K, K-wave and cluster partials are summed in a fixed order, so repeated calls give the same bytes.

Validation and unverified scope

One MI455X (ROCm 10.3.0, FlyDSL 0.5.3), on this revision's code (the rebase onto the latest main changed none of this PR's files):

  • all 351 gfx1250 rows through the production entry (gemm_a8w8_blockscale(isBpreshuffled=True) for MiniMax-M3, gemm_a8w8_mxfp8_bpreshuffle for DSV4), twice each: all pass (finite, repeats bit-identical, within the fp32-reference tolerance, dispatched kernel == row's kernel); outputs identical to the previously validated revision except the 3 retuned rows, also when served from the AOT cache;
  • every row's kernel is a tuner candidate and launchable; kernel IDs and names are unique;
  • python op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py: exit 0, no mismatch, including the new checks;
  • AITER_GEMM_TEST_ITERS=1 python op_tests/test_gemm_a8w8.py: exit 0. One earlier run reported a catastrophic delta on ptpc 32768x7168x16384, a row of a8w8_bpreshuffle_tuned_gemm.csv this PR does not touch; it did not recur in a rerun or in 30 repeats on this branch or on main;
  • pytest op_tests/test_graph_alloc.py: 4 passed, 3 skipped;
  • pytest tests/test_flydsl_aot_launch.py tests/test_flydsl_aot_cache.py tests/test_flydsl_aot_replay.py: 88 passed, 6 failed, 5 skipped, the same 6 failures on main in the same container;
  • GPU_ARCHS=gfx1250 python -m aiter.aot.flydsl.gemm --csv <the two tables>: 351 jobs ok, 0 failed, 0 refused (104 scanned in-range M), 250 entries, a second run builds nothing, --check passes; a production call of every kernel family (streaming, decode, skdec, fullm, compute, direct, B = 1 batched, untuned M) then loads its AOT entry with no JIT trace, and AITER_FLYDSL_AOT_CACHE=0 gives the same bytes;
  • black and ruff 0.16.0 clean.

Unverified: the commits one by one (only the final tree ran); the table against main was not re-measured; op_tests/test_gemm_group32_interface.py was not re-run; other GPUs, multi-GPU or model runs; FlyDSL other than 0.5.3.

PR-specific question

Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?

Only gfx1250, E4M3 operands, E8M0 1x32 scales and a (16, 16)-preshuffled weight, through a tuned row. The 1x32 lookup of gemm_a8w8_mxfp8_bpreshuffle checks each row's launch condition at the real M (tile and cluster fit, M >= tile_m for compute kernels, ragged N only where ragged_n_ok allows, each small-M kernel's own config check) and otherwise falls to the next padded row or main's heuristic; the blockscale table keeps main's rule. A row naming a decode, skdec or fullm kernel takes the direct kernel when the output is not bf16 or the A scales are preshuffled, and so does a 256x384 row with preshuffled A scales. The 256x384 and 192-wide fill compute profiles are accepted only for mxfp8_32 tuned rows (allow_wide), never by the untuned fallback. Launchers raise on unsupported configurations; the skdec and fullm checks admit only cluster shapes, wave splits and depths that ran on MI455X, and their workgroups synchronize only through the workgroup and cluster barriers (no spin wait).

Changed op tests

  • op_tests/test_gemm_a8w8.py: two per-token shapes sharing one tuned gfx1250 kernel, each run twice; repeats must match the first launch bit for bit.
  • op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py: a CPU, mocked check that batched, streaming, decode, skdec and fullm rows run the B = 1 batched runner and that preshuffled A scales (also on a 256x384 row) or fp16 output take the direct kernel; on gfx1250, every decode, skdec and fullm kernel the tuner offers for seven shapes against the fp32 reference, with rows past M left unwritten; and, on gfx1250, every 1x32 row of the two tuned tables must name a kernel that launches at its M (the blockscale entry runs rows without that check).
  • op_tests/test_graph_alloc.py: adds the fused split-K workspace to the private-graph-pool check.

🤖 Generated with Claude Code

@XiaobingSuper
XiaobingSuper requested review from a team and a balanced review from Copilot November 19, 2026 06:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 Radeon R9700 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 8273 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@github-actions github-actions Bot changed the title [FlyDSL][gfx1250] Optimize native MXFP8 GEMM across M regimes [FlyDSL] [gfx1250] Optimize native MXFP8 GEMM across M regimes Nov 19, 2026
@aiter-bot

aiter-bot commented Nov 19, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 0f3007c13d4a · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@XiaobingSuper
XiaobingSuper marked this pull request as draft November 19, 2026 07:13
lirui927 pushed a commit that referenced this pull request Nov 20, 2026
lirui927 pushed a commit that referenced this pull request Nov 20, 2026
The stack carried #8273 at 3c157e3. This is its increment to
cd6820a: the narrow-N MXFP8 path (cd6820a), the MiniMax-M3.1 indexer MXFP8
config rows (e83d633), and the removal of the small-M 1x32 kernel that did
not win (c6fb8a3).

Co-authored-by: XiaobingSuper <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
XiaobingSuper added a commit to XiaobingSuper/aiter that referenced this pull request Nov 22, 2026
…68-token fallback rows

The MiniMax-M3.1 TP4 routed MoE (E128 top-4, hidden 6144, inter 768,
MXFP4) rows at token 16384 and 32768 now take the E129 M=32768 cluster
config: 256x256x256 tiles, 2x2 waves for both stages, 3 + 3 buffers,
clusters 2x2 (GEMM1) and 4x4 (GEMM2), next-stage prefetch and LDS SoA
interleave on, no activation preshuffle. These rows serve the two largest
prefill token buckets; all other rows are unchanged.

The `us` column holds each row's own tuning-session value, so the old and
new values are not a like-for-like comparison. The A/B is in-model on
4x MI455X: output bitwise identical to the previous rows standalone; greedy
outputs identical on 3 long prompts; part of a 7.4 ms reduction of a
14336-token prefill on a 99968-token cached prefix (with the QKV MXFP8
rows of ROCm#8273).

Not adopted: the E129 M=8192 config with activation preshuffle measured
about 1 ms more saving but changes greedy outputs in-model; it is left out
pending investigation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
XiaobingSuper added a commit to XiaobingSuper/ATOM that referenced this pull request Nov 23, 2026
…'s decode GEMM (opt-in)

ATOM_M3_FAST_OPROJ=1 (default off, needs ATOM_MINIMAX_M3_PA_MXFP8_OUT). The
sparse layers run o_proj on the paged attention's MXFP8 output (E4M3 + E8M0
per 32) through aiter's gfx1250 mxfp8_decode_gemm (ROCm/aiter#8273), for the
token counts mxfp8_decode_gemm_supported serves (N 6144, K 2048, M <= 128).
Every other count keeps the linear's tuned GEMM.

- The call goes through a custom op, minimax_m3_o_proj_mxfp8, which looks the
  linear up by name. It is opaque to torch.compile, so the kernel is chosen
  per call, by token count, and a CUDA graph keeps the capture's choice.
- The weight conditions are checked at the op's first call and logged once:
  preshuffled E4M3, native 1x32 scales in [N, K/32], no bias, no own
  all-reduce. The weight's layout is settled by process_weights_after_loading,
  after construction.
- Same bytes up to the GEMM's FP32 K order. aiter#8273 reports at least
  99.98% of outputs bit-identical to gemm_a8w8_blockscale, and rel-L2 vs
  fp64 the same.

tests/test_minimax_m3_pa_mxfp8_out.py: the forward routes through the op;
decode rows take the GEMM and larger ones the linear; the weight is judged
at the first call; without a shuffled weight the linear is kept; the op and
its fake look the linear up by name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@XiaobingSuper

XiaobingSuper commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Superseded in part (see the next comment): only the gemm_a8w8_gfx1250 read-back ships; the gemm_a8w8_256x256_gfx1250 part was reverted in fdc7d49 and the grouped MoE PR (#8466) was closed.

Update: pushed 15b5803, a bugfix: the MXFP8 GEMM's C tile now leaves LDS through a ds_load read-back and plain global stores instead of the per-wave TDM store. It is on by default; AITER_TDM_C_LDS_STORE=0 restores the TDM store.

Scope.

  • launch_gemm_a8w8: bf16 / f16 C and unfused split-K partials (kernel name _clds).
  • launch_gemm_a8w8_256x256: the plain C store. Its ragged-N, persistent, relocated, cluster split-K and fused-quant stores keep the TDM store.

Why. It fixes the stray token-0 bug in MiniMax-M3.1 TP4 decode on 4x MI455X.

  • Location. At a bad step (rank 0, layer 45), the shared expert's down_proj output from this GEMM was corrupt only in rows 6-7 of N tile 51, columns 56-63.
  • What the bad bytes were. Those two 16-byte chunks are bit-identical to the FP8 activation bytes of k-tile 4, at the LDS offsets the C tile overlays.
  • Effect. Read as bf16 they are 1e25-1e38, never NaN. The residual is poisoned, RMSNorm outputs 0, the logits row is all zero, and argmax picks token 0.
  • Trigger. It fires when the routed MoE runs concurrently on the other HIP graph queue (dual-stream MoE). It reproduces on the plain integration image.

Evidence. Measured together with the same change in the grouped MXFP4 MoE GEMMs (#8466):

  • zero-row events dropped from 8 of 40 greedy passes to 0 of 40, 0 of 12 high-concurrency passes (384-row batches), 0 over full GSM8K, and 0 of 25 with default buckets;
  • the decode step is unchanged within the ±2% noise (bs1 / 4 / 10 / 16 pairs: 4.838 vs 4.797, 6.286 vs 6.257, 7.557 vs 7.608, 8.494 vs 8.657 ms);
  • GSM8K 0.9545 / 0.9538, and our serving gate passes.

Hardware / compiler note. On gfx1250, the LDS read of tensor_store_from_lds is not ordered behind ds_stores from the other waves of the workgroup, even after s_wait_dscnt 0 and s_barrier_signal / s_barrier_wait.

Re-checked after the rebase. The two files are byte-identical to the validated stack's versions. FlyDSL compile-only for gfx1250 (GPU-less container), through the real dispatchers: all 60 non-fused-split-K MiniMax-M3 mx32 kernelNames of the tuned CSV compile (wmma, compute_wmma, small_wmma and batched bmm); a negative control shows both read-back blocks are traversed. The one fused split-K name could not be exercised without a GPU stream; the read-back is off on that path anyway. py_compile, black and ruff (no new findings) are clean. Not re-run on GPUs.

@XiaobingSuper

Copy link
Copy Markdown
Contributor Author

Update: pushed fdc7d49, which narrows the bugfix to gemm_a8w8_gfx1250 only. It reverts the read-back in gemm_a8w8_256x256_gfx1250 from 15b5803, so that kernel keeps its TDM C store. The branch now carries exactly the validated fix: launch_gemm_a8w8's read-back, on by default, with AITER_TDM_C_LDS_STORE=0 restoring the TDM store.

Why narrowed. The 256x256 and grouped-MoE read-backs cost about 4% of prefill time (uncached prefill TTFT +3.7-4.5%, C64 P90 274.7 vs 281-283). No failure was ever observed in those kernels: all located events were in launch_gemm_a8w8, the non-fold GEMM2 op test was 0 / 12,000, and 0 / 12 high-concurrency passes at 384-row batches ran without the fix. They stay listed as a latent risk in the body's hardware / compiler note.

Re-checked. The launch_gemm_a8w8 change differs only in a comment from the version compiled earlier (FlyDSL compile-only, every mx32 non-fused-split-K kernelName of the M3 table). The 256x256 file is back to its previous content. Not re-run on GPUs.

XiaobingSuper added a commit to XiaobingSuper/aiter that referenced this pull request Nov 23, 2026
…e2e9)

Scope decision for the stray token-0 fix: only the read-back in
gemm_a8w8_gfx1250 ships (ROCm#8273); the grouped MoE PR (ROCm#8466) is
closed. This reverts both commits that brought it here:
- f3c9c30, the `cq_lds_store` wiring for launch_gemm_a8w4_tdm_tpg;
- the merge 77be2e9 of the grouped GEMM1 / GEMM2 read-back
  (`_c_lds_store`, `cq_lds_store`).

The grouped MoE read-back cost about 4% of prefill time (uncached prefill
TTFT +3.7-4.5%, C64 P90 274.7 vs 281-283), and no failure was ever observed
in these kernels. They keep the TDM store, a latent risk recorded in
ROCm#8273's hardware / compiler note. This branch's tree is again that of
9baf599.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@aoli26

aoli26 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

MiniMax M3 1x32 gfx1250 table retune

Pushed two commits on top of fdc7d4989 (fast-forward). They only merge origin/main and retune the M3 CSV; no kernel or tuner code is changed beyond the merge resolution.

  1. b5539e41f: merge origin/main (2eb9ef365, includes [FlyDSL] [gfx1250] Compute GEMMs: cluster_m as a launch argument, DSv4.1 Flash prefill rows #7868/[FlyDSL] [gfx1250] DSv4.1 Flash 32x32 GEMMs: tune C1024 decode, prefetch a8w8/a4w4 compute kernel code #7827). Two textual conflicts are resolved, and bounded_m is dropped as [FlyDSL] [gfx1250] Compute GEMMs: cluster_m as a launch argument, DSv4.1 Flash prefill rows #7868 did because it no longer has a reader (generated code unchanged). The PR is mergeable again.
  2. 8fa71a58c: retune the M3 table. 67 of the 132 gfx1250 rows get a different kernel and the other 65 keep yours. Only the CSV changes.

Result (gemm_a8w8_blockscale_bpreshuffle, CUDA graph; speedup over this PR's previous table, geomean; cold = weights not cached, hot = same weights replayed as in the tuner):

key M rows cold hot
all 132 rows 132 +14.0% +4.6%
≤ 16 40 +5.4% +2.1%
32–128 32 +42.3% +14.7%
256–1024 24 +15.1% +2.4%
≥ 2048 36 +1.6% +0.3%

The 356 sampled M values inside the served ranges give +16.1% cold and +5.5% hot. The 67 changed rows give +29.9% cold and +9.3% hot. Best single points: 6144×768 M=256 +93% (6.5 → 3.4 µs), 2304×6144 M=1024 +88% (24.9 → 13.3 µs).

The gain comes from cluster variants of the generic kernel (28 rows) and fused split-K tile and sk choices (24 rows), selected under both cold and hot timing. Your stream/decode rows (M ≤ 8, o_proj) and the large-M compute rows are mostly kept. A replacement had to satisfy cold ≥ 0.98x and hot ≥ 0.95x at its key M, and cold ≥ 0.97x and hot ≥ 0.93x at every sampled M in its range.

Checks: dense functional matrix 6312/6312 (full output written, finite, bitwise repeatable, max nRMSE 1.7e-3); black --check . is clean.

Unrelated to the table

  • run_preshuffle_gemm_a8_gfx1250 (ptpc) does not pass the new runtime arg_out, so every call after the first raises IndexError. It affects 451 gfx1250 table rows. The 2-line fix is ready.
  • The ruff job fails on two I001 import-order findings, in batched_gemm_a8w8_gfx1250.py:29 and mxfp8_decode_gemm_gfx1250.py:83. They are identical on fdc7d4989 and untouched here; ruff check --select I --fix on those two files clears them.
  • Three test_gemm_group32_interface.py tests fail on current origin/main as well.

XiaobingSuper added a commit to XiaobingSuper/ATOM that referenced this pull request Nov 23, 2026
…'s decode GEMM

When the NVFP4 sparse layers' paged attention writes o_proj's MXFP8 input
(ATOM_MINIMAX_M3_PA_MXFP8_OUT) and aiter has mxfp8_decode_gemm
(ROCm/aiter#8273), o_proj runs through a custom op that takes aiter's gfx1250
decode GEMM for the token counts mxfp8_decode_gemm_supported serves (N 6144,
K 2048, M <= 128) and keeps the linear's tuned GEMM otherwise.

- The op is opaque to torch.compile, so the kernel is chosen per call by token
  count; a CUDA graph keeps the capture's choice.
- The weight conditions (gfx1250 and (N, K) served, preshuffled E4M3, native
  1x32 scales in [N, K/32], no bias, no own all-reduce) are checked at the
  op's first call, after process_weights_after_loading, and logged once.
- Same bytes up to the GEMM's FP32 K order: at least 99.98% of outputs are
  bit-identical to gemm_a8w8_blockscale, rel-L2 vs fp64 the same.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@XiaobingSuper
XiaobingSuper marked this pull request as ready for review November 26, 2026 09:55
Copilot AI balanced review requested due to automatic review settings November 26, 2026 09:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions github-actions Bot changed the title [FlyDSL] [gfx1250] Optimize native MXFP8 GEMM across M regimes [HIP] [FlyDSL] [gfx1250] Optimize native MXFP8 GEMM across M regimes Nov 26, 2026
@github-actions github-actions Bot added the HIP label Nov 26, 2026
@XiaobingSuper
XiaobingSuper force-pushed the xiaobingsuper/gfx1250-mxscale-fp8-kernel-20261119 branch from 36a3368 to 6d28766 Compare November 30, 2026 06:21
Copilot AI balanced review requested due to automatic review settings November 30, 2026 06:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@XiaobingSuper
XiaobingSuper force-pushed the xiaobingsuper/gfx1250-mxscale-fp8-kernel-20261119 branch from 6d28766 to ff556f4 Compare December 2, 2026 07:38
Copilot AI balanced review requested due to automatic review settings December 2, 2026 07:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@XiaobingSuper

Copy link
Copy Markdown
Contributor Author

Rebased onto main (a84010d11) as 16 linear commits, head ff556f4aa. The earlier history and its merges are folded into the first commit and the tables commit, which keeps Co-authored-by for lirui927 and aoli26 (their MiniMax-M3 rows and retune). The comments above from Nov 23 refer to commits that are no longer on the branch:

Since the last description: the eight-wave _kw2 option is dropped (it served 3 rows; they were retuned), the skdec / full-M kernels share their 2-D TDM load and input checks, and the streaming, decode, skdec and fullm launches go through the AOT cache like the other gfx1250 a8w8 launches.

Reproducing the timings in the description. The script below times the gfx1250 1x32 rows of the two tables through the production entries as the description's A/B did (CUDA graph, every call on its own weight copy, about 1.2 GB of weight in all, activation and output hot, 1 s idle, median of 3 replays). For an A/B, run it alternately from the two trees on one GPU, swapping the order every round, and compare per-row medians (usage in the docstring).

ab_gfx1250_mxfp8.py
"""Time the gfx1250 MXFP8 1x32 rows of the tuned tables through the production entries.

usage: python ab_gfx1250_mxfp8.py <label> [all | <rows file>]
  rows file: one "table M N K" per line, table = mm (MiniMax-M3, gemm_a8w8_blockscale
  with isBpreshuffled=True) or ds (DSV4, gemm_a8w8_mxfp8_bpreshuffle).

Per row: a CUDA graph of `iters` calls, each reading its own copy of the weight and its
scales (>= ~1.2 GB of weight in all, so weights are not cache-resident, as in a model;
the activation and the output stay hot), 1 s idle, then the median of 3 replays.
Prints "AB <label> <table> M N K <us per call>".

A/B of two trees on one GPU: run it alternately from each tree, swapping the order
every round, and compare per-row medians, e.g.
  for r in 1 2 3 4; do
    order="base new"; [ $((r % 2)) -eq 0 ] && order="new base"
    for t in $order; do PYTHONPATH=$t python ab_gfx1250_mxfp8.py $t all; done
  done
"""

import csv
import math
import os
import statistics
import sys
import time

import aiter
import torch
from aiter.ops.gemm_op_a8w8 import gemm_a8w8_mxfp8_bpreshuffle
from aiter.ops.shuffle import shuffle_mxfp8_bpreshuffle_scale, shuffle_weight

CONFIGS = os.path.join(os.path.dirname(aiter.__file__), "configs", "model_configs")
TABLES = {
    "mm": "minimax_m3_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv",
    "ds": "dsv4_a8w8_mxfp8_bpreshuffle_tuned_gemm.csv",
}
ENTRIES = {
    "mm": lambda x, w, xs, ws: aiter.gemm_a8w8_blockscale(
        x, w, xs, ws, isBpreshuffled=True
    ),
    "ds": gemm_a8w8_mxfp8_bpreshuffle,
}
COLD_BYTES = 1.2e9


def table_rows():
    for table, name in TABLES.items():
        with open(os.path.join(CONFIGS, name)) as f:
            for r in csv.DictReader(f):
                if r["gfx"] == "gfx1250" and r["w_scale_block"] == "1x32":
                    yield table, int(r["M"]), int(r["N"]), int(r["K"])


def data(m, n, k, seed):
    g = torch.Generator(device="cuda").manual_seed(seed)
    w = (torch.randn(n, k, device="cuda", generator=g) * 0.5).clamp(-8, 8)
    x = torch.randn(m, k, device="cuda", generator=g).clamp(-8, 8)
    ws = torch.randint(118, 126, (n, k // 32), device="cuda", generator=g)
    xs = torch.randint(120, 127, (m, k // 32), device="cuda", generator=g)
    e8m0 = torch.float8_e8m0fnu
    return (
        x.to(torch.float8_e4m3fn),
        shuffle_weight(w.to(torch.float8_e4m3fn), layout=(16, 16)),
        xs.to(torch.uint8).view(e8m0),
        shuffle_mxfp8_bpreshuffle_scale(ws.to(torch.uint8).view(e8m0)),
    )


def time_row(table, m, n, k):
    fn = ENTRIES[table]
    x, w, xs, ws = data(m, n, k, m * 131 + n * 7 + k)
    copies = max(2, min(256, math.ceil(COLD_BYTES / (n * k * 33 / 32))))
    iters = max(64, min(256, copies))
    weights = [(w, ws)] + [
        (w.clone(), ws.clone()) for _ in range(min(copies, iters) - 1)
    ]
    fn(x, w, xs, ws)  # compile
    side = torch.cuda.Stream()
    side.wait_stream(torch.cuda.current_stream())
    with torch.cuda.stream(side):
        for wi, wsi in weights[:2]:
            fn(x, wi, xs, wsi)
    torch.cuda.current_stream().wait_stream(side)
    graph = torch.cuda.CUDAGraph()
    with torch.cuda.graph(graph):
        for i in range(iters):
            wi, wsi = weights[i % len(weights)]
            fn(x, wi, xs, wsi)
    graph.replay()
    torch.cuda.synchronize()
    time.sleep(1.0)  # idle before timing: back-to-back heavy kernels throttle clocks
    times = []
    for _ in range(3):
        start, end = (torch.cuda.Event(enable_timing=True) for _ in range(2))
        start.record()
        graph.replay()
        end.record()
        end.synchronize()
        times.append(start.elapsed_time(end) * 1000 / iters)
    return statistics.median(times)


def main():
    label = sys.argv[1]
    which = sys.argv[2] if len(sys.argv) > 2 else "all"
    if which == "all":
        rows = list(table_rows())
    else:
        with open(which) as f:
            rows = [
                (p[0], *map(int, p[1:4])) for p in (line.split() for line in f) if p
            ]
    for table, m, n, k in rows:
        us = time_row(table, m, n, k)
        print(f"AB {label} {table} {m} {n} {k} {us:.4f}", flush=True)
        torch.cuda.empty_cache()


if __name__ == "__main__":
    main()

XiaobingSuper pushed a commit that referenced this pull request Dec 2, 2026
…full-M ks 3 clusters

Brings the three B = 1 kernels of #8273 (head 6d28766, pre-AOT
launchers of f436c5d) to this branch so tuned 1x32 rows can name them:

- kernels/mxfp8_skdec_gemm_gfx1250.py, kernels/mxfp8_fullm_gemm_gfx1250.py (new)
  and kernels/mxfp8_decode_gemm_gfx1250.py (#8273's, a superset: kint, relaxed
  TDM chunk rule);
- mxfp8_decode_gemm_gfx1250.py: #8273's name / parse / launchable / candidate /
  run helpers for the three kernels; the fixed-table mxfp8_decode_gemm entry
  that ATOM's MiniMax-M3 TP4 o_proj calls (ATOM_M3_FAST_OPROJ) stays as it was;
- batched_gemm_a8w8_gfx1250.py: the B = 1 runner launches a decode, skdec or
  full-M kernelName the way it launches the streaming kernel.

Full-M also takes a 3-rank K split, (cn 1, ks 3), and wave splits (2, 1),
(4, 1), (4, 2): on MI455X they fill 231 of 256 CUs for N 9856 (77 slices x 3),
where ks 2 leaves 176 busy. The split-K reduce gives rank r the float4s from
r * TILE_F // ks on, so shares stay balanced when ks does not divide the tile;
for ks 1, 2 and 4 that is the old split, and the generated code of existing
configs is unchanged. The tuner's full-M candidates gain the ks 3 shapes.

op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py: #8273's per-candidate check of
the decode / skdec / full-M kernels against the fp32 reference (rows past M
untouched), with the DP-attention o_proj (6144 x 8192) and QKV (9856 x 6144)
shapes at 96 and 128 rows, which run the ks 3 split; and every MiniMax-M3
blockscale row naming one of these kernels must launch at its M.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
XiaobingSuper and others added 16 commits December 3, 2026 20:46
… options

The gfx1250 FlyDSL work for the native E4M3 / E8M0 1x32 MXFP8 GEMM that the
following commits build on (tables come last):

* Tuner (gemm_a8w8_mxfp8_bpreshuffle_tune.py): gfx1250 1x32 shapes over
  every legal direct, B = 1 batched, weight-streaming and decode kernel,
  timed in a CUDA graph over rotating weight copies (weights not
  cache-resident, as in a model); a candidate replaces the current row only
  if it wins every paired round and the median by --min-gain-pct (2%). The
  launch check and the tuner accept every tuned kernel that can launch at
  the real M.
* Compute kernel: 192-wide tiles, early A / B TDM merge, a 256x128 tile with
  M-only clusters for narrow N, a ragged last N tile (cluster_m 1, split-K
  1), wider A-scale panels for four-slot K loops, and an optional L2
  prefetch of the next-but-one K step, deduplicated within the cluster
  (_pf1 / _pf2).
* Direct kernel: cluster-fused split-K for 2-D mxfp8_32, summed in split
  order, with a per-stream graph-safe workspace; optionally issues its LDS
  reads two K steps ahead (_pd2), same WMMA order.
* Weight-streaming kernel for M <= 16: the preshuffled weight goes straight
  into VGPRs; wave partials are summed in wave order. Streaming and decode
  kernels can interleave K steps across K-waves (_ki).
* Decode kernel for M <= 128: weights straight into VGPRs, the activation in
  LDS by TDM, K split over up to 16 K-waves summed in wave order.
* Dispatch: tuned rows naming a batched, streaming or decode kernel run
  through the B = 1 batched runner, in gemm_a8w8_blockscale(isBpreshuffled=
  True) (kernelId bmm) and gemm_a8w8_mxfp8_bpreshuffle; the 1x32 lookup of
  the latter skips a row whose kernel cannot launch at the real M.
* Fix: the per-token gfx1250 GEMM passes the new arg_out runtime argument
  like the other callers.
* Op tests: a repeat check on two per-token shapes, a mocked B = 1 dispatch
  check, every decode candidate of five shapes against fp32, and the fused
  split-K workspace in the private-graph-pool check.

The direct, compute and split-K reduce launches go through main's AOT
launcher factories (gemm_a8w8_launcher, _gemm_a8w8_compute_bound_launcher,
splitk_reduce_launcher); the streaming and decode kernels launch on the JIT
path, as the other kernels no replay prebuilds. The direct kernel's cache
(aiter/aot/flydsl/sources.py) now declares the fused split-K epilogue it
imports.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A steady refill used one fence per slot boundary: each wave waited for its
TDM load of the next slot, then the barrier, then issued the refill of the
freed slot. A two-slot pipeline so kept one load in flight per wave, and
30-38% of the steady loop sat in s_wait_tensorcnt on cold weights.

_sf splits the fence: a first barrier only frees the slot, the refill is
issued, then each wave waits for its next-slot load and a second barrier
publishes it. Two loads are in flight: the TDM wait share drops to 16% and
the steady loop from 15.1 to 12.3 cycles per WMMA on 8192x6144x12288. The
WMMA order and the outputs are unchanged.

The extra barrier does not pay on four-slot or L2-prefetch kernels (0.5-4%
slower), so _sf is a tuner option of the two-slot compute profiles, after
every existing kernel ID, and never the untuned fallback.

Co-Authored-By: Claude Code <[email protected]>
A launch whose grid reads every weight byte once marks those loads
non-temporal (th=1), as the decode kernel already does:

* direct / B=1 batched kernel: the B tile's TDM load, when one M tile (or
  one cluster of M tiles sharing B by multicast) covers M; not with the
  clustered split-K epilogue (_fsk), where it measured 3-10% slower;
* streaming kernel: the weight buffer loads, when one 16-row tile covers M;
* split-K reduce kernel: the partial loads (each is read exactly once).

It is a compile-time flag picked per launch from M; kernel names, the
tuner's candidates and the outputs are unchanged. Only mxfp8_32 launches of
the direct kernel change.

MI455X, production entry in a CUDA graph, weights not cache-resident, old
and new alternating, median of 6 rounds: the 81 affected rows 564.3 ->
554.5 us (1.018, 0.96-1.11 per row); N=24576 rows 1.03-1.06, t128x128x256
split-K rows 1.04-1.10.

Co-Authored-By: Claude Code <[email protected]>
Each of the four waves keeps 96 fp32 accumulators (768 VGPRs) and the
eight A fragments of a K-tile, and streams B in pairs: pass p runs
(i, 2p) and (i, 2p + 1) for the eight A fragments while B pair p + 1
loads into the registers pair p - 1 left. Every fragment is read from
LDS once per K-tile, so a WMMA reads 427 LDS bytes instead of 512, the
TDM writes 213 bytes per WMMA instead of 256, and a grid has one third
fewer tiles. Three slots of one K-tile (271.5 KB of LDS). The previous
K-tile seeds A 0-5, B pair 0 and the scales; A 6-7 load at the start of
the K-tile, and in the last pass the next K-tile's A i loads three
WMMAs after A i's last read. Per output element the WMMA order is that
of the 256x256 kernel, so results are bit-identical. 1024 VGPRs, no
spills. N may end on a partial tile as for the other compute profiles.

The tuner appends the 24 variants (six clusters, four early-merge
choices) after every existing kernel ID, for mxfp8_32 tuned rows only:
kernel_fits_shape accepts the profile only with allow_wide, which the
mxfp8_32 check passes and the untuned fallback and mxfp8_128 do not.

Co-Authored-By: Claude Code <[email protected]>
…ters (_nm)

The compute kernel's waves alternate between two quadrant orders by wave
parity. _wo1 / _wo2 run every wave in the even or the odd order; on 128x256
and 192x256 tiles the odd waves finish a K step later and the barrier waits
for them. _nm numbers whole clusters N-first, so the clusters that read the
same B strip start apart in the dispatch window. Every accumulator sees the
same K order either way, so outputs are bit-identical to the base kernel.

The tuner derives both for split-K-1, non-persistent compute candidates
(kernelId 8_000_000 + 8 * catalog id + variant: _wo1, _wo2, _nm, _wo1_nm,
_wo2_nm); default launches compile as before. The 256x384 kernel runs one
schedule on every wave, so it takes only _nm.

Co-Authored-By: Claude Code <[email protected]>
Many M 256-2048 shapes leave CUs idle on the 256-wide tiles: 1024x6144 is
192 128x256 tiles on 256 CUs, but 256 128x192 ones; 1536x6144 is 192
192x256 tiles, but 256 192x192 ones. A grid that covers every CU also
spreads the load evenly; with a quarter of the CUs idle a single cluster
often runs 1.4x slower than the rest and sets the kernel time.

New compute profiles: 128x192 and 192x192 with three slots of two K-tiles,
256x192 with four slots of one K-tile (as 256-wide four-slot tiles). Three
192-row slots take two-step A-scale panels; four-step ones overflow LDS by
1.8 KB. The tuner catalog appends their 72 kernels (six clusters, four
early-merge choices, split_k 1) after every existing ID. The K order of
every accumulator is unchanged, so outputs match the 256-wide kernels bit
for bit; existing kernels compile to the same ISA.

Co-Authored-By: Claude Code <[email protected]>
A decode-shaped kernel that keeps the weight stream on the vector memory
path alone and moves the rest off it:

* the activation tile, its scales and the workgroup's weight scales go to
  LDS by TDM (optionally shared across a cluster by multicast, "_mc"); the
  decode kernel loads a weight scale with a vector load every K step;
* the W waves of a workgroup take interleaved K steps of one 16-column block
  at a time with D steps of weight loads in flight a wave (fewer, deeper
  waves stream best: W 4-8, D 6-12);
* a cluster of C workgroups splits its Q blocks into C equal runs of K steps
  in address order (stream-K); a head piece is streamed first and its FP32
  partial published, the matching tail piece is streamed last and adds it,
  so the exchange is off the critical path;
* finished blocks are reduced over the waves through LDS and kept in VGPRs;
  all outputs are stored after the last weight load (a store between weight
  loads makes its wave wait for the whole load queue: 1.5 us on 4x24576x6144).

Name flydsl_mxfp8_32_bpreshuffle_skdec_t{tile}_c{C}_q{Q}_w{W}_d{D}[_mc], run
through the B=1 batched runner like the decode kernel (bf16 only). The tuner
offers it per shape (ids 3_980_000+): tile 16 up to M 16, else 32 (one
workgroup set per 32 rows), C 1/2/4/8, the largest grid per C, W/D 16/3,
8/6, 8/8, 4/12, with and without multicast. The config check keeps to what
ran on MI455X: clusters of at most 8 (a sweep with 16-workgroup clusters,
2-wave and 16/24-deep variants never finished), 4..32 waves, depth <= 12.

FP32 sums run in a fixed order (bit-identical across runs); the K order
differs from the other kernels'. The op test runs every offered kernel of
its decode shapes against the fp32 reference.

Co-Authored-By: Claude Code <[email protected]>
The gfx1250 1x32 candidates were timed off a torch.profiler trace of the
CUDA Graph replay, with every input rotated. Kernel tracing slows some
kernels more than others (the 192-wide tiles by 6-7%, older ones by about
1%), and rotating the activation and the output makes them cold too, which
a model forward does not do. Both biased picks against kernels that win
in the production entry.

A small timer in the tuner now captures the graph itself: each launch
reads its own copy of the weight and its scales (about 1.2 GB of weight,
as before), the activation and the output stay one buffer each, and
run_perftest times whole replays with events (use_cuda_event), no
profiler; the tuner divides by the launches per replay. Tuning and
--run_config both use it. run_perftest and other tuners are unchanged.

Co-Authored-By: Claude Code <[email protected]>
M 256-768 x N 6144 grids leave a quarter to two thirds of the CUs idle on
128x128 / 128x256 tiles; 192-wide tiles reach 256 workgroups only with K
splits (256 x 6144 is 64 128x192 tiles, 256 with four splits; 768 x 6144 is
128 192x192 tiles), and the cluster-local split-K epilogue took only
power-of-two tile_m and rows of 128 // (tile_n / 4) vectors.

- The reduction takes a 192-column row (48 vectors, 128 threads) in 64-column
  chunks and issues every chunk's peer loads before the first sum; the batch
  is the largest row count that divides the stripe. A 192-row tile rotates its
  stripe with a compare instead of a mask.
- The compute kernel reads the peer stripes non-temporally: the scratch lines
  are not kept, and the next launch's peer TDM store no longer waits on them
  (512x6144x6144 128x192 sk2: peer store 2.3 -> 1.15 us, kernel 14.9 -> 13.7 us;
  256x6144x8192 128x128 sk2, a tuned row: 13.0 -> 12.5 us).
- Catalog: fused split-K 2/4/8 on the 128x192 nb3, 192x192 nb3 and 256x192
  nb4 profiles with each existing cluster that fits 16 workgroups (27
  kernels), appended after every existing ID. The 192x256 / 192x192 nb2
  fused IDs already in the catalog now launch as well.

The sum stays FP32 in split order, so outputs match the unfused kernels of the
same split bit for bit. Kernels without a compute fused split-K epilogue
compile to the same ISA; compute fused split-K kernels differ only in the
cache policy of the peer loads.

Co-Authored-By: Claude Code <[email protected]>
At M 48-128 the GEMM is bound by the weight stream, and the tile kernels in
the tables reach 35-60% of a pure weight scan: every M tile reads all of the
weights through LDS, and A is re-read per N tile. The new kernel holds every
row in one workgroup (tile_m = M rounded up to 16):

* weights go straight into VGPRs with non-temporal vector loads, each byte
  read once; 2-3 K steps in flight a wave (deeper queues flood the vector
  path and delay the activation);
* the activation is the remaining traffic, A[tile_m, the rank's K range] per
  workgroup. A cluster of ks x cn workgroups keeps it small: the ks ranks
  split K, and the cn ranks of a K range share their slice by TDM multicast.
  The slice goes to LDS in 512-byte K chunks (a ring of 3+ slots, refilled
  after a cluster barrier, when it does not fit);
* the ks FP32 partials meet in a global slab after a cluster barrier. With
  equal runs each rank sums a 1/ks share in rank order (reduce-scatter). With
  "_u" (ks 2) the reducer rank takes 4u more K steps; the publisher writes
  its whole partial and finishes first, so the exchange costs the reducer one
  read instead of four global round trips (about 2.3 us measured);
* the wk K-wave partials of a workgroup are summed in LDS in wave order, so
  results are bit-identical across runs.

Name flydsl_mxfp8_32_bpreshuffle_fullm_t{tile}_ks{ks}_cn{cn}_nb{nb}_wn{wn}
_wk{wk}_d{D}[_u{u}], run through the B=1 batched runner like the decode
kernels (bf16 only). The tuner offers it for M 48-128 (ids 3_990_000+: inside
the B=1 window below 4_000_000, so MiniMax rows keep kernelId "bmm", and above
skdec's ids). The config check, used by the launcher and by
launchable/candidates, keeps to what ran on MI455X: cluster shapes cn x ks of
1x1, 2x1, 1x2, 2x2, 4x1, 1x4, 4x2, 2x4 (all used by other kernels of this
GEMM), wave splits 1x4, 2x2, 2x4, 3x2, 3x4, depth <= 6, u <= 2, tile_m
48-128, LDS <= 320 KB, an estimated VGPR budget. Synchronization is the
workgroup barrier and the hardware cluster barrier, each workgroup signalling
and waiting the same number of times; there is no spin wait.

The op test runs every offered kernel of its decode shapes (now with
72x6144x6144) against the fp32 reference, rows past M unwritten.

Co-Authored-By: Claude Code <[email protected]>
The three-slot ring and the four-step A-scale panel left mod 3 / mod 4
arithmetic and per-wave selects for every refill descriptor, hoisted to
the K-loop head (137 SALU per three K-steps). The three panels now sit
side by side in one padded LDS row, so K-step s reads column s % 12 and
a panel always refills into the slot column of the K-step that frees
it. Each steady rev computes the A-scale state once, and the refill
descriptors take per-wave constants instead of selects: 55 SALU per
rev, 1080 -> 1049 cycles per K-step at 16384x6144x12288. Sums are
bit-identical.

Co-Authored-By: Claude Code <[email protected]>
minimax_m3_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv gains 315
gfx1250 1x32 rows (kernelId bmm on the rows that run the B = 1 runner);
31 of the 36 gfx1250 rows of dsv4_a8w8_mxfp8_bpreshuffle_tuned_gemm.csv
change. No gfx950 row changes.

Each kernel was picked by the tuner (paired rounds, weights not
cache-resident, at least 2% on the median and every round won) and kept
only when the production entry confirmed it: CUDA graph, old and new
processes alternating on one GPU, 6 rounds (4 for M >= 4096). A row that
won the median but lost one or two rounds was run again and kept at 10 of
12 rounds (7 of 8 for M >= 4096). us is the production-entry median.

Against the previous revision of these tables, production entry, 4
alternating rounds (total us before -> after, speedup of the total,
geomean):

  M <= 16      77 rows    405.7 ->   366.6  1.107  1.104
  M 17-47      27 rows    190.1 ->   168.8  1.126  1.129
  M 48-128     56 rows    423.6 ->   375.8  1.127  1.121
  M 160-192    14 rows    184.8 ->   178.8  1.034  1.043
  M 256-2048  109 rows   2644.1 ->  2486.2  1.063  1.053
  M >= 4096    68 rows  18577.2 -> 17028.9  1.091  1.134
  all         351 rows  22425.5 -> 20605.0  1.088  1.095

Co-authored-by: lirui927 <[email protected]>
Co-authored-by: aoli26 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cales on 256x384

kernel_fits_shape took the 192-wide fill profiles (128x192 / 192x192 nb3,
256x192 nb4) without allow_wide, so the untuned fallback and the mxfp8_128
candidates could pick them; a static replay of the fallback over 1190
shapes picked another kernel than the previous revision for 275 of them.
They now need allow_wide like the 256x384 profile: the fallback is back to
the previous revision's picks on all 1190, and the mxfp8_32 tuned rows and
candidates (allow_wide=True) are unchanged.

gemm_a8w8_mxfp8_bpreshuffle(a_scale_preshuffled=True) appended _aspre to a
tuned 256x384 name, a kernel that reads row-major A scales only (a
trace-time assert); such a row now takes the direct fallback, as a B=1 row
with preshuffled A scales already does.

The op test's mocked dispatch check covers a 256x384 row with preshuffled A
scales, and on gfx1250 the test checks every 1x32 row of the two tuned
tables with the launch check the mxfp8 entry uses (the blockscale entry runs
a row without it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bmm_mx32_kernel_launchable is a runtime check (tuned-row lookup and the
tuner), so it reads the LDS capacity of get_gfx_runtime(), not of
get_gfx(), which follows GPU_ARCHS and can name another target on a
multi-target build. Same answer on a single-target build or on gfx1250.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e AOT cache

The mxfp8_32 B = 1 kernels the tuned rows select (weight streaming,
decode, balanced decode, full M) still launched on the JIT path: the
gfx1250 replay compiled them but wrote no entry, and every process
traced them on their first call. Each launcher now has an aot_factory
with no argument that imports its kernel module, as the a8w8 launchers
of ROCm#8678 do, and the launch uses factory.lazy(). Every constexpr was
already in specialization_key, with one type.

The specialization keys held the device index. They hold the
torch.device now: in memory it keeps one launcher per device, as the
JIT path needs, and on disk only its type, so one entry serves every
GPU.

The four caches and their sources are declared in
aiter/aot/flydsl/sources.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The balanced decode and full-M kernels each defined the same tdm_2d
closure; it is now tdm_load_2d in the balanced decode module, taking the
LDS base as an argument, and the full-M kernel imports it. The full-M AOT
cache declares that module as a source.

The decode, balanced decode and full-M runners repeated the same operand
check; _check_operands takes the runner's label for the message.

No kernel change: the compiled code is the same.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@XiaobingSuper
XiaobingSuper force-pushed the xiaobingsuper/gfx1250-mxscale-fp8-kernel-20261119 branch from ff556f4 to 0f3007c Compare December 3, 2026 12:53
Copilot AI balanced review requested due to automatic review settings December 3, 2026 12:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@XiaobingSuper

XiaobingSuper commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased onto main 607b877925 as 0f3007c13d. The branch was 49 commits behind and conflicting; the same 16 commits, in order.

Conflicts. Both were in the first commit, and in both main and this PR had each added a block at the same spot, so both blocks are kept:

Other changes. git range-diff shows commits 5 and 13 changed only in context lines. Main also changed bpreshuffle_gemm_gfx1250.py (#7449), gemm_op_a8w8.py and aot/flydsl/sources.py; those merged without conflict.

CPU checks. All 19 changed Python files compile, and black is clean. CI's Check Code Style with Ruff and Black pass at this head. Main did not change this PR's tuned CSVs, so no row keys can collide.

GPU, partial (4x MI455X, FlyDSL 0.5.5 as main now pins it). op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py ran every tuned gfx1250 1x32 shape, and none logged an error-level mismatch (checkAllclose above its 5% ratio). Not captured:

  • the per-shape error values: the summary table needs tabulate, which the image lacks;
  • the decode-kernel check that runs after the summary.

The torch profiler's drain also hung at exit on that stack. I will rerun with those fixed when a gfx1250 node is free.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants