Skip to content

Support 32-bit hosts, and test on i686 Linux - #1062

Open
maleadt wants to merge 3 commits into
mainfrom
tb/runtime-sret
Open

maleadt wants to merge 3 commits into
mainfrom
tb/runtime-sret

Conversation

@maleadt

@maleadt maleadt commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

On 32-bit hosts, building the GPU runtime library fails, which breaks every compilation that links it. For example, any KernelAbstractions kernel on the PoCL back-end on i686 Linux (AcceleratedKernels.jl's x86 CI):

Invalid return type for runtime function 'unbox_int64': expected LLVM.IntegerType(i64), got LLVM.VoidType(void)

Julia's specsig ABI returns any value wider than a pointer, other than floating-point and vector values, through an sret argument. On i686 that includes the Int64/UInt64 returned by unbox_int64 and unbox_uint64, which compile to void (ptr sret(i64), ptr addrspace(10)), while runtime functions are expected (and declared by their callers) as i64 (ptr addrspace(10)).

This bridges the two ABIs the way Julia does for @cfunction: when the compiled function returns through sret, emit_function! emits a wrapper with the expected signature that calls it with a stack slot and returns the loaded value. The specfunc becomes internal, so it gets inlined into the wrapper. The wrapper is emitted before the per-function bitcode is cached, so cache hits contain it too. Any other signature mismatch still errors. The other runtime functions already have matching signatures on 32-bit: arguments such as the Int64 of box_int64 are passed by value, and floating-point and pointer-sized returns don't use sret. Adapting the callers instead would leave every call site, including those in back-ends, to deal with a host-dependent ABI. Predicting the signature with the (unused) deserves_sret would duplicate Julia's rule, while the sret attribute in the IR is authoritative.

To keep this working, the second commit makes the test suite pass on 32-bit hosts and the third adds i686 Linux jobs for every tested Julia version. Many tests assumed a 64-bit host: i64/Int64 for Int in FileCheck patterns and error messages, hand-written IR with 64-bit relocation words and no data layout (so LLVM's default 64-bit pointers applied), and JIT-executed kernels returning UInt64, which go through sret on i686 while the tests ccalled them as returning UInt. Those are now spelled in terms of the host's word size. Metal and BPF only have 64-bit pointers, so their tests are skipped on 32-bit hosts, as PTX and GCN already were (their back-end JLLs are only built for 64-bit hosts).

The new regression test emits a runtime function returning NTuple{2,Int64}, which uses sret on 64-bit hosts too, and checks the resulting signature, both freshly compiled and from the cache. The full suite passes on i686 Julia 1.10, 1.11, 1.12 and 1.13, and still passes on x86_64.

Not covered: struct layouts of SPIR-V kernels on 32-bit hosts, where Julia aligns Int64/Float64 to 4 bytes but the spirv32 data layout and OpenCL consumers align them to 8. That is #1063, stacked on this PR.

Julia returns values wider than a pointer, other than floating-point and
vector ones, through an `sret` argument. On 32-bit hosts this includes the
`Int64` and `UInt64` that `unbox_int64` and `unbox_uint64` return, so building
the runtime library failed with "Invalid return type for runtime function
'unbox_int64'", breaking every compilation that links it (e.g. any
KernelAbstractions kernel on the PoCL back-end on i686).

Callers expect runtime functions to return by value, so bridge the two ABIs
with a wrapper that calls the specfunc with a stack slot and returns the loaded
value, as Julia does for `@cfunction`. The specfunc becomes internal, so the
inliner folds it into its only caller.
Many tests assumed a 64-bit host: FileCheck patterns and error messages
spelling `Int` as `i64`/`Int64`, hand-written IR with 64-bit relocation
words (and no data layout, so LLVM's default 64-bit pointers applied),
narrow-slot checks using `i32`, and JIT-executed kernels returning
`UInt64`, which Julia returns through `sret` on 32-bit hosts while the
tests `ccall`ed them as returning a `UInt`. Spell those in terms of the
host's word size instead, through new `llvm_int` and `Native.datalayout()`
helpers, and have the kernels compute host words.

Metal and BPF have 64-bit pointers only, which a 32-bit host's Julia
codegen cannot target, so skip their tests there (PTX and GCN are already
skipped, as their back-end JLLs are only built for 64-bit hosts).
Run the test suite with i686 Julia, for every tested version, so that
32-bit hosts (e.g. KernelAbstractions' PoCL back-end on i686) keep working.
@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.32%. Comparing base (6602197) to head (45f8ced).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
src/rtlib.jl 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1062      +/-   ##
==========================================
- Coverage   92.40%   91.32%   -1.08%     
==========================================
  Files          31       31              
  Lines        7254     7807     +553     
==========================================
+ Hits         6703     7130     +427     
- Misses        551      677     +126     

☔ 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.

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