From 77f031f418364132c29c4cb20a05d0e14981db65 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Wed, 25 Nov 2026 11:49:40 +0100 Subject: [PATCH] Compile with GPUCompiler's do-block `compile` `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. --- Project.toml | 2 +- src/compiler/compilation.jl | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Project.toml b/Project.toml index ea9dcc65..f609e60b 100644 --- a/Project.toml +++ b/Project.toml @@ -34,7 +34,7 @@ SPIRVIntrinsics = {path = "lib/intrinsics"} [compat] Adapt = "4" GPUArrays = "12.1" -GPUCompiler = "2.23.2" +GPUCompiler = "2.24" GPUToolbox = "3.6" KernelAbstractions = "0.10" KernelInterface = "0.4" diff --git a/src/compiler/compilation.jl b/src/compiler/compilation.jl index 8b208ad3..8f5f50aa 100644 --- a/src/compiler/compilation.jl +++ b/src/compiler/compilation.jl @@ -247,15 +247,11 @@ const compilations = Threads.Atomic{Int}(0) function compile_to_obj(@nospecialize(job::CompilerJob)) Threads.atomic_add!(compilations, 1) - JuliaContext() do ctx - obj, meta = GPUCompiler.compile(:obj, job) - - # we own the IR: inspect it, then dispose of it - @dispose ir=meta.ir begin - entry = meta.entry.name - device_rng = haskey(meta.entry.function_attributes, "julia.opencl.rng") - (; obj, entry, device_rng, meta.exception_sites) - end + # the IR is only valid within the block: return plain data + GPUCompiler.compile(:obj, job) do obj, meta + entry = meta.entry.name + device_rng = haskey(meta.entry.function_attributes, "julia.opencl.rng") + (; obj, entry, device_rng, meta.exception_sites) end end