Conversation
A runtime-function CodeInstance revived from a package image can carry unoptimized inferred code; codegen then emits a runtime library full of dynamic dispatch, which poisons every kernel that links it. AMDGPU.jl's precompile workload triggers exactly this for the target it compiles (gfx1030), breaking all bounds-checked kernels for RDNA2 users on 1.13. Give runtime-function jobs their own cache owner that also records whether output was being generated, so runtime CodeInstances never cross the precompilation boundary in either direction. Rebuilding the handful of runtime functions once per session costs microseconds; kernel-level CodeInstance reuse is unaffected. Also validate runtime-function bitcode for dynamic-dispatch fallbacks: poisoned cached entries are discarded and recompiled, and fresh poisoned emissions are never cached. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FJL9JQhcpXUVWkhuuiA7ad
Member
|
That seems wrong? If the Runtime can be dynamic, why couldn't it be at normal runtime? This seems like the classic order constraint on generated functions? |
maleadt
requested changes
Sep 16, 2026
maleadt
left a comment
Member
There was a problem hiding this comment.
This is a Julia "property", where generators run in their definition world, so AMDGPU.jl needs to define kernel_state after the KernelState struct is defined just like other back-ends do.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #933 +/- ##
==========================================
- Coverage 85.78% 85.44% -0.35%
==========================================
Files 29 29
Lines 5613 5633 +20
==========================================
- Hits 4815 4813 -2
- Misses 798 820 +22 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the miscompilation reported in JuliaGPU/AcceleratedKernels.jl#123 (and the class behind it): on Julia 1.13, every bounds-checked kernel fails with
InvalidIRError: unsupported dynamic function invocation (call to kernel_state())— but only for users whose GPU matches the target that the back-end's precompile workload compiled (for AMDGPU.jl 2.8.0:gfx1030+ wavefront 32, i.e. every real RDNA2 user; other targets, and hence CI, are unaffected, which is what made this hard to see).Root cause. During a back-end package's own precompilation, its workload compiles a kernel; that builds the GPU runtime library, and the resulting owner-tagged
CodeInstances are serialized into the package image. Those CodeInstances carry inferred code where calls that inference normally resolves remain dynamic (getpropertyofkernel_state()::Any— decompressed from AMDGPU's image, the stored source forsignal_exceptionhasBase.getpropertyas a plain:call). On Julia 1.13,supports_relocatable_ir()is unconditionally true, so both the CodeInstances and the per-function runtime bitcode built from them persist across the boundary. At runtime, a job whose cache-owner token is egal to the workload's revives them: the linked runtime library containsijl_apply_generic/jl_f_throw_methoderror, and IR validation rejects the kernel. Fresh sessions without a matching image entry compile the identical code cleanly — inference is fine; only artifacts revived across the precompilation boundary are not.Fix.
runtime_confignow derives a dedicated cache owner,RuntimeCacheToken(parent, generating), which additionally records whether output was being generated. Runtime-function CodeInstances therefore never cross the precompilation boundary in either direction. Only the handful of runtime methods are affected — they re-infer once per session in microseconds — while kernel-level CodeInstance reuse (the TTFK win from package images) is untouched.emit_function!validates runtime modules for dynamic-dispatch fallbacks (ijl_apply_generic,jl_invoke,jl_f_*): poisoned cached bitcode is discarded and recompiled instead of linked, and poisoned fresh emissions are never cached. This also heals existing poisoned images without waiting for them to be rebuilt.Verification. Backported onto v2.6.0 and tested against registry AMDGPU.jl 2.8.0 on Julia 1.13.0: the previously deterministic
gfx1030failure compiles cleanly,gfx942stays green, and the built runtime library contains zero dynamic calls. Native test suite passes with the new tests (runtime owner partition + fallback detection).Root cause found (JuliaGPU/AMDGPU.jl#1075): generators run in their defining world, and AMDGPU's
@generated kernel_state()referencesAMDGPU.KernelState, defined after the device include. During AMDGPU's own precompilation the intra-package world ordering is live, the generator throwsUndefVarError: KernelState not defined in AMDGPU, andCompiler.get_stagedsilently swallows it ("user code might throw errors – ignore them") — inference then types the callAnyand the poisoned CodeInstance is cached. After image serialization the method and binding worlds collapse to the image-load world, which is why every other context expands the generator fine and the poison is only ever created at that one site.AMDGPU.jl#1075 fixes the ordering and adds a workload assertion; this PR remains the structural protection — any backend can hit the same silent
get_stagedfailure (an upstream Julia issue worth filing: real generator errors deserve a debug-visible path), and runtime-function CodeInstances should not cross the precompilation boundary regardless.🤖 Generated with Claude Code
https://claude.ai/code/session_01FJL9JQhcpXUVWkhuuiA7ad