Repository navigation
[FlyDSL] [CI] [AOT_TO_C] Fix/flydsl aot key guards hgemm - #8565
Conversation
…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]>
…ribute in a test) Co-Authored-By: Claude Fable 5.2 <[email protected]>
…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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
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.
zhiding512
left a comment
There was a problem hiding this comment.
Approving at 4abc1e3 (same head as #8537). I read the cache, binding and launcher changes against the base and the call sites in the tree. I did not find a correctness blocker. The launchers you converted all launch through _run_compiled (get_g2 goes through the run_compiled alias), and their per-call values (grid, M, sizes) are runtime fx.Int32 / fx.Int64 arguments, not Constexpr, so _BakedKernel will not trip on them. No production code calls cache_clear() on any of the converted factories.
I ran the tests myself on MI308X (gfx942), using the pinned flydsl==0.5.3 wheel and the PR worktree:
tests/test_flydsl_aot_launch.py: 13 passed underAITER_FLYDSL_AOT_CACHE=1and 13 passed underverify. That includestest_moe_gfx942_through_aot_cache.tests/test_flydsl_aot_cache.py: 1 passed, once. Its modes0,1miss,1hit,verifyand the env variant all agreed bitwise in that run, thesplit_k=2case included.
I did not run anything on gfx950.
Comments, none blocking (approval is conditional only on a green MI35X run on this head, see 7):
-
gfx1250 is touched through
moe_reduction. The summary says gfx1250 is not touched. Butcompile_moe_reductionis now anaot_factory, and_run_moe_reductiondoes not depend on the arch, so a gfx1250 MoE in reduce mode now launches the reduce through the cache. Docs §7 already says this is not validated. Please either say so in the PR body or run one gfx1250 reduce-mode MoE test underverify. -
The unexplained split-K mismatch in
tests/test_flydsl_aot_cache.py. This test asserts that all modes produce bitwise identical output, and the failing case (64x1024x2048,split_k=2) writes BF16 through the split-K fp32 workspace. If the order of that reduction is not fixed, this is the same class of problem as #8374, not the cache. One way to tell: under the same load, compare mode0against mode0. If that also differs about 1 time in 15, takesplit_k>1out of the bitwise cross-mode assertion, or give that case fp32 output. Otherwise it will flake now that CI runsverify. -
HGEMM
_PARAM_ITEMS[id(param)]. This works today because everyparamthat reachesgemm_a16w16comes from_gemm_a16w16_gfx950_param_for, whose unbounded cache keeps it alive. Anid()-keyed side table is still fragile, though. Two threads making the first call for the same items can each build a param, and the one the cache does not keep can later be collected and its id reused. A future caller that passes its own param gets aKeyError.make_gemm_a16w16_param_and_validatealready buildstuple(sorted(kwargs.items())). Computing the same tuple ingemm_a16w16, or returning(param, items)from the cached helper, would remove the side table. -
get_g2.bind_aot(compile_g2(), ..., compile_g2)still callscompile_gemm2_a4w4_port, which is uncached, the first time each key is seen. On a disk miss it is called a second time inside the build. So MX stage 2 does not get the "a hit never runs the factory" benefit that.lazy()gives the other launchers. This is not a correctness issue. A_LazyLauncher(_AotBinding(cache, key, compile_g2, compile_g2))handle, built the wayaot_factory.lazybuilds one, would give stage 2 the same benefit. -
Silent coverage loss on a FlyDSL bump.
_device_bitcode_digest()falls back to"unknown:<Exc>"and_flydsl_cache_env()falls back to()when FlyDSL internals move. Both fallbacks are silent, so the fingerprint quietly stops covering those inputs._link_libsfails loudly underverify, which is good. A one-line test that assertsnot _device_bitcode_digest().startswith("unknown:")on the pinned FlyDSL would make the next bump fail CI instead. -
Steady-state host cost and wheel size. These are trade-offs worth stating next to the breaking changes:
- A cache hit costs +1.0 us per launch for the MX MoE GEMMs and +2.1 us for preshuffle, blockscale and 8-wave, against the JIT path. That does not matter under graph capture, but eager decode pays it on every launch.
- The body gives about 53 MiB in the wheel for the gfx950 GEMM entries, and docs §7 says 180 MB on disk where the body says 146 MiB. What is the total wheel growth once the 2882 MoE entries are included? And does the wheel still ship FlyDSL's own
.pklartifacts for the same kernels?
-
Process.
- #8537 is still open at the same head. Closing one of the two keeps reviews and CI in one place.
- When I looked, the standard MI35X tests on this head were still in progress, with no results yet. The evidence for gfx950 at runtime is the earlier #8537 run (6/8 shards; the a4w4 failure is fixed by the merge of main, and the hgemm failure is #8374). A full green run on 4abc1e3 before merging would close that gap.
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]>
ptr_buf_tensor and its helpers emit code, so the source check no longer exempts the file: the caches whose kernels import it declare it. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…they were hashed - The source digest is read once per process, but a kernel module may be imported later (a factory's first miss, the trace). An entry is now stored only if its declared sources still have the hashed contents, checked before and after the build.
…r XCD - Kernels size themselves by these per-arch constants, which live outside aiter/ops/flydsl where no cache declares sources.
- kernels_common.py, tensor_shim.py, buffer_ops.py and the jit hardware tables (chip_info.py, lds_capacity.py) are sources of every cache; a cache lists only its own files.
chip_info.py is a common source of every FlyDSL AOT cache. The partition code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565 then rejects every cache, and the wheel build fails in run_aot. These variables select the GPU only. The arch and the CU count of that GPU are already in the cache fingerprint, and a replay sets them to "". Add them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every entry on the visible GPUs. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
chip_info.py is a common source of every FlyDSL AOT cache. The partition code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565 then rejects every cache, and the wheel build fails in run_aot. These variables select the GPU only. The arch and the CU count of that GPU are already in the cache fingerprint, and a replay sets them to "". Add them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every entry on the visible GPUs. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]> (cherry picked from commit 1016ff2) Signed-off-by: Andreas Karatzas <[email protected]>
chip_info.py is a common source of every FlyDSL AOT cache. The partition code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565 then rejects every cache, and the wheel build fails in run_aot. These variables select the GPU only. The arch and the CU count of that GPU are already in the cache fingerprint, and a replay sets them to "". Add them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every entry on the visible GPUs. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]> (cherry picked from commit 1016ff2) Signed-off-by: Andreas Karatzas <[email protected]>
chip_info.py is a common source of every FlyDSL AOT cache. The partition code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565 then rejects every cache, and the wheel build fails in run_aot. These variables select the GPU only. The arch and the CU count of that GPU are already in the cache fingerprint, and a replay sets them to "". Add them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every entry on the visible GPUs. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]> (cherry picked from commit 1016ff2) Signed-off-by: Andreas Karatzas <[email protected]>
chip_info.py is a common source of every FlyDSL AOT cache. The partition code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565 then rejects every cache, and the wheel build fails in run_aot. These variables select the GPU only. The arch and the CU count of that GPU are already in the cache fingerprint, and a replay sets them to "". Add them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every entry on the visible GPUs. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]> (cherry picked from commit 1016ff2) Signed-off-by: Andreas Karatzas <[email protected]>
chip_info.py is a common source of every FlyDSL AOT cache. The partition code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565 then rejects every cache, and the wheel build fails in run_aot. These variables select the GPU only. The arch and the CU count of that GPU are already in the cache fingerprint, and a replay sets them to "". Add them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every entry on the visible GPUs. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]> (cherry picked from commit 1016ff2) Signed-off-by: Andreas Karatzas <[email protected]>
chip_info.py is a common source of every FlyDSL AOT cache. The partition code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565 then rejects every cache, and the wheel build fails in run_aot. These variables select the GPU only. The arch and the CU count of that GPU are already in the cache fingerprint, and a replay sets them to "". Add them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every entry on the visible GPUs. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]> (cherry picked from commit 1016ff2) Signed-off-by: Andreas Karatzas <[email protected]>
chip_info.py is a common source of every FlyDSL AOT cache. The partition code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565 then rejects every cache, and the wheel build fails in run_aot. These variables select the GPU only. The arch and the CU count of that GPU are already in the cache fingerprint, and a replay sets them to "". Add them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every entry on the visible GPUs. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]> (cherry picked from commit 1016ff2) Signed-off-by: Andreas Karatzas <[email protected]>
chip_info.py is a common source of every FlyDSL AOT cache. The partition code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565 then rejects every cache, and the wheel build fails in run_aot. These variables select the GPU only. The arch and the CU count of that GPU are already in the cache fingerprint, and a replay sets them to "". Add them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every entry on the visible GPUs. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]> (cherry picked from commit 1016ff2) Signed-off-by: Andreas Karatzas <[email protected]>
chip_info.py is a common source of every FlyDSL AOT cache. The partition code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565 then rejects every cache, and the wheel build fails in run_aot. These variables select the GPU only. The arch and the CU count of that GPU are already in the cache fingerprint, and a replay sets them to "". Add them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every entry on the visible GPUs. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]> (cherry picked from commit 1016ff2) Signed-off-by: Andreas Karatzas <[email protected]>
chip_info.py is a common source of every FlyDSL AOT cache. The partition code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565 then rejects every cache, and the wheel build fails in run_aot. These variables select the GPU only. The arch and the CU count of that GPU are already in the cache fingerprint, and a replay sets them to "". Add them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every entry on the visible GPUs. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]> (cherry picked from commit 1016ff2) Signed-off-by: Andreas Karatzas <[email protected]>
chip_info.py is a common source of every FlyDSL AOT cache. The partition code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565 then rejects every cache, and the wheel build fails in run_aot. These variables select the GPU only. The arch and the CU count of that GPU are already in the cache fingerprint, and a replay sets them to "". Add them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every entry on the visible GPUs. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]> (cherry picked from commit 1016ff2) Signed-off-by: Andreas Karatzas <[email protected]>
chip_info.py is a common source of every FlyDSL AOT cache. The partition code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565 then rejects every cache, and the wheel build fails in run_aot. These variables select the GPU only. The arch and the CU count of that GPU are already in the cache fingerprint, and a replay sets them to "". Add them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every entry on the visible GPUs. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]> (cherry picked from commit 1016ff2) Signed-off-by: Andreas Karatzas <[email protected]>
chip_info.py is a common source of every FlyDSL AOT cache. The partition code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565 then rejects every cache, and the wheel build fails in run_aot. These variables select the GPU only. The arch and the CU count of that GPU are already in the cache fingerprint, and a replay sets them to "". Add them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every entry on the visible GPUs. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]> (cherry picked from commit 1016ff2) Signed-off-by: Andreas Karatzas <[email protected]>
chip_info.py is a common source of every FlyDSL AOT cache. The partition code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565 then rejects every cache, and the wheel build fails in run_aot. These variables select the GPU only. The arch and the CU count of that GPU are already in the cache fingerprint, and a replay sets them to "". Add them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every entry on the visible GPUs. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]> (cherry picked from commit 1016ff2) Signed-off-by: Andreas Karatzas <[email protected]>
Summary
Follow-up to #8451 (FlyDSL AOT cache through
_run_compiled).Constexprlaunch 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.gfx1250 is not touched. Replaces #8537 (closed).
Motivation
FlyDSL keys its artifacts by the traced IR, so every new process traces every kernel again on first use (70 ms to several seconds each). #8451 added a cache of exported objects that skips the trace, for a first set of launchers. Two things were missing: the cache key did not cover everything an exported object bakes in, and most GEMM and MoE launchers of gfx942 and gfx950 still took the JIT path.
Changes
Cache (
aiter/ops/flydsl/aot_cache.py,aot_launch.py):AITER_FLYDSL_*/FLYDSL_*variable was in the fingerprint: setting one that a single kernel reads made every cache missenv=); a prebuild and a unit test raise for one read by a literal name and not declaredverifycompared exported objects byte for byte, but the code generator can make different bytes of one IRverifycompares thatCOMPILE_ONLY, as the replays inaiter/aot/flydslrun) builds entries. A launch loads an entry or, with none, logs an error and traces on the JIT pathlogger.error(no entry, failed load or export, a key the cache cannot store, a launcher it cannot bind, a reset factory). Nothing raises;AITER_FLYDSL_AOT_CACHE=0stays silentConstexprlaunch arguments not in the key: another process silently loads the wrong objectbaked) and compared on lookup. Within a process, one key launched with another value raises. Ints, floats, bools, strings,Noneand tuples are supportedspecialization_keyholding an Enum or numpy scalar raised on every launchfactory.cache_clear()kept the loaded kernelssys.setprofile); what a build runs depends on what the process ran before, so an edit to a missed file left stale entriesgen_jit_spec(name, sources)does:aot_factory(name, sources=[...], env=[...]). Their contents and the variables' values are hashed into the entry's name. Nothing is detected at run time_UndeclaredSourceErrorin every mode. A unit test runs the check over every cache in the tree.tensor_shim.pycounts as a kernel file (ptr_buf_tensoremits code)link_externnot in the keysources; a build that links undeclared bitcode raisesLLVM_GFX1250_ANY_XNACK_CODEGENnot in the fingerprintCompilationContext.compile_hintsnot in the keybind_aotraiseflyc.compileto identify kernels counted as an export failure underverifylazy()keys its handles withfunctools.cacheLaunchers moved to the cache (gfx942 / gfx950):
gemm_a16w16_gfx950bind_aot; launched through_run_compiledwith its config items and device as the specialization key, in place of its privateflyc.compilecache (run_cached, removed). Its dynamic-layout tensor arguments now carrytorch_tensorgemm_a16w16_band_gfx950,gemm_a16w16_skinny_gfx950aot_factorygemm_a8w8_fp8_8wave,gemm_a8w8_int8_4waveaot_factorymixed_moe_gemm1/2,mixed_fhmoe_gemm1/2aot_factorymxfp4_moe_gemm1aot_factorymxmoe_gemm2mxmoe_dispatcher.get_g2)bind_aotunderget_g2's keymoe_reductionaot_factoryCI:
.github/scripts/aiter_test.shruns the op tests underAITER_FLYDSL_AOT_CACHE=verifyunless the variable is already set. An entry a test loads from disk (built by the wheel's prebuild) is re-traced and compared byte for byte, and a load failure fails the test. A test shape with no prebuilt entry takes the JIT path and is not checked. Running a test by hand is unchanged (mode1).Also:
.claude/skills/flydsl-aot-export/SKILL.mdand pointers to it, and a merge of main for the Triton 3.9.0 bump (#8266).Performance (if applicable)
Host time of one launch, MI308X (gfx942), FlyDSL 0.5.3, an empty kernel, arguments built on every call, pinned cores. "Before" is the JIT path (
AITER_FLYDSL_AOT_CACHE=0), "After" is a cache hit.torch_tensor, constexpr struct, arguments prebuilt (the gfx950 HGEMM's argument shape)torch_tensorCompiled kernels are unchanged: the replays below leave the same FlyDSL artifacts, byte for byte, with
AITER_FLYDSL_AOT_CACHE=0and=1(4874 gfx950 GEMM, 80 gfx942 GEMM, 2747 gfx950 MoE, 100 gfx942 MoE).Size: an exported object averages 29 KiB against 6.5 KiB for FlyDSL's own cache file of the same kernel. For the gfx950 GEMMs that is 146 MiB on disk and about 53 MiB inside a wheel.
Testing
Documentation
docs/flydsl_aot_cache.md(sections 4.2, 5.4, 6, 7) and the module docstring ofaot_launch.py.Dependencies
Breaking Changes
moe_gfx942_gemm,moe_gfx942_sorted_sum,moe_gfx942_absmax,moe_gfx942_quant_per_tensor) have no replay, so they take the JIT path until one is added.aot_factory(..., extra_sources=)is nowsources=, andbind_aothas norebuildargument. A cache whose kernel files import a kernel file it does not declare, or whosesources=names a missing file, fails its prebuild.Constexprlaunch arguments that is launched under one key with two values now raises_BakedArgumentError; the JIT path silently ran the first.kernels_common.run_cachedis removed (its only user wasgemm_a16w16_gfx950). It 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.PR Self-Review
Reviewed revision
cd3c7b0
Behavior and intent
A launch of a FlyDSL kernel that is bound to the AOT cache loads an exported object instead of tracing the kernel. Before this change the cache could hand a later process an object built for other compile-time inputs:
Constexprlaunch arguments, linked bitcode, the ROCm device bitcode,LLVM_GFX1250_ANY_XNACK_CODEGENand the caller's compile hints were not part of an entry's identity. They are now, and the cache falls back to the JIT path where it used to raise for inputs it cannot key. An entry's sources are the files its cache declares, in place of the files a build happened to run.The GEMM and 2-stage MoE launchers that the AOT replays compile for gfx942 and gfx950 now use the cache, so a serving process no longer traces them on first use. Their compiled code is unchanged.
Validation and unverified scope
MI308X (gfx942), FlyDSL 0.5.3, on the pre-merge head plus the commits after the merge of main (the merged head needs Triton 3.9.0, which that machine lacks; there only lint and a static run of the source check ran: 25 caches, none missing a file).
flyc.compilelogged:GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.gemm(5240 entries),GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.moe --row-tokens-only(2877),GPU_ARCHS=gfx942 python -m aiter.aot.flydsl.gemm(80),GPU_ARCHS=gfx942 python -m aiter.aot.flydsl.moe --row-tokens-only(132). The second run builds nothing; no launcher is compiled by the JIT path. The gfx950 MoE replay exits 1 for one row it rejects before compiling (stage-2 output over the 32-bit buffer limit), with the cache on or off.AITER_FLYDSL_AOT_CACHE=0runs of an earlier revision: all identical in the last run (gfx950 GEMM 4874, gfx950 MoE 2747, gfx942 GEMM 80, gfx942 MoE 100); see below for earlier runs.0,verifyand1:op_tests/test_gemm_a8w8.pyloads 80 entries, no miss;op_tests/test_flydsl_moe_a16wfp4.pyloads 11, no miss;op_tests/test_flydsl_moe_gfx942.pyloads none and logs 138 misses (no replay builds those caches). All pass,verifyfinds no stale entry, and no run adds a file to the cache directory.tests/test_flydsl_aot_launch.pyandtests/test_flydsl_aot_cache.pyunder1,verifyand0.AITER_FLYDSL_*variable set, 0 built; with a common one (AITER_FLYDSL_KERNARG_PRELOAD=0), 80 built and 0 on the next run; withFLYDSL_COMPILE_OPT_LEVEL=1, 80 built in another fingerprint directory.verify, on the GPU, with a kernel whose code depends on a value outside its key: mode1returns the prebuilt value,verifyraises (traces to other IR).sources=, the gfx942 GEMM replay fails with_UndeclaredSourceErrorand writes no entry; an edit to an undeclared file builds 0, an edit to a declared file rebuilds its 80, reverting builds 0; a kernel linking real bitcode raises when the bitcode is not declared, and replacing declared bitcode makes a new entry with the new result.Unverified or known:
verifyon gfx950 and gfx1250 runners.flydsl_mxpsh_96x256x128_F8_F8_B16_w0_x4_sk4…(gfx950) compiled alone in a fresh process gives the rarer of two binaries in 6 of 45 runs, also with one worker and with address randomization off. The two differ in register allocation and instruction order. Which LLVM pass does it is not found; their equivalence is read from the disassembly, not run.verifyno longer depends on the bytes.verifyfinds them only when a process loads the entry with another value.os.environ.get(f"X_{stage}")) is not seen. The three variablestensor_shim.pyreads are inputs of every cache. On the merged head the check was run statically (25 caches, none missing a variable).COMPILE_ONLYon for the process; launches of other threads meanwhile do not run (as on the JIT path).PR-specific question
The CI change is one line in
.github/scripts/aiter_test.sh: it exportsAITER_FLYDSL_AOT_CACHE=verifywhen the variable is not already set. It changes no workflow file, nopermissionsblock, no token or secret, and adds no input read from PR text (title, body, labels, branch name). The variable is read byaiter/ops/flydsl/aot_cache.pyinside the test processes the existing jobs already run, and selects a mode of an on-disk cache under the job's own aiter install. Code from a fork PR runs in those test jobs today under the repository's existing policy; this change gives it no new execution path and no access it did not have.Changed op tests
None. (
tests/test_flydsl_aot_launch.pychanges; it is not underop_tests/.)🤖 Generated with Claude Code