Skip to content

[CK] [FlyDSL] FlyDSL A4W4 decode GEMM for M<=16 on gfx950 - #6218

Open
johannes-graner wants to merge 21 commits into
mainfrom
jograner/decode-gemm-mxfp4-SILOTIGER-1219
Open

johannes-graner wants to merge 21 commits into
mainfrom
jograner/decode-gemm-mxfp4-SILOTIGER-1219

Conversation

@johannes-graner

@johannes-graner johannes-graner commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Qwen3.8-27B MXFP4 decode on MI355X runs small-M dense GEMMs through the asm f4gemm_bf16_per1x32Fp4_BpreShuffle_32x128 and _64x128 kernels via gemm_a4w4. This adds a FlyDSL A4W4 (MXFP4, per_1x32 e8m0) decode GEMM that is 1.7-2.3x faster on the tuned shapes with N<=8192.

Technical Details

  • New kernel kernels/decode_gemm_mxfp4.py plus optional split-K reduce kernel kernels/decode_gemm_mxfp4_reduce.py, with wrapper aiter/ops/flydsl/decode_gemm_mxfp4.py. Targets M<=16 on gfx950.
  • Constraints: N % tile_n == 0, K % 64 == 0. Valid (tile_n, k_waves) pairs: (32, 2) and (64, 1).
  • Dispatch: gemm_a4w4 routes kernelName prefix flydsl_decode_t16x{tile_n}x{256*k_waves}_kw{k_waves}_nb{num_buffers}_sk{split_k} to the kernel. Unsupported shapes and unparsable names fall back to the asm heuristic.
  • 25 rows added to model_configs/qwen38_27b_a4w4_blockscale_tuned_gemm.csv.
  • Tuner: gemm_a4w4_blockscale_tune.py gains --backends flydsl. Split-K candidates require --splitK and splitK is stored as log2(partitions), as for CK and asm.
  • CK gen_instances.py excludes flydsl_* rows.
  • AOT: decode rows are prebuilt by main's runtime-replay AOT, which replays the public gemm_a4w4 call through the existing A4W4 table. That keeps the runtime compile args and cache key. Only exact-M rows are enrolled, because main routes padded-M FlyDSL lookups to asm. The shipped CSVs give 25 decode jobs.
  • CSV timing method: committed rows use decode-accurate cold-ring HIP-graph medians, not tuner CLI output. The tuner's run_perftest path reads 2-19% higher on 20 of 25 shapes, most on short K=3072 kernels (+15-19%), because of launch overhead; graph replay reproduces the CSV values. At 3 points it picks a different num_buffers (7168x5120 M=16; 8192x5120 M=1 and M=16). Rows were kept because dispatch reads only kernelName, the cold-ring method better represents decode with non-cache-resident weights, and the tuner still picks FlyDSL over asm at all ten checked points. A plain re-tune therefore yields slightly different rows.
  • Known gap: FlyDSL loses to asm on wide-N shapes at K=16384; no rows ship there.

Design notes for reviewers:

  • The A swizzle and the A/B operand thread mappings stay hand-written. Structured swizzled views and MMA-derived tiled copies were prototyped and lowered to extra address arithmetic (+2 VGPRs, more s_waitcnt). Code comments state the constraint.

Test Plan

  • op_tests/flydsl_tests/test_decode_gemm_mxfp4.py: 29 oracle-based tests; each also checks that the call reached the FlyDSL kernel, so a silent fallback to asm fails the test.
  • op_tests/test_gemm_a4w4.py: now includes the 25 decode shapes.
  • Decode AOT parse/replay tests in op_tests/test_gemm_group32_interface.py, the padded-M parity test in op_tests/test_gemm_host_dispatch_cache.py, and a runtime-replay AOT prebuild from the shipped CSV.
  • End-to-end timing against the replaced asm kernels (run_perftest, 10 warmup, 101 iters).

Test Result

  • Decode suite 29/29 passed; test_gemm_a4w4.py err 0 on all 94 rows; AOT run of 3 decode shapes 3/3 success on gfx950. op_tests/test_gemm_a4w4.py -mnk 1,5120,3072 4,8192,5120 16,17408,5120 with FLYDSL_RUNTIME_RUN_ONLY=1 gave 3 disk-cache hits, error 0, at 3.0/3.7/9.4 us.
  • CI runs test_gemm_a4w4.py on gfx950 and gfx1250 (the test skips other archs).
  • End to end vs asm on the 25 tuned shapes: 1.71-2.30x for N<=8192, 1.01-1.06x for N=17408 (bandwidth-bound). All 25 dispatch FlyDSL; output is bit-identical to asm.
N K M speedup vs asm
5120 3072 1-16 1.76-1.79x
7168 5120 1-16 1.79-1.83x
8192 5120 1-16 1.71-2.30x
5120 8704 1-16 2.07-2.28x
17408 5120 1-16 1.01-1.06x

N=8192 K=5120 at M=1,2,4,8 has no asm row at the merge-base; asm there used the default heuristic.

Submission Checklist

PR Self-Review

Reviewed revision

428f355

Behavior and intent

Qwen3.8-27B MXFP4 decode on gfx950 previously ran small-M dense GEMMs through the asm f4gemm_bf16_per1x32Fp4_BpreShuffle_32x128 and _64x128 kernels. This PR adds a FlyDSL A4W4 decode GEMM with optional split-K, dispatched from gemm_a4w4 by flydsl_decode_* kernelName rows. It ships 25 tuned rows for the Qwen3.8-27B shapes, adds tuner and AOT prebuild support, and keeps the asm path as the fallback for everything else.

Validation and unverified scope

Validated on gfx950 on 2026-11-18 at head 428f355cca, with ENABLE_CK=0 FLYDSL_RUNTIME_ENABLE_CACHE=0:

  • python3 -m pytest op_tests/flydsl_tests/test_decode_gemm_mxfp4.py: 32 passed.
  • python3 -m pytest op_tests/test_gemm_host_dispatch_cache.py: 34 passed (includes test_padded_m_parity).
  • python3 -m pytest op_tests/test_gemm_group32_interface.py: 215 passed, 13 skipped (includes the decode AOT parse/replay tests).
  • python3 op_tests/test_gemm_a4w4.py -mnk 8,5120,3072: err 0, 3.76 us, served by tuned row flydsl_decode_t16x32x512_kw2_nb4_sk1.
  • python3 -m pytest op_tests/test_config_shape_collision.py: 33 passed.
  • GPU-free AOT collection gives 25 decode jobs, equal to the 25 tuned decode rows (exact-M only, since padded-M FlyDSL lookups go to asm after [HIP] [CK] [FlyDSL] [GEMM][gfx950] Tune narrow-N MXFP4 with CSV-selected preshuffle kernels #7317).
  • Earlier at a4c944f8af, the 94-row test_gemm_a4w4.py sweep gave err 0 with all 25 tuned shapes dispatched to FlyDSL; that sweep was not repeated at this head.

Remaining limitations: gfx942 and other archs are not tested (the path falls back to asm), the CI wheel build result is pending, FlyDSL loses to asm on wide-N K=16384 shapes (no rows ship), and the eager-mode host overhead is not measured here, since decode runs under HIP graph.

PR-specific question

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

Dispatch requires a kernelName row matching flydsl_decode_t16x{tile_n}x{256*k_waves}_kw{k_waves}_nb{num_buffers}_sk{split_k}, so only the 25 shipped Qwen3.8-27B rows can select it. The branch also requires gfx950 (checked with get_gfx_runtime()), plain MXFP4 per_1x32 e8m0 arguments, and a kernel LDS footprint within the 163840 byte gfx950 limit. The kernel targets M<=16, N % tile_n == 0 and K % 64 == 0, with valid (tile_n, k_waves) pairs (32, 2) and (64, 1). The name parser rejects a t-token that disagrees with kw and rejects the old name format. A parse failure, wrapper ValueError, LDS overflow, non-gfx950 device, or missing FlyDSL import falls back to the asm heuristic, covered by the LDS-fallback case (16,256,20480) and the forced-import-failure run. Shapes with no row never reach the kernel.

Changed op tests

  • op_tests/flydsl_tests/test_decode_gemm_mxfp4.py: new oracle test of the kernel (all shipped shapes, M between CSV rows, split-K, LDS fallback, parser). It also asserts that the FlyDSL kernel was actually called, so a silent asm fallback fails. No existing test covers this kernel.
  • op_tests/test_gemm_a4w4.py: adds the 25 decode shapes to the existing a4w4 perf and correctness sweep, so CI exercises real gemm_a4w4 dispatch of the tuned rows end to end, which the kernel-level test does not.
  • op_tests/test_gemm_host_dispatch_cache.py: adds test_padded_m_parity[0/1], which checks that the pure-Python padded_m_py matches the compiled get_padded_m, protecting GPU-free AOT padding. No other test compares the two. It lives in this file because CI already discovers it.
  • op_tests/test_gemm_group32_interface.py: adds five decode AOT parse/replay tests next to the existing aot.parse_csv tests, covering exact-M-only rows and the replayed gemm_a4w4 call. No GPU-free test covered decode enrollment before this PR.

A4W4 (MXFP4, per_1x32 e8m0) dense GEMM for M<=16 with optional stateless split-K reduce kernel. Valid (tile_n, k_waves) pairs are (32,2) and (64,1); requires N % tile_n == 0 and K % 64 == 0.
…e shapes

Rows whose kernelName starts with flydsl_decode_ route to the FlyDSL kernel; unsupported shapes and unparsable names fall back to the asm heuristic. Adds 25 rows to the qwen38_27b model config.
… rows in CK gen_instances

Split-K candidates are enumerated only with --splitK and encoded as log2(partitions), matching CK and asm.
Reuses OpKind.GEMM; expands every padded M served by a tuned row (80 jobs).
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 6218 --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.

…mxfp4-SILOTIGER-1219

# Conflicts:
#	aiter/aot/flydsl/gemm.py
Comment thread aiter/ops/gemm_op_a4w4.py Resolved
Comment thread aiter/ops/flydsl/decode_gemm_mxfp4.py Resolved
@msaffari-amd

Copy link
Copy Markdown
Contributor

Thanks for the PR, nice speedup for decode!

I checked it locally on gfx950: output is bit-identical to asm on all 80 shipped (N, K, M) cases including padded M, and split-K / K-tail edge cases also pass. Kernel logic looks good to me.

Main point is the top-level flydsl import in gemm_op_a4w4.py (import aiter fails without flydsl). The other comments are small (tests, tuner, host overhead).

Lazy-import flydsl decode helpers in gemm_a4w4 dispatch; fall back to asm on ImportError
Add M between CSV rows decode test cases
Dedupe tuner num_buffers candidates by effective depth
Cache parse_flydsl_decode_name; use get_gfx_runtime for arch check
Replace heavy LDS fallback test shape with (16,256,20480)
Exclude flydsl_ kernel names from CK path in bench_gemm_mixed_mxfp
@johannes-graner
johannes-graner marked this pull request as ready for review October 16, 2026 14:22
@johannes-graner
johannes-graner requested review from a team and a balanced review from Copilot October 16, 2026 14:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@github-actions github-actions Bot changed the title FlyDSL A4W4 decode GEMM for M<=16 on gfx950 [HIP] [CK] [FlyDSL] FlyDSL A4W4 decode GEMM for M<=16 on gfx950 Oct 16, 2026
Copilot AI balanced review requested due to automatic review settings October 30, 2026 06:52

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.

@aiter-bot

aiter-bot commented Oct 30, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 428f355cca1e · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

Qwen3.8-27B MXFP4 decode on gfx950 previously ran small-M dense GEMMs through the asm `f4gemm_bf16_per1x32Fp4_BpreShuffle_32x128` and `_64x128` kernels. This PR adds a FlyDSL A4W4 decode GEMM with optional split-K, dispatched from `gemm_a4w4` by `flydsl_decode_*` kernelName rows. It ships 25 tuned rows for the Qwen3.8-27B shapes, adds tuner and AOT prebuild support, and keeps the asm path as the fallback for everything else.

Validation and unverified scope

Validated on gfx950 on 2026-11-18 at head `428f355cca`, with `ENABLE_CK=0 FLYDSL_RUNTIME_ENABLE_CACHE=0`:
- `python3 -m pytest op_tests/flydsl_tests/test_decode_gemm_mxfp4.py`: 32 passed.
- `python3 -m pytest op_tests/test_gemm_host_dispatch_cache.py`: 34 passed (includes `test_padded_m_parity`).
- `python3 -m pytest op_tests/test_gemm_group32_interface.py`: 215 passed, 13 skipped (includes the decode AOT parse/replay tests).
- `python3 op_tests/test_gemm_a4w4.py -mnk 8,5120,3072`: err 0, 3.76 us, served by tuned row `flydsl_decode_t16x32x512_kw2_nb4_sk1`.
- `python3 -m pytest op_tests/test_config_shape_collision.py`: 33 passed.
- GPU-free AOT collection gives 25 decode jobs, equal to the 25 tuned decode rows (exact-M only, since padded-M FlyDSL lookups go to asm after #7317).
- Earlier at `a4c944f8af`, the 94-row `test_gemm_a4w4.py` sweep gave err 0 with all 25 tuned shapes dispatched to FlyDSL; that sweep was not repeated at this head.

Remaining limitations: gfx942 and other archs are not tested (the path falls back to asm), the CI wheel build result is pending, FlyDSL loses to asm on wide-N K=16384 shapes (no rows ship), and the eager-mode host overhead is not measured here, since decode runs under HIP graph.

PR-specific question

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

Dispatch requires a `kernelName` row matching `flydsl_decode_t16x{tile_n}x{256*k_waves}_kw{k_waves}_nb{num_buffers}_sk{split_k}`, so only the 25 shipped Qwen3.8-27B rows can select it. The branch also requires gfx950 (checked with `get_gfx_runtime()`), plain MXFP4 per_1x32 e8m0 arguments, and a kernel LDS footprint within the 163840 byte gfx950 limit. The kernel targets M<=16, `N % tile_n == 0` and `K % 64 == 0`, with valid `(tile_n, k_waves)` pairs `(32, 2)` and `(64, 1)`. The name parser rejects a t-token that disagrees with kw and rejects the old name format. A parse failure, wrapper `ValueError`, LDS overflow, non-gfx950 device, or missing FlyDSL import falls back to the asm heuristic, covered by the LDS-fallback case `(16,256,20480)` and the forced-import-failure run. Shapes with no row never reach the kernel.

Changed op tests

- `op_tests/flydsl_tests/test_decode_gemm_mxfp4.py`: new oracle test of the kernel (all shipped shapes, M between CSV rows, split-K, LDS fallback, parser). It also asserts that the FlyDSL kernel was actually called, so a silent asm fallback fails. No existing test covers this kernel.
- `op_tests/test_gemm_a4w4.py`: adds the 25 decode shapes to the existing a4w4 perf and correctness sweep, so CI exercises real `gemm_a4w4` dispatch of the tuned rows end to end, which the kernel-level test does not.
- `op_tests/test_gemm_host_dispatch_cache.py`: adds `test_padded_m_parity[0/1]`, which checks that the pure-Python `padded_m_py` matches the compiled `get_padded_m`, protecting GPU-free AOT padding. No other test compares the two. It lives in this file because CI already discovers it.
- `op_tests/test_gemm_group32_interface.py`: adds five decode AOT parse/replay tests next to the existing `aot.parse_csv` tests, covering exact-M-only rows and the replayed `gemm_a4w4` call. No GPU-free test covered decode enrollment before this PR.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

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

Copilot AI balanced review requested due to automatic review settings November 2, 2026 06:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The wrapper accepts buffers beyond the kernel’s supported addressing range, allowing large inputs to pass validation even though trailing-column accesses cannot reach the intended weights.

5 open issues

Review effort: Balanced

Comment thread aiter/ops/flydsl/decode_gemm_mxfp4.py Resolved
Comment thread aiter/ops/flydsl/decode_gemm_mxfp4.py Resolved
The direct gcnArchName probe duplicated device detection; get_gfx_runtime reads the actual device, unlike get_gfx which returns GPU_ARCHS when set.
Descriptors are fixed-base with 32-bit num_records and offsets, and the K-tail B sentinel offset can wrap near 2 GiB. Raising ValueError lets gemm_a4w4 fall back to asm.
…mxfp4-SILOTIGER-1219

# Conflicts:
#	aiter/aot/flydsl/gemm.py
#	csrc/ck_gemm_a4w4_blockscale/gemm_a4w4_blockscale_tune.py
#	csrc/ck_gemm_a4w4_blockscale/gen_instances.py
#	op_tests/op_benchmarks/hip/bench_gemm_mixed_mxfp.py
Enroll decode rows in the existing A4W4 table caller and prebuild only
exact M values that runtime dispatch serves. Adapt parser tests to the
replay job contract and cover both split-K launch identities.
@github-actions github-actions Bot changed the title [HIP] [CK] [FlyDSL] FlyDSL A4W4 decode GEMM for M<=16 on gfx950 [CK] [FlyDSL] FlyDSL A4W4 decode GEMM for M<=16 on gfx950 Nov 6, 2026
@github-actions github-actions Bot removed the HIP label Nov 6, 2026
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: MIT

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.

No need to add a separate test file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 428f355: the parity check is now test_padded_m_parity in op_tests/test_gemm_host_dispatch_cache.py, which CI already discovers, and the separate file is removed.

Comment thread aiter/aot/test/test_flydsl_gemm.py Outdated
@@ -0,0 +1,91 @@
# SPDX-License-Identifier: MIT

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.

No need to add a separate test file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 428f355: the decode AOT parse/replay tests moved into op_tests/test_gemm_group32_interface.py next to the existing aot.parse_csv tests, and aiter/aot/test/test_flydsl_gemm.py is removed.

Addresses review: no separate test files. Parity test moves to
test_gemm_host_dispatch_cache.py and the AOT decode-job tests move to
test_gemm_group32_interface.py, both already discovered by CI.
The parity test's DECODE_MAX_M import was stale; bound M by 512 directly.
@johannes-graner

Copy link
Copy Markdown
Contributor Author

@solinzby1 The issues you raised are addressed.

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.

7 participants