Repository navigation
ew kernels support on gfx12. - #3330
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
There was a problem hiding this comment.
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 threev_pk_mul_f32sites (aiter_opus_plus.h::pk_mul_f32,rmsnorm_quant_kernels.cu,fused_qk_norm.cu). - Gate
can_impl_fmha_v3_fwd()(regular + varlen) onget_gfx() in ("gfx942", "gfx950")so non-gfx9 archs fall back to ck-tile. - Add
_ck_targets_flag()helper inmha_recipes.pythat appends--targets <gfx>togenerate.pyinvocations inget_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.
82c31e8 to
8a88232
Compare
9229985 to
41365ce
Compare
49b4f9b to
4620d89
Compare
4620d89 to
fef9ee7
Compare
fef9ee7 to
81fc73c
Compare
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:
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