Skip to content

Compile with GPUCompiler's do-block compile - #1250

Merged
maleadt merged 1 commit into
mainfrom
tb/compile-do-block
Nov 25, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/compile-do-block

Conversation

@maleadt

@maleadt maleadt commented Nov 25, 2026

Copy link
Copy Markdown
Member

hipcompile now uses GPUCompiler.compile(f, :obj, job) (JuliaGPU/GPUCompiler.jl#1124) instead of creating a JuliaContext, 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.name outside its context calls Julia's libLLVM on libLLVMGPU's values. Under that toolchain the current code segfaults in LLVMGetValueName during 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 and finish_module! run on Julia's LLVM before the IR moves to libLLVMGPU, and finish_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 in core/codegen's atomic metadata tests: when libLLVMGPU reads the bitcode, LLVM upgrades the kernel's amdgpu-unsafe-fp-atomics attribute into ignore-denormal metadata on every FP atomicrmw, including Float64 fadd and Float32 fsub. That behavior predates this change and is not about IR lifetime. One gpuarrays/base worker crash in that run did not reproduce: the test passed alone (171/171), and the whole gpuarrays group passed on a rerun (10320/10320).

`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.
@maleadt
maleadt merged commit 3c212d0 into main Nov 25, 2026
12 checks passed
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