Repository navigation
Fix leakage of device-only methods into the global method table on Julia 1.13 - #3248
Merged
Merged
Conversation
`@device_functions` macro-expanded its block first and then wrapped every top-level definition in `@device_function`. Julia 1.13 (julia#62236) now expands `@doc` into `if true; var"#val" = (f() = ...); end`, which the rewrite did not descend into, so every documented device function (`sync_threads`, `threadfence`, `clock`, ...) silently ended up in the global method table with its GPU-only body. Ahead-of-time compilation then fails with `LLVM ERROR: Cannot select: intrinsic %llvm.nvvm.membar.gl` (JuliaGPU/GPUCompiler.jl#611). An earlier workaround (#3020) matched the previous 1.13 shape of the expansion and broke again when it changed. Rewrite definitions before expansion instead: docstring macrocalls are entered directly, other macros are expanded per statement, and as a fallback the walker also descends into `if` blocks and temporary assignments. `@device_function` marks its CPU stub with `@__doc__` so docstrings still attach to the function binding. Add a source-driven test that every definition inside `@device_function(s)` has an erroring CPU stub and no global method at the definition's own location, which is what an escaped definition looks like.
`exit`, `nanosleep`, the RNG state accessors, the cooperative-groups grid barriers and `map_shared_rank` contain inline PTX or NVPTX intrinsics but were plain global methods. Julia's compile-all pass (`--output-o`: PackageCompiler.jl, juliac) compiles every method with a concrete signature whether or not it is called, so e.g. `exit()` aborted sysimage builds with `invalid instruction mnemonic 'exit'` (JuliaGPU/GPUCompiler.jl#611).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3248 +/- ##
==========================================
- Coverage 92.66% 92.66% -0.01%
==========================================
Files 184 184
Lines 16176 16176
==========================================
- Hits 14990 14989 -1
- Misses 1186 1187 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
CUDA.jl BenchmarksDetails
This comment was automatically generated by workflow using github-action-benchmark. |
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 Julia 1.13 recurrence of JuliaGPU/GPUCompiler.jl#611: ahead-of-time compilation of anything loading CUDA.jl (PackageCompiler.jl, juliac) aborts with
LLVM ERROR: Cannot select: intrinsic %llvm.nvvm.membar.gl, orinvalid instruction mnemonic 'exit'followed by a segfault. Two culprits:@doctoif true; var"#val" = (f() = …); end.@device_functionsmacro-expanded its block first and then wrapped top-level definitions in@device_function, without descending intoif, so every documented device function (sync_threads,threadfence*,clock,sync_warp, … 12 in total) silently kept its realllvmcallbody in the global method table. Support Julia 1.13 #3020 had matched the previous 1.13 shape of the expansion and broke again when it changed. On 1.12 all 70 device functions are correctly stubbed; on 1.13-rc3, 12 are not.exit,nanosleep,global_random_keys/global_random_counters,CG.barrier_arrive/barrier_waitandmap_shared_rankwere never marked as device functions at all.exit()(@asmcall("exit;")) is enough to abort a sysimage build even with (1) fixed.