Repository navigation
Add opus fp8 mxscale BMM kernels for gfx950 - #4320
Merged
Merged
Conversation
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
Contributor
Author
yzhou103
marked this pull request as ready for review
July 27, 2026 09:27
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds gfx950-only OPUS fp8 (e8m0) mxscale batched GEMM/BMM support as a self-contained kernel + codegen + Python-binding stack, plus tuned configs and a new op_test to validate DeepSeek-V4-style wo_a layouts.
Changes:
- Introduces new gfx950 OPUS BMM frontends (C++ + pybind) and Python wrappers for fp8 e8m0 mxscale flatmm split-K dispatch (tuned CSV + heuristic fallback).
- Extends OPUS codegen/instance plumbing to emit and name the new BMM kernel families and generate the int-kid tuning lookup.
- Adds a new regression/perf op_test and a model-specific tuned CSV; updates the config-collision guard to include the new config family.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| op_tests/tuning_tests/test_config_shape_collision.py | Adds the new mxscale batched-GEMM config family to the shape-collision guard suite. |
| op_tests/test_opus_a8w8_bmm.py | New correctness + perf sweep covering mxscale BMM paths (including batch-major round trip). |
| csrc/pybind/opus_gemm_pybind.cu | Registers the new OPUS BMM pybind entry point. |
| csrc/opus_gemm/opus_gemm_common.py | Extends instance metadata/naming and adds curated gfx950 mxscale BMM kernel lists for codegen/tuning. |
| csrc/opus_gemm/opus_bmm.cu | Adds the host-side gfx950 mxscale BMM dispatcher/front-end and split-K reduce explicit instantiations. |
| csrc/opus_gemm/opus_bmm_bake.cu | Adds a currently-disabled experimental/placeholder TU (needs cleanup before merge). |
| csrc/opus_gemm/include/opus_bmm.h | New public C++ header declaring the OPUS mxscale BMM entry point. |
| csrc/opus_gemm/include/gfx950/splitk_reduce_gfx950.cuh | Adds a BMM-specific split-K reduce kernel template for the fp32 workspace → final Y cast/store. |
| csrc/opus_gemm/include/gfx950/opus_gemm_traits_a8w8_scale_gfx950.cuh | Adds split-K kargs + new mxscale flatmm split-K traits used by the BMM kernel families. |
| csrc/opus_gemm/include/gfx950/opus_gemm_traits_a16w16_gfx950.cuh | Minor comment/style changes for consistency. |
| csrc/opus_gemm/include/gfx950/opus_gemm_pipeline_a8w8_scale_gfx950.cuh | Removes the old monolithic kernel body (now provided via the new pipeline header mapping). |
| csrc/opus_gemm/include/gfx950/opus_bmm_pipeline_a8w8_mxscale_gfx950.cuh | New combined pipeline header providing scaled MFMA helpers + BMM/GEMM scale kernels used by gfx950 codegen. |
| csrc/opus_gemm/include/gfx950/opus_bmm_launchers_a8w8_mxscale_gfx950.cuh | Adds host-only common checks and forward decls for BMM kernel templates (currently needs signature fixes). |
| csrc/opus_gemm/gen_instances.py | Extends instance generation to support BMM mxscale tags and emits a BMM kid→launcher tuning map. |
| csrc/include/rocm_ops.hpp | Adds the pybind macro for opus_bmm_a8w8_mxscale_flatmm_splitk. |
| aiter/ops/opus/bmm_op.py | New Python raw binding + tuned CSV lookup/heuristic wrapper for mxscale BMM. |
| aiter/ops/opus/init.py | Exposes the new BMM ops under aiter.ops.opus. |
| aiter/ops/batched_gemm_op_a8w8.py | Adds backend-neutral public entry batched_gemm_a8w8_mxscale (currently selecting OPUS backend). |
| aiter/jit/optCompilerConfig.json | Adds opus_bmm.cu to the OPUS JIT module build sources. |
| aiter/jit/core.py | Registers the new config env var/path and improves tuned→untuned name derivation + dedup key robustness. |
| aiter/configs/model_configs/dsv4_batched_gemm_a8w8_blockscale_mxscale_tuned.csv | Adds DeepSeek-V4-tuned mxscale batched-GEMM/BMM entries for gfx950. |
Comments suppressed due to low confidence (1)
csrc/opus_gemm/include/gfx950/opus_bmm_launchers_a8w8_mxscale_gfx950.cuh:25
- The forward declaration for
gemm_a8w8_mxscale_flatmm_splitk_mouter_kernelis missing theSKIP_SCALE_WAITbool template parameter (the real kernel istemplate<typename Traits, typename D_OUT, bool SKIP_SCALE_WAIT=false>). Generated launchers for kids that setskip_scale_wait=Truewill fail to compile against this header.
template<typename Traits, typename D_OUT>
__global__ void gemm_a8w8_mxscale_flatmm_splitk_mouter_kernel(opus_gemm_scale_splitk_kargs_gfx950 kargs);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+22
to
+23
| template<typename Traits, typename D_OUT, bool DIRECT_ONLY> | ||
| __global__ void gemm_a8w8_mxscale_flatmm_splitk_kernel(opus_gemm_scale_splitk_kargs_gfx950 kargs); |
| @@ -200,7 +200,7 @@ __global__ void splitk_reduce_kernel( | |||
| c_idx + g * STEP); | |||
| }); | |||
| } else if (n_base < N) { | |||
| // Tail path: decompose valid ∈ [1, VEC-1] into descending | |||
| // Tail path: decompose valid ? [1, VEC-1] into descending | |||
zufayu
requested review from
amd-ruitang3,
demonsan and
valarLip
and removed request for
amd-ruitang3
July 28, 2026 01:44
Contributor
Author
yzhou103
force-pushed
the
fp8-mxscale-bmm
branch
from
July 31, 2026 05:34
b3e0d4a to
266fef4
Compare
demonsan
previously approved these changes
Aug 5, 2026
yzhou103
added a commit
to yzhou103/aiter
that referenced
this pull request
Aug 6, 2026
test_mxscale_bmm_batch_first logged only us/err; add the roofline columns test_mxscale_bmm already emits so the two tables compare. Addresses the Copilot review note on ROCm#4320. Co-authored-by: Cursor <[email protected]>
yzhou103
force-pushed
the
fp8-mxscale-bmm
branch
from
August 6, 2026 03:39
4c417ed to
c97cc76
Compare
- gfx950 kernel family with codegen'd launchers, split-K and split-K reduce - dispatch for tile-unaligned M: padded-M lookup, sub-tile gating, M-split fallback - tuned-row lookup in the a8w8 batched family layer, libtype-dispatched and lru_cached - kid -> M alignment derived from codegen, asserted at build time and in the op test - self-contained tuner plus the DeepSeek-V4 tuned CSV gsm8k 5-shot exact_match 0.953 on DeepSeek-V4-Pro (tp8, fp8 kv, mxscale on). Co-authored-by: Cursor <[email protected]>
yzhou103
force-pushed
the
fp8-mxscale-bmm
branch
from
August 6, 2026 04:14
c97cc76 to
4b1e7dc
Compare
Guard the tuned lookup behind a functional custom op while keeping focused dispatch and tileN regression coverage. Co-authored-by: Cursor <[email protected]>
demonsan
self-requested a review
August 7, 2026 03:32
demonsan
previously approved these changes
Aug 7, 2026
Remove the remaining comment-only formatting differences from this PR. Co-authored-by: Cursor <[email protected]>
valarLip
approved these changes
Aug 12, 2026
demonsan
added a commit
that referenced
this pull request
Aug 13, 2026
Conflicts came from main's new a8w8_mxscale BMM family (#4320) landing in the same two files this branch edits, and both sides were purely additive: * opus_gemm_common.py OpusGemmInstance: keep this branch's fuse_* axes next to main's mxscale BMM axes; both groups are defaulted trailing fields. * gen_instances.py manifest emit: keep both signature templates and fold the gfx1250 6-arg workspace choice into main's A16W16_TUNE_TAGS branch, after the BMM branch (the tag sets are disjoint, so the order is free). Verified after the merge: 496 gfx1250 kids with none in the fuse band, tuner candidate counts unchanged, and codegen over gfx950+gfx942+gfx1250 emits both the 44 BMM and the 63 workspace launcher declarations. Co-authored-by: Cursor <[email protected]>
yzhou103
added a commit
to yzhou103/aiter
that referenced
this pull request
Sep 28, 2026
Upstream reworked the OPUS BMM path underneath this branch, so this is a port rather than a merge. Three changes drove every conflict: * ROCm#4961 "Unify OPUS GEMM/BMM interfaces and use Torch workspaces" deleted aiter/ops/opus/bmm_op.py, replaced opus_bmm_a8w8_mxscale with opus_gemm_a8w8_mxscale_bmm_launch, and moved the split-K workspace from a kernel-held ws_handle to a caller-owned pointer (kargs.ptr_ws). * BMM kid ids moved into the 8000 band (BMM_MXSCALE_KID_OFFSET). PR ROCm#4320's private namespace collided with the canonical registry. * A per-instance workspace_preload_sf was added to work around a ROCm 7.2.4 clang-22 illegal-register-class miscompile in the D_OUT=void specialization. What this commit does with them: bmm_op.py is gone, as upstream has it. Its three kid gates -- M alignment, B layout, scale layout -- moved to policy.py beside the other kid policy and collapsed into one cached table; bmm_a8w8_mxscale_opus moved to gemm_op_a8w8.py beside the launch entry it wraps; the local heuristic was dropped because upstream's _heuristic_mxscale_bmm_kid is the same function with the ids globalized. All eight call sites now use the unified entry and pass kid/split_k by keyword: the new tail is (workspace, kid, split_k), the reverse of the old (splitK, kernelId), and positionally both orders type-check and run. All 131 BMM kids are globalized. Checked for collisions first -- our 84 local ids shifted by 8000 do not touch upstream's 47. The 133 gfx950 rows of the bpreshuffle tuned table are renumbered with them, and re-verified: all 26 kids they name pass the B-layout, plain-scale and M-alignment gates. lookup_mxscale_bmm_config had two implementations differing only by the bpreshuffle switch. One is left, in policy.py, with the switch folded in. Codegen keeps both sides: upstream's @@SPLITK_PRELOAD@@ and our @@SFMPACK@@ / @@panel@@ describe different axes of the same template, and taking either side whole would have dropped a feature. Not done here: the tree builds only as far as this commit's own check went. The wave8 pipeline's three kargs.ws_handle reads are converted to ptr_ws, which is what the first real compile caught -- that file merged cleanly and so was never reviewed. A full codegen+compile of all 131 instances has not passed yet. Co-authored-by: Cursor <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Motivation
Adds the opus fp8 e8m0 mxscale (block-scale) batched GEMM (BMM) path for
gfx950, exposed as
aiter.batched_gemm_a8w8_mxscale. The per-kid devicekernels and host launchers are fully code-generated (mirroring the opus_gemm
module), and dispatch is driven by a tuned CSV with padded-M / M-split /
heuristic fallbacks. Also includes a round of dead-kernel and naming cleanup.
Technical Details
Reuses the shared opus GEMM gfx950 backend; every kid is codegen'd into its own _C{void,bf16,fp32}.device.cu (device symbol) + inlined host launcher, no hand-written adapters.
Table-driven kid -> launcher dispatch (opus_bmm_a8w8_mxscale_tune_dispatch) instead of a large switch.
Kernel families: fused, pipeline, minterleave, mouter / mouter_tunable, wave8n2, wave4m2_selfload, plus OOB-masked sub-tiles (311/313/320/321/324/640/650/653).
Dispatch logic (kernelId=None)
Exact tuned CSV hit → use its kid + splitK.
Padded-M: round M up to the nearest tuned bucket in the same (g,n,k) family; accepted only for OOB-masked sub-tiles (run the real smaller M with no pad/copy).
M-split: for large tile-unaligned M, split into an aligned strong-tile bulk (157/150) + a <256-row OOB-safe tail. Gated on total bulk work g*m >= 8192 (measured break-even), not on g alone.
Heuristic single-kid fallback otherwise.
Test Plan
op_tests/test_opus_a8w8_bmm.py: correctness (fp8 vs bf16 einsum, err 0) across g∈{2,8}, m=1..16384, both m-major and batch-first layouts, and per-family kids.
Test Result
together with #4428
gfx950 x8, DeepSeek-V4-Pro (
kv_cache_dtype=fp8,-tp 8, expert parallel).WOA=1is the fp8 e8m0 mxscale batched-GEMM path this PR touches,WOA=0theexisting bf16 dequant + einsum baseline.
Accuracy — gsm8k 5-shot, 1319 problems, flexible-extract / strict-match, stderr ±0.006 on every row:
The whole spread is 0.9500-0.9568, about one stderr, so the mxscale path is indistinguishable from the baseline.
Throughput —
benchmark_serving, random 8192 in / 1024 out, range ratio 0.8, concurrency 128, 1280 prompts,--ignore-eos. Medians over 2-3 rounds per arm:Submission Checklist