Skip to content

[HIP] [OPUS] Add opus gfx950 blockscale_mxfp8 nn/tt/tn layout gemm - #8283

Open
Fyzyukk wants to merge 18 commits into
ROCm:mainfrom
Fyzyukk:fyz/opus_mxfp8_blockscale_nn_tt_tn_v2
Open

Fyzyukk wants to merge 18 commits into
ROCm:mainfrom
Fyzyukk:fyz/opus_mxfp8_blockscale_nn_tt_tn_v2

Conversation

@Fyzyukk

@Fyzyukk Fyzyukk commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a gfx950 OPUS MXFP8 1x128 blockscale GEMM for the NT, NN, TT and TN operand layouts with plain (not shuffled) A and B, as DeepGEMM's fp8_gemm_{nt,nn,tn,tt}. Training callers (dgrad / wgrad, where B is an activation or a gradient produced every step) run directly from the stored tensors, with no transpose copy and no shuffle_weight pass. The preshuffled-B NT kernels from #6696 / #7387 are unchanged. The kernels take any M, N and K >= 1 and read A, B and the scales in place, with no padded copy of any tensor; A, B and the output may each be 4 GiB or larger.

Details

  • One pipeline for four layouts: opus_gemm_pipeline_a8w8_blockscale_mxfp8_4wave_gfx950.cuh / opus_gemm_traits_a8w8_blockscale_mxfp8_4wave_gfx950.cuh. A and B share the same copy / LDS / read layouts (B passes N as M); each operand picks its path by its storage: K-contiguous ([M, K] / [N, K]) reads with ds_read_b128, A_T (A stored [K, M]) / B_T (B stored [K, N]) with ds_read_b64_tr_b8. NT = (0, 0), NN = (0, 1), TT = (1, 0), TN = (1, 1). Both LDS layouts are XOR-swizzled, so the operand reads are free of bank conflicts. 2x2 waves, LDS-DMA copies, A / B and part of C pinned to AGPRs.

  • Formats: FP8 A / B as stored, E8M0 scales (1x128 for A, 128x128 for B), BF16 C. The scales have ceil(K / 128) K groups and ceil(N / 128) N groups; the last group covers the elements left.

  • Any M, N, K in the kernel: every kid takes every shape.

    • M: tiles overlap instead of being partial. The last M tile starts at M - 256, and a single tile of 128 <= M < 256 rows puts its second 128-row half at M - 128; the shared rows are computed twice with the same result. The main loop is the same as for an aligned shape. Only M < 128 has partial halves.
    • N: B's scale is per aligned 128-column group, so N tiles cannot overlap. The view of B ends with its last valid row, so the buffer bounds check rejects the rows past it, and the epilogue masks the output columns past N.
    • K: the last K tile may be partial; K below 16 needs no padding.
    • Every view of A, B, the scales and C ends with its operand, so each access is inside the operand or rejected by the bounds check. A rejected 16-byte load that holds valid bytes (the chunk with K of a K-contiguous operand, the last 16-column group in the last K row of a [K, M] / [K, N] one, the last 16 rows of x_scale) is reloaded exactly with 8 / 4 / 2 / 1-byte loads before that K tile is read.
    • Views have a 64-bit base and a 32-bit range, so only one view must stay below 2**31 bytes (128 rows of a K-contiguous operand, 128 K rows of a transposed one, 256 rows of the output, x_scale).
    • An operand may be a view of a wider buffer: rows of a [M, K] / [N, K] operand any pitch >= K apart, K rows of a [K, M] / [K, N] one any pitch >= M / N apart, output rows any pitch >= N apart.
  • Kids: 8 per layout (NT 0-7, NN 8-15, TT 16-23, TN 24-31): 256x256, 256x128, and GroupM 4 / 8 / 16 of each. All 32 COs have zero VGPR / SGPR spills, no scratch, and the AGPR pins checked by the builder.

  • Interface: new aiter.ops.opus.gemm_a8w8_blockscale_opus(XQ, WQ, x_scale, w_scale, *, kernelId=None, out=None). The layout is read from the operand strides (pass .t() views, never copies); without kernelId a kid is picked by shape. The kids also run through the exact-kid opus_gemm(..., family="a8w8_blockscale_mxfp8", layout="plain", kid=...), which takes the same shapes. An empty product (M, N or K of 0) returns an empty or zero output without a launch. A single row or column is stored both ways at once and is taken by the kids of every layout.

  • Kid pick: 256x128 tiles while they do not outnumber the CUs, else 256x256; GroupM for a tall, narrow grid. On a sweep of every kid over 264 shapes per layout (256 CUs, three timings per kid) the pick is 1.0 - 1.2% slower than the fastest kid on average.

  • CO build: -fuse-cuid=none in the manifest makes the images reproducible bit for bit, from any checkout path. build_info.json is build_co.py's own output; gen_co/README.md has the rebuild command.

Performance

MI355X (gfx950, 256 CUs), BF16 output, microseconds from op_tests/test_opus_a8w8_blockscale_mxfp8.py (kid picked by shape). NT shuffle = a preshuffled-B NT CO (a8w8_blockscale_bpreshuffle) on shuffle_weight(B).

Shape (M x N x K) NT shuffle (us) NT plain (us / vs NT shuffle) NN (us / vs NT plain) TT (us / vs NT plain) TN (us / vs NT plain)
16384 x 16384 x 16384 3913.4 3881.3 / -0.8% 3860.7 / -0.5% 4015.0 / +3.4% 4014.6 / +3.4%
8192 x 8192 x 8192 365.1 367.2 / +0.6% 381.4 / +3.9% 385.0 / +4.8% 376.4 / +2.5%
4096 x 4096 x 4096 53.2 55.0 / +3.4% 55.3 / +0.5% 54.1 / -1.6% 54.4 / -1.1%

Ragged shapes, us for NT / NN / TT / TN. "Before" is the previous revision of this PR, which zero-padded copies of the operands in Python.

Shape (M x N x K) Before After
1023 x 1023 x 1023 62.0 / 62.0 / 61.9 / 60.9 22.5 / 23.1 / 21.6 / 21.9
4095 x 4096 x 4096 83.9 / 84.9 / 91.4 / 91.8 54.9 / 55.1 / 67.9 / 67.3
4096 x 4095 x 4096 83.6 / 94.0 / 84.8 / 93.2 66.4 / 77.0 / 65.4 / 75.3
4096 x 4096 x 4095 87.3 / 65.6 / 71.1 / 59.6 82.4 / 68.5 / 65.9 / 54.6
4095 x 4095 x 4095 113.9 / 108.2 / 109.6 / 108.5 94.5 / 92.2 / 91.4 / 89.6

Test Plan

  • op_tests/test_opus_co_integration.py -k gfx950: 619 passed. Every a8w8_blockscale_mxfp8 kid against an fp32 reference on aligned and ragged shapes through the exact-kid path, wrong-layout rejection, gemm_a8w8_blockscale_opus over runs of M, N and K around the tile, half-tile, 16-row and K-tile edges, pitched operand and output views, single rows and columns, empty products, K mismatch and strided-output rejection, A / B / C past 4 GiB, views past 2 GiB rejected, the kid pick, and the tracked .co images against the hashes in build_info.json. Operands are followed by FP8 NaN bytes and the output by canaries.
  • op_tests/test_opus_a8w8_blockscale_mxfp8.py: 36 rows (4 layouts x 9 shapes), err = 0 on all.
  • op_tests/test_opus_a8w8_interface.py: 8 passed.
  • The launchers generated for every other family (517 files, the preshuffled-B ones included) are byte-identical to those before this change.

Test Plan

  • op_tests/test_opus_co_integration.py -k gfx950: 295 passed (every a8w8_blockscale_mxfp8 kid against an fp32 reference, wrong-layout rejection, gemm_a8w8_blockscale_opus with any M / N / K, wide-row views, A / B / C past 4 GiB, views past 2 GiB rejected, the kid pick).
  • op_tests/test_opus_a8w8_interface.py: 8 passed.

@Fyzyukk
Fyzyukk requested a review from a team November 19, 2026 08:03
@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 8283 --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 gfx950 blockscale_mxfp8 nn/tt/tn layout gemm [HIP] [OPUS] Add opus gfx950 blockscale_mxfp8 nn/tt/tn layout gemm Nov 19, 2026
@aiter-bot

aiter-bot commented Nov 19, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 8e9674fe4862 · 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_a8w8_blockscale_mxfp8.py
  • 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_mxfp8_blockscale_nn_tt_tn_v2 branch from 87d9ffd to ad4ab51 Compare November 19, 2026 08:15
@zufayu
zufayu requested review from demonsan and yifehuan November 20, 2026 01:24
Extends the gfx950 OPUS MXFP8 blockscale GEMM (FP8 A / B, E8M0 scales 1x128 for
A and 128x128 for B, BF16 C) from NT to the three other operand layouts, without
a transpose copy. Stacked on PR ROCm#7387.

- One pipeline / traits pair for the three directions:
  opus_gemm_pipeline_mxfp8_4wave_gfx950.cuh / opus_gemm_traits_mxfp8_4wave_gfx950.cuh.
  Each operand picks its LDS path from its storage: A_T (A stored [K, M]) and B_T
  (B stored [K, N]) read with ds_read_tr8; NN = (0, 1), TT = (1, 0), TN = (1, 1).
  2x2 waves, LDS-DMA copies, A / B and part of C pinned to AGPRs; TR8 reads use
  the ds_read_tr8 builtin so their results land in AGPRs.
- Traits <BM, BN, PadM, GroupM>: 256x256 or 256x128 tiles, optional PadM, GroupM
  0 (2x2 raster) / 4 / 8 / 16 as NT's gm.
- CO kids 56-85, appended to co_kernels_gfx950_a8w8_blockscale_bpreshuffle.json;
  images and build records in gen_co/gfx950/a8w8_blockscale_bpreshuffle/
  (pin toolchain, 0 spills):
    56-67  NN / TT / TN x {256x256, 256x256 PadM, 256x128, 256x128 PadM}
    68-85  NN / TT / TN x {256x256, 256x128} x GroupM {4, 8, 16}
- Same kargs and launcher family as NT (a8w8_blockscale_bpreshuffle); the
  direction comes from the kernel name (_mxfp8_(nn|tt|tn)_) and the generated
  launcher checks that direction's operand / scale strides.
- Called through the public exact-kid entry opus_gemm(..., family=
  "a8w8_blockscale_bpreshuffle", layout="bpreshuffle", kid=56..85); a tensor
  layout of another direction is rejected by the launcher's stride check. The
  shape heuristic / tuner never pick the direction kids. Like the other gfx950
  MXFP8 kids they are compiled on request (tuned rows, the compiled-kids sidecar
  or opus_gemm_tune._ensure_kids_compiled), not by default.
- build_co: the pin check of the direction kids accepts AGPR ranges filled by
  plain or TR8 LDS reads.
- test_opus_co_integration.py: NN / TT / TN kids (256x256 across the scale panel,
  256x128 PadM, GroupM 16) against a torch reference, and another direction's
  launcher rejecting the strides.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Fyzyukk
Fyzyukk force-pushed the fyz/opus_mxfp8_blockscale_nn_tt_tn_v2 branch from ad4ab51 to 8673a97 Compare November 20, 2026 13:07
@github-actions github-actions Bot changed the title [HIP] [OPUS] Add opus gfx950 blockscale_mxfp8 nn/tt/tn layout gemm [OPUS] Add opus gfx950 blockscale_mxfp8 nn/tt/tn layout gemm Nov 20, 2026
@github-actions github-actions Bot removed the HIP label Nov 20, 2026
Fyzyukk and others added 6 commits November 21, 2026 11:10
… TT / TN

- aiter.ops.opus.gemm_a8w8_blockscale_bpreshuffle_opus(XQ, WQ, x_scale,
  w_scale, dtype, *, kernelId=None, out=None): reads NN / TT / TN from the
  operand strides, rejects NT, and picks a kid by shape when kernelId is
  not given (256x128 for N % 256 or outputs up to 2048 x 2048, GroupM 16
  from M = 16384, PadM only when M % 256).
- default_compiled_keys adds kids 56-85 on gfx950, so the API runs on a
  fresh JIT build; no tuned row or heuristic requests these kids.
- test_opus_co_integration: every kid 56-85 against the reference, plus
  API tests (shape-picked kid per layout, explicit kernelId + out, NT and
  unsupported-shape rejection).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…T / TN

Merge _BPRESHUFFLE_ARGUMENTS and _mxfp8_direction_arguments into one
_bpreshuffle_arguments(direction) template; only the XQ/WQ layout check,
the scale layout check and stride_a / stride_b / stride_sfb differ per
direction. Read the direction from the CO manifest "pipeline" field
instead of matching the kernel name.

Generated NT sources (8784 instances) are byte-identical; the 30 NN/TT/TN
sources differ by one line break only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace the kernel-name regex MXFP8_DIRECTION_PATTERN with
mxfp8_direction(entry), which maps the manifest "pipeline" field
(mxfp8_nn / mxfp8_tt / mxfp8_tn) to "NN" / "TT" / "TN". Used by the
candidate filter, default_compiled_keys, the gfx950 host codegen, the
build_co pin check and the gemm_a8w8_blockscale_bpreshuffle_opus kid
selection.

Same 30 direction kids as before; generated sources are byte-identical
and the 30 rebuilt .co disassemble identically.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Training callers (dgrad / wgrad) pass activations and gradients as B, so B
must not need shuffle_weight, as in DeepGEMM's fp8_gemm_{nt,nn,tn,tt}.

- B reuses A's copy / LDS / read layout builders (N as M): K-contiguous
  storage reads with ds_read_b128, [K, N] storage with ds_read_b64_tr_b8 and
  the same XOR swizzle as A_T. The shuffled-B builders are removed.
