Skip to content

Define device-only functions as overlays, so sysimages load - #598

Merged
maleadt merged 2 commits into
mainfrom
tb/host-leaks
Oct 28, 2026
Merged

maleadt merged 2 commits into
mainfrom
tb/host-leaks

Conversation

@maleadt

@maleadt maleadt commented Oct 28, 2026

Copy link
Copy Markdown
Member

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 with RTLD_NOW, it fails to load. This is the OpenCL.jl side of JuliaGPU/KernelAbstractions.jl#930.

Two commits:

  • SPIRVIntrinsics implements @device_override and @device_function with GPUToolbox 3.5's Overlays.device_override / Overlays.device_function. The old @device_function defined 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's method_table, so OpenCL.jl, oneAPI.jl and KernelAbstractions keep defining into their own tables. Drops ExprTools; version bumped to 1.6.0.
  • OpenCL.jl marks what GPUToolbox.Overlays.host_leaks(OpenCL) reported as device functions: exception_info, signal_exception, kernel_state, random_keys/random_counters, global_random_keys/global_random_counters and initialize_rng_state. finish_module! looks initialize_rng_state up through the job's method tables and calls it as a void function, instead of inferring its return type with the native interpreter. A new host leaks test checks that host_leaks is 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.

maleadt and others added 2 commits October 28, 2026 08:37
`@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>
@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.57%. Comparing base (fe5410b) to head (176227f).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt
maleadt merged commit 920fb3e into main Oct 28, 2026
17 of 18 checks passed
@maleadt
maleadt deleted the tb/host-leaks branch October 28, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant