Skip to content

[ASM] [HIP] [CI] [gfx1250] add 192x256 no-ps & fix dispatch for A4W4 - #6607

Merged
valarLip merged 6 commits into
mainfrom
gfx1250/f4gemm_nps
Oct 21, 2026
Merged

valarLip merged 6 commits into
mainfrom
gfx1250/f4gemm_nps

Conversation

@dbyoung18

@dbyoung18 dbyoung18 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
  • add tile-size: 192-256 no-persistent & no A-shuffle to cover case 1536z7168x16384 (40us -> 30us)
  • add bit-match to asm ut compared with gluon (all pass)
  • fix dispatch logic

test cmd:

python op_tests/test_f4gemm.py --mode perf --intype mxfp4 --apre 0 --outtype bf16 -mnk 1536,7168,16384
intype M N K apre outtype data_init scale_init knl_name asm us asm TFLOPS asm TB/s asm err asm result
mxfp4 1536 7168 16384 0 bf16 constant constant f4gemm_bf16_mxfp4_BpreShuffle_192x256_4x4 26.71 13509.3 3.66 0 pass
mxfp4 1536 7168 16384 0 bf16 uniform auto f4gemm_bf16_mxfp4_BpreShuffle_192x256_4x4 30.61 11786.9 3.19 0 pass

@dbyoung18
dbyoung18 requested review from a team, WangJessie926 and coderfeli October 16, 2026 03:24
@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:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 6607 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@github-actions github-actions Bot changed the title [ASM][gfx1250] add 192x256 no-ps & fix dispatch for A4W4 [ASM] [HIP] [JIT] [gfx1250] add 192x256 no-ps & fix dispatch for A4W4 Oct 16, 2026
@dbyoung18 dbyoung18 added the ASM label Oct 16, 2026
@dbyoung18
dbyoung18 requested a review from valarLip October 16, 2026 03:30

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this at 75c13daa, by reading the code and the CI scripts. I have no gfx1250 hardware, so nothing here was run on a GPU. Below are the points I could confirm from the code, grouped by theme, each with an example. Inline comments point at the lines.

1. The new coverage does not run in CI

