Skip to content

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

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 the do-block form of GPUCompiler.compile from JuliaGPU/GPUCompiler.jl#1124, which compiles in a context of its own, runs the block with the IR and disposes of it afterwards. With the upcoming llvmgpu toolchain (JuliaGPU/GPUCompiler.jl#1122), the IR can belong to libLLVMGPU, a newer LLVM than Julia's, and reading meta.entry.name from our own JuliaContext then calls Julia's libLLVM on a libLLVMGPU value and segfaults. The do-block activates the IR's context around the block, so this works with either toolchain.

add_heap!, which runs from finish_ir! after optimization, used convert(LLVMType, ...) to lower KernelState, Csize_t and the heap pointer. Under llvmgpu that errors, because Julia's code generator can only create types in Julia's LLVM. It now takes the state and heap pointer types from the kernel's state parameter (which GPUCompiler adds to every kernel during optimization), and only runs on optimized kernels, since unoptimized IR has no state parameter. The GPUCompiler compat is raised to 2.24.

Validated on an Iris Xe with GPUCompiler #1122 plus the do-block form, Julia 1.12: the full test suite passes with the default toolchain (25313 passed, 37 broken, 0 failed). Without a device, SPIR-V compilation of plain, Ref-allocating and Any-boxing kernels (with both the LLVM and Khronos back-ends, optimized and unoptimized) also works under llvmgpu, where the old code fails or crashes, and with the default toolchain on 1.10 (typed pointers). The full suite under llvmgpu still has wrong integer dims reductions and some driver segfaults, also in kernels that don't allocate, so those come from the toolchain and not from this change.

GPUCompiler 2.24 can run a callback with the IR of a compilation and dispose of it
afterwards. With GPUCompiler's llvmgpu toolchain, the IR can belong to libLLVMGPU, a newer
LLVM than Julia's; the do-block activates the IR's context before the callback reads the
entry point's name, which crashes from a `JuliaContext` of our own.

For the same reason, `add_heap!` (run from `finish_ir!`, after optimization) can no longer
use Julia's code generator to lower `KernelState` and its heap field to LLVM types. Take
them from the kernel's state parameter instead, and only on optimized kernels, as
optimization is what adds that parameter.
@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.86%. Comparing base (592513a) to head (1917eb5).

Files with missing lines Patch % Lines
src/compiler/compilation.jl 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #780      +/-   ##
==========================================
+ Coverage   86.71%   86.86%   +0.14%     
==========================================
  Files          55       55              
  Lines        5143     5093      -50     
==========================================
- Hits         4460     4424      -36     
+ Misses        683      669      -14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt
maleadt merged commit 3c96106 into main Nov 25, 2026
5 checks passed
@maleadt
maleadt deleted the tb/compile-do-block branch November 25, 2026 17:47
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