Skip to content

ew kernels support on gfx12. - #3330

Merged
stevenshenyj merged 1 commit into
ROCm:mainfrom
stevenshenyj:ew_kernels_gfx1201
Jun 1, 2026
Merged

stevenshenyj merged 1 commit into
ROCm:mainfrom
stevenshenyj:ew_kernels_gfx1201

Conversation

@stevenshenyj

@stevenshenyj stevenshenyj commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Enable building and running [aiter] on RDNA4 (gfx1201, e.g. Radeon RX 9700) GPUs. Several kernels currently fail to compile or dispatch on gfx1201:

v_pk_mul_f32 in fused-qk-norm kernel — this packed FP32 SIMD instruction exists on CDNA (gfx9xx) but is not available on RDNA4, causing a backend assembler error when building for gfx1201.

v_cmp_u_f32 with explicit SGPR dest + v_add3_u32 in [rope_common.h]— the [f32x2_to_bf16x2_rne()] function uses CDNA-specific inline assembly (explicit SGPR destination for v_cmp, 3-operand integer add). RDNA4's v_cmp can only write to implicit VCC, and v_add3_u32 does not exist, causing "invalid operand for instruction" errors.

fmha_v3 ASM kernels — hand-written gfx9 assembly (gfx942/gfx950 only). On non-gfx9 hosts, can_impl_fmha_v3_fwd() unconditionally returned True, causing dispatch failures ("invalid argument for fmha_fwd") instead of falling back to the ck-tile path.

ck-tile MHA generate.py targets — defaults to --targets gfx9,gfx950, so non-gfx9 hosts get an empty kernel set and mha_fwd fails at dispatch.

As a result, downstream users (sglang on Radeon) cannot use aiter's fused-qk-norm-rope, fused-qk-norm-rope-cache-quant, or flash-attention paths at all on RDNA4.

Technical Details

csrc/kernels/fused_qk_norm.cu: Added [#if defined(gfx906) || ... || defined(gfx950)]positive-enumeration guard at both v_pk_mul_f32 sites. CDNA archs keep the asm fast path; all other archs fall back to portable element-wise multiplies (v_mul_f32 x2).

csrc/kernels/rope/rope_common.h: Added arch guard around the [f32x2_to_bf16x2_rne()] inline asm block. The CDNA path uses v_cmp_u_f32 (explicit SGPR dest) + v_add3_u32 + v_and_or_b32 for high-throughput packed bf16 conversion. The #else path implements identical RNE + NaN logic in portable C++ (compiler emits standard RDNA scalar instructions).

aiter/ops/mha.py: can_impl_fmha_v3_fwd() now gates on get_gfx() in ("gfx942", "gfx950") before enabling the v3 ASM path. Non-gfx9 archs cleanly fall through to the ck-tile FmhaFwd implementation.

aiter/jit/utils/mha_recipes.py: Added _ck_targets_flag() helper that detects runtime GPU arch. For non-gfx9 hosts, it appends --targets (e.g. --targets gfx1201) to ck-tile's generate.py invocations, ensuring the correct kernel variants are generated instead of defaulting to gfx9-only.

Files changed:

aiter_pr1

All changes are guarded by positive CDNA arch enumeration macros or runtime get_gfx() checks, so:
gfx1201 builds: take the scalar/portable path (compiles and runs); MHA dispatches via ck-tile.
gfx9 builds (gfx942/gfx950): bit-for-bit unchanged (same asm / same fmha_v3 as before).

Test Plan

Test Result

Submission Checklist

@github-actions

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:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
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 3330 --add-label <label>

@stevenshenyj stevenshenyj changed the title rmsnorm_quant_kernel support on gfx12. ew kernels support on gfx12. May 27, 2026
@stevenshenyj
stevenshenyj marked this pull request as ready for review May 29, 2026 02:11
@stevenshenyj
stevenshenyj requested review from a team and Copilot May 29, 2026 02:11

Copilot AI 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.

Pull request overview

Enables building and running aiter on RDNA4 (gfx1201) by adding scalar fallbacks for the CDNA-only v_pk_mul_f32 packed-FP32 instruction in selected kernels, gating the hand-written gfx9 fmha_v3 forward ASM dispatch on gfx942/gfx950, and injecting a --targets <runtime arch> flag into the CK-tile MHA varlen prebuild codegen commands so non-gfx9 hosts get a non-empty kernel set.

Changes:

  • Add #if defined(__gfx1201__) scalar fallbacks at three v_pk_mul_f32 sites (aiter_opus_plus.h::pk_mul_f32, rmsnorm_quant_kernels.cu, fused_qk_norm.cu).
  • Gate can_impl_fmha_v3_fwd() (regular + varlen) on get_gfx() in ("gfx942", "gfx950") so non-gfx9 archs fall back to ck-tile.
  • Add _ck_targets_flag() helper in mha_recipes.py that appends --targets <gfx> to generate.py invocations in get_mha_varlen_prebuild_variants_by_names() on non-gfx9 hosts.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
csrc/include/aiter_opus_plus.h Scalar fallback for pk_mul_f32 helper under __gfx1201__.
csrc/kernels/rmsnorm_quant_kernels.cu Scalar fallback at two v_pk_mul_f32 sites in add_rmsnorm_quant_kernel.
csrc/kernels/fused_qk_norm.cu Scalar fallback at two v_pk_mul_f32 sites in fused_qk_rmsnorm_kernel.
aiter/ops/mha.py Gate can_impl_fmha_v3_fwd() (fwd and varlen) on gfx942/gfx950.
aiter/jit/utils/mha_recipes.py New _ck_targets_flag() helper appended to varlen prebuild CK-tile generate.py commands.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread csrc/include/aiter_opus_plus.h Resolved
Comment thread aiter/jit/utils/mha_recipes.py Resolved
Comment thread aiter/jit/utils/mha_recipes.py Resolved
@stevenshenyj
stevenshenyj force-pushed the ew_kernels_gfx1201 branch 3 times, most recently from 82c31e8 to 8a88232 Compare May 29, 2026 03:11
junhaha666
junhaha666 previously approved these changes May 29, 2026

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread aiter/jit/utils/mha_recipes.py Resolved
@stevenshenyj
stevenshenyj force-pushed the ew_kernels_gfx1201 branch 4 times, most recently from 49b4f9b to 4620d89 Compare May 29, 2026 16:38
Comment thread setup.py Resolved
@stevenshenyj
stevenshenyj merged commit e3029be into ROCm:main Jun 1, 2026
45 checks passed
@stevenshenyj
stevenshenyj deleted the ew_kernels_gfx1201 branch June 2, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants