Skip to content

[HIP] [OPUS] [JIT] Add Blockscale_mxfp8 OPUS GEMM - #6696

Merged
demonsan merged 49 commits into
ROCm:mainfrom
Fyzyukk:fyz/opus_blockscale_mxfp8_gemm
Nov 18, 2026
Merged

demonsan merged 49 commits into
ROCm:mainfrom
Fyzyukk:fyz/opus_blockscale_mxfp8_gemm

Conversation

@Fyzyukk

@Fyzyukk Fyzyukk commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Add an OPUS backend for blockscale mxfp8 GEMM with B preshuffle on gfx950, and improve performance for large shapes (M > 1024). Enable the existing gemm_a8w8_blockscale_bpreshuffle interface to select tuned OPUS kernels.

Details

  • 4wave_pin_agpr: Uses a four-wave schedule with AGPR pinning to reduce VGPR/AGPR transfers in the main loop, with padded-M support.
  • b_vgpr: Stages A through LDS and prefetches B directly into VGPRs, with regular and operand-overlap scheduling options.
  • m_repeat: Stages A and B through LDS, computes one M repeat at a time, and replaces operands for the next tile after their last use.
  • Pin variants require a compiler supporting clang::amdgpu_pin_agpr.
  • Connect OPUS to the existing blockscale GEMM interface for FP8 inputs, native E8M0 scales (1x128 for A and 128x128 for B), and BF16 output. Reuse the scale bytes through the required logical tensor view.

Speedup Distribution

421 gfx950/CU256 shapes, the tuned table selects OPUS for 359 shapes

Speedup range Shapes
5% 160
10% 101
15% 56
20% 25
≥20% 17

@Fyzyukk
Fyzyukk requested a review from a team October 20, 2026 03:58
@github-actions

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
ci:windows Windows JIT op smoke test on the gfx1201 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 6696 --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.

@github-actions github-actions Bot changed the title Add Blockscale_mxfp8 OPUS GEMM [HIP] [OPUS] Add Blockscale_mxfp8 OPUS GEMM Oct 20, 2026
Use matching descriptive names for CO files, ELF entries, launchers, and tuned rows. Share identical configurations while preserving all dispatch IDs and launch constraints. Rebuild the COs and verify unchanged machine code and resource metadata.
Tune available legal OPUS candidates in one mp_tuner pass alongside FlyDSL. Require prebuilt COs, reuse JIT preparation, and remove staged search and duplicate task construction.

Simplify gfx950 instance generation and registration, and share CO metadata parsing while preserving kernel IDs and generated launch code.
Consolidate bpreshuffle candidate filtering and CO/JIT generation, and remove unused registration wrappers and empty candidate expansion. Preserve all 56 local-kid configurations and CO identities.

Reuse the public OPUS launcher with the existing packed scale bytes, restore upstream comments and CSV handling, and fix Black formatting and Ruff import order.

Validation: CPU candidate-selection parity, complete registry/CO metadata equivalence, generated-source equivalence, repository Black and Ruff, and diff checks. No native build or GPU execution.
Express layouts with named shape and dimension tuples followed by unfolded strides and partition coordinates. Group matrix A, matrix B, scale A, scale B and output layouts consistently across the three pipelines.

Preserve offset order, XOR swizzles and kernel schedules, including the direct B VGPR path. Validation: static structure checks, CPU layout/address equivalence and diff checks; no native compilation or GPU execution.
@aiter-bot

aiter-bot commented Oct 30, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 8ad5d6860bcb · 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 — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_opus_co_integration.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

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

@Fyzyukk
Fyzyukk force-pushed the fyz/opus_blockscale_mxfp8_gemm branch from db342eb to 1089467 Compare October 30, 2026 17:48
@Fyzyukk
Fyzyukk force-pushed the fyz/opus_blockscale_mxfp8_gemm branch from 1089467 to fedcaeb Compare October 30, 2026 18:48
Enforce shape-specific CO launch contracts and route FP16 outputs through a supported fallback. Restore production validation in the MXFP8 tuner and add integration coverage. Restore the original FlyDSL records for five configurations after paired rechecks.
Compile the gfx950 regression kernels with the same AITER package and resolved JIT directory as the pytest parent. Prevent installed-wheel tests from loading a different subset binary and reporting unknown kernel IDs.
Include the gfx950 bpreshuffle family in mandatory non-A16W16 compilation. Fresh JIT code generation now covers the default MXFP8 tuned table without tuner sidecars or extra kernel keys.

