Skip to content

[HIP] [CK] [OPUS] Add opus mxfp4 bpreshuffle nt gemm - #7979

Open
Fyzyukk wants to merge 14 commits into
ROCm:mainfrom
Fyzyukk:fyz/opus_mxfp4_nt_gemm
Open

Fyzyukk wants to merge 14 commits into
ROCm:mainfrom
Fyzyukk:fyz/opus_mxfp4_nt_gemm

Conversation

@Fyzyukk

@Fyzyukk Fyzyukk commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Add an OPUS backend for MXFP4 x MXFP4 NT GEMM with B preshuffle on gfx950. gemm_a4w4(bpreshuffle=True) interface to select tuned OPUS kernels.

Details

  • 2x2 4-wave pipeline: pre-compiled .co kernels with persistent/splitK/nob.
  • 1x4 small-tile pipeline: JIT-built for M <= 512.
  • Support MXFP4 (fp4x2) inputs, native 1x32 E8M0 scales in the e8m0_shuffle layout, B in the shuffle_weight(16, 16) layout and BF16 output through the existing a4w4 GEMM interface. Tuned rows select OPUS kernels via opus_a4w4_kid, and the a4w4 tuner gets an opus backend.

Speedup Distribution

Across all 1464 gfx950/CU256 shapes, the tuned table selects OPUS for 692 shapes:

Speedup range Shapes
0–5% 219
5–10% 102
10–15% 53
15–20% 34
≥20% 284

@Fyzyukk
Fyzyukk requested a review from a team November 15, 2026 06:42
@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 7979 --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 Add opus mxfp4 bpreshuffle nt gemm [HIP] [CK] [OPUS] Add opus mxfp4 bpreshuffle nt gemm Nov 15, 2026
@aiter-bot

aiter-bot commented Nov 15, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision cf26c9e22066 · 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_gemm_a4w4.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_mxfp4_nt_gemm branch 5 times, most recently from 1be6485 to b9bd7da Compare November 15, 2026 13:37
…ackend

Add OPUS MXFP4 x MXFP4 NT GEMM kernels for gfx950 aiter.gemm_a4w4(bpreshuffle=True) inputs (A row-major
fp4x2, B shuffle_weight(16, 16), 1x32 UE8M0 e8m0_shuffle scales, bf16 C):
- 2x2 4-wave pipeline, 18 pre-compiled .co (tiles 128/192/256 x 128/192/256; persistent, one tile per
  block, split-K, no-boundary), registered in gen_co/co_kernels.json under gfx950 and rebuilt
  byte-identically by build_co.py --arch gfx950;
- 1x4 small-tile pipeline (M <= 512), JIT-built with stock ROCm, in-block K split for very small M.
Family a4w4 / gfx950 with local kids 0-5, 10-15, 21-25, 30 (.co) and 410-416 (small), launched through
opus_gemm / opus_bmm (family="a4w4", layout="bpreshuffle"); Python plans split-K and allocates Torch
workspaces. aiter.gemm_a4w4 dispatches tuned rows whose kernelName is the OPUS instance name
(kernelId = local kid), as the a8w8 / bf16 OPUS rows do. The a4w4 tuner gets an opus backend.
a4w4_blockscale_tuned_gemm.csv: 692 of 1464 gfx950 rows switch to OPUS kernels where they beat the best
asm / CK kernel in the same tuning run (MI355X); all other rows unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fyzyukk and others added 5 commits November 16, 2026 02:10
…igned

get_GEMM_config reuses a row tuned at a padded M for every M that pads up to
it, so a row tuned with the no-bounds-check 256x256x256_nob kernel (needs
M % 256 == 0 and N % 256 == 0) is also returned for e.g. M=1664 via the
M=2048 row. _gemm_a4w4_opus launched it anyway and _a4w4_plan raised
ValueError, failing op_tests/test_gemm_a4w4.py (M=1664, N=8192, K=28672).
Switch to the same tile without _nob in that case (None -> CK/asm fallback
if no twin is registered).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…w4_bpreshuffle/

