Repository navigation
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1114 +/- ##
==========================================
- Coverage 92.23% 89.33% -2.90%
==========================================
Files 32 33 +1
Lines 8292 8513 +221
==========================================
- Hits 7648 7605 -43
- Misses 644 908 +264 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
maleadt
force-pushed
the
tb/late-handoff
branch
from
November 18, 2026 23:59
ecb7854 to
5c6d779
Compare
maleadt
force-pushed
the
tb/late-handoff
branch
3 times, most recently
from
November 19, 2026 07:38
9458498 to
3b021c6
Compare
Everything that happens to the optimized IR, from `finish_ir!` to collecting relocations, moves into its own function, so that it can run with another LLVM library than optimization did.
GPUCompiler optimizes with Julia's LLVM, which is old and fixed per Julia release. With `handoff=:late` (or the `handoff` preference), the optimized module is transferred as bitcode to a standalone LLVM with GPU back-ends, libLLVMGPU (LLVM 23, registered with LLVM.jl as `:gpu`, or provided by LLVMGPU_jll), optimized again with its standard pipeline, and finalized, validated and compiled there. Code generation then goes through the C API of that library instead of the per-target back-end JLLs, so optimizer and code generator are the same, current LLVM. The IR that `compile` returns belongs to that library, in a context owned by the enclosing `JuliaContext` block. This is supported for PTX, GCN (with the external back-end, whose datalayout the library shares) and SPIR-V (both back-ends; not optimized again, as the standard pipeline cannot honor its restrictions). Metal and the native target keep using Julia's LLVM, as do nested jobs, which are linked into their parent before the hand-off. What the back-end JLLs did beyond `llc` is reproduced: processors, PTX versions, AMDGPU features and SPIR-V extensions are validated up front, `-nvptx-fma-level=1`, the AMDGPU `i128:64` ABI for Julia < 1.12, per-target SPIR-V extensions, verification before code generation, function CPU and feature attributes, and serialized code generation. Not reproduced: recovery from fatal LLVM errors (which now end the process), catching C++ exceptions, the Windows locale workaround for SPIR-V, and the target library info. Results of handed-off jobs are not persisted in package images, which don't track the library.
A job per Julia version runs the test suite with the `handoff` preference set, so that PTX, GCN and SPIR-V go through libLLVMGPU from LLVMGPU_jll.
maleadt
force-pushed
the
tb/late-handoff
branch
from
November 19, 2026 19:22
3b021c6 to
5405b6c
Compare
Member
Author
|
Superseded by #1122, which combines JuliaIR's passes and the hand-off to libLLVMGPU behind a single |
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.
GPUCompiler optimizes code with Julia's LLVM, which is old and fixed for each Julia release. This PR adds an opt-in mode,
CompilerConfig(...; handoff=:late)or thehandoff = "late"preference, that works as follows:finish_ir!, validation, relocation collection,prepare_execution!and code generation with that library too, throughLLVMTargetMachineEmitToMemoryBufferinstead of the per-target back-end JLLs.Optimizer and code generator are then the same, current LLVM. This is "G1" of the plan to move the middle-end to a newer LLVM. It is experimental, and the default path is unchanged.
The library is whichever one is registered with LLVM.jl as
:gpu, or else LLVMGPU_jll's if that package is loaded. The IR thatcompilereturns belongs to that library, in a context owned by the enclosingJuliaContextblock. Callers have to work with it insidecontext!(context(ir)): LLVM.jl routes calls on values (unlike modules) to the current library, so for examplemeta.entry.nameoutside that block calls Julia's LLVM on a libLLVMGPU value. Downstream packages need small changes for that. Only CUDA.jl'semit_ptxand OpenCL.jl'scompile_to_objneeded one for the tests below.Targets
default<O2>cannot honor SPIR-V'sswitch_to_lookup=false.What the back-end JLLs did beyond
llc-nvptx-fma-level=1.i128:64ABI for Julia < 1.12.--spirv-extreplaces the set, while-NAMEdisables an extension for good, so only+NAMElists are passed, under a lock.target-cpu/target-featuresare set on functions.Results of handed-off jobs aren't persisted in package images, which don't track the library.
Tests
test/handoff.jlcovers:emit_asmaftercompile(:llvm);denormal-fp-math-f32when reading bitcode;Validation (pegasus, Linux x86_64, with a local build of the library)
GPUCompiler test suite:
julia_passes = "ports"): everything passes on 1.12 except Take Julia's LLVM passes from JuliaIR.jl, as an opt-in #1026'sjulia_passestest, which inspects compiled IR outside its context.CUDA.jl on an RTX 5080: passes with the one-line
emit_ptxchange. The test covers vector add, saxpy, an atomic reduction, device exceptions, broadcast, mapreduce and accumulate.OpenCL.jl with PoCL: the same kernels and atomics pass.
Compile time (median of 15, warm):
code_ptx(vadd, atomic reduce, math, shared memory)Registering the library takes 30–130 ms, and initializing it 8 ms.
Stacked on #1113.