Repository navigation
Compile with GPUCompiler's do-block compile - #1250
Merged
Merged
Conversation
`hipcompile` now uses `GPUCompiler.compile(f, :obj, job)`, which compiles in an LLVM context of its own, runs the block with the IR's context active and frees the IR afterwards, instead of creating a `JuliaContext` and disposing of the IR itself. With GPUCompiler's llvmgpu toolchain, the IR can belong to libLLVMGPU, a newer LLVM than Julia's. Reading it (e.g. the entry point's name) outside of that context calls Julia's libLLVM on libLLVMGPU's values, which segfaulted while precompiling AMDGPU. The do-block form works under both toolchains. This requires GPUCompiler 2.24.
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.
hipcompilenow usesGPUCompiler.compile(f, :obj, job)(JuliaGPU/GPUCompiler.jl#1124) instead of creating aJuliaContext, compiling and disposing of the IR itself. Everything that reads the IR (externally-initialized globals, global hostcalls, the entry point's name) happens in the block, which returns only the object code and Julia data. This requires GPUCompiler 2.24, so the compat entry is bumped.With GPUCompiler's upcoming llvmgpu toolchain (JuliaGPU/GPUCompiler.jl#1122), the IR can belong to libLLVMGPU, a newer LLVM than Julia's, and reading
meta.entry.nameoutside its context calls Julia's libLLVM on libLLVMGPU's values. Under that toolchain the current code segfaults inLLVMGetValueNameduring AMDGPU's precompile workload. The do-block form activates the IR's context around the block, so the same code works under both toolchains. None of the compiler hooks needed changes: device-library linking andfinish_module!run on Julia's LLVM before the IR moves to libLLVMGPU, andfinish_ir!only builds metadata and gets its target machine from GPUCompiler.Validated on Julia 1.12 with a gfx1036 (
--jobs=2). With the default toolchain, the full suite passes (32327 passed, 14 broken; hostcalls 41/41). With llvmgpu, 32153 passed. The 3 failures are incore/codegen's atomic metadata tests: when libLLVMGPU reads the bitcode, LLVM upgrades the kernel'samdgpu-unsafe-fp-atomicsattribute into ignore-denormal metadata on every FPatomicrmw, including Float64faddand Float32fsub. That behavior predates this change and is not about IR lifetime. Onegpuarrays/baseworker crash in that run did not reproduce: the test passed alone (171/171), and the whole gpuarrays group passed on a rerun (10320/10320).