Repository navigation
Conversation
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
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.
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):
Julia's specsig ABI returns any value wider than a pointer, other than floating-point and vector values, through an
sretargument. On i686 that includes theInt64/UInt64returned byunbox_int64andunbox_uint64, which compile tovoid (ptr sret(i64), ptr addrspace(10)), while runtime functions are expected (and declared by their callers) asi64 (ptr addrspace(10)).This bridges the two ABIs the way Julia does for
@cfunction: when the compiled function returns throughsret,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 theInt64ofbox_int64are passed by value, and floating-point and pointer-sized returns don't usesret. 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_sretwould duplicate Julia's rule, while thesretattribute 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/Int64forIntin 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 returningUInt64, which go throughsreton i686 while the testsccalled them as returningUInt. 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 usessreton 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/Float64to 4 bytes but the spirv32 data layout and OpenCL consumers align them to 8. That is #1063, stacked on this PR.