Skip to content

[FlyDSL] [CI] AOT cache: key constexpr launch arguments; move the gfx942/gfx950 GEMM and 2-stage MoE launchers to it - #8537

Closed
coderfeli wants to merge 12 commits into
mainfrom
fix/flydsl-aot-key-guards
Closed

coderfeli wants to merge 12 commits into
mainfrom
fix/flydsl-aot-key-guards

Conversation

@coderfeli

@coderfeli coderfeli commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #8451 (FlyDSL AOT cache through _run_compiled). Two parts:

  1. Cache fixes. An exported object ignores a launcher's Constexpr launch arguments, so an entry built with one value was loaded by a later process that passed another. The cache now records what an entry bakes in and only serves calls that match.
  2. Coverage. Every FlyDSL launcher that the GEMM and 2-stage MoE AOT replays compile for gfx942 and gfx950 now launches through the cache.

gfx1250 is not touched.

Cache fixes

Problem Fix
Constexpr launch arguments not in the key: another process silently loads the wrong object Values are recorded in the entry's sidecar (baked) and compared on lookup. Within a process, one key launched with another value raises. Ints, floats, bools, strings, None and tuples are supported
A specialization_key holding an Enum or numpy scalar raised on every launch That key takes the JIT path, with one warning
factory.cache_clear() kept the loaded kernels Drops them and keeps the factory on the JIT path for the rest of the process
Bitcode linked with link_extern not in the key Hashed into the entry's sources
ROCm device bitcode (ocml, ockl) not in the fingerprint FlyDSL's own digest of it is added
LLVM_GFX1250_ANY_XNACK_CODEGEN not in the fingerprint The fingerprint follows FlyDSL's own list of cache-invalidating variables
Caller's CompilationContext.compile_hints not in the key Hashed into the disk digest
A factory returning a tuple or dict made bind_aot raise Left unbound, on the JIT path
A bound launch cost about 4 us more host time than the JIT path (20-argument factory) A binding keeps the kernels the cache loaded for it; lazy() keys its handles with functools.cache. Now +0.5 us through lazy(), +1.8 us through an unchanged call site

The cache schema goes from 5 to 6, so existing entries are rebuilt once.

CI now runs the op tests under AITER_FLYDSL_AOT_CACHE=verify (.github/scripts/aiter_test.sh): an entry a test loads from disk is re-traced and compared byte for byte, and an export or load failure fails the test instead of falling back to the JIT path.

Launchers moved to the cache (gfx942 / gfx950)

Cache Launcher How
gemm_a16w16_gfx950 default HGEMM bind_aot; launched through _run_compiled with its config items and device as the specialization key, in place of its private flyc.compile cache (run_cached, removed). Its dynamic-layout tensor arguments now carry torch_tensor (see launch overhead)
gemm_a16w16_band_gfx950, gemm_a16w16_skinny_gfx950 band and skinny HGEMM aot_factory
gemm_a8w8_fp8_8wave, gemm_a8w8_int8_4wave per-token-per-channel a8w8 aot_factory
mixed_moe_gemm1/2, mixed_fhmoe_gemm1/2 MX 2-stage MoE, FHMoE aot_factory
mxfp4_moe_gemm1 a4w4 stage 1 aot_factory
mxmoe_gemm2 MX stage 2 (mxmoe_dispatcher.get_g2) bind_aot under get_g2's key
moe_reduction stage-2 reduce aot_factory

Other call sites are unchanged.

Validation

On MI308X (gfx942), FlyDSL 0.5.3, at the head of this branch.

Coverage. Compile-only replays, each run twice on one cache directory, with every flyc.compile logged:

Replay Entries Second run builds Launchers compiled by the JIT path JIT fallbacks
GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.gemm 5240 0 0 0
GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.moe 2882 0 0 0
GPU_ARCHS=gfx942 python -m aiter.aot.flydsl.gemm 80 0 0 0
GPU_ARCHS=gfx942 python -m aiter.aot.flydsl.moe 132 0 0 0

Compiled kernels are unchanged. The same replays with AITER_FLYDSL_AOT_CACHE=0 leave the same FlyDSL artifacts, byte for byte: 4874 for the gfx950 GEMM (794 of them the HGEMM), 80 for the gfx942 GEMM, 2747 for the gfx950 MoE and 100 for the gfx942 MoE. No artifact is present in only one mode for the GEMMs; for the MoE the =0 run used --row-tokens-only, and all of its artifacts are in the full run, identical.

Launch overhead. Host time of one launch, an empty kernel, arguments built on every call, pinned cores:

Launch arguments as passed by JIT path this cache
6 typed pointers, 2 ints mxscale, bmm, the gfx942 MoE 20.5 us 20.3 us
6 raw addresses, 2 ints, 2 floats the a16wmix and MX MoE GEMMs 10.3 us 11.3 us
5 flat tensors, 2 ints preshuffle, blockscale, 8-wave 12.1 us 14.2 us
3 dynamic-layout tensors with torch_tensor, constexpr struct (arguments prebuilt) the gfx950 HGEMM 11.9 us 12.5 us
the same without torch_tensor 11.8 us 30.8 us

The HGEMM rows are a launcher of the HGEMM's argument shape run on gfx942 (row- and column-major tensors give the same results on both paths). A function loaded with flyc.load_module makes a DLPack view of a from_dlpack argument in every fill unless the argument carries its tensor as torch_tensor.

On the GPU, under verify, each run twice on one cache directory (the second run re-traces every entry the first built): op_tests/test_flydsl_moe_gfx942.py (138 entries), op_tests/test_flydsl_moe_a16wfp4.py (46), op_tests/test_gemm_a8w8.py (80), tests/test_flydsl_aot_launch.py, tests/test_flydsl_aot_cache.py. No stale entry and no fallback.