Add a CPU regression check using the production blob generation command and validate each tuned kernel against its generated dispatch table.
Remove unselected geometry and schedule groups from generation parameters while preserving surviving kernel IDs. Restore the two affected tuned rows to the original FlyDSL nb5 baseline and remove the two OPUS Python tests requested for this PR.
Keep the full tuning table while limiting this branch's tuning changes to M > 1024. Retain the 15 records added on main so the small-shape integration can preserve them.
Remove the 15 gfx1250 records copied from main. Restore the A8W8 CPU interface regression test unchanged from main.

Validation: all 8 interface tests pass. The CSV merges cleanly with main and preserves its gfx1250 records.
Pass the merged mxscale bpreshuffle tuning table to module_deepgemm_opus codegen. Select gfx950 bpreshuffle kernels from tuned rows, saved compiled keys and explicit requests, without the mandatory sweep or unconditional kid 0 floor.

Keep --tune for full sweep builds. Report missing literal tuned files while allowing optional model globs.

Validation: clean gfx942;gfx950 module prebuild with ROCm 7.2.4 and 64 workers succeeded in 51.5s. The gfx950 MXFP8 selection contains 55 JIT kernels and 33 CO entries. Selection, saved-key/request expansion, missing CSV, 5 A16W16 registry tests, Ruff and Black checks passed.
@github-actions github-actions Bot changed the title [HIP] [OPUS] Add Blockscale_mxfp8 OPUS GEMM [HIP] [OPUS] [JIT] Add Blockscale_mxfp8 OPUS GEMM Nov 17, 2026
@github-actions github-actions Bot added the JIT label Nov 17, 2026

@demonsan demonsan 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.

LGTM

@demonsan
demonsan merged commit 14c32f7 into ROCm:main Nov 18, 2026
Fyzyukk added a commit to Fyzyukk/aiter that referenced this pull request Nov 18, 2026
ZLkanyo009 added a commit that referenced this pull request Nov 18, 2026
Conflict in aiter/ops/flydsl/mxfp8_bpreshuffle_gemm_gfx1250.py with #7659
(32x32 w_scale + bmm): both sides added independent parameters to
_run_mxfp8_bpreshuffle_gemm_a8_gfx1250 and to the 2-D launch specialization.
Kept both: main's w_scale_32x32 / batch in place with this branch's
a_scale_preload after them, main's stride_ascale_k = batch * k_blocks for
mxfp8_32 (which never reads a row-major A scale, a_scale_m_major = False),
and w_scale_32x32 followed by a_scale_m_major in the specialization key.

#6696 (OPUS mxfp8 bpreshuffle) needs no change here: its rows are gfx950
only, they run from _gemm_mxscale_bpreshuffle, which gets column-major
x_scale bytes (a row-major one is transposed first), and on gfx1250 the
mxfp8_128 config ignores any non-triton/flydsl row, so the row-major query
and the dispatch keep resolving the same FlyDSL kernel.

Co-authored-by: Cursor <[email protected]>
Fyzyukk added a commit to Fyzyukk/aiter that referenced this pull request Nov 20, 2026
…ily a4w4)

OPUS gfx950 MXFP4 x MXFP4 NT GEMM with plain row-major A / B / 1x32 e8m0
scales (layout="plain", the layout of Triton gemm_afp4wfp4):

- 2x2 4-wave pipeline, pre-compiled .co (gen_co/gfx950/a4w4, kids 100-130),
  64-bit tile addressing;
- 1x4 small-tile JIT pipeline (kids 500-504): LDS-DMA ring for A / B and a
  K-deep scale panel per ring cycle, in-block K split, split-K through
  splitk_reduce;
- policy.a4w4_heuristic_kid; gemm_afp4wfp4_opus drop-in;
- op_tests/test_gemm_a4w4.py plain kid / large-offset / Triton sweep tests.

