Repository navigation
[ASM] [HIP] [JIT] Add a gfx950 asm GEMM with BF16 activations and FP8 weights for decode - #6101
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
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]>
106260f to
aba4743
Compare
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]>
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
aiter.gemm_a16w8_asm(A, B, B_scale, out=None)inaiter/ops/gemm_op_a16w8.py. It computesout = (A @ B.T) * B_scale.Ais [M, K] BF16,Bis [N, K]torch.float8_e4m3fn,B_scaleholds N fp32 scales, one per row ofB, andoutis [M, N] BF16. The op allocatesoutwhen it is not given.RuntimeError.hsa/gfx950/a16w8gemm/, one code object per M and shape. The launchercsrc/py_itfs_cu/asm_gemm_a16w8.cuuses the ctypes entry point like the other asm launchers.module_gemm_a16w8_asmis added tooptCompilerConfig.json, andaiter/__init__.pyexports the op next togemm_op_a16w16.Test Plan
python3 op_tests/test_gemm_a16w8_asm.pyon MI355X (gfx950) with ROCm 7.2 and PyTorch 2.13. AITER is this branch, built in JIT mode.exactmode 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.randnmode quantizes random weights per row with scale amax / 448 and compares with rtol 1e-2 and atol 1e-3.torch.mmon the same weights in BF16.A, a shortB_scaleand an fp16outraiseRuntimeError, and M 0 is a no-op.op_tests/test_gemm_a16w16.pyruns on this branch and on main.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.pyexits 0 with the same results on this branch and on main.Times from the op test in
randnmode.run_perftestrotates copies of the inputs, so the inputs are not in cache between calls.(N, K) = (4608, 8192):
(N, K) = (8192, 2048):
At M = 1 the kernel reads the FP8 weights of (4608, 8192) at 4.6 TB/s.
Submission Checklist