Skip to content

Upgrade to LLVM.jl 10 - #656

Merged
maleadt merged 4 commits into
mainfrom
tb/llvm10
Oct 3, 2026
Merged

maleadt merged 4 commits into
mainfrom
tb/llvm10

Conversation

@maleadt

@maleadt maleadt commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

Ports oneAPI.jl to LLVM.jl 10. LLVM.jl is only used in the compiler glue that reserves the device heap's private-memory arena and lowers bfloat to i16 on drivers without SPV_KHR_bfloat16.

Main changes:

  • Mechanical port: compat, vocabulary imports and properties. The OpenCL/SPIR-V version metadata is looked up with get!, the kernel state's users are collected before the heap is inserted (users is a live view), and the arena goes in at an explicit insertion point.
  • No more raw C API: instruction types and properties instead of opcode dispatch and C API calls.
  • Simpler IR rewrites: alloca!'s align keyword, operand views, and a single builder for the bfloat lowering. The BFloatType check is gone, since it's always true on LLVM 15+.
  • Leak fix: compile_to_obj never disposed of the IR that GPUCompiler returns, and read the entry point after leaving its context. Both now happen inside the JuliaContext block.

The heap and bfloat kernels generate the same instructions as before. Some pre-existing issues are not addressed here. The bfloat lowering drops alignment, volatility, ordering and metadata, and it swaps bfloat values for i16 ones with replace_uses!, which LLVM builds with assertions reject. The version metadata is also emitted twice and accumulates when the runtime library is linked in.

Tested on an Intel Iris Xe on Julia 1.10, 1.12 and 1.13. Results match main, plus GPUArrays' newer tests.

Requires GPUCompiler 2.11 (JuliaGPU/GPUCompiler.jl#974), GPUToolbox 3.3.3 (JuliaGPU/GPUToolbox.jl#28), UnsafeAtomics 0.3.3 (JuliaConcurrent/UnsafeAtomics.jl#31) and GPUArrays 11.5.16 (JuliaGPU/GPUArrays.jl#801), and SPIRVIntrinsics 1.2 (JuliaGPU/OpenCL.jl#525).


Disclaimer: this PR is AI-assisted and has not been reviewed in detail. Tests pass locally, so it should be a good starting point for a maintainer to complete the upgrade.

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Your PR no longer requires formatting changes. Thank you for your contribution!

Import the IR and Build vocabularies next to LLVM.Interop, since
`using LLVM` no longer exports the API, and use properties instead of
the removed accessor functions (parameters, users, operands, value
types, names, the module's functions and metadata, ...).

Named metadata is no longer created by indexing, so the OpenCL and
SPIR-V version nodes are looked up with `get!`. The users of the kernel
state are collected before the heap is inserted, as the users view is
live and would otherwise include the new insertvalue. The heap arena is
inserted at the beginning of the entry block with an explicit insertion
point.
Dispatch on the instruction types rather than on opcodes from the C API,
and use the source_element_type, inbounds and indices properties and
erase! instead of the corresponding C functions.
Pass the heap's alignment to alloca!, replace the kernel state in the
operands of its users with replace!, and refer to the operands of
loads, stores and GEPs by name. The bfloat lowering now uses a single
builder (with @dispose) that is repositioned before every instruction it
rewrites, instead of creating and disposing of one per instruction, and
it skips declarations with isdeclaration.

LLVM.jl 10 only supports LLVM 15 and later, which all have BFloatType,
so drop that check.
GPUCompiler now hands the module that Julia's code generator produced to
the caller of compile, so the IR of every kernel that compile_to_obj
compiled was leaked, keeping its context alive (memcheck reports one
undisposed module per compilation). compile_to_obj only needs the name
of the entry point: read it and dispose of the IR inside the
JuliaContext block. This also stops reading the entry function after
the context has been exited, which only worked because the native code
kept the context alive.
@codecov

codecov Bot commented Oct 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 29.62963% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.35%. Comparing base (5a3557a) to head (1bd40b0).

Files with missing lines Patch % Lines
src/compiler/compilation.jl 29.62% 38 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #656      +/-   ##
==========================================
- Coverage   80.87%   79.35%   -1.52%     
==========================================
  Files          57       57              
  Lines        4105     4084      -21     
==========================================
- Hits         3320     3241      -79     
- Misses        785      843      +58     

☔ 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 4c5d9ae into main Oct 3, 2026
4 of 5 checks passed
@maleadt
maleadt deleted the tb/llvm10 branch October 3, 2026 19:07
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