Skip to content

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

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

compile_to_obj now uses GPUCompiler.compile(f, :obj, job) (JuliaGPU/GPUCompiler.jl#1124), which creates the context, calls f with the SPIR-V and its metadata, and frees the IR afterwards. The entry name and the julia.opencl.rng attribute are read inside the block; only plain data leaves it.

With GPUCompiler's upcoming llvmgpu toolchain (JuliaGPU/GPUCompiler.jl#1122), the IR can belong to libLLVMGPU, a newer LLVM than Julia's. The current code then reads meta.entry.name through Julia's libLLVM and segfaults; the do-block form activates the IR's own context around f. The GPUCompiler hooks (finish_module!, finish_linked_module!) run while the IR is still in Julia's LLVM, so they are unchanged. GPUCompiler compat is raised to 2.24.

Validated on PoCL with Julia 1.12 and GPUCompiler 2.24.0 + #1122: the full suite passes with the default toolchain and with toolchain = "llvmgpu" (53604 passed, 9 broken, 0 failed each). Under llvmgpu, a kernel launch segfaults in LLVMGetValueName with the old code and runs correctly with the new one.

`compile_to_obj` now uses `GPUCompiler.compile(f, :obj, job)`, which
creates the context, calls `f` with the code and metadata, and frees the
IR afterwards. The entry name and RNG attribute are read inside the
block.

With GPUCompiler's llvmgpu toolchain, the IR can belong to libLLVMGPU, a
newer LLVM than Julia's. Reading the entry's name from inside our own
`JuliaContext` then called into Julia's libLLVM and segfaulted; the
do-block form activates the IR's own context around `f`.

Requires GPUCompiler 2.24.
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