Skip to content

[gfx1201] Enable quantization kernels for gfx1201 - #3

Closed
big-yellow-duck wants to merge 1458 commits into
mainfrom
rdna4-quant-support
Closed

[gfx1201] Enable quantization kernels for gfx1201#3
big-yellow-duck wants to merge 1458 commits into
mainfrom
rdna4-quant-support

Conversation

@big-yellow-duck

@big-yellow-duck big-yellow-duck commented Mar 13, 2026

Copy link
Copy Markdown

Motivation

FP8 quantization operations fail on AMD gfx1201 (RDNA4) architecture due to three compatibility issues:

  1. FP8 dtype is not registered for gfx1201 in the dtype mapping
  2. v_pk_mul_f32 assembly instruction is not supported on gfx11/gfx12
  3. DPP broadcast operations (0x142, 0x143) used in hip reduce are not supported on gfx11/gfx12

This PR enables FP8 quantization support on gfx1201 by addressing these incompatibilities.

Technical Details

1. FP8 Dtype Registration (aiter/utility/dtypes.py)

Added gfx1201 to the default FP8 dtype mapping to enable torch.float8_e4m3fn support on RDNA4.

2. Scalar Multiplication Fallback (csrc/include/ck_tile/vec_convert.h)

The v_pk_mul_f32 assembly instruction is not supported on gfx11/gfx12. Added amd_scalar_mul_f32() function as a portable fallback:

CK_TILE_DEVICE fp32x2_v amd_scalar_mul_f32(fp32x2_v a, fp32x2_t b){
    fp32x2_v c;
    c[0] = a[0] * b[0];
    c[1] = a[1] * b[1];
    return c;
}

The conversion functions fp32x2_t_to_fp8x2_t and fp32x2_t_to_int8x2_t now conditionally use the scalar path:

#if defined(__gfx11__) || defined(__gfx12__)
    tmp = amd_scalar_mul_f32(x, fp32x2_t{inverted_scale, inverted_scale});
#else
    tmp = amd_assembly_pk_mul_f32(x, fp32x2_t{inverted_scale, inverted_scale});
#endif

3. DPP Broadcast Replacement (csrc/include/hip_reduce.h)

DPP broadcast operations are not supported on gfx11/gfx12. Replaced with rocprim::warp_shuffle() for cross-lane communication in:

  • wave_reduce() - for WarpSize > 16 and WarpSize > 32 reductions
  • multithread_reduce() - for 16-thread and 32-thread reduction paths

Example change:

#if defined(__gfx12__) || defined(__gfx11__)
    // Use shuffle for gfx12 instead of DPP broadcast
    T v_remote = rocprim::warp_shuffle(local, 15, WarpSize);
    local      = reduce_op(v_remote, local);
#else
    // row_bcast:15
    local = reduce_op(rocprim::detail::warp_move_dpp<T, 0x142>(local), local);
#endif

4. Naive load to LDS fallback (csrc/kernels/quant_kernels.cu)

gfx12x Fallback to naive loading from global memory to LDS in smooth_per_token_scaled_quant_kernel.

for(int i = 0; i < async_load_num; i++)
        {
            #if defined(__gfx12__)
                int idx = threadIdx.x + i * block_size;
                if(idx < smooth_scale_map_hash_size)
                {
                    // RDNA4 doesn't support buffer_load_* with LDS modifier
                    // Use standard global load to VGPR then write to LDS
                    smooth_scale_map_hash_shared[idx] = smooth_scale_map_hash[idx];
                }
            #else
                const int lds_ptr_sgpr = __builtin_amdgcn_readfirstlane((reinterpret_cast<uintptr_t>((smooth_scale_map_hash_shared + threadIdx.x / WARP_SIZE * WARP_SIZE + i * block_size))));
                uint32_t offset = threadIdx.x * sizeof(int) + i * block_size * sizeof(int);
                asm volatile( "s_mov_b32 m0 %0\n\t"
                "buffer_load_dword %1, %2, 0 offen offset:0 lds\n\t"
                ::"s"(lds_ptr_sgpr), "v"(offset), "s"(buffer_hash.cached_rsrc): "memory", "m0");
            #endif
        }

Test Plan

Run the quantization test suite with various tensor sizes:

python op_tests/test_quant.py -m 1 2 16 32 64 128 192 256 512 1024 16384

Test Result

All quantization tests pass successfully on gfx1201:

m n q_type q_dtype h_dtype triton dq triton dq err hip dq hip dq err
1 4096 2 torch.float8_e4m3fn torch.bfloat16 3.64439 0 1.93756 0
2 4096 2 torch.float8_e4m3fn torch.bfloat16 3.64966 0 1.96232 0
16 4096 2 torch.float8_e4m3fn torch.bfloat16 3.77261 0.000518799 2.11611 0
32 4096 2 torch.float8_e4m3fn torch.bfloat16 4.16686 0.000236511 2.2483 0
64 4096 2 torch.float8_e4m3fn torch.bfloat16 4.45646 0.000331879 2.55272 0
128 4096 2 torch.float8_e4m3fn torch.bfloat16 6.31186 0.000110626 11.6767 0
192 4096 2 torch.float8_e4m3fn torch.bfloat16 7.81408 0.000104268 15.3828 0
256 4096 2 torch.float8_e4m3fn torch.bfloat16 10.096 0.000151634 12.9491 0
512 4096 2 torch.float8_e4m3fn torch.bfloat16 16.904 0.000132084 13.9252 0
1024 4096 2 torch.float8_e4m3fn torch.bfloat16 28.8941 0.000131607 20.9024 0
16384 4096 2 torch.float8_e4m3fn torch.bfloat16 332.715 9.91374e-05 329.895 2.98023e-08
1 8192 2 torch.float8_e4m3fn torch.bfloat16 6.09301 0 2.18569 0
2 8192 2 torch.float8_e4m3fn torch.bfloat16 5.53158 0 2.09682 0
16 8192 2 torch.float8_e4m3fn torch.bfloat16 6.17309 0 2.22647 0
32 8192 2 torch.float8_e4m3fn torch.bfloat16 6.34547 0.000667572 2.41126 0
64 8192 2 torch.float8_e4m3fn torch.bfloat16 7.87828 0 15.0149 0
128 8192 2 torch.float8_e4m3fn torch.bfloat16 11.1925 0.00028801 15.949 0
192 8192 2 torch.float8_e4m3fn torch.bfloat16 14.0472 0.000234604 15.7946 0
256 8192 2 torch.float8_e4m3fn torch.bfloat16 19.2459 0.000182629 12.6191 0
512 8192 2 torch.float8_e4m3fn torch.bfloat16 29.9609 0.000250578 19.6405 0
1024 8192 2 torch.float8_e4m3fn torch.bfloat16 52.7824 0.000243187 40.564 1.19209e-07
16384 8192 2 torch.float8_e4m3fn torch.bfloat16 672.725 0.000171259 660.283 8.9407e-08
The scalar multiplication fallback and warp shuffle replacements provide correct functionality while maintaining compatibility with the RDNA4 architecture.

Submission Checklist

carlushuang and others added 30 commits January 14, 2026 16:25
* rebase and init moe optimization

* add avg col in common

* fix
Aiter fails import test with error ModuleNotFoundError: No module named 'packaging'

The aiter package imports and uses 'packaging' module at runtime in
multiple files, but only declares it in setup_requires (build-time) instead of also declaring in install_requires (runtime).
This causes "ModuleNotFoundError: No module named 'packaging'" when
importing aiter in environments where 'packaging' is not already installed.

This PR looks to fix this issue by patching setup.py to include aiter packaging as a runtime dependency.

Signed-off-by: Anu Oguntayo <aoguntay@redhat.com>
GitHub Actions CI pipeline is aborted if a process exits with a code other than
zero. This commit fixes a bug in Triton test selection script, no matter the
test selection outcome, CI pipeline shouldn't be aborted.
* enable gptoss_sink

Signed-off-by: Linjun-AMD <Jun.Lin@amd.com>

* Update csrc/py_itfs_ck/mha_batch_prefill_kernels.cu

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update mha_batch_prefill_kernels.cu

* update mha_bwd parameter

Signed-off-by: Linjun-AMD <Jun.Lin@amd.com>

* Update mha.py

* Fix formatting for bias argument in rocm_ops.hpp

* fix some format error

Signed-off-by: Linjun-AMD <Jun.Lin@amd.com>

* Update mha.py

* update args

Signed-off-by: Linjun-AMD <Jun.Lin@amd.com>

* Update mha_fwd.cpp

* update ck commit

Signed-off-by: Linjun-AMD <Jun.Lin@amd.com>

* use atier main branch ck commit

Signed-off-by: Linjun-AMD <Jun.Lin@amd.com>

* update ck commit

Signed-off-by: Linjun-AMD <Jun.Lin@amd.com>

* Update mha_batch_prefill_kernels.cu

---------

Signed-off-by: Linjun-AMD <Jun.Lin@amd.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: solin <bingzhou@amd.com>
Co-authored-by: Xin Huang <Xin.Huang@amd.com>
* fix(paps): fix support for multi kheads

Signed-off-by: Double Young <yang.yang2@amd.com>

* fix(paps): fix reset work_indptr and use empty init in ut

Signed-off-by: Double Young <yang.yang2@amd.com>

---------

Signed-off-by: Double Young <yang.yang2@amd.com>
…ROCm#1762)

* [Docs] Add README for Triton Ops detailing general maintenance points
* initial commit

* fix

* test ck tile tuning

* temp save

* tem save

* refactor

* fix tile

* support ck tile abquant

* fix error

* fix error

* fix error

* fix error

* fix error

* test tuning

* fix tile compile error

* add more tile instance

* test tile instance tuning

* add more valid instances

* fix test bug

* fix default tile instance

* fix

* fix actions error

* format code style

* Apply Black 25.12.0 formatting to match CI

* fix CI

* fix CI

* rename lagacy

* add profile result

* update ck

* code format

* fix mismatch ck kernel

* fix CI

* delete tune flag

* update ck

* merge aiter main branch
* Testing fake_tensor fix

* Same logic for var len attn

* Fix

---------

Co-authored-by: Lingpeng Jin <103567126+valarLip@users.noreply.github.com>
…ernally (ROCm#1821)

* Implement a new api that will be switching between asm and hip pa

Inference engines should be calling paged_attention_common now with
shuffled kv cache layout and aiter internally will decide between asm
or hip kernel. HIP is more performant for lower concurrencies ( < 128).
Also a unit test has been updated to include the new interface.

Note that support for the shuffled scales in HIP is not supported and is
always redirected to asm now when KV cache is  in int8 or fp8 formats.

* Delete op_tests/README_pa_merged_tests.md

* Delete op_tests/test_pa_merged.py

* Fix formatting according to Black requirements

* Fix one last place with broken formatting

* Remove modification to pa_v1, we already have pa for 5D kv cache

* Fix another formatting issue

* Add proper quant support for the common API

* Apply formatting

* Remove redundant parameters

* Remove redundant parameters

---------

Co-authored-by: Sergey Solo <ssolovye@amd.com>
Co-authored-by: Mikko Tukiainen <mikko.tukiainen@amd.com>
* add_tune_dsfp4_gemm

* update

* Update aiter/jit/core.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Fused rope_kv and bmm

* Apply suggestion from @github-actions[bot]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Apply suggestion from @github-actions[bot]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update fused_bmm_rope_kv_cache.py

* Update fused_bmm_rope_kv_cache.py

* add test

* update

* update

* parse bmm config

* fp8 API and kernel change

* fp8 UT

* Apply suggestion from @github-actions[bot]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Apply suggestion from @github-actions[bot]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Formatting with black

* pytest skip if fp4/8 is not avail on device

* code format with black

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: ShaoChunLee <Shao-Chun.Lee@amd.com>
TODO: improve moe tuner.
)

* [CK_TILE][FMHA] Support page size 16 for batch prefill kernel

* handle GQA cases in reference outputs.

---------

Co-authored-by: Lingpeng Jin <103567126+valarLip@users.noreply.github.com>
* fix accuracy issue on triton paged_pa_mqa

Signed-off-by: ganyi <ygan@amd.com>

* add int64 annotation for input stride

Signed-off-by: ganyi <ygan@amd.com>

---------

Signed-off-by: ganyi <ygan@amd.com>
* Fix code style after updating Black to 26.1.0

* Update aiter/ops/mha.py

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…x950 (ROCm#1857)

* first commit for mla prefill

* add test for mla prefill

* support ut and mla python reduce verison

* support reduce in torch and triton

* push 350 .co file

* add triton reduce op and reconstruct mla dispatch

* first commit for mla prefill

* support ut and mla python reduce verison

* support reduce in torch and triton

* push 350 .co file

* fix gqa bug

* first commit for mla prefill

* support ut and mla python reduce verison

* support reduce in torch and triton

* push 350 .co file

* rebase and force

* use hip reduce for test

* change ut

* support triton reduce kernel without head info

* feat(ps): add host v1_2 generate_ps_metadata & ut for mla_prefill

Signed-off-by: Double Young <yang.yang2@amd.com>

* fix(ps): fix ps metadata allocation

* fix triton reduce fallback error

* fix(ps): fix OOM in mla prefill

Signed-off-by: Double Young <yang.yang2@amd.com>

* fix(ps): reduce pre-allocation

Signed-off-by: Double Young <yang.yang2@amd.com>

* test(mla_prefill): enhance mla_prefill_ps ut & generate_ps_metadata

Signed-off-by: Double Young <yang.yang2@amd.com>

* slove asm_mla.cu conflict and add conflict co in csv

* format code

* reformat

* test(mla_prefill): fix reduce perf measure and format

Signed-off-by: Double Young <yang.yang2@amd.com>

* refactor(mla_prefill): fix ruff format

Signed-off-by: Double Young <yang.yang2@amd.com>

* refactor(mla_prefill): fix ruff format

Signed-off-by: Double Young <yang.yang2@amd.com>

* fix(mla_prefill): fix nan in sp3

Signed-off-by: Double Young <yang.yang2@amd.com>

* fix new pr rename .co and update cu and csv

---------

Signed-off-by: Double Young <yang.yang2@amd.com>
Co-authored-by: ZhangLirong-amd <lirzhang@amd.com>
Co-authored-by: ZhangLirong-amd <Lirong.Zhang@amd.com>
* opt_unit_test

* remove test_gemm_a8w8_blockscale_mi350.py
* spkil mla_prefill_ps when gfx942

* use chip info
kensclin and others added 18 commits March 10, 2026 21:19
A8W8 is missing support for splitk. Added support and a unit test.
If the `git` binary is missing, `FileNotFoundError` is raised in
place of `subprocess.CalledProcessError`, causing a crash on import.
* opt prefill

* fix atomic mode bugs

* Apply suggestions from code format review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* update moe tunner stride

* format

* format

* update flydsl tunner

* update flydsl tunner config

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
* revert to unfused quant kernels for perf
* int64 offsets to avoid bhsd overflow of int32
* support activation input in mxfp4 format.

* support activation input in mxfp4 format.
…p4 (ROCm#2169)

* Walk around "BLOCK_SIZE_S3" error

* Remove workaround for "BLOCK_SIZE_S3" key in GEMM configuration functions

* Revert "Copy config before mutate (ROCm#2173)"

This reverts commit 213b76f.
* add hipblaslt error log

* Update gradlib/csrc/hipbsolgemm.cu

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…Cm#2259)

Add 4 missing fields in fmha_fwd_args aggregate initialization in mha_fwd.cu to match new CK struct layout:
- seqstart_v_scale_ptr (nullptr)
- stride_q_descale, stride_k_descale, stride_v_descale (0)
ROCm#2167)

* Prepare repository for size optimization

This commit introduces safeguards and documentation to prepare for
a major repository cleanup that will reduce the repo size from 547 MB
to ~130 MB (76% reduction).

Changes:
- Enhanced .gitignore to prevent large files (test data, build artifacts)
- Created test data download script framework
- Documented cleanup plan and migration process

The actual history cleanup will be performed separately during a
scheduled maintenance window, requiring all contributors to re-clone.

See REPO_CLEANUP_PLAN.md for full details.

Impact: No immediate changes to functionality. Protective measures only.

* Address Copilot code review feedback

- Fix migration steps to preserve local changes using patch files instead of git stash
- Update size reduction numbers to match actual test results (105MB vs aspirational 50MB)
- Clarify that pre-commit hook for size checks is not included (to avoid conflict with existing hook)
- Update hook installation instructions to align with existing CONTRIBUTE.md workflow
- Fix test data download script to exit with error code when unconfigured
- Remove references to non-existent files (paths_to_remove.txt, aiter_cleanup_results.md)

All changes address feedback from Copilot code review.

* docs: add documentation website

Add comprehensive Sphinx-based documentation website for AITER.

Features:
- Installation guide with 3 installation methods
- Quick start tutorial with runnable examples
- API reference for attention, GEMM, and operators
- Basic usage tutorial with performance comparisons
- Configuration for doc.aiter.amd.com hosting

Structure:
- docs/conf.py: Sphinx configuration with AMD branding
- docs/index.rst: Main documentation landing page
- docs/installation.rst: Detailed installation instructions
- docs/quickstart.rst: 5-minute getting started guide
- docs/api/: Complete API reference documentation
- docs/tutorials/: Hands-on tutorials with code examples

The documentation can be built locally with:
  cd docs && pip install -r requirements.txt && make html

This brings AITER documentation quality on par with FlashInfer.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* ci: add GitHub Actions workflow for documentation

Add automated build and deployment workflow for Sphinx documentation.

Features:
- Automatic build on push to docs-website and main branches
- Deploys to GitHub Pages via gh-pages branch
- Build artifacts available for PR previews
- Uses sphinx-build with all extensions
- Caches pip dependencies for faster builds

Workflow:
1. Checkout code
2. Install Python and dependencies
3. Build Sphinx HTML documentation
4. Upload build artifacts
5. Deploy to gh-pages branch (on push)

Documentation will be available at:
  https://sunway513.github.io/aiter/

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* ci: trigger documentation workflow

* fix: trigger workflow on docs-website branch

* fix: add missing _static and _templates directories for Sphinx

* fix: simplify Sphinx build to avoid treating warnings as errors

* docs: add comprehensive 'How to Add a New Operator' tutorial

Add detailed step-by-step guide for adding custom operators to AITER.

Features:
- Complete workflow from Python interface to ROCm kernel
- Real code examples for each step
- PyBind11 bindings setup
- Testing and benchmarking guidelines
- Best practices and debugging tips
- Complete RMSNorm example as reference

This addresses team feedback: "搞个how to add new op之类的就完美了"

Includes:
- Step 1: Define operator interface (Python)
- Step 2: Implement ROCm/HIP kernel
- Step 3: Create PyBind11 bindings
- Step 4: Update build configuration
- Step 5: Add comprehensive tests
- Step 6: Build and install
- Step 7: Register in main module

Advanced topics:
- CK (Composable Kernel) integration
- Triton kernel development
- Fused operations pattern
- In-place operations
- Autograd support for training

Also updated:
- docs/index.rst: Added Quick Links section highlighting the tutorial
- docs/tutorials/index.rst: Added to Advanced Topics section

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* docs: fix critical factual errors in documentation

Fix high-priority documentation errors discovered in factual accuracy audit:

## Critical Fixes
- Fix incorrect package name (aiter → amd-aiter) in installation instructions
- Replace non-working verification code with functional examples
- Fix MOE quickstart example to use actual fmoe() API instead of non-existent grouped_gemm()

## Changes
- docs/installation.rst: Update pip install command and verification code
- docs/quickstart.rst: Replace grouped_gemm with working fmoe example
- docs/DOCUMENTATION_AUDIT_REPORT.md: Add comprehensive audit findings

## Audit Summary
Discovered 22 factual errors across documentation. This commit addresses
the 3 highest-priority issues that would immediately block users.

See DOCUMENTATION_AUDIT_REPORT.md for complete findings and recommendations.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* ci: add path filters to docs workflow

Only trigger docs build/deploy when docs/** or the workflow file
itself is modified, avoiding unnecessary CI runs on non-doc changes.

Addresses review feedback from @gyohuangxin.

* fix: apply black formatting to docs/conf.py

Replace single quotes with double quotes and add trailing commas
to pass CI code style check.

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Xin Huang <Xin.Huang@amd.com>
Co-authored-by: valarLip <340077269@qq.com>
* opt kernel when batch>=32 and add more decode test

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* add max_tokens_per_batch interface to support more Scenarios

* Update test_fused_qk_norm_rope_cache_quant.py

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:sglang SGLang integration tests
ci:atom ATOM benchmark (DeepSeek-R1 + GPT-OSS)
ci:vllm vLLM benchmark
ci:all All of the above

Add labels via the sidebar or gh pr edit 3 --add-label <label>

Comment thread csrc/include/ck_tile/vec_convert.h Outdated
Comment thread csrc/include/hip_reduce.h Outdated
Comment thread csrc/kernels/quant_kernels.cu Outdated
Comment thread csrc/kernels/quant_kernels.cu Outdated
Comment thread csrc/include/hip_reduce.h Outdated
@big-yellow-duck
big-yellow-duck deleted the rdna4-quant-support branch March 19, 2026 08:14
big-yellow-duck pushed a commit that referenced this pull request Apr 13, 2026
* Fix precision issue for 32x256, 64x128, 64x256 kernels silu and gelu variants
---------

Co-authored-by: Sergey Solo <ssolovye@amd.com>
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.