Repository navigation
Define device-only functions as overlays, so sysimages load - #1205
Merged
Merged
Conversation
… host images Sysimage builds compile methods from the global method table for the host (every compileable signature on Julia 1.12+), so device-only code there ends up in the image as references to `julia.gpu.state_getter` or AMDGPU LLVM intrinsics, and the image then fails to load. Implement `@device_override` and `@device_function` with GPUToolbox's `Overlays`, dropping the ExprTools dependency, and mark the runtime functions that read the kernel state (`kernel_state`, the hostcall contexts, `signal_exception`, `malloc` and `free`) and ROCKernels' lane helpers as device functions. Their host methods now only throw. `malloc` and `free` lose their return type annotations, which Julia 1.10's `@overlay` can't handle. A new test checks with `GPUToolbox.Overlays.host_leaks` that no host-compiled method reaches device code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Benchmark resultsCompared with 6ecd201bb, the merge base.
All benchmarks
|
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 (e.g. those left by
Core.Compiler.return_type(initialize_rng_state)infinish_module!). The image then refers to device symbols likejulia.gpu.state_getter, and since sysimages are loaded withRTLD_NOW, it fails to load. Same fix as JuliaGPU/KernelAbstractions.jl#930 and JuliaGPU/OpenCL.jl#598, using the shared definitions from GPUToolbox 3.5.@device_overrideand@device_functionare one-liners aroundGPUToolbox.Overlays.device_override/device_function; ExprTools is no longer needed.GPUToolbox.Overlays.host_leaks(AMDGPU)reported is now a device function:output_context,printf_output_context,malloc_hc,free_hc,signal_exception,malloc,free(julia.gpu.state_getter), and ROCKernels'hardware_laneandlane_id(llvm.amdgcn.mbcnt.lo). Alsokernel_state, which compile-all skips as a generated function, but which is the source of these. The KernelInterface functions built on the lane helpers already were@device_overrides.mallocandfreelose their return type annotations, which Julia 1.10's@overlaycan't parse;mallocasserts its result type instead.core/host_leakstest checks thathost_leaksis empty for AMDGPU and its extensions.Tested locally on a gfx1036 with Julia 1.13 (core, device, KernelAbstractions and KernelInterface tests) and 1.10.