Rebased on main (ROCm#6696): opus_co_launch_gfx950.cuh co_kernel() takes an
optional co_dir and opus_co_launch_gfx950 an optional kernarg size (defaults
keep the a8w8 blockscale bpreshuffle images); build_co.py --arch gfx950
--family a4w4 builds these images next to the a8w8 family.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fyzyukk added a commit to Fyzyukk/aiter that referenced this pull request Nov 20, 2026
Resolve the conflicts with ROCm#6696 (gfx950 a8w8 blockscale bpreshuffle CO path),
which added the same gfx950 CO loader header and gfx950 support in build_co.py:

- include/gfx950/opus_co_launch_gfx950.cuh: one loader for both gfx950 CO
  families, sharing read_co_image / CoModule(path). co_kernel(symbol,
  image_name) + opus_co_launch_gfx950 serve a8w8_blockscale_bpreshuffle
  (gfx950/a8w8_blockscale_bpreshuffle/), co_kernel(symbol, device) + launch
  serve the a16w16 4-wave images (gfx950/a16w16/). launch is a template, so
  the header no longer includes the a16w16 traits.
- gen_co/build_co.py: --arch gfx950 takes --family {a8w8_blockscale_bpreshuffle
  (default), a16w16}; the a16w16 helpers are renamed (build_one_a16w16_gfx950,
  _build_a16w16_gfx950, ...) so they no longer shadow upstream's
  build_one_gfx950 / _GFX950_STUB_TEMPLATE; --kids follows the new nargs form;
  the default output dir is gen_co/gfx950/<family>.
- opus_gemm_common.py / gen_instances_gfx950.py: keep both sides.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fyzyukk added a commit to Fyzyukk/aiter that referenced this pull request Nov 23, 2026
… MoE training

FP8 e4m3 grouped GEMMs with E8M0 block scales and no shuffling of operands or scales, on the
MXFP8 1x128 4-wave pipeline (1x32 scale MFMA 16x16x128), with the DeepGEMM interfaces of the
bf16 grouped GEMMs:
  m_grouped_fp8_blockscale_gemm_{nt,nn}_contiguous / _nt_masked   fwd / dgrad, x 1x128, W 128x128
  k_grouped_fp8_blockscale_gemm_tn_contiguous                       wgrad, dY / X 128x1 along tokens

Unshuffled B takes A's copy / LDS / reader layouts ([N, K] as [M, K], [K, N] as [K, M]); wgrad's
per-column B scales take A's scale panel (op_sel per fragment). M-grouped: 256-row tiles numbered
by the bf16 grouped helpers (single-height branch added); K-grouped: the bf16 plan kernel, turn
counters and fp32 read-modify-write (deterministic segment order), bounds-checked VGPR offsets
so rows past a segment read 0. Kids: m_grouped 0 (256x256) / 1 (256x128), k_grouped 10;
images built by build_co.py --family a8w8_blockscale_grouped (shares build_co_a16w16_grouped's
builder; bf16 images unchanged). Outputs bit-identical to the ROCm#6696 NT kernel on dense shapes.

Test op_tests/test_opus_a8w8_blockscale_grouped_gemm.py: GLM-5.3 / Kimi-K3 shapes, 5 token
distributions, masked; vs SonicMoE blockwise FP8 (fwd 1.9-2.2x, dgrad 2.2-2.5x geomean on gfx950).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fyzyukk added a commit to Fyzyukk/aiter that referenced this pull request Nov 23, 2026
… MoE training

FP8 e4m3 grouped GEMMs with E8M0 block scales and no shuffling of operands or scales, on the
MXFP8 1x128 4-wave pipeline (1x32 scale MFMA 16x16x128), with the DeepGEMM interfaces of the
bf16 grouped GEMMs:
  m_grouped_fp8_blockscale_gemm_{nt,nn}_contiguous / _nt_masked   fwd / dgrad, x 1x128, W 128x128
  k_grouped_fp8_blockscale_gemm_tn_contiguous                       wgrad, dY / X 128x1 along tokens

Unshuffled B takes A's copy / LDS / reader layouts ([N, K] as [M, K], [K, N] as [K, M]); wgrad's
per-column B scales take A's scale panel (op_sel per fragment). M-grouped: 256-row tiles numbered
by the bf16 grouped helpers (single-height branch added); K-grouped: the bf16 plan kernel, turn
counters and fp32 read-modify-write (deterministic segment order), bounds-checked VGPR offsets
so rows past a segment read 0. Outputs bit-identical to the ROCm#6696 NT kernel on dense shapes.

Kernels opus_gemm_gfx950_mxfp8_{m,k}_grouped_*: m_grouped kids 0 (256x256) / 1 (256x128),
k_grouped 10; images built by gen_co/build_co_a8w8_blockscale_grouped.py (the bf16 grouped
builder, parameterized by a Family; bf16 images unchanged).

Test op_tests/test_opus_a8w8_blockscale_grouped_gemm.py: GLM-5.3 / Kimi-K3 shapes, 5 token
distributions, masked; vs SonicMoE blockwise FP8 (fwd 1.9-2.2x, dgrad 2.2-2.5x geomean on gfx950)
and the dense ROCm#6696 kernel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fyzyukk added a commit to Fyzyukk/aiter that referenced this pull request Nov 23, 2026
… MoE training

FP8 e4m3 grouped GEMMs with E8M0 block scales and no shuffling of operands or scales, on the
MXFP8 1x128 4-wave pipeline (1x32 scale MFMA 16x16x128), with the DeepGEMM interfaces of the
bf16 grouped GEMMs:
  m_grouped_fp8_blockscale_gemm_{nt,nn}_contiguous / _nt_masked   fwd / dgrad, x 1x128, W 128x128
  k_grouped_fp8_blockscale_gemm_tn_contiguous                       wgrad, dY / X 128x1 along tokens

Unshuffled B takes A's copy / LDS / reader layouts ([N, K] as [M, K], [K, N] as [K, M]); wgrad's
per-column B scales take A's scale panel (op_sel per fragment). M-grouped: 256-row tiles numbered
by the bf16 grouped helpers (single-height branch added); K-grouped: the bf16 plan kernel, turn
counters and fp32 read-modify-write (deterministic segment order), bounds-checked VGPR offsets
so rows past a segment read 0. Outputs bit-identical to the ROCm#6696 NT kernel on dense shapes.

Kernels opus_gemm_gfx950_mxfp8_{m,k}_grouped_*: m_grouped kids 0 (256x256) / 1 (256x128),
k_grouped 10; images built by build_co.py --arch gfx950 --family a8w8_blockscale_grouped (a
second GROUPED_FAMILIES entry; bf16 images unchanged).

Test op_tests/test_opus_a8w8_blockscale_grouped_gemm.py: GLM-5.3 / Kimi-K3 shapes, 5 token
distributions, masked; vs SonicMoE blockwise FP8 (fwd 1.9-2.2x, dgrad 2.2-2.5x geomean on gfx950)
and the dense ROCm#6696 kernel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fyzyukk added a commit to Fyzyukk/aiter that referenced this pull request Nov 23, 2026
… MoE training

FP8 e4m3 grouped GEMMs with E8M0 block scales and no shuffling of operands or scales, on the
MXFP8 1x128 4-wave pipeline (1x32 scale MFMA 16x16x128), with the DeepGEMM interfaces of the
bf16 grouped GEMMs:
  m_grouped_fp8_blockscale_gemm_{nt,nn}_contiguous / _nt_masked   fwd / dgrad, x 1x128, W 128x128
  k_grouped_fp8_blockscale_gemm_tn_contiguous                       wgrad, dY / X 128x1 along tokens

Unshuffled B takes A's copy / LDS / reader layouts ([N, K] as [M, K], [K, N] as [K, M]); wgrad's
per-column B scales take A's scale panel (op_sel per fragment). M-grouped: 256-row tiles numbered
by the bf16 grouped helpers (single-height branch added); K-grouped: the bf16 plan kernel, turn
counters and fp32 read-modify-write (deterministic segment order), bounds-checked VGPR offsets
so rows past a segment read 0. Outputs bit-identical to the ROCm#6696 NT kernel on dense shapes.

Kernels opus_gemm_gfx950_mxfp8_{m,k}_grouped_*: m_grouped kids 0 (256x256) / 1 (256x128),
k_grouped 10; images built by build_co.py --arch gfx950 --family a8w8_blockscale_grouped (a
second GROUPED_FAMILIES entry; bf16 images unchanged).

Test op_tests/test_opus_a8w8_blockscale_grouped_gemm.py: GLM-5.3 / Kimi-K3 shapes, 5 token
distributions, masked; vs SonicMoE blockwise FP8 (fwd 1.9-2.2x, dgrad 2.2-2.5x geomean on gfx950)
and the dense ROCm#6696 kernel.

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.

3 participants