op_tests/test_f4gemm_dispatch.py is pytest-only and has no __main__ block. .github/scripts/aiter_test.sh collects op_tests/*.py with find op_tests -maxdepth 1 -name '*.py' and runs each one as timeout 60m python3 "$file". Only a few listed files, such as test_flydsl_pa_decode.py, get python3 -m pytest. Running this file directly just defines functions and exits 0.

As a result, the bit-match tests, test_launch_config, the test_reject_* tests, test_persistent_override_preserves_nps and the C++ geometry checks never run in CI. Yet they are the only coverage for this PR's two main changes:

  • the NPS kernel;
  • runtime cluster shapes for the persistent kernels. The .co files are unchanged, but select_launch_geometry now launches them as 4x1, 2x1, 1x2, … instead of the CSV's fixed 4x4. For example, M = 768, N = 1024 on the PS path gets a 4x1 cluster, and M = 1..32 gets 2x1.

I see from asm_f4gemm_dispatch.hpp that the cluster size reaches the shader through ttmp6 and that the grid goes in the log2 kernargs, so this looks intentional. Could you add the file to the pytest case in aiter_test.sh (or give it a __main__)? It would also help to note in the description which shapes were run on gfx1250 hardware for the non-4x4 clusters.

2. Behaviour changes on the dispatch path

  • M = 0 now raises instead of launching. supports_shape returns false for M <= 0, so with zero tokens every config is rejected and get_heuristic_kernel raises "cannot get heuristic kernel". On main the same call passed the M % m_align check (0 % 16 == 0) and launched. Neither _f4gemm_asm_dispatch nor gemm_mxfp4_asm / gemm_nvfp4_asm guards M == 0. For example, gemm_a4w4 on gfx1250 with an empty batch fails. select_launch_geometry itself accepts M >= 0, so an early return of an empty output in the Python entries would cover it.
  • The NPS kernel wins for every aligned shape, at any size. get_heuristic_kernel prefers ps_mode == 0 whenever supports_shape accepts it. So any shape with M % 768, N % 1024 and K % 256 all zero, e.g. 12288 x 16384 x 16384, moves from the persistent 256x256 kernel to the non-persistent 192x256 one. The PR description is empty, and PERF_SHAPES = [(16384, 16384, 16384)] is not M % 768, so the NPS kernel is never perf-tested. Please share perf data for large aligned shapes, or add a size bound.
  • The config query hard-codes the arch, and the cache is shared. f4gemm_launch_config calls get_kernel_config(..., "gfx1250", ...), while the launch path passes get_gpu_arch(). Both fill the same static heuristic_kernel_dict, whose key (M, N, K, intype, apre, out) has no arch. This is harmless while only gfx1250 rows exist. Once a second arch registers f4gemm rows, a query can cache a gfx1250 kernel name that a later launch on the other arch reuses.

3. Python API defaults and outputs

  • get_f4gemm_launch_config defaults to a_preshuffle=False, while gemm_mxfp4_asm defaults to a_preshuffle=True. So get_f4gemm_launch_config(768, 1024, 256) reports the NPS 192x256 tile, but gemm_mxfp4_asm(...) with defaults runs the 256x256 PS kernel. The two defaults should match.
  • y= was added to gemm_mxfp4_asm but not to gemm_nvfp4_asm, so NVFP4 callers cannot pass a preallocated output.

4. Test harness

  • test_f4gemm.py: _kernel_config(...) now runs before the try that maps missing kernels to "not support". It calls get_f4gemm_launch_config, i.e. the same get_kernel_config. A config with no registered .co, or an explicit --knl-name that isn't registered, now raises "cannot get heuristic kernel", "kernel not in cfg_f4gemm" or "selected kernel not in f4gemm manifest" outside the try. The sweep aborts instead of emitting a "not support" row, and _NOT_SUPPORTED_MARKERS no longer catches anything.
  • dispatch_lib fixture: it only checks that the .so exists. hsa/codegen.py filters rows by AITER_GPU_ARCHS, so a build without gfx1250 (e.g. a gfx950 prebuild) has an empty cfg_f4gemm. In that case test_launch_config, the test_reject_* tests and test_persistent_override_preserves_nps fail with "no kernel registered for f4gemm" instead of skipping.
  • f4gemm_ut fixture: it saves torch.get_default_device() before from op_tests import test_f4gemm. That module calls torch.set_default_device("cuda") at import. If pytest has already collected and imported test_f4gemm.py, the saved device is already cuda, and the restore does nothing.

5. Dead code, naming, and docs

  • Unreachable code object. hsa/gfx1250/f4gemm/f4gemm_bf16_mxfp4_ABpreShuffle_192x256_4x4.co (34.5 KB) is added, but f4gemm.csv has no row for it, and supports_shape requires a_preshuffle == 0 for NPS. Nothing can select it, and an explicit kernelName for it fails with "kernel not in cfg_f4gemm". Either register it (and relax the AP0 check), or leave it out.
  • Misleading error message. The supports_shape failure in get_kernel_config always appends "192x256 NPS requires MXFP4/BF16/AP0, M%768=0, N%1024=0, K%256=0", even when the selected kernel is a persistent one failing the generic alignment. For example, an explicit PS kernelName with N % 16 != 0, or gemm_mxfp4_asm(apre=1) with M = 17 (which bypasses the Python M % 16 check), reports an NPS constraint. The hint should be added only when cfg.ps_mode == 0.
  • AITER_F4GEMM_TUNE. It is read with getenv on every persistent launch, and it is not documented anywhere except the test. Users cannot discover it. A stale value left in the environment silently changes the geometry of every persistent F4GEMM. Reading it once (a static), and documenting it, would fix both.
  • Module name. module_f4gemm_asm → module_f4gemm_asm_nps_dispatch works as a JIT cache-bust, but the module still dispatches all the persistent kernels too, so the name now describes only part of it.
  • Stale docs.
    • The support-matrix header at the top of asm_f4gemm.cu still lists only the persistent constraints. It does not mention the 192x256 NPS kernel or its MXFP4/BF16/AP0, M % 768 / N % 1024 / K % 256 limits.
    • In test_f4gemm.py, the comment says the op picks the .co "by (intype, a_preshuffle, outtype)", but the choice is now shape-dependent.
    • The "not support" row still hard-codes ..._256x256_4x4_ps as the kernel name.

Comment thread op_tests/test_f4gemm_dispatch.py Outdated
@@ -0,0 +1,423 @@
# SPDX-License-Identifier: MIT

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI runs op_tests/*.py as python3 "$file" (aiter_test.sh). This file has no __main__, so importing it defines the tests and exits 0, and none of them run in CI. It needs a pytest case in aiter_test.sh, like test_flydsl_pa_decode.py.

template <typename Config>
static bool supports_shape(const Config& cfg, int M, int N, int K)
{
if(M <= 0 || N <= 0 || K <= 0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes M = 0 (an empty batch) raise "cannot get heuristic kernel" for every config, whereas main launched it (0 % align == 0). No Python caller guards M == 0. An early return of an empty output in gemm_mxfp4_asm / gemm_nvfp4_asm would keep the old behaviour.

selectedKernelName = el.first;
break;
if(selectedKernelName.empty() ||
cfg.ps_mode < cfgs->at(selectedKernelName).ps_mode ||

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NPS wins for every shape with M % 768, N % 1024 and K % 256 all zero, whatever its size, e.g. 12288 x 16384 x 16384 leaves the persistent kernel. PERF_SHAPES (16384^3) isn't M % 768, so this is never perf-tested. Is there data for large shapes?

Comment thread csrc/py_itfs_cu/asm_f4gemm.cu Outdated
AITER_CHECK(supports_shape(cfg, M, N, K),
__func__, " selected kernel does not support M/N/K=",
M, "/", N, "/", K,
"; 192x256 NPS requires MXFP4/BF16/AP0, M%768=0, N%1024=0, K%256=0");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hint is appended even when the selected kernel is a persistent one failing the generic alignment, e.g. an explicit PS kernelName with N % 16 != 0. It should be added only when cfg.ps_mode == 0.

Comment thread csrc/py_itfs_cu/asm_f4gemm.cu Outdated
"f4gemm persistent geometry requires the registered 256x256 tile");
auto geometry = aiter::f4gemm::select_launch_geometry(M, N);
// The override only applies to persistent kernels; NPS requires full 4x4 clusters.
if(const char* tune = std::getenv("AITER_F4GEMM_TUNE"))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getenv on every persistent launch, and AITER_F4GEMM_TUNE isn't documented outside the test. A stale value silently changes every persistent F4GEMM's geometry. Reading it once (static), and documenting it, would help.

Comment thread op_tests/test_f4gemm_dispatch.py Outdated

# The CLI module selects CUDA as its default device; restore the caller's
# default when this module's tests finish.
previous_device = torch.get_default_device()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_f4gemm sets the default device to cuda at import. If pytest already imported it (by collecting test_f4gemm.py), this saves cuda, and the restore does nothing.

Comment thread op_tests/test_f4gemm_dispatch.py Outdated
"AITER_JIT_DIR", Path(__file__).resolve().parents[1] / "aiter/jit"
)
)
path = jit_dir / "module_f4gemm_asm_nps_dispatch.so"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the file is checked. A build without gfx1250 in AITER_GPU_ARCHS has an empty cfg_f4gemm, so the dispatch tests fail with "no kernel registered for f4gemm" instead of skipping.

Comment thread aiter/ops/gemm_op_a4w4.py Outdated
*,
intype: str = "mxfp4",
outtype: str = "bf16",
a_preshuffle: bool = False,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gemm_mxfp4_asm defaults to a_preshuffle=True, so get_f4gemm_launch_config(768, 1024, 256) reports the NPS tile while gemm_mxfp4_asm(...) with defaults runs the PS kernel. Also, y= was added to gemm_mxfp4_asm but not gemm_nvfp4_asm.

Comment thread aiter/jit/optCompilerConfig.json Outdated
"blob_gen_cmd": "f'{AITER_META_DIR}/hsa/codegen.py -m f4f6gemm --output_dir {{}}'"
},
"module_f4gemm_asm": {
"module_f4gemm_asm_nps_dispatch": {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module still dispatches all the persistent kernels, so _nps_dispatch describes only part of it. If the goal is a cache bust, a neutral name would be clearer.

Comment thread hsa/gfx1250/f4gemm/f4gemm.csv Resolved
@github-actions github-actions Bot changed the title [ASM] [HIP] [JIT] [gfx1250] add 192x256 no-ps & fix dispatch for A4W4 [ASM] [HIP] [gfx1250] add 192x256 no-ps & fix dispatch for A4W4 Oct 16, 2026
@github-actions github-actions Bot removed the JIT label Oct 16, 2026
@github-actions github-actions Bot changed the title [ASM] [HIP] [gfx1250] add 192x256 no-ps & fix dispatch for A4W4 [ASM] [HIP] [CI] [gfx1250] add 192x256 no-ps & fix dispatch for A4W4 Oct 16, 2026
@github-actions github-actions Bot added the CI label Oct 16, 2026
@valarLip
valarLip merged commit 1c2500c into main Oct 21, 2026
@valarLip
valarLip deleted the gfx1250/f4gemm_nps branch October 21, 2026 09:37
@dbyoung18
dbyoung18 restored the gfx1250/f4gemm_nps branch October 21, 2026 10:58
@dbyoung18
dbyoung18 deleted the gfx1250/f4gemm_nps branch October 21, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants