Skip to content

[FlyDSL] [Bugfix] Let the runtime find gfx950 hgemm AOT entries - #7021

Closed
eppaneamd wants to merge 2 commits into
mainfrom
eppaneamd/flydsl-aot-hgemm-semaphore-dtype
Closed

eppaneamd wants to merge 2 commits into
mainfrom
eppaneamd/flydsl-aot-hgemm-semaphore-dtype

Conversation

@eppaneamd

Copy link
Copy Markdown
Contributor

Motivation

The AOT build of the gfx950 A16W16 GEMM (python -m aiter.aot.flydsl.gemm, which setup.py also runs during a prebuild) compiles every tuned flydsl_hgemm_* row into the FlyDSL cache, but the runtime never finds these entries. Since #6494 the runtime allocates the split-K semaphore as int64 (get_split_k_buffers), while _compile_hgemm_to_cache still passes an int32 tensor. FlyDSL's cache key holds each tensor argument's dtype and alignment, so the two keys differ in the semaphore entry only (keys computed in the image listed under Tests, for one configuration, once with each semaphore dtype):

AOT:     ('semaphore', (TorchTensorJitArg, torch.int32, 4, False, (-1,), (1,)))
runtime: ('semaphore', (TorchTensorJitArg, torch.int64, 8, False, (-1,), (1,)))

As a result, each tuned FlyDSL hgemm configuration compiles again the first time a process uses it, even with a complete AOT cache. In a serving process this happens inside the first requests that reach the configuration.

Changes

aiter/ops/flydsl/kernels/gemm_a16w16_gfx950.py: make_split_k_buffers(device) allocates the split-K semaphore (int64) and signal (int32). get_split_k_buffers calls it under persistent_alloc, as before.

aiter/aot/flydsl/gemm.py: _compile_hgemm_to_cache passes make_split_k_buffers on the CPU instead of its own int32 tensors.

op_tests/test_flydsl_hgemm_aot.py: test_hgemm_aot_cache_is_retrievable_in_run_only_mode follows test_fhmoe_aot_cache_is_retrievable_in_run_only_mode in op_tests/test_fhmoe.py. It copies one split-K row from dsv3_bf16_tuned_gemm.csv into a temporary table, builds it with python -m aiter.aot.flydsl.gemm --csv, and runs it through aiter.tuned_gemm.flydsl_gemm with FLYDSL_RUNTIME_RUN_ONLY=1. In run-only mode FlyDSL raises instead of compiling when no entry matches. It is skipped on other architectures.

op_tests/test_graph_alloc.py: passes the split_k argument that #6494 added to get_split_k_buffers; the two-argument call raised TypeError.

AOT caches built before this change keep their int32-keyed entries, so they are not used until they are rebuilt.

Scope

All gfx950 FlyDSL hgemm rows of the tuned bf16 GEMM tables: at the base commit, 2,543 rows (1,022 distinct kernels) in bf16_tuned_gemm.csv and 19 model tables. Measured with the 81 distinct kernels of glm53_flash_bf16_tuned_gemm.csv. The gfx1250 A16W16 AOT path already passes the same counter dtype as its runtime (int32) and is not changed.

Tests

Setup:

  • AMD Instinct MI355X (gfx950), one GPU.
  • Image lmsysorg/sglang-rocm:v0.5.22-rocm724-mi35x-20261021 (AITER 285579b). For "with this PR", this PR's change applied to that commit's aiter/aot/flydsl/gemm.py, aiter/ops/flydsl/kernels/gemm_a16w16_gfx950.py and op_tests/test_graph_alloc.py; the touched functions are the same as on main. The new test file is added to the container in both arms.
  • Two fresh containers per arm, in the order without, with, with, without.

Results:

  • test_hgemm_aot_cache_is_retrievable_in_run_only_mode: fails in both containers without this PR (RuntimeError: FLYDSL_RUNTIME_RUN_ONLY=1 but no usable AOT cache for gemm_a16w16_gfx950) and passes in both with it.
  • pytest op_tests/test_graph_alloc.py: without this PR 1 failed, 2 passed in both containers (test_every_cached_scratch_comes_from_the_private_pool: TypeError: get_split_k_buffers() missing 1 required positional argument: 'split_k'); with it 3 passed in both.

Performance

First use of each of the 81 tuned FlyDSL hgemm kernels of glm53_flash_bf16_tuned_gemm.csv, after building them with the AOT driver into an empty cache: one call per kernel at the shape of its first row, in a fresh process, wall time with device synchronization.

Without this PR With this PR (two containers)
Cache entries written by the fresh process 81 0, 0
Total first-call time 24.6 s 1.52 s, 1.52 s
Median per kernel 289 ms 14.1 ms, 14.3 ms
Max per kernel 718 ms 197 ms, 194 ms

The AOT driver wrote 81 entries in every container. Without this PR, the table shows the first container; the second ran while another process compiled on the same host, so its times are left out (its tests gave the same results).

This change was developed with AI assistance (Claude); I reviewed every line and ran the tests listed.

The AOT build of the gfx950 A16W16 GEMM (aiter.aot.flydsl.gemm) passes an
int32 split-K semaphore, but the runtime allocates it as int64 since #6494.
FlyDSL puts the tensor dtype into the cache key, so no AOT entry matches a
runtime call, and every tuned FlyDSL hgemm configuration compiles again on
first use.

Allocate both split-K buffers in one function that the runtime and the AOT
build share. The new test builds one tuned split-K row with the AOT driver
and runs it in FlyDSL run-only mode, which raises instead of compiling on a
miss. op_tests/test_graph_alloc.py now passes the split_k argument that
#6494 added to get_split_k_buffers.

Signed-off-by: Rony Leppänen <[email protected]>
Co-authored-by: Claude <[email protected]>
@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 7021 --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.

@eppaneamd

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #6712, which makes the same semaphore dtype fix. Measured impact posted there; the test_graph_alloc.py fix moved to #7039.

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.

1 participant