Repository navigation
Conversation
maleadt
force-pushed
the
tb/juliair-ports
branch
from
October 19, 2026 14:51
f834190 to
4136fdd
Compare
maleadt
force-pushed
the
tb/juliair-ports
branch
from
October 19, 2026 17:33
4136fdd to
74311bb
Compare
maleadt
force-pushed
the
tb/juliair-ports
branch
2 times, most recently
from
October 21, 2026 09:53
ca56bc2 to
b004fbc
Compare
maleadt
force-pushed
the
tb/juliair-ports
branch
2 times, most recently
from
October 28, 2026 19:46
38b51b7 to
36731e6
Compare
maleadt
force-pushed
the
tb/juliair-ports
branch
5 times, most recently
from
November 18, 2026 22:33
4f34206 to
2a60c9e
Compare
maleadt
force-pushed
the
tb/juliair-ports
branch
from
November 19, 2026 00:36
2a60c9e to
7ac1f37
Compare
maleadt
marked this pull request as ready for review
November 19, 2026 05:46
maleadt
force-pushed
the
tb/juliair-ports
branch
from
November 19, 2026 07:35
7ac1f37 to
c9f1827
Compare
This was referenced Nov 19, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1026 +/- ##
==========================================
+ Coverage 93.02% 93.06% +0.03%
==========================================
Files 32 33 +1
Lines 8302 8332 +30
==========================================
+ Hits 7723 7754 +31
+ Misses 579 578 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
maleadt
force-pushed
the
tb/juliair-ports
branch
from
November 20, 2026 18:47
c9f1827 to
952facc
Compare
`CompilerConfig` gains `julia_passes`: `:cpp` for the passes of Julia's code generator (wrapped by `LLVM.Interop`), `:ports` for their ports in JuliaIR.jl. The default comes from the `julia_passes` preference. Being a config field, it is part of the identity of every cached LLVM artifact, but not of the inference caches. JuliaIR.jl is a weak dependency: its extension tells GPUCompiler how to register the ports and which of Julia's passes they replace. Loading it alone changes nothing; selecting `:ports` without it is an error before compilation starts. Until JuliaIR.jl is registered, the test environment takes it from `[sources]`.
`optimize!` now asks `julia_pass` for each of Julia's passes, which returns the C++ pass or, with `julia_passes=:ports`, the name of the port, registered on the pass builder. Passes JuliaIR.jl does not port yet (FinalLowerGC, JuliaLICM, LowerPTLS, RemoveJuliaAddrspaces) run as the C++ pass in both modes; the extension lists them explicitly.
…sses JuliaIR.jl's passes only support opaque pointers, while Julia 1.10 and 1.11 use typed pointers by default. With `julia_passes=:ports`, the reflection entry points create opaque contexts, and `JuliaContext()` does so too when the preference selects the ports, so that the many callers that create their own context follow the preference. Compiling a `:ports` job in a typed context is an error. Without the preference, `JuliaContext()` keeps LLVM's default. The precompilation workload pins the C++ passes, as JuliaIR.jl is not loaded while GPUCompiler precompiles.
On Julia 1.10 and 1.11, contexts may use typed or opaque pointers, and compiling with the ports of Julia's passes makes opaque ones common there. The bitcode of runtime functions is cached per configuration, so a function compiled in one kind of context was read back in the other, which fails for opaque bitcode in a typed context. Recompile it instead.
Running the suite with the `julia_passes` preference set to "ports" needs JuliaIR.jl loaded, also in the processes some tests spawn. The test of Metal's lowering of atomics on thread-private objects pins the C++ passes: JuliaIR.jl's AllocOpt uses the escape analysis of Julia 1.13 on every version, which removes the object, so the IR it lowers would not occur.
Covers the configuration, the providers and the passes left to C++, the requirements (JuliaIR.jl loaded, opaque pointers), and, through JuliaIR.jl's ledger, that the ports run. A differential compiles a corpus of kernels (allocations, `@simd` loops, Float16, exceptions, Int128 and aggregate arguments, closures) for every target with both providers in opaque-pointer contexts and requires identical IR, modulo name counters. On Julia 1.10 and 1.11, a second set judges the switch from typed to opaque pointers that the ports need, with the C++ passes: PTX code is identical, other targets compile or fail alike.
`classify_arguments` treats `Type{T}` arguments as ghosts, which matches
codegen only when the signature keys them as `Core.TypeEgal`, as
GPUCompiler's `methodinstance` does. A job built from another
MethodInstance could get a boxed `Type{T}` parameter, misaligning every
later argument without an error. Before optimization the number of
parameters is known, so check it.
With the preference selecting the ports, precompilation workloads of packages that don't depend on JuliaIR.jl (GPUCompiler's own, or a back-end's) would fail, as they compile in a process without it. There, configurations now default to the C++ passes. That is part of the configuration, so whatever such a workload caches is not used for configurations selecting the ports.
Explains the `julia_passes` setting and its preference, what the ports require, and how to run the test suite with them.
With `--opaque-pointers` on Julia 1.10 and 1.11, Julia's code generator does not support typed-pointer contexts, so the code generated in one differs and the comparison of typed with opaque pointers fails. Julia then never generates typed IR, so there is nothing to compare.
Packages building on GPUCompiler do not load JuliaIR.jl, so with the julia_passes preference set to "ports", their compilations failed for want of the ports unless the user loaded it. When the preference selects the ports, GPUCompiler now loads JuliaIR.jl at initialization if the environment provides it (not while precompiling), and the extension registers the ports once GPUCompiler has loaded. This also makes the preference usable in a package's test suite, by adding JuliaIR.jl to its test environment.
JuliaIR.jl now ports RemoveJuliaAddrspaces, FinalLowerGC, LowerPTLS and JuliaLICM too, so with julia_passes=:ports every one of Julia's passes in the pipeline is a port and none falls back to the C++ pass. The ledger test now also expects JuliaLICM and RemoveJuliaAddrspaces, and FinalLowerGC and LowerPTLS for a target that uses Julia's runtime. [only cuda oneapi amdgpu metal opencl]
Both test/native/precompile.jl and the test of precompilation without JuliaIR.jl created a package named NativeCompiler. When one ran after the other on the same worker, the cache of the second test's package depended on a NativeCompiler other than the loaded one, so it was loaded from source in the test process: the workload then reported the ports, and native/precompile found results and inferred code that should only exist in the precompilation process.
On Julia 1.10 and 1.11 on AArch64, where Julia aligns Int128 to 16 bytes, the PTX of the aggregate kernel taking its argument by reference differs between typed and opaque pointers: with opaque pointers the argument's padding is copied too. Only the padding bytes of the stored value differ, so there only require the code to be generated.
Julia's LLVM is built without the AMDGPU target on macOS, so GCNCompilerTarget has no datalayout there and Julia emits allocas in addrspace(0). Since LLVM 23 the verifier rejects those for an amdgcn triple, aborting the julia_passes test on macOS with Julia nightly. The GCN test suite itself is skipped on macOS already.
On Julia master (1.15), `Base.@cancel_check` emits `julia.cancellation_point()` calls, which Julia lowers with CancellationLowering right before LateLowerGCFrame (JuliaLang/julia#62604). GPUCompiler never ran that pass, so native jobs using Julia's runtime kept the calls unlowered. Run it there, as the port with `julia_passes=:ports`, or else by its pipeline name since LLVM.jl has no constructor for it. Other targets have no task to deliver a cancellation to. Julia 1.14 reverted the cancellation work before its first beta (JuliaLang/julia#64651), so it has neither the intrinsic nor the pass.
Resolve JuliaIR through General in the test and downstream environments. Keep both provider variants and their ledger checks in CI. The tests run with the flags and the coverage reporting of julia-runtest, which the separate set-up step replaces. [only cuda, amdgpu, metal, oneapi, opencl]
With JuliaIR.jl as a weak dependency, precompilation workloads ran without it and compiled with the C++ passes, so a session that selects the ports recompiled what packages had precompiled (Metal.jl's precompilation test counted the recompilations), and loading it at initialization when the preference selected the ports deadlocked once a package image depended on it. As a regular dependency the ports are always available: the `julia_passes` preference only selects them, also in workloads, so that what they cache matches the configurations of a session with the same preference.
Julia 1.10 to 1.13 zero a GC frame with a volatile memset, as their FinalLowerGC passes the frame's TBAA tag as the volatility flag (fixed in JuliaLang/julia#62061). The ports zero it as Julia 1.14 does, so dead-store elimination later drops the zeroing of the header slots, which pushing the frame overwrites. That showed in the differential test on Julia 1.10 with `--check-bounds=yes`, where the BoundsError constructor of a `@simd` loop's range keeps a frame. Compare such IR after making the C++ memset non-volatile and running dead-store elimination and InstCombine on both sides.
The logger truncates the two modules, which left failures on CI hosts that can't be reproduced locally without the difference.
FinalLowerGC builds the load of the previous frame and the address of the frame's slot for it as two arguments of one C++ call, so their order depends on the compiler that built Julia: Julia's aarch64 Linux builds load first, the ports and the x86_64 builds compute the address first. Before comparing again, put the address first wherever such an independent pair feeds the store that links the frame.
The IR can live in another LLVM library than Julia's (with the late hand-off to libLLVMGPU), and LLVM.jl sends calls on its values to the library of the active context.
maleadt
force-pushed
the
tb/juliair-ports
branch
from
November 20, 2026 20:37
952facc to
62a2b73
Compare
The test picks opaque-pointer IR based on `typed_ptrs`, which describes a `JuliaContext`, but parsed it in a plain `Context`. With the ports on Julia 1.11 the two differ: Julia contexts use opaque pointers, plain ones typed pointers.
maleadt
force-pushed
the
tb/juliair-ports
branch
from
November 20, 2026 21:08
62a2b73 to
bbcfe55
Compare
JuliaIR.jl 0.1.0 predates changes to Julia's passes that its ports have to follow: LowerPTLS reads the GC stack from the wrong thread register on AArch64 macOS since JuliaLang/julia#63921, and RemoveJuliaAddrspaces moves function bodies since JuliaLang/julia#65016. 0.1.1 follows both; 0.1.2 fixes RemoveJuliaAddrspaces on modules with inline assembly (the Julia master job's failure), 0.1.3 moves function bodies the way Julia 1.15 does, and 0.1.4 follows the C++ more closely in AllocOpt's preserve regions and in debug locations after debug intrinsics.
maleadt
force-pushed
the
tb/juliair-ports
branch
from
November 21, 2026 09:16
bbcfe55 to
864f604
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's optimization pipeline runs fifteen of the LLVM passes of Julia's code
generator (AllocOpt, LateLowerGCFrame, PropagateJuliaAddrspaces, ...), which only exist
inside Julia's own libLLVM. This lets a compilation take them from
JuliaIR.jl instead, which ports them to Julia, as
the first step towards running GPUCompiler's middle end on a newer LLVM than Julia's.
Nothing changes by default.
CompilerConfiggets ajulia_passesfield,:cpp(Julia's passes, as today) or:ports.Its default comes from the
julia_passespreference. It is part of the configuration, socached artifacts are keyed on it; inference caches are not.
provider, also in precompilation workloads, so what a package precompiles is used by a
session with the same preference.
optim.jlgets each Julia pass fromjulia_pass(job, :Name).opaque-pointer context,
JuliaContext()creates one when the preference selects theports, and compiling a
:portsjob in a typed context is an error.recompiled when read in the other kind of context (on 1.10 and 1.11, reading opaque
bitcode in a typed context failed; a pre-existing issue that mixing the modes exposes).
classify_argumentschecks that the number of parameters matches the signature, which aType{T}argument not keyed asCore.TypeEgalwould silently break.lowering, as Julia does (cancellation: Wire up compute cancellation JuliaLang/julia#62604). Julia 1.14 reverted the cancellation
work before its first beta ([1.14] Revert task cancellation (moving to 1.15) JuliaLang/julia#64651), so it is not run there.
Load time and time to first
code_native(native target, a small kernel), Julia 1.13.4 onx86_64 Linux, median of 10 fresh processes on a shared machine:
using GPUCompilercode_nativecpp, JuliaIR.jl as extensioncpp, JuliaIR.jl as dependencyports, JuliaIR.jl as extensionports, JuliaIR.jl as dependencyWith the C++ passes, both are within noise. With the ports, GPUCompiler's own workload
now compiles through them, so their code is in the package image: loading takes 0.1 s
longer, and the first compilation no longer spends 11 s compiling the ports.
Tests:
test/julia_passes.jlcovers the configuration, the providers, the requirements, aprecompilation workload under the preference, that the ports actually run (JuliaIR.jl's
ledger), and a differential: a corpus of kernels compiled for PTX, GCN, SPIR-V, Metal,
native and BPF with both providers must give identical IR. It compares IR without the
names of values and blocks, because LLVM's per-function counter for unique names advances
differently when a port names its temporaries differently, and that shows only in the
suffixes later passes pick. On Julia before 1.14, the C++ FinalLowerGC zeroes GC frames
with a volatile
memset(it passes the TBAA tag as the volatility flag; fixed inJuliaLang/julia#62061). The ports zero them as 1.14 does, so such IR is compared after
making that
memsetnon-volatile and running dead-store elimination on both sides. TheC++ FinalLowerGC also builds the two halves of a frame push as arguments of one call,
whose order depends on the compiler that built Julia (it differs on aarch64 Linux), so
that independent pair is put in one order on both sides. A failing comparison prints a
line diff of the two modules. On
1.10 and 1.11 the test also compares typed with opaque pointers using the C++ passes
(unless Julia itself runs with
--opaque-pointers). With the preference set to the ports,the existing precompilation tests check that what a workload caches is found again.
CI
GitHub Actions tests both pass providers (
cppandports). Each job sets up the testenvironment with the selected preference and runs the suite with the flags and coverage
reporting of
julia-runtest; ports jobs also check that the preference was applied andthat JuliaIR's ledger records the core passes.
Buildkite runs the back-end suites with their normal provider and in a separate ports
environment. Each ports step requires ledger evidence that the passes ran. Back-end steps
remain skipped on this draft unless selected by a commit tag:
[only ports],[only cuda](etc.), or[only cuda, amdgpu, metal, oneapi, opencl]for both variants ofall five back-ends.
JuliaIR.jl version
This requires JuliaIR.jl 0.1.4, which follows changes to Julia's passes since 0.1.0: the GC
stack's thread-local storage on macOS (JuliaLang/julia#63921), RemoveJuliaAddrspaces moving
function bodies (JuliaLang/julia#65016, done like Julia 1.15 since 0.1.3), and modules with
inline assembly in RemoveJuliaAddrspaces (the Julia master failure, fixed in 0.1.2), and
AllocOpt's preserve regions and debug locations after debug intrinsics (0.1.4), among
others.
Known failure not caused by this PR: Julia 1.13 on aarch64 Linux can crash in Julia's own
LateLowerGCFrame while compiling JuliaIR.jl's code (JuliaLang/julia#62899, fixed by
JuliaLang/julia#62933 in 1.14 and backported for the next 1.13 release, not to 1.12).