Gives the bpreshuffle family its own directory (and build_info.json) under
gen_co/gfx950/ instead of sharing the arch root. Files are moved unchanged;
build_co.py's default gfx950 output, the runtime loader and co_image_path
follow the new location.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The JSON list key now matches the image directory (A4W4_CO_KEY, relative to
gen_co/), so co_image_path and build_co.py's default output derive from it.
The manifest test checks the arch part of "<arch>/<family>" keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the gfx950 a4w4 bpreshuffle entries out of the shared co_kernels.json
(back to its main content) into gen_co/co_kernels_gfx950_a4w4_bpreshuffle.json;
images stay in gen_co/gfx950/a4w4_bpreshuffle/ (A4W4_CO_DIR). Drops the
previous key rename and its manifest-test change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
opus_co_launch_mxfp4_gfx950.cuh becomes the family-agnostic
opus_co_launch_gfx950.cuh: the launcher passes its image directory under
gen_co/ (co_kernel(symbol, co_dir), cache keyed by co_dir/symbol) and calls
opus_co_launch_gfx950. Read / ELF check / launch logic unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fyzyukk added a commit to Fyzyukk/aiter that referenced this pull request Nov 16, 2026
New a8w8_mxfp8 opus_gemm family: MXFP8 x MXFP8 with 1x32 UE8M0 scales (row-major
x_scale [M, K/32] / w_scale [N, K/32], not shuffled), B in shuffle_weight(16, 16),
bf16 output, in all four operand layouts (NT = gemm_a8w8_mxfp8_bpreshuffle's
inputs; NN: B stored [K, N]; TT: A stored [K, M]; TN: both).

- 2x2-wave pipeline (pre-compiled .co, pin toolchain): tiles 256/192/128 x
  256/192/128, one tile per block / persistent / split-K, M/N boundary
  handling; transposed operands go through LDS k-major and ds_read_tr8.
  Kids 0-16 (co_kernels_gfx950_a8w8_mxfp8_bpreshuffle.json), one image per
  layout in gen_co/gfx950/a8w8_mxfp8_bpreshuffle/.
- Split-K: fp32 partials summed by splitk_reduce_kernel.
- opus layer: _launch_a8w8_mxfp8_gemm picks the layout from the XQ / WQ
  strides (as the a16w16 4-wave family); A stored [K, M] needs M % 16 and B
  stored [K, N] needs N % 32.
- gemm_a8w8_mxfp8_bpreshuffle runs libtype "opus" rows of the tuned CSV (NT),
  falling back to FlyDSL when the tile does not fit; the tuner adds the OPUS
  kids as candidates. No tuned-CSV changes.

Shares the gfx950 pre-compiled .co infrastructure with the MXFP4 NT PR (ROCm#7979):
its code is included here, its kid table, .co images and tuned CSV are not
(they come with ROCm#7979).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fyzyukk and others added 7 commits November 17, 2026 07:06
…y lookup

- test_gemm_a4w4: tuned_shapes()/baseline use _A4W4_PRESHUFFLE_PREFIXES so the
  OPUS rows run in CI; opus_a4w4_kid_sweep() launches every registered kid
  (off-grid M, forced split_k=2 on split-K and small-tile kids); add padded-M
  shapes that reach OPUS rows; assert only the tuned kernel (the default ASM
  baseline is wrong on some large-M shapes, e.g. M=6528 N=7040 K=5632).
- gemm_a4w4_blockscale_tune: opus_candidates returns {} for a CU count with no
  OPUS a4w4 table instead of aborting the default-backend tune.
- get_GEMM_config: document why OPUS rows also serve a padded M.
- a4w4 traits: the split-K counter block is zeroed by the launcher every launch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…impler dispatch

The a4w4 family now has two layouts; this PR is layout="bpreshuffle" and every
name it adds carries it, so it can coexist with layout="plain" kids.

- Naming: tags a4w4_mxfp4_nt_bpreshuffle_co / a4w4_mxfp4_nt_bpreshuffle_small,
  headers opus_gemm_{pipeline,traits}_a4w4_mxfp4_nt_bpreshuffle[_small]_gfx950.cuh,
  kargs / traits / kernel functions / OPUS_MXFP4_BPRESHUFFLE_* and the
  opus_gemm_common.py constants, .co symbols
  opus_gemm_gfx950_a4w4_mxfp4_nt_bpreshuffle_co_*, tuned CSV kernelNames.
  Kids are unchanged (0-30, 410-416).
- C++ entry opus_gemm_a4w4_bpreshuffle_launch (own e8m0_shuffle scale checks);
  opus_check_a8_family_tensors takes the A/B dtype.
- .co pipeline: 64-bit tile base offsets (batch strides long long, row / column
  offsets widened, host kargs too), buffer ranges bounded to one tile; a Y of
  > 2^31 elements no longer overflows (reachable through the padded-M lookup,
  e.g. M >= 262145, N = 6144, K = 16384 on the M = 8192 row). 18 .co rebuilt,
  kernarg 136 B.
- aiter/ops/opus/gemm_op_a4w4.py follows the a8w8 structure:
  _launch_a4w4_bpreshuffle_gemm / _bmm picked by dispatch, shape checks left to
  the C++ entry, split-K pick folded into _a4w4_bpreshuffle_plan.
- gemm_a4w4: OPUS rows match the "opus_" prefix; _gemm_a4w4_opus maps the
  name to its kid (nob -> bounded twin when M/N are not tile-aligned) and lets
  the C++ entry check shapes; kernelId is no longer threaded through.
- test_gemm_a4w4: > 2^31-element Y through kids 0, 10, 30.

All 692 OPUS rows pass, every kid passes the sweep (incl. split_k=2), and the
large-offset case passes; .co kids are within 0.3% of the previous build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ines

Big pipeline: own namespace (opus_mxfp4_bpreshuffle), constexpr cache policies,
ROW_PAIR / A_SPLIT_PAIR / B_SPLIT_PAIR, async_load_rows / async_load_blocks,
opus layouts for the e8m0_shuffle scale panels (make_layout_gsf / ssf / rsf),
one generic sched_quadrant (the hand-tuned 256x256 schedules are dropped),
mma_quadrant as a function, the odd K tile step with a compile-time stage, and
no split_k < 0 separate-reduce mode (aiter launches S > 0 only).
Small pipeline: g_a / g_b / g_sfa / g_sfb up front with out-of-range K tiles by
offset, wave-dim layouts, one LDS array with restrict read views, tiled MMA +
mma_step / sched_step, KS partials in the ring, nt C stores with an OOB offset;
B and the raw scale dwords stay in the register ring. kargs gain stride_b.
All 18 .co rebuilt; every .co / small / split-K kid gives bitwise the same C as
before (153 cases).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts with ROCm#6696 (gfx950 blockscale MXFP8 .co) and ROCm#6067 (ASM f4gemm _ps):
- opus_co_launch_gfx950.cuh: main's loader with an optional co_dir for
  co_kernel() and an optional kernarg size for opus_co_launch_gfx950 (the
  defaults keep the a8w8 blockscale bpreshuffle images); the a4w4 bpreshuffle
  launcher passes "<name>.co", gfx950/a4w4_bpreshuffle and 136.
- build_co.py: main's builder plus --family a4w4_bpreshuffle
  (build_one_a4w4_bpreshuffle, device-only clang++ on the pin toolchain); it
  rebuilds the 18 committed .co byte-identically.
- opus_gemm_common.py / gen_instances*.py: both families registered.
- a4w4_blockscale_tuned_gemm.csv: for each shape both sides retuned, the row
  with the lower us (121 OPUS, 267 main ASM).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…thout family

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

3 participants