The verify default in CI. All 85 op_tests/test_*.py that mention FlyDSL were run on gfx942 with AITER_FLYDSL_AOT_CACHE=1 and then with verify on the same cache directory. No test passes under 1 and fails under verify, no launch falls back, no entry is stale. (20 of the 85 fail in both modes here, from this checkout's missing CK submodule and similar.) One test did fail only under verify on an earlier commit: test_gemm_group32_interface.py runs an AOT replay hook that stops flyc.compile to identify kernels, which verify treated as an export failure; the cache now takes the JIT path for it in every mode.

Concurrency. Two replays started together on one empty cache built 123 and 9 of the 132 gfx942 MoE entries, each once, left no temporary directory, and a third built none.

Not covered

  • gfx950 runtime. No gfx950 hardware here; gfx950 kernels are validated compile-only, the HGEMM included.
  • One unexplained mismatch. tests/test_flydsl_aot_cache.py compares the output of a preshuffle GEMM across the JIT path, a cache miss, a hit and verify. In one run of about fifteen, with 16 other op tests sharing the GPUs, the split-K case (64x1024x2048, split_k=2) differed in one of the four modes; the test does not report which. It did not reproduce in 3100 launches of that case (JIT, hit and verify, fresh processes, with and without other load on the GPU), which all gave one output.
  • verify on gfx950 and gfx1250 runners. The sweep above is gfx942 only.
  • Linked bitcode is covered by a unit test with a stand-in object only; MORI is not installed here.
  • Not converted: gfx1250 kernels, attention (pa_decode_plan, gfx950 FP8 flash attention, GDN), MegaMoE, a8w4 comm_fused_moe.

Known behaviour changes

  • run_cached serialised the first compile of an HGEMM config with a lock; _run_compiled's JIT path does not, so with the cache off two threads may both compile a config. Results are unaffected.
  • A launcher with Constexpr launch arguments that is launched under one key with two values now raises _BakedArgumentError; the JIT path silently ran the first.
  • The aot_factory wrapper no longer moves a launcher to the JIT path when a factory returns the same launcher object for two argument sets; it stays under its first key. The object is the same kernel either way.

🤖 Generated with Claude Code

coderfeli and others added 6 commits November 23, 2026 09:39
…d compile hints

An exported object ignores a launcher's Constexpr launch arguments, so an
entry built with one value was loaded by a later process that passed
another. Record the values an entry was built with in its sidecar and
accept a disk entry only for a call that passes them; one in-memory key
launched with two values raises. Strings, None and tuples are keyed too.

Also:
- a specialization_key the cache cannot key on disk (an Enum, a numpy
  scalar) launches through the JIT path instead of raising on every launch
- factory.cache_clear() drops the launchers the cache loaded and keeps the
  factory on the JIT path for the rest of the process
- bitcode a kernel links with link_extern is hashed into its entry, and the
  ROCm device bitcode into the fingerprint
- the fingerprint follows FlyDSL's own list of cache-invalidating
  variables (LLVM_GFX1250_ANY_XNACK_CODEGEN)
- CompilationContext.compile_hints of the caller are part of the disk key
- CI runs the op tests under AITER_FLYDSL_AOT_CACHE=verify

The cache schema goes from 5 to 6: existing entries are rebuilt once.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…inked bitcode

- A loaded launcher with constexpr launch arguments raises when a later
  launch of the key passes another number of arguments: a constexpr the
  first launch left to its default was not compared.
- A tuple constexpr is compared as the disk entry is, so (True, 2) is not
  (1, 2).
- A linked bitcode file may be newer than the process (extracted on first
  use): it is hashed as the compile read it, and no longer keeps the entry
  from being written.
- The device bitcode digest follows the environment instead of being cached
  per process.
- bind_aot leaves a factory result that is not one launcher (a tuple or a
  dict of them) on the JIT path instead of raising.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…h the AOT cache

Every FlyDSL launcher the GEMM and MoE AOT replays compile for gfx942 and
gfx950 now launches through FlyDSLAotCache, so a later process loads the
exported object instead of tracing the kernel again:

- gemm_a16w16_gfx950 (the default HGEMM): launched through _run_compiled
  with its config items as the specialization key, in place of its own
  flyc.compile cache (run_cached, removed)
- the band and skinny HGEMM, the a8w8 4-wave and 8-wave GEMMs
- the MX 2-stage MoE and FHMoE GEMMs, the a4w4 stage 1, the MX stage 2
  (mxmoe_dispatcher.get_g2) and the stage-2 reduce

Compile-only on gfx942 with the full replays, each run twice on one cache
directory: gfx950 GEMM 5240 entries, gfx950 MoE 2882, gfx942 GEMM 80,
gfx942 MoE 132; the second run builds none, no launcher is compiled by the
JIT path and none falls back. Runtime on gfx950 is still to be checked.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…conversion

- gemm_a16w16_gfx950 keys its launches by the device too: a JIT handle
  launches only on the device it was compiled on.
- mxmoe_dispatcher.get_g2 lets the cache compile the launcher an entry is
  built from, so the files that compile runs are recorded with the entry.
- A launcher with constexpr launch arguments may leave trailing runtime
  arguments to their defaults; only a launch with more arguments, or too
  few for the baked ones, raises.
- Constexpr values other than ints, bools and strings are compared as the
  disk entry is (-0.0 is not 0.0).
- A factory whose result cannot be bound is not asked to bind it again on
  every call.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
A launch through the cache cost about 4 us more host time than the JIT path
for a factory with 20 keyword arguments (MI308X, trivial kernel: 13.4 us
against 9.4 us), most of it hashing the factory's arguments again:

- A binding keeps the objects the cache loaded for it, by specialization
  key, so a launch no longer hashes the whole key; cache.invalidate() bumps
  an epoch that drops them.
- factory.lazy() keys its handles with functools.cache, as the factory keys
  its launchers.
- The factory wrapper binds a launcher only if it is not bound yet, which
  costs one attribute read on later calls.

Now 9.9 us through factory.lazy() and 11.1 us through an unchanged call
site, against 9.3 us on the JIT path.

Also fixes four statements in the docs that the code contradicted.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ing race

- gemm_a16w16_gfx950 goes back to its own flyc.compile cache (run_cached),
  as on main. It passes its tensors as flyc.from_dlpack dynamic-layout
  arguments, and a function loaded with flyc.load_module takes 27 us to
  launch with three of them, against 9.6 us for the JIT one: a launch would
  cost about 55 us of host time instead of 35 us (MI308X, empty kernel).
- A binding kept a kernel read from the cache under the epoch that followed
  a concurrent invalidate(), and then launched it for good. It now keeps a
  kernel only under the epoch it read before the launch, and lets go of
  what it holds when the epoch moves.

Docs: host time of a launch for the argument kinds the converted kernels
pass, and the replays' artifacts compared with AITER_FLYDSL_AOT_CACHE=0.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderfeli
coderfeli requested a review from a team November 24, 2026 04:41
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 Radeon R9700 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 8537 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@github-actions github-actions Bot changed the title [FlyDSL] AOT cache: key constexpr launch arguments; move the gfx942/gfx950 GEMM and 2-stage MoE launchers to it [FlyDSL] [CI] AOT cache: key constexpr launch arguments; move the gfx942/gfx950 GEMM and 2-stage MoE launchers to it Nov 24, 2026
@aiter-bot

aiter-bot commented Nov 24, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision e50ceed6247b · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What permissions and untrusted-input boundary does this CI change have, and can fork PR code or text reach a privileged execution path?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

coderfeli and others added 5 commits November 24, 2026 06:29
…fy-only hook pass verify

- gemm_a16w16_gfx950 launches through _run_compiled and the cache again,
  with its config items and device as the specialization key. Its
  dynamic-layout tensor arguments now carry their torch tensor
  (`torch_tensor`, as FlyDSL's TorchTensorJitArg does), which FlyDSL's
  launch-argument fills read instead of making a DLPack view per fill. On
  MI308X with a launcher of the same shape, a launch with prebuilt arguments
  takes 22 us through a loaded object and 23.5 us through the JIT, against
  35 us on the JIT path before and 68-80 us through a loaded object
  without the attribute. Row- and column-major layouts give the same
  results on both paths.
- A compile hook that stops flyc.compile (an AOT replay that only
  identifies the kernels a call requests) leaves nothing to export. That is
  not an export failure: the key takes the JIT path, under verify too.
  op_tests/test_gemm_group32_interface.py relies on it.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Corrects the numbers given with the previous commit, which were taken on a
loaded machine. On a quiet MI308X, a launch of a launcher with the HGEMM's
argument shape (three dynamic-layout tensors, a constexpr struct, arguments
prebuilt) takes 11.9 us on the JIT path and 12.5 us through a loaded
object when the arguments carry `torch_tensor`, and 30.8 us through a
loaded object when they do not. The attribute does not change the JIT path.

The full gfx950 GEMM replay now writes 5240 entries, compiles no launcher
on the JIT path, and leaves the same 4874 FlyDSL artifacts, byte for byte,
as with AITER_FLYDSL_AOT_CACHE=0.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
A procedure and checklist for moving a FlyDSL launch onto the export_to_c
AOT cache and for reviewing such a change: the three launcher patterns,
what must be in the key or specialization_key, compile-only validation
without the target GPU, and a table of the cache's errors and fallbacks.
AGENTS.md and the FlyDSL review instructions point to it.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Picks up the Triton 3.9.0 bump (#8266): CI installs that Triton wheel, and
without the matching aiter/utility/fp4_utils.py op_tests/test_gemm_a4w4.py
fails to compile its quant kernel.
An entry used to record the files its build ran (sys.setprofile) and
compare them on a lookup. What a build runs depends on what the process
ran before (a memoized factory, a module already imported), so the
recorded set could miss a file, and an edit to it left stale entries.

Each cache now lists the files its launchers are built from, as
FlashInfer's gen_jit_spec(name, sources) does:

    @aot_factory("my_kernel", sources=["kernels/my_kernel.py", ...])

- The contents of the declared files, and the values of the variables
  named in env=, are hashed into the digest that names an entry. An edit
  makes new entries for that cache only; going back finds the earlier
  ones. The file creating the cache is always a source.
- Nothing is detected at run time. A forgotten source is checked for
  when an entry is built: a declared kernel file that imports an
  undeclared kernel file, or linked bitcode that is not declared, raises
  _UndeclaredSourceError in every mode. A unit test runs the import
  check over every cache in the tree.
- A declared .py edited after the process imported aiter's FlyDSL code
  keeps that cache on the JIT path for the process.
- bind_aot loses its rebuild argument, aot_factory's extra_sources is
  now sources, and the cache schema is 7.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderfeli

Copy link
Copy Markdown
Collaborator Author

Superseded by #8565 (same branch content, now at e50ceed with the declared-sources cache).

@coderfeli coderfeli closed this Nov 24, 2026
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.

2 participants