Repository navigation
[ASM] [HIP] [CI] [gfx1250] add 192x256 no-ps & fix dispatch for A4W4 - #6607
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
valarLip
left a comment
There was a problem hiding this comment.
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
.cofiles are unchanged, butselect_launch_geometrynow 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_shapereturns false forM <= 0, so with zero tokens every config is rejected andget_heuristic_kernelraises "cannot get heuristic kernel". Onmainthe same call passed theM % m_aligncheck (0 % 16 == 0) and launched. Neither_f4gemm_asm_dispatchnorgemm_mxfp4_asm/gemm_nvfp4_asmguardsM == 0. For example,gemm_a4w4on gfx1250 with an empty batch fails.select_launch_geometryitself acceptsM >= 0, so an earlyreturnof an empty output in the Python entries would cover it. - The NPS kernel wins for every aligned shape, at any size.
get_heuristic_kernelprefersps_mode == 0wheneversupports_shapeaccepts 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, andPERF_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_configcallsget_kernel_config(..., "gfx1250", ...), while the launch path passesget_gpu_arch(). Both fill the same staticheuristic_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_configdefaults toa_preshuffle=False, whilegemm_mxfp4_asmdefaults toa_preshuffle=True. Soget_f4gemm_launch_config(768, 1024, 256)reports the NPS 192x256 tile, butgemm_mxfp4_asm(...)with defaults runs the 256x256 PS kernel. The two defaults should match.y=was added togemm_mxfp4_asmbut not togemm_nvfp4_asm, so NVFP4 callers cannot pass a preallocated output.
4. Test harness
test_f4gemm.py:_kernel_config(...)now runs before thetrythat maps missing kernels to "not support". It callsget_f4gemm_launch_config, i.e. the sameget_kernel_config. A config with no registered.co, or an explicit--knl-namethat isn't registered, now raises "cannot get heuristic kernel", "kernel not in cfg_f4gemm" or "selected kernel not in f4gemm manifest" outside thetry. The sweep aborts instead of emitting a "not support" row, and_NOT_SUPPORTED_MARKERSno longer catches anything.dispatch_libfixture: it only checks that the.soexists.hsa/codegen.pyfilters rows byAITER_GPU_ARCHS, so a build without gfx1250 (e.g. a gfx950 prebuild) has an emptycfg_f4gemm. In that casetest_launch_config, thetest_reject_*tests andtest_persistent_override_preserves_npsfail with "no kernel registered for f4gemm" instead of skipping.f4gemm_utfixture: it savestorch.get_default_device()beforefrom op_tests import test_f4gemm. That module callstorch.set_default_device("cuda")at import. If pytest has already collected and importedtest_f4gemm.py, the saved device is alreadycuda, 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, butf4gemm.csvhas no row for it, andsupports_shaperequiresa_preshuffle == 0for NPS. Nothing can select it, and an explicitkernelNamefor 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_shapefailure inget_kernel_configalways 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 PSkernelNamewith N % 16 != 0, orgemm_mxfp4_asm(apre=1)with M = 17 (which bypasses the Python M % 16 check), reports an NPS constraint. The hint should be added only whencfg.ps_mode == 0. AITER_F4GEMM_TUNE. It is read withgetenvon 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_dispatchworks 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.custill 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_psas the kernel name.
- The support-matrix header at the top of
| @@ -0,0 +1,423 @@ | |||
| # SPDX-License-Identifier: MIT | |||
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 || |
There was a problem hiding this comment.
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?
| 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"); |
There was a problem hiding this comment.
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.
| "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")) |
There was a problem hiding this comment.
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.
|
|
||
| # 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() |
There was a problem hiding this comment.
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.
| "AITER_JIT_DIR", Path(__file__).resolve().parents[1] / "aiter/jit" | ||
| ) | ||
| ) | ||
| path = jit_dir / "module_f4gemm_asm_nps_dispatch.so" |
There was a problem hiding this comment.
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.
| *, | ||
| intype: str = "mxfp4", | ||
| outtype: str = "bf16", | ||
| a_preshuffle: bool = False, |
There was a problem hiding this comment.
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.
| "blob_gen_cmd": "f'{AITER_META_DIR}/hsa/codegen.py -m f4f6gemm --output_dir {{}}'" | ||
| }, | ||
| "module_f4gemm_asm": { | ||
| "module_f4gemm_asm_nps_dispatch": { |
There was a problem hiding this comment.
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.
75c13da to
32b14ef
Compare
Signed-off-by: Double Young <[email protected]>
Signed-off-by: Double Young <[email protected]>
6e83ef6 to
da31b17
Compare
test cmd: