Skip to content

[HIP] [FlyDSL] [Perf] gfx950: 4-wave MXFP8 for DSv4.1 32x32 dense and batched wo_a GEMMs - #8975

Merged
solinzby1 merged 9 commits into
mainfrom
perf_check
Dec 3, 2026
Merged

solinzby1 merged 9 commits into
mainfrom
perf_check

Conversation

@solinzby1

@solinzby1 solinzby1 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Lets the gfx950 4-wave MXFP8 kernel (#8582) run DeepSeek-V4.1's 32x32-weight-scale dense GEMMs and batched wo_a (with fused MXFP8 output quant), adds an mxpsh XCD order _x1_, and switches the DSv4.1 gfx950 tuned rows to them. Prefill GEMMs at M=16384 gain 8-20% TFLOPS on MI355X.

Motivation

The 4-wave kernel is the fastest gfx950 MXFP8 GEMM at large M, but it only took 1x32 weight scales and had no batched entry, so these DSv4.1 GEMMs ran on the slower 8-wave, mxpsh or bmm kernels.

Changes

gfx950 only; used only where a tuned row names the kernel.

  • 32x32 w_scale: read inside the kernel (switch b_scale_32x32, suffix _w32), no host expansion or cache.
  • Batched wo_a: switches batch / a_scale_rowmajor / fuse_quant (off by default); entry flydsl_mxfp8_4wave_bmm, routed from the bmm runner and the fused-quant op.
  • Fused quant: one helper shared with the bmm kernel; scale capped at 254 like per_1x32_mx_quant_hip (bmm output changes only on bf16 overflow).
  • Operand layouts: XQ is made contiguous on every path; an Out with a padded row stride runs into a contiguous scratch copied back, as the 8-wave backend does.
  • x_scale shuffle: one coalesced Triton kernel, same bytes, 1.2-9x faster.
  • mxpsh _x1_: M tiles sharing a weight tile stay on one XCD.
  • Tuners: can pick the 4-wave kernel and mxpsh XCD variants.
  • Tuned CSVs (gfx950 32x32 rows only): dsv41_..._tuned_gemm.csv 231 rows -> 4-wave (M >= 512), 14 new rows (M = 4224 / 8320), 30 rows at M <= 512 re-selected; dsv4_batched_..._tuned.csv 56 wo_a rows -> 4-wave, 2 new rows.

Performance (if applicable)

MI355X (gfx950, 256 CU), tuned-table kernel time, switched rows confirmed by interleaved A/B.

Hardware Workload (N,K,M) Before After Change (TFLOPS)
MI355X wq_b 32768,1280,16384 1967 (mxpsh) 2362 +20.1%
MI355X wo_b 5120,8192,16384 2713 (8-wave) 2936 +8.2%
MI355X engram 25600,6144,16384 2665 (8-wave) 2982 +11.9%
MI355X gate_up 4608,5120,16384 2383 (8-wave) 2679 +12.4%
MI355X wo_a b=8, 1024,4096,2048 1850 (OPUS bmm) 2168 +17.2%
MI355X wo_a b=8, 1024,4096,16384 2203 (FlyDSL bmm) 2458 +11.6%

M <= 512: 30 rows +2.6% to +7.9% TFLOPS; at M = 288, 7 non-main-path rows changed kernel, main-path rows unchanged. In-kernel 32x32 read: +0.44% median vs the host expansion the table was measured with.

Testing

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

Documentation

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

Dependencies

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

Breaking Changes

None.

PR Self-Review

Reviewed revision

2f9b5c1

Behavior and intent

DSv4.1's 32x32 dense GEMMs and batched wo_a run the 4-wave kernel where tuned rows name it; before, the kernel rejected these shapes.

Validation and unverified scope

MI355X, this revision:

  • 4wave, 4wave_dispatch, batched_mxscale_bpreshuffle and AOT-launch tests: 207 passed, 1 skipped; test_flydsl_batched_gemm.py bit-exact.
  • Outputs bit-exact vs the 8-wave kernel (dense) and bmm + quantize_fp8 (batched); in-kernel 32x32 bit-exact vs host expansion.

Not verified: MI250X / MI300X (no changed path runs there), end-to-end model run; _x1_ has no CI test. 3 test_gemm_group32_interface.py failures also occur on base.

PR-specific question

gfx950, MXFP8 with 1x32 x_scale and 32x32 or 1x32 w_scale, only where a tuned row names the kernel; shapes it does not take (N, K multiples of 256, K >= 512, 32-bit sizes) fall back to the existing heuristic.

Changed op tests

  • op_tests/test_mxfp8_gemm_4wave_dispatch.py: dense 32x32 and batched 4-wave (incl. fused quant) bit-exact with a dispatch spy, batched with 1x32 and 32x32 w_scale (both gather paths), a padded-row-stride Out vs 8-wave, plus a bf16-overflow case for the 254 scale cap. Not covered elsewhere.

@solinzby1
solinzby1 requested review from a team and a balanced review from Copilot December 1, 2026 01:48
@github-actions github-actions Bot changed the title [FlyDSL] [Perf] gfx950: 4-wave MXFP8 for DSv4.1 32x32 dense and batched wo_a GEMMs [HIP] [FlyDSL] [Perf] gfx950: 4-wave MXFP8 for DSv4.1 32x32 dense and batched wo_a GEMMs Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

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

@aiter-bot

aiter-bot commented Dec 1, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 2f9b5c184f65 · 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 — validation answer must explicitly state what remains unverified (or say none with a reason)

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

Critical scale-cache, weight-size overflow, and assembly clobber defects remain unresolved, while tests can silently exercise fallback paths and lack an independent numerical reference.

5 open issues
What changed in this PR

This PR extends AITER’s gfx950 4-wave MXFP8 backend to DeepSeek-V4.1 dense GEMMs with 32x32 weight scales and batched wo_a GEMMs.

Changes:

  • Adds batched addressing, scale handling, and fused FP8 output quantization.
  • Expands tuning candidates and updates model-specific kernel selections.
  • Adds bit-exact comparisons, fallback coverage, and XCD scheduling tests.
File Description
op_tests/​test_mxfp8_gemm_4wave_dispatch.py Tests dense 32x32 scales, batched outputs, fused quantization, and fallback.
op_tests/​test_gemm_group32_interface.py Tests the new XCD tile ordering.
csrc/​gemm_a8w8_mxfp8_bpreshuffle/​gemm_a8w8_mxfp8_bpreshuffle_tune.py Adds XCD variants seeded from nearby tuned shapes.
csrc/​bmm_a8w8_mxscale/​bmm_a8w8_mxscale_bpreshuffle_tune.py Adds batched 4-wave tuning candidates.
aiter/​ops/​flydsl/​mxscale_preshuffle_kernels.py Enables 4-wave dispatch for 32x32 weight scales.
aiter/​ops/​flydsl/​kernels/​mxfp8_scale_shuffle_triton.py Adds a coalesced row-major scale shuffle.
aiter/​ops/​flydsl/​kernels/​mxfp8_gemm_4wave.py Implements batched addressing and fused quantization.
aiter/​ops/​flydsl/​kernels/​gemm/​mxscale_preshuffle.py Adds XCD scheduling that groups M tiles together.
aiter/​ops/​flydsl/​gemm_tune/​flydsl_gemm_mxscale_preshuffle_common.py Registers 4-wave support for 32x32 scales.
aiter/​ops/​flydsl/​gemm_a8w8_mxfp8_4wave.py Adds weight-scale expansion and batched launch wrappers.
aiter/​ops/​flydsl/​batched_gemm_a8w8_gfx950.py Routes supported tuned rows to the 4-wave backend.
aiter/​ops/​batched_gemm_op_a8w8.py Allocates shared storage for quantized codes and scales.
aiter/​configs/​model_configs/​dsv4_batched_gemm_a8w8_blockscale_mxscale_bpreshuffle_tuned.csv Updates selected 32x32 workloads to 4-wave kernels.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings December 1, 2026 08: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.

🟡 Changes recommended

The batched path can pass CPU or cross-device operands to a GPU launcher without validation, while the new launcher bypasses AOT export caching and the test runner may skip the added cases.

2 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Bind the 4-wave launcher through the AOT export path

aiter/​ops/​flydsl/​batched_gemm_a8w8_gfx950.py:474

This return bypasses the existing _bound_launcher.lazy(...) export-to-C path, while compile_mxfp8_4wave_gemm has no AOT binding or source registration. The switched BMM rows therefore take ordinary JIT compilation instead of producing and loading export-cache entries through the GEMM prebuild. Register the 4-wave launcher with aot_factory and its source dependencies, and use its .lazy(...) handle for both prebuild and runtime execution.

Medium severity Ensure the test runner executes the XCD-remapping cases

op_tests/​test_gemm_group32_interface.py:831

The Aiter Test runner defaults to python3 "$file" (.github/scripts/aiter_test.sh:106), but this file has no pytest entry point and is not among its pytest exceptions. Its shard can therefore exit successfully without executing the new XCD-remapping cases. Add a pytest.main entry point or register this file in the runner's pytest cases.

4 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings December 1, 2026 09:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Missing dtype and device validation can cause incorrect kernel inputs or invalid memory accesses, while overflow scale handling breaks quantization equivalence.

2 open issues
3 previously missed issues

In code that hasn't changed since last review

High severity Reject multi-byte inputs before reinterpreting tensors as FP8

aiter/​ops/​flydsl/​gemm_a8w8_mxfp8_4wave.py:429

Direct calls to this BMM entry accept multi-byte A/B tensors and reinterpret their bytes as FP8, producing incorrect inputs to the kernel. For example, contiguous float16 XQ shaped [256, 2, 512] occupies 524,288 bytes, but the kernel uses strides and bounds for 262,144 FP8 bytes. Reject non-1-byte XQ/WQ here, as the dense _check_operands does.

High severity Reject non-CUDA inputs and enforce a shared device

aiter/​ops/​flydsl/​gemm_a8w8_mxfp8_4wave.py:467

For M=64, B=2, N=256, K=512, XQ on cuda:0 and a contiguous BF16 Out on CPU or cuda:1 pass this wrapper's checks and reach a cuda:0 launch. These tensors are consumed as device-buffer addresses, so the mismatch can cause invalid memory accesses rather than an input error. Reject non-CUDA XQ and require WQ, both scales, and Out to share its device before shuffling or launching.

High severity Cap E8M0 scale on overflow to match the HIP quantizer

aiter/​ops/​flydsl/​kernels/​mxfp8_gemm_4wave.py:769

When a BF16 output group contains Inf, emit_mx_e8m0_scale returns 0xFF (an E8M0 NaN), whereas the HIP quantizer caps the scale at 0xFE via mxfp8_cap_scale in csrc/include/mx_quant_utils.h:121. This breaks the promised quantization equivalence for overflow inputs, such as M=1, B=1, N=256, K=512 with A=W=1, x_scale=0xFE, and w_scale=0x7F. Cap the exponent before conversion and storage, and add an overflow regression case.

Review effort: Balanced

@solinzby1
solinzby1 requested a review from valarLip December 2, 2026 01:18
Copilot AI balanced review requested due to automatic review settings December 2, 2026 02:07

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

Missing input-storage and device validation can produce invalid GPU results, while overflow handling causes fused quantization to diverge from the standalone implementation.

4 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings December 2, 2026 03:04

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 added fused-quant tests never exercise the new overflow clamp, leaving its behavior unverified against the HIP reference.

2 open issues
3 resolved since last review

Review effort: Balanced

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (9)

Thanks. Every switched tuned row is faster than the row it replaces. Dense and batched dispatch fall back cleanly when a 4-wave row does not fit the shape, and non-gfx950 paths are unchanged. Some items need fixing first:

  1. Share the fused-quant epilogue, don't copy it. StoreCLds._quant_store in kernels/mxfp8_gemm_4wave.py (:751-790) repeats kernels/bmm_a8w8_mxscale_gfx950.py:1187-1218: the 1e-10 floor, emit_mx_e8m0_scale, and the cvt_scalef32_pk_fp8_bf16 pack. The copies already differ: only the 4-wave one caps E8M0 at 254 (:771). On bf16 overflow, the two gfx950 kernels behind batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant therefore write different y_scale bytes for the same input. Put one helper in kernels/quant_utils.py and call it from both kernels.
  2. Read 32x32 w_scale in the kernel instead of expanding it on the host. _w_scale_shuffled caches a 32x expansion to 1x32, N*K/32 bytes per weight (4.9 MB for 25600x6144, 2 MB for wo_a at b=16). Entries are never evicted, and past _W_SCALE_CACHE_MAX = 512 every call silently re-expands and reallocates. The 8-wave kernel already reads 32x32 scales (gemm_a8w8_mxfp8_8wave.py:353). If you keep the expansion, state the per-GPU memory and the weight count at the shipped TP.
  3. Delete the dead _shuffle_scale_kernel (kernels/mxfp8_scale_shuffle_triton.py:12-34). Nothing calls it anymore. Move its layout docstring to _shuffle_scale_rm_kernel, whose docstring now only points at the old kernel (:41).
  4. Test the 254 clamp, and close the Copilot threads. The test scale bytes are 110-139 at K ≤ 4096, so deleting _min(e8, 254) (mxfp8_gemm_4wave.py:771) still passes. Add a deterministic overflow case checked against per_1x32_mx_quant_hip. Fix or rebut the independent-fp32-reference thread (test_mxfp8_gemm_4wave_dispatch.py:376), then resolve both threads.
  5. Correct the PR body.
    • The wq_b 32768,1280,16384 "before" kernel is mxpsh (flydsl_mxpsh_128x256x128_..._x4_sk1), not 8-wave.
    • The body gives both "29 decode rows" and "30 rows 2.6-7.9%". The CSV has 30 changed rows at M ≤ 512, gaining 2.5-7.3%.
    • "bs48 rows (M = 288) unchanged" is wrong: 7 M=288 rows change kernel (1536/2304/4608x5120, 5120x15360, 6400/12800x6144, 16384x1280).
    • "x_scale shuffle up to 9x faster" contradicts gemm_a8w8_mxfp8_4wave.py:166 ("2-4x"). The _shuffled_scale docstring still says "about 3x slower".
    • "Mostly M ≥ 1536" leaves out 20 M values from 512 to 1472 that also move to 4-wave.
    • "Reviewed revision f2002a0" is stale.
  6. Fix the stale comments. The comment above _W_SCALE_CACHE leaves out the new rows key field. kernels/gemm/mxscale_preshuffle.py:514 says "no-op when xcd_swizzle<=0", but the bound is now <=1. The batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant docstring does not mention the gfx950 4-wave path.
  7. Handle _x1_ with fused split-K. The x1 remap runs only when bids is None. In the 1-D fused_l2 grid (mxscale_preshuffle.py:1683-1700), x1 therefore means no swizzle. mxpsh_xcd_candidates still generates x1 variants of _fsk seeds. Exclude that combination in the tuner; no shipped row uses it today.
  8. Follow the aiter/ops/flydsl/AGENTS.md raw-API rule. The new raw calls carry no comment naming the missing stable API: create_buffer_resource/buffer_store in the quant store, _llvm.LoadOp/_rocdl.perm_b32 in _read_half_rowmajor, fx.arith.select/trunci, and the new inline asm in gather_soff. Use fx.copy/buffer tensors where they exist; otherwise add the comment.
  9. Squash text. The commits include "refine code" three times, "fix conflict", and a malformed "FlyDSL] [Perf] ... restore the 128-bit quad reduce" whose change is not in the final diff. Use the PR title plus a corrected body as the squash message.

Checked OK: CSV rows (274 = 260 + 14, 58 = 56 + 2) are all gfx950 32x32 with no duplicates, including across the family merge; they are sorted by (N,K) then M, and untouched rows are identical. The cache key includes rows. The x1 tile map is bijective. The int32 bounds hold. The AOT sources are declared. The new op test is picked up by the MI35X shards; it covers dense 32x32, bmm, fused quant and both x_scale layouts, but not _x1_.

Root cause vs patch: right direction with patch-like parts. The kernel extension and the retune are real wins. Two parts are patches: 32x32 support is a host-side 32x scale expansion cached forever, where the root fix is the kernel reading 32x32 scales like the 8-wave one. The fused-quant epilogue is a drifting copy, where the root fix is one shared helper.


Reviewed at 99f66be (round 1, passA; size-split waived by the user).

Copilot AI balanced review requested due to automatic review settings December 2, 2026 07: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.

🟡 Changes recommended

The new 32x32 path can produce incorrect results for column-strided activations and rejects padded-row caller-owned outputs supported by the existing backend.

4 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings December 2, 2026 07:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because the added tests exercise a different kernel, leaving the new mxpsh XCD swizzle’s tile and split assignments without direct correctness coverage.

3 open issues
1 resolved since last review

Review effort: Balanced

@solinzby1

Copy link
Copy Markdown
Contributor Author

⚠️ Action required before merge (9)

Thanks. Every switched tuned row is faster than the row it replaces. Dense and batched dispatch fall back cleanly when a 4-wave row does not fit the shape, and non-gfx950 paths are unchanged. Some items need fixing first:

  1. Share the fused-quant epilogue, don't copy it. StoreCLds._quant_store in kernels/mxfp8_gemm_4wave.py (:751-790) repeats kernels/bmm_a8w8_mxscale_gfx950.py:1187-1218: the 1e-10 floor, emit_mx_e8m0_scale, and the cvt_scalef32_pk_fp8_bf16 pack. The copies already differ: only the 4-wave one caps E8M0 at 254 (:771). On bf16 overflow, the two gfx950 kernels behind batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant therefore write different y_scale bytes for the same input. Put one helper in kernels/quant_utils.py and call it from both kernels.

  2. Read 32x32 w_scale in the kernel instead of expanding it on the host. _w_scale_shuffled caches a 32x expansion to 1x32, N*K/32 bytes per weight (4.9 MB for 25600x6144, 2 MB for wo_a at b=16). Entries are never evicted, and past _W_SCALE_CACHE_MAX = 512 every call silently re-expands and reallocates. The 8-wave kernel already reads 32x32 scales (gemm_a8w8_mxfp8_8wave.py:353). If you keep the expansion, state the per-GPU memory and the weight count at the shipped TP.

  3. Delete the dead _shuffle_scale_kernel (kernels/mxfp8_scale_shuffle_triton.py:12-34). Nothing calls it anymore. Move its layout docstring to _shuffle_scale_rm_kernel, whose docstring now only points at the old kernel (:41).

  4. Test the 254 clamp, and close the Copilot threads. The test scale bytes are 110-139 at K ≤ 4096, so deleting _min(e8, 254) (mxfp8_gemm_4wave.py:771) still passes. Add a deterministic overflow case checked against per_1x32_mx_quant_hip. Fix or rebut the independent-fp32-reference thread (test_mxfp8_gemm_4wave_dispatch.py:376), then resolve both threads.

  5. Correct the PR body.

    • The wq_b 32768,1280,16384 "before" kernel is mxpsh (flydsl_mxpsh_128x256x128_..._x4_sk1), not 8-wave.
    • The body gives both "29 decode rows" and "30 rows 2.6-7.9%". The CSV has 30 changed rows at M ≤ 512, gaining 2.5-7.3%.
    • "bs48 rows (M = 288) unchanged" is wrong: 7 M=288 rows change kernel (1536/2304/4608x5120, 5120x15360, 6400/12800x6144, 16384x1280).
    • "x_scale shuffle up to 9x faster" contradicts gemm_a8w8_mxfp8_4wave.py:166 ("2-4x"). The _shuffled_scale docstring still says "about 3x slower".
    • "Mostly M ≥ 1536" leaves out 20 M values from 512 to 1472 that also move to 4-wave.
    • "Reviewed revision f2002a0" is stale.
  6. Fix the stale comments. The comment above _W_SCALE_CACHE leaves out the new rows key field. kernels/gemm/mxscale_preshuffle.py:514 says "no-op when xcd_swizzle<=0", but the bound is now <=1. The batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant docstring does not mention the gfx950 4-wave path.

  7. Handle _x1_ with fused split-K. The x1 remap runs only when bids is None. In the 1-D fused_l2 grid (mxscale_preshuffle.py:1683-1700), x1 therefore means no swizzle. mxpsh_xcd_candidates still generates x1 variants of _fsk seeds. Exclude that combination in the tuner; no shipped row uses it today.

  8. Follow the aiter/ops/flydsl/AGENTS.md raw-API rule. The new raw calls carry no comment naming the missing stable API: create_buffer_resource/buffer_store in the quant store, _llvm.LoadOp/_rocdl.perm_b32 in _read_half_rowmajor, fx.arith.select/trunci, and the new inline asm in gather_soff. Use fx.copy/buffer tensors where they exist; otherwise add the comment.

  9. Squash text. The commits include "refine code" three times, "fix conflict", and a malformed "FlyDSL] [Perf] ... restore the 128-bit quad reduce" whose change is not in the final diff. Use the PR title plus a corrected body as the squash message.

Checked OK: CSV rows (274 = 260 + 14, 58 = 56 + 2) are all gfx950 32x32 with no duplicates, including across the family merge; they are sorted by (N,K) then M, and untouched rows are identical. The cache key includes rows. The x1 tile map is bijective. The int32 bounds hold. The AOT sources are declared. The new op test is picked up by the MI35X shards; it covers dense 32x32, bmm, fused quant and both x_scale layouts, but not _x1_.

Root cause vs patch: right direction with patch-like parts. The kernel extension and the retune are real wins. Two parts are patches: 32x32 support is a host-side 32x scale expansion cached forever, where the root fix is the kernel reading 32x32 scales like the 8-wave one. The fused-quant epilogue is a drifting copy, where the root fix is one shared helper.

Reviewed at 99f66be (round 1, passA; size-split waived by the user).

Thanks for the second review.

  1. Shared quant tail: 4-wave and bmm both call quant_utils.emit_mxfp8_quant_bf16_words; both cap the scale at 254, so the bmm output changes only on bf16 overflow.
  2. 32x32 w_scale: read in the kernel (switch b_scale_32x32, suffix _w32); no host expansion, no cache entry. Bit-identical to the old path; +0.44% median kernel time. ISA unchanged with the switch off.
  3. _shuffle_scale_kernel removed; its layout notes moved to _shuffle_scale_rm_kernel.
  4. Cap test added: test_bmm_fused_quant_caps_the_scale_on_bf16_overflow (4-wave and bmm, byte-exact vs per_1x32_mx_quant_hip; fails without the cap). FP32 reference: my earlier reply overstated it. test_4wave_vs_fp32_reference covers dense 1x32 only; the 32x32 and batched paths are covered through bit-equality with the bmm kernel, which test_flydsl_batched_gemm.py checks against FP32. Happy to add a direct FP32 check if you want it.
  5. Description corrections (carried into the squash message): wq_b 32768,1280 and 4096,1280 were mxpsh, not 8-wave; 30 rows changed at M <= 512 (TFLOPS +2.6% to +7.9%); at M = 288, 7 non-main-path rows changed kernel, main-path rows unchanged; 4-wave rows start at M = 512; x_scale shuffle is 1.2-2.6x faster dense and 9x for batched wo_a.
  6. Stale comments fixed (_W_SCALE_CACHE, xcd_swizzle, fused_quant docstring).
  7. _x1_ + _fsk: the tuner no longer offers xcd 1 for fused split-K seeds.
  8. Raw APIs: the row-major scale LDS read uses fx.copy; the remaining raw calls are commented with the missing API and evidence (fx.copy store: 4988 -> 5471 instructions).
  9. Squash: PR title + description with the corrections in (5).

Validation (MI355X): 4-wave / dispatch / batched / AOT-launch tests 198 passed, 1 skipped; test_flydsl_batched_gemm.py bit-exact; group32 failures same as base.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (5)

Thanks. The kernel now reads 32x32 w_scales itself, and both gfx950 kernels share one fused-quant helper with the 254 cap. I emulated the new 32x32 gather and read on CPU against the old 1x32 shuffled layout, for both gather paths, and every byte matches. The cap test and all 8 _w32 dispatch cases ran in MI35X shard 5 (82 passed, 0 skipped). Prior asks 1, 2, 3, 6, 7, 8 and 9 are fixed. Ask 4 is partly done: the threads are still open. Ask 5 is partly done: the reviewed revision is stale. Small items left:

  1. Stale text from removing the host expansion. gemm_tune/flydsl_gemm_mxscale_preshuffle_common.py:633 still says "The backend expands a 32x32 w_scale to 1x32 rows (cached per weight)". Change it to "the kernel reads a 32x32 w_scale as is". In gemm_a8w8_mxfp8_4wave.py:221-224, the _launch docstring says **batched holds only batch / n_per_batch / a_scale_rowmajor / fuse_quant. The dense 32x32 path now also passes b_scale_32x32 through it. Rename the kwargs and list b_scale_32x32.
  2. Dead branches in ScaleGatherLDS (kernels/mxfp8_gemm_4wave.py). self.four (:428) is only an alias of a_rowmajor. _set_tile_voff_four runs only when a_rowmajor is set, so its else: va = (grp * row_i32 + L) * 4 (:502-503) and the A else soff_v in gather_soff (:533) never run. Drop the alias and both branches. _read_half_w32 and _read_half_rowmajor also build the same 8-byte LDS pointer type and UniversalCopy64b atom: share one ds_read_b64 helper.
  3. Batched 1x32 w_scale lost its test. Before this round, every batched test ran the four-load gather with shuffled W scales, because 32x32 was expanded to 1x32. Now _bmm_operands and the cap test only build 32x32 scales. bmm_4wave_runs still accepts 1x32 (w_n in (1, 32)), but no test covers the four-load shuffled-W branch (:504-507). Parametrize test_bmm_bit_identical_to_bmm_kernel over 1x32 and 32x32. Include one row-major x_scale shape (300,8,1024,4096) and one shuffled shape (4224,8,1024,4096).
  4. Close the three Copilot threads. The padded-stride fix (gemm_a8w8_mxfp8_4wave.py:407-420, scratch copied back as the 8-wave backend does) has no test. Add Copilot's case: M=300, N=1792, K=5120, with Out = backing[:, :1792], compared with 8-wave. Your FP32-reference rebuttal is sound: 32x32 and batched outputs are bit-equal to the bmm kernel, and test_flydsl_batched_gemm.py checks that kernel against FP32. Post it in the thread at test:376. Then resolve that thread, the clamp thread (now covered by test_bmm_fused_quant_caps_the_scale_on_bf16_overflow) and the stride thread.
  5. PR body: "Reviewed revision 3d8d46d" is stale. eb7f388 changed the Out handling and the 32x32 XQ contiguity after that validation. Set it to eb7f388 and state the validation at that revision; this also clears the aiter-bot Self-Review SHA check.

Checked OK: CSVs are unchanged since round 1. Rerun against base: 14 + 2 new rows, all gfx950 / 256 CU / 32x32. There are no duplicates within a file or across the family merge. New rows are sorted by M within (N, K), and no switched row is slower. The body numbers match the CSV (231 rows switch to 4-wave from M=512; 30 decode rows gain +2.6% to +7.9% TFLOPS). Tuned names need no _w32 suffix, because the backend picks the 32x32 read from the w_scale shape. The tuner no longer offers x1 for _fsk seeds (mutant checked). New raw calls carry the AGENTS.md comment, and the row-major LDS read uses fx.copy. The +0.44% median for the in-kernel read is smaller than the smallest switched-row gain (2.1%).

Root cause vs patch: root fix. The 32x32 host expansion and the copied quant epilogue are replaced by the in-kernel 32x32 read and one shared helper. The items above are cleanup and coverage.


Reviewed at eb7f388 (round 2, passA; pass B not needed, verdict request_changes; size-split waived by the user). Already fixed: shared quant helper + cap, in-kernel 32x32 w_scale, dead shuffle kernel, stale comments, x1/fsk tuner filter, raw-API comments, body numbers. Merger: the repo squash default is COMMIT_MESSAGES ("refine code" x4, "fix conflict"), so squash with the PR title + body as agreed.

Copilot AI balanced review requested due to automatic review settings December 3, 2026 02:36

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 new _x1_ coordinate remap lacks explicit regression coverage against _x0_ for tile boundaries, eight-group rounds, and non-fused split-K, leaving tile coverage and batch/split indexing unverified.

4 open issues

Review effort: Balanced

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ LGTM

Thanks. 2f9b5c1 fixes all five round-2 asks, and the delta adds nothing new to fix.

Prior asks (round 2, eb7f388):

  1. Stale text: fixed. flydsl_gemm_mxscale_preshuffle_common.py:633 now says the kernel reads 32x32 as is, and the _launch docstring lists b_scale_32x32.
  2. Dead branches: fixed. self.four is gone. _set_tile_voff_four and the four-load gather_soff are reachable only under a_rowmajor (set_tile_voff at :482; call sites :1273/:1325/:1484). _ds_read_b64 keeps the same pointer type, alignment, view and copy atom, at the same addresses.
  3. Lost 1x32 coverage: fixed. test_bmm_bit_identical_to_bmm_kernel adds two 1x32 rows. On a 256-CU gfx950, M=300 takes the four-load gather (row-major x_scale) and M=4224 takes the dwordx4 gather. The spy also checks b_scale_32x32.
  4. Padded-stride Out: fixed. test_dispatch_padded_row_stride_output (M=300, N=1792, K=5120, Out = backing[:, :1792]) asserts that the 4-wave kernel ran, that the output is bit-equal to the 8-wave output, and that the padding is untouched. All review threads are resolved.
  5. Reviewed revision in the body: fixed (2f9b5c1).

Before merge: the new GPU tests (1 padded-stride + 8 bmm) have no CI run at this head yet. Only the wheel build is pending, and no MI35X op-test shard has run. Merge after a green MI35X op-test shard. Squash with the PR title + body as agreed: aiter's default squash uses the commit list ("refine code ×5", "fix conflict").

Root cause vs patch

Root fix. The kernel reads the 32x32 w_scale itself, and both gfx950 kernels share one fused-quant helper with the 254 cap. Nothing in this round is patch-like.


Reviewed at 2f9b5c1 (round 3, passes A+B; delta eb7f388..2f9b5c1 read in full).

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved at 2f9b5c1 (round 3, passes A+B). Merge after a green MI35X op-test shard, squashing with the PR title + body.

@solinzby1
solinzby1 merged commit 22c1888 into main Dec 3, 2026
64 checks passed
@solinzby1
solinzby1 deleted the perf_check branch December 3, 2026 06:31
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Dec 4, 2026
…red group-32 scale


_fused_quant_tuned_kernel imports the gfx1250 compute-kernel name check
only on gfx1250, after the table lookup; gfx950 returns the flydsl row's
name directly, as before the merge with the gfx1250 lookup. The gfx950 bmm
fused epilogue calls emit_mxfp8_group32_scale instead of its own copy of
the same steps (1e-10 floor, RoundUp e8m0, f32 scale). Two docstrings no
longer say the fused epilogue always quantizes the bf16 C tile.

Tests: FUSED_QUANT_TILES also pins the DSv4.1 wo_a tuned tiles the fused
entry runs (t192x128x256, t128x256x256 mw1 nw4, t96x128x256, and the
LDS-staged t32x32x512); the gfx1250 tuned-row fixture uses a CU count
other than the gfx950 one so the lookup must forward the caller's.

Rebased onto main: ROCm#8975 already moved the gfx950 bmm fused epilogue onto
quant_utils.emit_mxfp8_quant_bf16_words, so that file keeps main's version.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

6 participants