Skip to content

[ASM] [HIP] [JIT] Add a gfx950 asm GEMM with BF16 activations and FP8 weights for decode - #6101

Merged
yifehuan merged 1 commit into
ROCm:mainfrom
maeehart:asm-gemm-a16w8-gfx950
Oct 13, 2026
Merged

yifehuan merged 1 commit into
ROCm:mainfrom
maeehart:asm-gemm-a16w8-gfx950

Conversation

@maeehart

@maeehart maeehart commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Motivation

At 1 to 8 tokens a GEMM is bound by reading its weights. This PR adds an asm GEMM for gfx950 with BF16 activations and FP8 weights that have one scale per output channel. It reads half the weight bytes of a BF16 GEMM, and it does not quantize the activations.

The code objects cover (N, K) = (4608, 8192) and (8192, 2048). These are the per-rank linear attention input projection (in_proj_qkvz) and output projection (out_proj) of Qwen/Qwen3.8-2.4T-A95B at tensor parallel 8.

Technical Details

  • New op aiter.gemm_a16w8_asm(A, B, B_scale, out=None) in aiter/ops/gemm_op_a16w8.py. It computes out = (A @ B.T) * B_scale.
    • A is [M, K] BF16, B is [N, K] torch.float8_e4m3fn, B_scale holds N fp32 scales, one per row of B, and out is [M, N] BF16. The op allocates out when it is not given.
    • M is 1 to 8. Other shapes, FNUZ FP8 weights and other GPUs raise RuntimeError.
  • The kernel converts the FP8 weights to BF16, which is exact, sums the products in fp32, multiplies each output by its row scale and rounds to BF16.
  • The code objects and their CSV are in hsa/gfx950/a16w8gemm/, one code object per M and shape. The launcher csrc/py_itfs_cu/asm_gemm_a16w8.cu uses the ctypes entry point like the other asm launchers. module_gemm_a16w8_asm is added to optCompilerConfig.json, and aiter/__init__.py exports the op next to gemm_op_a16w16.

Test Plan

python3 op_tests/test_gemm_a16w8_asm.py on MI355X (gfx950) with ROCm 7.2 and PyTorch 2.13. AITER is this branch, built in JIT mode.

  • exact mode uses small integer weights, activations that are multiples of 1/64 and power-of-two scales. Every output is exact, so it must match the reference bit for bit.
  • randn mode quantizes random weights per row with scale amax / 448 and compares with rtol 1e-2 and atol 1e-3.
  • Both modes run M 1 to 8 for both shapes against a float64 reference rounded to BF16, and time the op against torch.mm on the same weights in BF16.
  • Guard checks: M 9, N 4640, FNUZ weights, a strided A, a short B_scale and an fp16 out raise RuntimeError, and M 0 is a no-op.
  • op_tests/test_gemm_a16w16.py runs on this branch and on main.
  • black and ruff 0.16.0 pass.

Test Result

Every check of the new test passes for M 1 to 8, both shapes and both modes, and so do the guard checks. test_gemm_a16w16.py exits 0 with the same results on this branch and on main.

Times from the op test in randn mode. run_perftest rotates copies of the inputs, so the inputs are not in cache between calls.

(N, K) = (4608, 8192):

M torch.mm BF16 (us) gemm_a16w8_asm (us) speedup
1 18.89 8.13 2.32x
2 19.93 8.71 2.29x
3 19.91 9.51 2.09x
4 21.05 10.01 2.10x
5 20.93 11.56 1.81x
6 21.08 13.65 1.54x
7 20.70 14.54 1.42x
8 21.67 16.83 1.29x

(N, K) = (8192, 2048):

M torch.mm BF16 (us) gemm_a16w8_asm (us) speedup
1 14.46 5.11 2.83x
2 13.11 5.29 2.48x
3 13.18 5.73 2.30x
4 13.53 6.31 2.14x
5 13.12 6.75 1.94x
6 13.36 7.23 1.85x
7 9.82 7.73 1.27x
8 9.83 8.29 1.19x

At M = 1 the kernel reads the FP8 weights of (4608, 8192) at 4.6 TB/s.

Submission Checklist

@github-actions

github-actions Bot commented Oct 2, 2026

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
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 6101 --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.

gemm_a16w8_asm computes (A @ B.T) * B_scale with BF16 activations, FP8 e4m3fn weights and one scale per weight row for 1 to 8 tokens. The activations are not quantized, and the kernel reads half the weight bytes of a BF16 GEMM. The code objects cover (N, K) = (4608, 8192) and (8192, 2048), the linear attention input and output projections of Qwen/Qwen3.8-2.4T-A95B at tensor parallel 8.

Signed-off-by: Markus Hartikainen <[email protected]>
Co-authored-by: Cursor <[email protected]>
@maeehart
maeehart force-pushed the asm-gemm-a16w8-gfx950 branch from 106260f to aba4743 Compare October 7, 2026 15:58
@maeehart
maeehart marked this pull request as ready for review October 7, 2026 15:58
@maeehart
maeehart requested a review from a team October 7, 2026 15:58
@github-actions github-actions Bot changed the title [ASM] [HIP] Add a gfx950 asm GEMM with BF16 activations and FP8 weights for decode [ASM] [HIP] [JIT] Add a gfx950 asm GEMM with BF16 activations and FP8 weights for decode Oct 7, 2026
@zufayu
zufayu requested a review from yifehuan October 8, 2026 02:09

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

@yifehuan
yifehuan merged commit 5517f99 into ROCm:main Oct 13, 2026
jhartika-amd pushed a commit to jhartika-amd/aiter that referenced this pull request Oct 14, 2026
Resolve the conflicts with ROCm#6101 (gemm_a16w8_asm) by keeping both modules:
aiter/__init__.py imports gemm_op_a16w8 and gemm_op_a16w8_mxfp8, and
optCompilerConfig.json has both module_gemm_a16w8_asm and
module_gemm_a16w8_mxfp8_asm. Both run hsa/codegen.py -m a16w8gemm, which
writes one header with a table per arch (cfg_a16w8gemm for gfx950,
cfg_a16w8gemm_mxfp8 for gfx942); each loader reads only its own.

Signed-off-by: Jouni Hartikainen <[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.

2 participants