- Add plain NT, (A_T, B_T) = (0, 0): kids 86-95 (pipeline mxfp8_nt), the
  same 10 tile variants as each other layout. The 256x256 A-first schedule
  splits A reloads by a_chunks (NT's plain A has 2 chunks per fragment).
- Non-NN-schedule B copies use per-pass layouts, which keeps B's buffer
  resource in SGPRs (no waterfall loops in TN GroupM / TT PadM).
- Rename the API to gemm_a8w8_blockscale_opus; it accepts NT as well.
- Rebuild all 40 COs (kids 56-95) and sync build_info.json.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
[M, K] / [N, K] operand slots hold 8 rows of 128 bytes, so the plain
ds_read_b128 operand reads hit the same banks: SQ_LDS_BANK_CONFLICT per
8192^3 call was 18.7M for NN (A) and TT (B) and 35.5M for NT (both),
against 2.0M for TN. Pad these slots by 64 bytes and store chunk c of
row r at c ^ (r % 4) (copy lane permutation + a constant per-lane read
shift); every layout is now at 2.0M. The pad / swizzle pair was picked
with an LDS microbenchmark of the reader's addresses.

256x256 NT / NN / TT get 1.5-7% faster; 256x128, GroupM and TN are
unchanged. Rebuild the 40 COs (kids 56-95).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…MXFP8

The NT / NN / TT / TN kernels take plain B, so they no longer live with
the preshuffled-B COs:

- kids 56-95 move to gen_co/co_kernels_gfx950_a8w8_blockscale.json and
  gen_co/gfx950/a8w8_blockscale/ (with their own build_info.json); the
  bpreshuffle manifest and directory are back to their ROCm#7387 contents.
- each manifest entry carries its image_dir; the CO loader takes the image
  path relative to gen_co/gfx950/, and build_co writes to the kids' own
  directory by default.
- headers renamed to opus_gemm_{pipeline,traits}_a8w8_blockscale_mxfp8_4wave_gfx950.cuh.

The 40 COs are moved, not rebuilt; rebuilding them from the renamed
sources gives identical disassembly.

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

Stacked on ROCm#7387 / ROCm#8283. Two gfx950 families of one pre-compiled 2x2 pipeline
(opus_gemm_pipeline_a8w8_mxfp8_gfx950.cuh, traits B_SHUF picks the B layout),
each with the same 17 tiles / variants (nob 256x256; np 256x256 / 256x128 /
128x256 / 128x128 / 192x256 / 256x192; persistent and split-K on those tiles
but 256x256, which runs out of registers there):
- a8w8_mxfp8: kids 100-116, plain operands, one image per layout
  <name>_<nt|nn|tt|tn>.co (68 .co); the launcher picks NT / NN / TT / TN
  from the XQ / WQ strides.
  B is copied and read as the mirror of A: B [N, K] with A [M, K]'s LDS
  swizzle, B stored [K, N] k-major + ds_read_tr8 as A stored [K, M].
  A stored [K, M] needs M % 16, B stored [K, N] N % 16.
- a8w8_mxfp8_bpreshuffle: kids 0-16 (kid + 100 is the same tile / variant in
  a8w8_mxfp8), NT with B = shuffle_weight(w, (16, 16)) (the input of
  gemm_a8w8_mxfp8_bpreshuffle), one image <name>.co (17 .co).
Row-major 1x32 e8m0 scales, bf16 C, per-tile 64-bit C base (outputs past
4 GiB), split-K partials summed by splitk_reduce_kernel.
gemm_a8w8_mxfp8_bpreshuffle routes libtype "opus" tuned rows to the
bpreshuffle kids; the mxfp8 tuner times them; DSV4 gfx950 1x32 M >= 1024 rows
retuned (OPUS on 18 of 18).

C++ entries opus_gemm_a8w8_mxfp8_launch / opus_gemm_a8w8_mxfp8_bpreshuffle_launch
(one shared check, per-family kid tables).

gfx950 pre-compiled kernel infrastructure (on ROCm#8283's loader / build_co):
- opus_co_launch_gfx950.cuh: opus_co_launch_gfx950<int KARGS_BYTES = 96> for
  the 112-byte MXFP8 kargs; the launchers load "<family>/<name>.co" through
  ROCm#8283's co_kernel(symbol, image relative to gen_co/gfx950/).
- build_co.py --arch gfx950 --family a8w8_mxfp8 | a8w8_mxfp8_bpreshuffle
  builds a family on its own (as ROCm#7983's a4w4): device-only clang++ on the pin
  toolchain, -cuid pinned, into gen_co/gfx950/<family>/ with its
  build_info.json. The blockscale build is unchanged (the default family).
- gen_instances.py: host launchers marked splitk_reduce_arch emit the reduce TU.
- tuner: opus_mxfp8_candidates / run_gemm_opus_mxfp8 beside the blockscale
  OPUS search (only blockscale kids go to ensure_opus_kids_compiled).
MXFP8 names are prefixed (a8w8_mxfp8_co_kernels_declared, ...), so nothing
collides with gfx950_co_kernels_declared / opus_candidates / run_gemm_opus.

The 85 .co are byte-reproducible with the build above.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The NT / NN / TT / TN kernels take plain B, so they no longer register
under a8w8_blockscale_bpreshuffle or need layout="bpreshuffle":

- new family a8w8_blockscale_mxfp8 (kernel tag a8w8_blockscale_mxfp8,
  layout "plain", BF16 Y), gfx950 only, own kid space 0-39: NT 0-9,
  NN 10-19, TT 20-29, TN 30-39 (manifest renumbered; COs unchanged).
- C++ entry opus_gemm_a8w8_blockscale_mxfp8_launch with its own gfx950
  kid table (GENERATE_A8W8_BLOCKSCALE_MXFP8_KID_DISPATCH_GFX950).
- opus_gemm(..., family="a8w8_blockscale_mxfp8", layout="plain", kid=...)
  and gemm_a8w8_blockscale_opus route through it.
- The family is compiled as a mandatory family, so candidate_kids_for_shape
  and default_compiled_keys are back to ROCm#7387.
- build_co --family selects the gfx950 CO manifest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot changed the title [OPUS] Add opus gfx950 blockscale_mxfp8 nn/tt/tn layout gemm [HIP] [OPUS] Add opus gfx950 blockscale_mxfp8 nn/tt/tn layout gemm Nov 23, 2026
@github-actions github-actions Bot added the HIP label Nov 23, 2026
Fyzyukk added a commit to Fyzyukk/aiter that referenced this pull request Nov 23, 2026
… bpreshuffle

Stacked on ROCm#7387 / ROCm#8283. Two gfx950 families of one pre-compiled 2x2 pipeline
(opus_gemm_pipeline_a8w8_mxfp8_gfx950.cuh, traits B_SHUF picks the B layout),
each with the same 17 tiles / variants (nob 256x256; np 256x256 / 256x128 /
128x256 / 128x128 / 192x256 / 256x192; persistent and split-K on those tiles
but 256x256, which runs out of registers there):
- a8w8_mxfp8: kids 100-116, plain operands, one image per layout
  <name>_<nt|nn|tt|tn>.co (68 .co); the launcher picks NT / NN / TT / TN
  from the XQ / WQ strides.
  B is copied and read as the mirror of A: B [N, K] with A [M, K]'s LDS
  swizzle, B stored [K, N] k-major + ds_read_tr8 as A stored [K, M].
  A stored [K, M] needs M % 16, B stored [K, N] N % 16.
- a8w8_mxfp8_bpreshuffle: kids 0-16 (kid + 100 is the same tile / variant in
  a8w8_mxfp8), NT with B = shuffle_weight(w, (16, 16)) (the input of
  gemm_a8w8_mxfp8_bpreshuffle), one image <name>.co (17 .co).
Row-major 1x32 e8m0 scales, bf16 C, per-tile 64-bit C base (outputs past
4 GiB), split-K partials summed by splitk_reduce_kernel.
gemm_a8w8_mxfp8_bpreshuffle routes libtype "opus" tuned rows to the
bpreshuffle kids; the mxfp8 tuner times them; DSV4 gfx950 1x32 M >= 1024 rows
retuned (OPUS on 18 of 18).

C++ entries opus_gemm_a8w8_mxfp8_launch / opus_gemm_a8w8_mxfp8_bpreshuffle_launch
(one shared check, per-family kid tables).

gfx950 pre-compiled kernel infrastructure (on ROCm#8283's loader / build_co):
- opus_co_launch_gfx950.cuh: opus_co_launch_gfx950<int KARGS_BYTES = 96> for
  the 112-byte MXFP8 kargs; the launchers load "<family>/<name>.co" through
  ROCm#8283's co_kernel(symbol, image relative to gen_co/gfx950/).
- build_co.py --arch gfx950 --family a8w8_mxfp8 | a8w8_mxfp8_bpreshuffle
  builds a family on its own (as ROCm#7983's a4w4): device-only clang++ on the pin
  toolchain, -cuid pinned, into gen_co/gfx950/<family>/ with its
  build_info.json. The blockscale build is unchanged (the default family).
- gen_instances.py: host launchers marked splitk_reduce_arch emit the reduce TU.
- tuner: opus_mxfp8_candidates / run_gemm_opus_mxfp8 beside the blockscale
  OPUS search (only blockscale kids go to ensure_opus_kids_compiled).
MXFP8 names are prefixed (a8w8_mxfp8_co_kernels_declared, ...), so nothing
collides with gfx950_co_kernels_declared / opus_candidates / run_gemm_opus.

The 85 .co are byte-reproducible with the build above.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fyzyukk and others added 5 commits November 25, 2026 04:53
…tests

- _select_mxfp8_direction_kid is cached per shape (it filtered the registry on every call).
- Tests: the PadM / GroupM kids at K = 1024 in all four layouts, contiguous column-major
  x_scale.
- build_info.json: the images were built as kids 56-95 and renumbered to 0-39 without a
  rebuild.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…main, ROCm#8266)

The CI image is on triton 3.9, which rejects scalar[None, :] in
_dynamic_mxfp4_quant_kernel_asm_layout; op_tests/test_gemm_a4w4.py fails to compile it on
this branch. Same line as upstream main, so a later merge of main is a no-op here.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
… kid pick

Kernel (NT / NN / TT / TN, all 40 COs rebuilt, zero spills):
- A and B are addressed from a 64-bit base per tile, or per K tile for an
  operand stored [K, M] / [K, N], with a range of just that view, so A, B and
  the output may each be 4 GiB or larger. The limit is now one view below
  2**31 bytes instead of the whole operand.
- K need not be a multiple of 128. A [K, M] / [K, N] view of the last K tile
  ends with the last K row, so the rows past K read zero. A K-contiguous
  operand's last tile is copied as before and then rewritten from the last 16
  bytes of each row, shifted and zero-filled, which never reads past the row.
  The iteration that copies the last K tile runs after the steady loop.
- The rows of a K-contiguous operand may be more than K apart.

Launcher and shape checks: wide_input / pad_k in the CO manifest; ceil(K / 128)
scale groups; K >= 16 with a K-contiguous operand.

gemm_a8w8_blockscale_opus:
- Any M, N, K: M is zero-padded to a multiple of 16 (XQ and x_scale), N to a
  multiple of 128 (WQ), K below 16 to 16, and [M, N] is cut from the padded
  output.
- The kid pick is refitted to a sweep of every kid over 264 shapes per
  direction on a 256-CU gfx950: 256x128 tiles while they do not outnumber the
  CUs, GroupM 4 / 8 for a tall, narrow grid. Against the fastest kid it is 0.5%
  slower on average (was 3.2%, worst case 48%); 1.6% on 120 shapes outside
  the grid (was 5.2%).

Not addressed: a K % 128 != 0 operand packed [M, K] / [N, K] has rows that do
not start on a 128-byte boundary, which the kernel reads up to 2x slower on a
small GEMM (TN, and rows a multiple of 128 apart, are unaffected).

Co-Authored-By: Claude Fable 5.2 <[email protected]>

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

Reviewed at head 633109985c5f. Nice work on the 4-layout pipeline and per-tile 64-bit addressing. Before merging, we need genuine all-shape support (and a few edge-case/hygiene fixes):

1. Support arbitrary (M, N, K) shapes natively (not via full-tensor Python padding copies)

Right now, the kernels themselves still require M % 16 == 0 (pm1 kids only; non-pm1 kids require M % 256 == 0), N % 128 == 0, and K >= 16 for K-contiguous layouts (NT/NN/TT). gemm_a8w8_blockscale_opus works around this by allocating zero-padded copies of XQ, x_scale, WQ, and Y in Python (plus a full Y[:M, :N].contiguous() copy on output), while exact-kid opus_gemm(..., family="a8w8_blockscale_mxfp8") rejects unaligned shapes outright.

For training dgrad/wgrad on large tensors, full-matrix padding copies double peak HBM and add HBM round-trips. Please support arbitrary (M, N, K) in the kernel (arbitrary M / N tail handling without full-tensor copies, e.g., column-bounded epilogue / N-tail OOB and M % 16 != 0 handling), and also handle empty tensors (M == 0 / N == 0 / K == 0) cleanly if callers pass them.

2. Shape & layout edge-case bugs in gemm_a8w8_blockscale_opus

Even with the current wrapper, several shape/layout edge cases are broken or inconsistent:

  • Silent K-mismatch when K < 16 (aiter/ops/opus/gemm_op_a8w8.py:659-678): WQ.shape[1] == XQ.shape[1] is never validated before padding. For non-TN calls where both K dimensions are < 16 and differ (e.g. XQ=[16, 8], WQ=[128, 12]), both operands get zero-padded to run_k = 16, bypassing C++'s WQ.size(-1) == k check and silently returning wrong output.
  • Wide-row stride vs. K extent mismatch (csrc/opus_gemm/opus_gemm_common.py:3963-3966 vs. csrc/opus_gemm/codegen/gen_instances_gfx950.py:3332): Python checks B_M * k <= INT32_MAX (using logical k), whereas the C++ launcher checks B_M * XQ.stride(-2) <= INT32_MAX. A wide-row view with stride(0) > 8,388,607 and smaller k passes kid selection and then fails in C++. Also on non-gfx950 devices, an empty registry currently surfaces the misleading "below 2**31 bytes" ValueError.
  • M=1, K=1 / N=1, K=1 stride ambiguity (aiter/ops/opus/gemm_op_a8w8.py:486-505): stride == (1, 1) always resolves to k_contiguous ("N" / "T"), which causes explicit TT/TN kernelId calls to fail after padding into the wrong storage layout.
  • Explicit non-pm1 kernelId with M % 256 != 0 (aiter/ops/opus/gemm_op_a8w8.py:559-568, 671): _mxfp8_run_shape always pads M to a multiple of 16 regardless of the requested kernelId's m_align (256 for non-pm1 kids).
  • Layout asymmetries:
    • Strided views (stride > M/N) are accepted for K-contiguous operands ([M, K]/[N, K]), but rejected for A_T/B_T ([K, M]/[K, N], which require exact (1, M)/(1, N)).
    • Non-contiguous out fails in C++ (Y.is_contiguous()) when (M, N) is already aligned, yet succeeds via out.copy_(Y[:M, :N]) when padded.

3. Binary verification, reproducibility, docs & PR hygiene

  • .co hash check: please add a test in op_tests/test_opus_co_integration.py verifying all 40 shipped .co files match co_sha256 in build_info.json (like the gfx1250 test) and document the exact rebuild command.
  • Benchmark reproducibility: please include the benchmark/sweep script (or a --scenario bench path) backing the latency table and the 264-shape kid-selection fit (m_tiles >= 4, n_tiles <= 8), so reviewers can reproduce numbers and re-fit for 128-CU parts.
  • Docs & Self-Review: please update csrc/opus_gemm/gen_co/README.md for --family and gfx950/a8w8_blockscale/, and fill in the PR Self-Review section (currently WAITING ON AUTHOR).
  • PR size: at ~6.5k lines / 59 files, consider splitting into stacked PRs (1. codegen/launcher plumbing, 2. kernel headers + .co + build_info.json, 3. Python API + tests) to make review easier.

Fyzyukk and others added 4 commits November 30, 2026 08:52
…pies

Kernel (NT / NN / TT / TN; 32 COs, zero spills, AGPR pins kept):
- Every kid takes any M, N and K >= 1 and reads A, B and x_scale in place.
  M tiles overlap instead of being partial (the last one starts at M - 256, a
  single tile of 128 <= M < 256 rows puts its second half at M - 128), so the
  main loop is unchanged. A partial N tile is handled by the buffer bounds
  check on the B view and a column mask in the epilogue.
- Each view ends with its operand, so every load is inside the operand or
  rejected. A rejected 16-byte load that holds valid bytes (the chunk with K
  of a K-contiguous operand, the last 16-column group in the last K row of a
  [K, M] / [K, N] one, the last 16 rows of x_scale) is reloaded exactly with
  8 / 4 / 2 / 1-byte loads before the K tile is read. K below 16 no longer
  needs padding.
- What only the fix-ups, the scale panel refill and the epilogue need is
  parked in LDS, not kept in SGPRs across the main loop.
- The PadM kids are gone (every kid does what they did): 8 kids per layout,
  NT 0-7, NN 8-15, TT 16-23, TN 24-31.

Launcher and registry: any_shape in the CO manifest replaces wide_input /
pad_k; grid and scale groups round up; a [K, M] / [K, N] operand and the output
may be views of a wider buffer; the view limits go by the pitch, in Python as in
the launcher.

gemm_a8w8_blockscale_opus: no padding and no output copy; XQ / WQ K mismatch is
an error; an empty product returns an empty or zero output; a single row or
column is taken by the kids of every layout; a strided-column out is rejected
whatever M is; the pick may take 256x256 tiles on a ragged N; the registry is
no longer read on every call.

CO build: -fuse-cuid=none makes the images reproducible bit for bit;
build_info.json is build_co.py's own output and a test checks the tracked
images against its hashes. gen_co/README.md documents the family and the
rebuild command; op_tests/op_benchmarks/hip/bench_opus_a8w8_blockscale_mxfp8.py
reruns the latency table and the kid-pick sweep.

Co-authored-by: Fyzyukk-AMD <[email protected]>
Nested ifs merged, a placeholder-free f-string made a plain string, imports
sorted, a lambda made a def and a self-assignment dropped. No behaviour change.

Co-authored-by: Fyzyukk-AMD <[email protected]>
… the launcher

The tune entry looks the kid up in the registry on every call, which costs
several hundred microseconds and hid the kernels behind it: every preshuffled-B
kid timed about 420 us. Launch with the instance instead, and skip a kid the
JIT module has no launcher for.

Co-authored-by: Fyzyukk-AMD <[email protected]>
op_tests/test_opus_a8w8_blockscale_mxfp8.py follows the op_test layout: per
(layout, M, N, K), gemm_a8w8_blockscale_opus against an fp32 torch reference
with its time, TFLOPS and TB/s, aligned shapes next to ragged ones, and for NT
the preshuffled-B kernel when the build has a launcher for one of its CO kids.
It replaces op_tests/op_benchmarks/hip/bench_opus_a8w8_blockscale_mxfp8.py.

Co-authored-by: Fyzyukk-AMD <[email protected]>
@Fyzyukk

Fyzyukk commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

1. Support arbitrary (M, N, K) shapes natively (not via full-tensor Python padding copies)

The kernels now take any M, N, K >= 1 natively. The Python wrapper no longer pads or copies, and the exact-kid path takes the same shapes. Empty tensors return an empty or zero output. Every kid takes any M, so the PadM kids are removed (8 kids per layout).

2. Shape & layout edge-case bugs in gemm_a8w8_blockscale_opus

All fixed, each with a test:

  • K mismatch is now a ValueError.
  • Python and the launcher use the same extent check, based on the row pitch.
  • M = 1 / N = 1 / K = 1 work on the kids of every layout.
  • Any kid works with any M.
  • [K, M] / [K, N] operands accept pitched views, like K-contiguous ones.
  • out with a row pitch is accepted and strided columns are rejected, whatever M is.

Each has a test in op_tests/test_opus_co_integration.py.

3. Binary verification, reproducibility, docs & PR hygiene

  • A test checks all 32 .co files against co_sha256. The build is now bit-reproducible, and the rebuild command is in gen_co/README.md.
  • op_tests/test_opus_a8w8_blockscale_mxfp8.py reproduces the latency table.
  • gen_co/README.md covers --family and the new directory. The Self-Review section is filled in.
  • Kept as one PR: the kernel, the .co images and the Python API have to change together.

@Fyzyukk
Fyzyukk requested a review from demonsan December 1, 2026 02:07
@demonsan

demonsan commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

aiter-bot — queued behind 9 review(s); expect to start in about 2.6 h. The box reviews one PR at a time.

@aiter-bot

Copy link
Copy Markdown

⚠️ aiter-bot — this review could not complete: a problem with the runner environment (gh, token, git), not with this PR.

fetch produced no WORK dir -- check gh auth/token, network, git and disk on the runner

@zufayu — please take a look.

Re-comment @aiter-bot review once it is resolved.

@demonsan

demonsan commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

⚠️ aiter-bot — this review could not complete: a problem with the runner environment (gh, token, git), not with this PR.

fetch produced no WORK dir -- check gh auth/token, network, git and disk on the runner

@zufayu — please take a look.

Re-comment @aiter-bot review once it is resolved.

zufayu added a commit that referenced this pull request Dec 4, 2026
…runcated watchdog read, size the agent timeouts for the 4-lane pool (#9201)

* [CI] review-bot: read WORK out of a binary fetch log, retry a stalled watchdog read, size the agent timeouts for the 4-lane pool

Three failure modes from the 2026-12-04 outage (6 failed runs, 01:24-03:02):

- run_one.sh extracted WORK= from the tee'd fetch log with a bare grep, so a PR
  with binary artifacts (OPUS .co blobs put NULs in that log) made grep answer
  "binary file matches" instead of the match -- a fetch that SUCCEEDED was
  reported as "fetch produced no WORK dir" on every retry (#8283/#7979/#7983).
  grep -a reads the log as text.

- watchdog.py caught only HTTPError, so a 30s socket timeout crashed the
  watchdog with a bare TimeoutError and failed a run whose review had already
  published a green card (#9178). A stalled GET is now retried (3 attempts,
  5s backoff); a POST is never retried, because a retried comment can land
  twice, and a failed POST degrades to 0, which the caller already warns about.

- AITER_AGENT_TIMEOUT=2400s was sized for one review at a time; the 4-lane
  pool serves four through the same GLM endpoint and workers measured 25-40+
  min under that load, so 2400s timed out live while the backend answered
  normally (#8983/#8541). Defaults now 3300s/agent and 6900s/run (115 min,
  still under the job's timeout-minutes of 120; check_prompts.py asserts it).

watchdog_test.py gains real-socket transport checks (the retry lives below the
_get/_post seam its fakes replace) with a mutation guard; _fetchfail_test.sh
gains the binary-log case. selftest: 156 green / 0 red.

Co-Authored-By: Claude Code <[email protected]>

* watchdog: retry a truncated response body, not just a stalled read

A response that dies mid-body raises http.client.IncompleteRead -- an
HTTPException, not an OSError -- so the OSError-only retry net added for
the 2026-12-04 stall let it escape unretried and unnamed: the same
bare-traceback crash one layer up, and _post's RuntimeError guard could
not degrade it either. Name the family in the catch so a truncated GET is
retried like a stalled one and a truncated POST degrades to 0.

Co-Authored-By: Claude Code <[email protected]>

---------

Co-authored-by: zufayu <[email protected]>
Co-authored-by: Claude Code <[email protected]>
@zufayu

zufayu commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

aiter-bot — queued behind 3 review(s); expect to start in about 39 min. The box reviews up to 4 PRs at a time.

@aiter-bot aiter-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ROCm/aiter PR #8283 — [HIP] [OPUS] Add opus gfx950 blockscale_mxfp8 nn/tt/tn layout gemm

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — triage required the target op_tests/test_opus_a8w8_blockscale_mxfp8.py (the one test target this PR adds) but auto-validation is disabled (REVIEW_AUTO_VALIDATE=0) and this box has no idle GPU to run it by hand (all 8 GPUs ~90% busy, torch.cuda unavailable); CI at head 8e9674f ran the new tests green (Aiter Test and OPUS Test on MI35X), which is not a head-matched report.
Perf (advisory): NOT RUN — perf triage required the target (it ships the perftest harness) but no idle GPU and no validator on this box; the PR's latency table is head-only (measured against the preshuffled NT kernel and against the PR's own previous revision, not against main).
Size: 6120 lines / 53 files — over the review bar
Design (advisory): SPLIT — (1) the family plumbing: registry, codegen, launcher, dispatch and contract (opus_gemm_common.py, gen_instances_gfx950.py, gen_instances.py, opus_co_launch_gfx950.cuh, opus_gemm_arch_gfx950.cuh, opus_gemm.h, opus_gemm.cu, rocm_ops.hpp, opus_gemm_pybind.cu, dispatch.py, launch_plan.py); (2) the kernel and its binaries: the two new gfx950 pipeline/traits headers, the CO manifest, the 32 .co images, build_info.json, build_co.py, gen_co/README.md; (3) the Python API and its tests: gemm_op_a8w8.py, aiter/ops/opus/init.py, op_tests/test_opus_a8w8_blockscale_mxfp8.py, op_tests/test_opus_co_integration.py — the author's case for one PR (kernel, .co images and Python API change together) is real, but at this size a review degrades from reading to sampling; ghstack keeps the together-ness while making each part readable.
Human: recommend demonsan review whether the one-pipeline-four-layouts design of PR #8283 (shared A/B copy and LDS layouts with B passing N as M, overlapping M tiles and 32-bit-range buffer views replacing Python-side zero-padding) is the right contract for the a8w8_blockscale_mxfp8 training callers, and where the stacked seams should fall.

⚠️ [verified] No independent or base-vs-head timing exists for the new family: the perf target op_tests/test_opus_a8w8_blockscale_mxfp8.py was never run on a locked GPU (auto-validation disabled, no idle GPU on this box), and the PR's own table is head-only — its baselines are the preshuffled NT kernel and the PR's own previous revision, so a regression against main cannot show — so the central claims (within −0.8 %..+4.8 % of the preshuffled path on aligned shapes, 1.2–1.9× on ragged shapes) are unreproduced. Author must take (or ask for) one run of python3 op_tests/test_opus_a8w8_blockscale_mxfp8.py on a locked MI35X before merge.

⚠️ [verified] The PR description at head 8e9674f carries two conflicting "## Test Plan" sections (619 passed vs 295 passed) and no "PR Self-Review" section, while the author's Nov 30 comment claims "The Self-Review section is filled in" — the repo's aiter-bot gate lists those sections as FAIL (shadow mode today, enforce later), so a reviewer cannot tell which test count is current and the self-review answers the bot demands are absent. Author must delete the stale Test Plan section and add the Self-Review answers at the current head SHA.

📝 [verified] The new op ships dormant: nothing outside the two test files calls gemm_a8w8_blockscale_opus, and no consumer PR is mentioned for the DeepGEMM-style fp8_gemm_{nt,nn,tn,tt} training caller the interface mirrors. Reviewer should ask who lands the first consumer and where that work is tracked.

📝 [verified] The kid-pick rule in gemm_op_a8w8.py was fitted to a 264-shape sweep on a 256-CU gfx950 only, but the family registry maps the same 32 kids to 128-CU gfx950 parts too, where the pick's fit is stated nowhere and the kid-pick test skips unless cu_num == 256 — a 128-CU part could be getting silently suboptimal kid choices (latency only, not correctness, and unmeasured here). Author must state or measure the 128-CU fit, or scope the pick's claim to 256-CU parts.

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