Skip to content

[CI] [JIT] gfx1201 RDNA4 a8w8 blockscale GEMM tuning - #4322

Closed
pds-amd wants to merge 5 commits into
ROCm:mainfrom
pds-amd:gfx1201-a8w8-gemm-tuning
Closed

pds-amd wants to merge 5 commits into
ROCm:mainfrom
pds-amd:gfx1201-a8w8-gemm-tuning

Conversation

@pds-amd

@pds-amd pds-amd commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Offline GEMM tuning is inert on RDNA GPUs (gfx11xx/gfx12xx). Every tuned a8w8_blockscale row is a silent miss at runtime, so the op always falls back to the default kernel (... not found tuned config ..., will use default config!), and --run_config reports No shapes to benchmark. This PR fixes the root cause and adds the first RDNA4 (gfx1201) tuned coverage for this family.

Technical Details

Two commits:

1. fix(tuner): key tuned configs by true CU count on RDNA

Tuned GEMM rows are keyed by (gfx, cu_num, M, N, K). The runtime lookup (aiter.ops.gemm_op_a8w8.get_CKGEMM_config) resolves cu_num via aiter.jit.utils.chip_info.get_cu_num() (rocminfo Compute Unit), but BaseTuner.get_cu_num() read torch.cuda.get_device_properties().multi_processor_count. On RDNA that value is the WGP count = half the true CU count (gfx1201 Radeon AI PRO R9700: torch reports 32, actual CU count is 64). So the tuner stamped rows with cu_num=32 while the runtime looked them up with cu_num=64; the keys never matched.

Fix: delegate get_cu_num() (and get_gfx()) to the same chip_info accessors the runtime uses, so the tuner and the lookup can never disagree. No tuner subclass overrides get_cu_num, so this covers every family. No-op on CDNA, where CU and WGP counts coincide (e.g. the existing gfx950,256 configs resolve correctly today and are unaffected).

2. feat(gemm_a8w8_blockscale): add gfx1201 (RDNA4) tuned config via model_configs

Adds 255 gfx1201 (cu_num=64) tuned rows as a new aiter/configs/model_configs/a8w8_blockscale_tuned_gemm_gfx1201.csv, with the matching model_configs/a8w8_blockscale_untuned_gemm_gfx1201.csv. The canonical aiter/configs/a8w8_blockscale_tuned_gemm.csv is not modified — the runtime merges model_configs/* into the family via get_config_file. First RDNA4 coverage for this family.

Shapes come from an RDNA4 diffusion-inference sweep spanning multiple models (FLUX / FLUX.2 t2i/i2i/multi, FLUX.2-klein, flux-kontext, qwen-image, qwen-image-edit, stablediffusion-3.5, wan2.2, z-image).

Rows are pruned against the get_CKGEMM_config fallback chain (gl=None / gl=0 / gl=1, first existing key wins, target kernel irrelevant), so no row duplicates what runtime dispatch would already resolve. op_tests/test_tuned_config_csv.py, added here and requiring no GPU, enforces this for the gfx1201 file.

Every added row was verified through the production op (not just the tuner's direct-kernel check) via test_run_config.py on gfx1201. Six tiny-M shapes (M ∈ {1,2,8}: (8,3840,3840), (1,4864,2432), (2,4864,2432), (8,10240,3840), (1,14592,2432), (2,14592,2432)) were intentionally excluded: they mismatch the run_torch reference through the production op for both the tuned and the default kernel, so the discrepancy is independent of tuning (a kernel- or reference-side issue at very small M) and is left to fall back to the default.

Test Plan

  • test_csv_validation.py — CSV integrity (dedup key (cu_num,M,N,K), us > 0, errRatio <= 0.2, no conflict markers).
  • test_config_shape_collision.py — family-wide runtime merge (canonical + model_configs/) is duplicate-free on the runtime key.
  • test_tuned_config_csv.py (added) — no gfx1201 row is redundant under the get_CKGEMM_config fallback chain; no GPU required.
  • test_run_config.py (a8w8_blockscale) on gfx1201 — runs the production op for every tuned shape; expects 0 MISMATCH/ERROR.
  • Verified chip_info.get_gfx_runtime()/get_cu_num() vs torch.multi_processor_count on gfx1201.

Test Result

  • gfx1201 (Radeon AI PRO R9700): chip_info.get_gfx_runtime() = gfx1201, get_cu_num() = 64; torch.multi_processor_count = 32.
  • Before: --run_config -> No shapes to benchmark.
    After: loads all rows at cu_num=64, sets AITER_CONFIG_GEMM_A8W8_BLOCKSCALE, and benchmarks every shape.
  • test_csv_validation.py (a8w8_blockscale): PASS -- canonical file unchanged at 6630 gfx950,256 rows; the 255 new gfx1201,64 rows live in model_configs/; all us > 0, all errRatio <= 0.2, 0 duplicates on (cu_num,M,N,K).
  • test_config_shape_collision.py (a8w8_blockscale): PASS, 0 collisions -- runtime merge of the canonical file + 10 model_configs/ files is duplicate-free; both planted-duplicate / clean self-check controls pass.
  • test_tuned_config_csv.py: PASS -- 0 redundant rows in the gfx1201 file.
  • Production-op accuracy on gfx1201: all merged shapes (incl. every gfx1201 row) match the run_torch reference -- 0 MISMATCH, 0 ERROR (equivalent to test_run_config.py's check).
  • CDNA unchanged (chip_info == torch.multi_processor_count); existing gfx950,256 rows resolve as before.

Submission Checklist

@pds-amd
pds-amd requested a review from a team July 21, 2026 13:23
@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 4322 --add-label <label>

@zufayu
zufayu requested a review from yzhou103 July 22, 2026 01:24
@yzhou103

Copy link
Copy Markdown
Contributor

The bug fix in commit 1 looks correct — delegating to chip_info.get_cu_num() aligns the tuner with runtime dispatch. No-op on CDNA, clean fix.

For the tuned config rows: many of them are likely redundant due to the runtime's M-padding fallback. get_CKGEMM_config in gemm_op_a8w8.py:416-458 tries three lookups in order:

  1. gl=None — exact M match
  2. gl=0 — fine-grained pad (M≤256 → align 16, M≤1024 → align 32, M≤4096 → align 64, M>4096 → align 128)
  3. gl=1 — coarse pad (next power of 2)

So if a raw M pads (gl=0) to an aligned M that's already in the CSV, and both map to the same kernel, the raw-M row is redundant — runtime will fall through to the padded entry automatically.

Looking at the existing gfx950 data, ~74% of rows are eliminable by this logic. Most M values within a (N, K) pair resolve to the same dominant kernel; only a handful of small-M entries genuinely need a different kernel than their padded neighbor.

Suggest keeping only: (a) gl=0-aligned M values, and (b) raw M values whose best kernel actually differs from their padded target's kernel. This would likely reduce the 358 rows to ~90-100 without any performance or correctness impact — runtime dispatch covers the rest via fallback.

@pds-amd

pds-amd commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 3 commits:

  1. refactor: drop redundant gfx1201 rows
    • removed 50 rows whose kernelName is identical to what the get_CKGEMM_config fallback (gl=0/gl=1) would already select. The remaining 308 gfx1201 rows use non-standard M values (333, 666, 784…) with no padded counterpart in the CSV. Removing those would fall back to default config, which is a regression. Your 74% figure holds for gfx950's dense/regular M coverage but not for gfx1201.
  2. test: add op_tests/test_tuned_config_csv.py
    • no-GPU pytest that asserts no row in the CSV is reachable via the fallback chain with the same kernel. Catches redundant rows at commit time going forward.
  3. refactor: drop redundant gfx950 rows
    • same logic applied to gfx950, removing 5120 rows. Test now passes on the full file.

@pds-amd
pds-amd force-pushed the gfx1201-a8w8-gemm-tuning branch from fa6699a to b44ad01 Compare July 22, 2026 07:27
@yzhou103

yzhou103 commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Hi @pds-amd , it seems some gfx950 rows are removed unsafely (perf regressions)28 of the removed rows are not redundant, and dropping them changes the kernel the runtime dispatch actually selects.

Root cause — the redundancy check in test_tuned_config_csv.py (and the removal script mirroring it) does not match the runtime fallback semantics in get_CKGEMM_config / gemm_a8w8_bpreshuffle.cu:

Runtime tries gl ∈ [None, 0, 1] and returns on the first padded-M key that exists (existence only — kernel is irrelevant).
The check treats the gl=0 step as "matched" only when the gl=0 row exists and has the same kernel; otherwise it falls through to gl=1. So when a gl=0 row exists with a different kernel, the check wrongly proceeds to gl=1 and marks the row redundant — but at runtime gl=0 already returns that different kernel and gl=1 is never reached.
Also missing a if pm1 == M: continue guard, so M ∈ {1,2,4,8} (where nextPow2(M)==M) self-match on gl=1.
Concrete example — M=2198, N=3072, K=6144 (gfx950):
imageMeasured on gfx950 (gemm_a8w8_blockscale, --ck_preshuffle False, pre- vs post-removal CSV): 12/28 shapes regressed, e.g. M=4139/4207 +46%, the M=2198–2216 cluster +33–38%, M=88/104/168 +20–22%. (The other 16 got faster, so the removal is unsafe/inconsistent, not uniformly bad.)

def _fallback_kernel(rows, gfx, cu, M, N, K):
    # mirror get_CKGEMM_config: first EXISTING key in [gl=0, gl=1] wins
    for gl in (0, 1):
        pm = _get_padded_m(M, N, K, gl)
        if pm == M:            # padded target is the row itself, skip
            continue
        k = rows.get((gfx, cu, pm, N, K))
        if k is not None:      # existence, not kernel-equality
            return k
    return None

# redundant iff the row we'd fall back to exists AND has the same kernel
fb = _fallback_kernel(rows, gfx, cu, M, N, K)
if fb is not None and fb == kernel:
    redundant.append(...)

@yzhou103

Copy link
Copy Markdown
Contributor

please move the gfx1201 shape in aiter/configs/model_configs/a8w8_blockscale_tuned_gemm_gfx1201.csv, also add a untuned file.

@pds-amd
pds-amd force-pushed the gfx1201-a8w8-gemm-tuning branch from b44ad01 to 4ce76b4 Compare July 22, 2026 10:58
@pds-amd

pds-amd commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Reworked to keep the blast radius minimal:

  • no changes to a8w8_blockscale_tuned_gemm.csv (reverted completely)
  • gfx1201 moved to model_configs/ as requested:
    • model_configs/a8w8_blockscale_tuned_gemm_gfx1201.csv (merged into the family at runtime by get_config_file)
    • model_configs/a8w8_blockscale_untuned_gemm_gfx1201.csv (matching untuned)
  • Redundancy check fixed to match get_CKGEMM_config exactly. It probes [gl=None, gl=0, gl=1] and returns the first key that exists (target kernel irrelevant), with a pm==M self-probe guard. The test is now gated only to the incoming gfx1201 file. The gfx1201 rows are pruned under that corrected check and verified: every tuned shape plus a dense non-tuned M sweep across all (N,K) resolves to an identical kernel with the pruned set (0 mismatches).

A broader clean-up of existing CSVs could be undertaken as future work based on this added test.

yzhou103
yzhou103 previously approved these changes Jul 23, 2026

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

Copilot AI lite review requested due to automatic review settings August 4, 2026 08:01
@pds-amd
pds-amd force-pushed the gfx1201-a8w8-gemm-tuning branch from 4ce76b4 to 4dfcfea Compare August 4, 2026 08:01

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.

🟡 Not ready to approve

The PR description’s claims about which CSV was updated (and the added row count) do not match the actual files committed, so the description/results need to be aligned with the implementation.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

Fixes RDNA (gfx11xx/gfx12xx) GEMM tuning key mismatches by aligning the tuner’s (gfx, cu_num, M, N, K) keying with the runtime’s chip_info-based CU count, and adds initial gfx1201 (RDNA4) a8w8_blockscale tuned coverage via a new model-config CSV.

Changes:

  • Update BaseTuner.get_cu_num() to use aiter.jit.utils.chip_info.get_cu_num() so tuned rows key by true CU count (not torch’s WGP count on RDNA).
  • Add gfx1201 tuned and untuned shape CSVs under aiter/configs/model_configs/.
  • Add a new pytest that detects tuned rows that are redundant under the get_CKGEMM_config fallback chain.
File summaries
File Description
op_tests/test_tuned_config_csv.py Adds a static CSV-level redundancy check mirroring get_CKGEMM_config’s fallback probing behavior.
aiter/utility/base_tuner.py Switches tuner CU detection to chip_info to match runtime dispatch key construction on RDNA GPUs.
aiter/configs/model_configs/a8w8_blockscale_untuned_gemm_gfx1201.csv Adds the gfx1201 untuned shape list used for tuning coverage.
aiter/configs/model_configs/a8w8_blockscale_tuned_gemm_gfx1201.csv Adds gfx1201 tuned rows keyed by cu_num=64 for runtime merge/lookup.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@pds-amd
pds-amd force-pushed the gfx1201-a8w8-gemm-tuning branch from 4dfcfea to 67d8bd2 Compare August 4, 2026 08:11
@jcaraban
jcaraban requested a review from a team August 12, 2026 08:07
@pds-amd
pds-amd force-pushed the gfx1201-a8w8-gemm-tuning branch from 67d8bd2 to ec7a1d8 Compare August 12, 2026 08:08
BaseTuner.get_cu_num() used torch multi_processor_count, which on RDNA
(gfx11xx/gfx12xx) reports WGPs (half the CU count). The runtime resolves
cu_num via chip_info.get_cu_num() (true CU count), so tuner-written keys
(gfx, cu_num, M, N, K) never matched at runtime and every RDNA row
silently fell back to the default kernel. Delegate get_cu_num() to the
same chip_info accessor. No-op on CDNA (gfx942/gfx950).
…l_configs

Adds first RDNA4 (gfx1201, cu_num=64) tuned coverage for a8w8_blockscale as
model_configs files, leaving the canonical CSV (gfx950) untouched:

- model_configs/a8w8_blockscale_tuned_gemm_gfx1201.csv (255 rows), merged into
  the family at runtime by core.get_config_file.
- model_configs/a8w8_blockscale_untuned_gemm_gfx1201.csv (matching untuned).

Rows are pruned of entries redundant under get_CKGEMM_config's fallback, which
probes [gl=None, gl=0, gl=1] and returns the first key that EXISTS (target
kernel irrelevant). op_tests/test_tuned_config_csv.py enforces this: a row is
redundant iff its first existing gl0/gl1 fallback target carries the same
kernel (with a pm==M self-probe guard). Verified every tuned shape plus a
dense non-tuned M sweep across all (N,K) resolve to an identical kernel with
the pruned set (0 mismatches).

Shapes from an RDNA4 diffusion-inference sweep (FLUX / FLUX.2, qwen-image,
stablediffusion-3.5, wan2.2, z-image, ...).
@pds-amd
pds-amd force-pushed the gfx1201-a8w8-gemm-tuning branch from ec7a1d8 to 1c9e1eb Compare August 12, 2026 08:23
@pds-amd

pds-amd commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@yzhou103 - could you please re-approve? The CI failure is unrelated to this work.

Copilot AI review requested due to automatic review settings August 24, 2026 08:21

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.

Suppressed comments (3)

aiter/configs/model_configs/a8w8_blockscale_tuned_gemm_gfx1201.csv:2

  • [verified] The normal explicit-target build path still rejects GPU_ARCHS=gfx1201: get_build_targets_env() only accepts architectures in GFX_CU_NUM_MAP (aiter/jit/utils/build_targets.py:39-43), which has no gfx1201 entry. Thus a clean gfx1201 build cannot generate the registry needed by these rows and fails before tuning/config integration. Author must add the gfx1201 CU default/target handling to the build path (with the corresponding CK support) or avoid shipping CK rows that cannot be built.
gfx1201,64,333,2432,2432,ck,5,0,42.0445,a8w8_blockscale_1x128x128_256x16x128x128_8x16_16x16_1x2_16x16x1_8x32x1_1x16x1x16_8_1x2_intrawave_v1,93.69,198.46,0.0

aiter/utility/base_tuner.py:477

  • [verified] This now calls chip_info.get_cu_num(), whose implementation scans every GPU reported by rocminfo and asserts that all CU counts are identical. On a host exposing, for example, gfx1201/64 and gfx950/256, tuning the selected device raises AssertionError before producing a config, whereas the previous implementation queried torch.cuda.current_device() only. Author must preserve device-specific CU selection or explicitly reject and document heterogeneous-device tuning.
        return _chip_get_cu_num()

op_tests/test_tuned_config_csv.py:103

  • [verified] This new regression test is outside op_tests/tuning_tests/, but .github/workflows/tuning-tests.yaml:88-96 invokes only the explicitly listed op_tests.tuning_tests.* modules and no workflow command matches this file. Thus the redundancy check is not run in CI and can regress unnoticed. Author must add this test to a CI command (or place it under the existing tuning-test suite) so the guard is enforced.
@pytest.mark.parametrize("csv_path", TUNED_CONFIG_CSVS)
def test_no_redundant_rows(csv_path):
    redundant = _find_redundant_rows(csv_path)

@@ -0,0 +1,256 @@
gfx,cu_num,M,N,K,libtype,kernelId,splitK,us,kernelName,tflops,bw,errRatio
gfx1201,64,333,2432,2432,ck,5,0,42.0445,a8w8_blockscale_1x128x128_256x16x128x128_8x16_16x16_1x2_16x16x1_8x32x1_1x16x1x16_8_1x2_intrawave_v1,93.69,198.46,0.0
Copilot AI review requested due to automatic review settings September 2, 2026 14:26
@github-actions github-actions Bot changed the title gfx1201 RDNA4 a8w8 blockscale GEMM tuning [CI] [JIT] gfx1201 RDNA4 a8w8 blockscale GEMM tuning Sep 2, 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.

🔵 Needs a closer look

It changes GPU-arch gating and runtime dispatch behavior where a misconfiguration could cause hard-to-debug runtime failures (e.g., unsafe launches), so it warrants final human validation despite good test additions.

Review details
  • Files reviewed: 10/10 changed files
  • Comments generated: 3
  • Review effort level: Lite

Comment on lines +78 to +80
with open(REPO_ROOT / csv_path) as f:
for r in csv.DictReader(f):
key = (
Comment on lines +668 to +671
csv_triton = _make_temp_csv(f"""
gfx,cu_num,M,N,K,kernelId,libtype,splitK,us,kernelName,tflops,bw,errRatio
{gfx},{cu_num},{m},{n},{k},-1,triton,0,10.0,,100.0,500.0,0.0
""")
Comment on lines +54 to +60
def _fallback_target(rows: dict, gfx, cu, M, N, K):
"""
Mirror get_CKGEMM_config's probe order for a row's own shape: the runtime
tries gl=0 then gl=1 and returns the FIRST key that EXISTS (kernel of the
target is not consulted). Returns (padded_M, kernelName) of that target, or
None if neither exists. The gl=None probe is the row itself and is excluded.
"""
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI JIT stale The PR hasn't been updated in 2 weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants