Skip to content

Make the runtime's boxing functions linkable on the host - #1067

Merged
maleadt merged 1 commit into
mainfrom
tb/box-tags
Oct 28, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/box-tags

Conversation

@maleadt

@maleadt maleadt commented Oct 27, 2026

Copy link
Copy Markdown
Member

The runtime's box_* functions get their type tag by declaring the data symbol jl_<type>_type as an LLVM function and loading through it. These are ordinary host methods. Sysimage builds compile them for the host: Julia 1.12+ compiles every concrete method, and on 1.11, native code instances leak in. Package images do the same on 1.11. That only links when the symbol is resolved by name at load time. On Windows, lld can't link it:

lld: error: undefined symbol: jl_int8_type
>>> referenced by GPUCompiler/src/runtime.jl:204
>>>               jl_600.tmp(text#0.o):(julia_box_uint8_29012)

This is why KernelAbstractions doesn't precompile a kernel launch on Julia 1.11 on Windows.

Nothing in these functions is device-specific, so instead of hiding them from the host, this writes the tag the way Julia's jl_set_typeof does. The types in jl_small_typeof (all the integers and Bool) get their small tag, a constant for a given build of Julia. Float32 and Float64 get the address of their type object, which goes through the existing relocation of Julia values in the runtime library. This is the same header decoding as materialize_box!.

Tested with the full suite on 1.12, plus the native tests on 1.10 and 1.13. The new test checks that the host IR of every box_* is free of jl_*_type references, and that the tags match Julia's. In a Windows VM on Julia 1.11, KernelAbstractions (with JuliaGPU/KernelAbstractions.jl#930) now precompiles with its kernel-launch workload enabled, and loads and runs kernels.

The runtime's `box_*` functions read their type tag by declaring the data
symbol `jl_<type>_type` as a function and loading through it. Sysimage
builds and package images compile these functions for the host, where
this only links if the symbol is resolved by name at load time: on
Windows, lld can't link it, which keeps KernelAbstractions from
precompiling a kernel launch on Julia 1.11.

Write the tag as Julia does instead: a constant for the types in
`jl_small_typeof`, and the address of the type object otherwise.
@maleadt

maleadt commented Oct 28, 2026

Copy link
Copy Markdown
Member Author

CI failures unrelated, fixed downstream.

@maleadt
maleadt merged commit b029e84 into main Oct 28, 2026
35 of 36 checks passed
@maleadt
maleadt deleted the tb/box-tags branch October 28, 2026 07:22
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