Repository navigation
Define device-only functions as overlays, so sysimages load - #598
Merged
Merged
Conversation
`@device_function` defined its body as a consistent overlay, which lets inference constant-fold calls into the host method's error. Implement `@device_override` and `@device_function` with GPUToolbox's shared definitions instead, where the body of a device function is a plain overlay. The table still resolves in the caller's module, so back ends that use these macros keep defining methods in their own table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The exception mailbox, `kernel_state` and the RNG state accessors were ordinary methods whose bodies declare device intrinsics, like `julia.gpu.state_getter` and `julia.opencl.random_keys`. Sysimage builds compile such methods for the host, and a sysimage that refers to undefined symbols fails to load. Make them `@device_function`s, look up `initialize_rng_state` through the job's method tables and call it as a void function rather than inferring its return type natively, and test that no method reaches device code on the host with GPUToolbox's `host_leaks`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 28, 2026
Open
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #598 +/- ##
==========================================
- Coverage 90.58% 90.57% -0.01%
==========================================
Files 18 18
Lines 1741 1740 -1
==========================================
- Hits 1577 1576 -1
Misses 164 164 ☔ 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.
Device-only code in the global method table gets compiled for the host by sysimage builds: Julia 1.12+ compiles every method with a compileable signature, and 1.11 keeps native code instances such as those left by
Core.Compiler.return_type(initialize_rng_state). The image then refers to device symbols (julia.gpu.state_getter,julia.opencl.random_keys, ...), and since sysimages are loaded withRTLD_NOW, it fails to load. This is the OpenCL.jl side of JuliaGPU/KernelAbstractions.jl#930.Two commits:
@device_overrideand@device_functionwith GPUToolbox 3.5'sOverlays.device_override/Overlays.device_function. The old@device_functiondefined its body as a consistent overlay, which lets inference constant-fold calls into the throwing host method; the body is now a plain overlay. The macros still use the caller'smethod_table, so OpenCL.jl, oneAPI.jl and KernelAbstractions keep defining into their own tables. Drops ExprTools; version bumped to 1.6.0.GPUToolbox.Overlays.host_leaks(OpenCL)reported as device functions:exception_info,signal_exception,kernel_state,random_keys/random_counters,global_random_keys/global_random_countersandinitialize_rng_state.finish_module!looksinitialize_rng_stateup through the job's method tables and calls it as a void function, instead of inferring its return type with the native interpreter. A newhost leakstest checks thathost_leaksis empty for both OpenCL and SPIRVIntrinsics.oneAPI.jl and KernelAbstractions pick up the macro change through SPIRVIntrinsics 1.6, so that needs to be tagged after this merges.
Tested locally with PoCL on Julia 1.13.