Materialize isbits boxed constants as device globals#874
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #874 +/- ##
==========================================
+ Coverage 81.35% 81.57% +0.22%
==========================================
Files 25 25
Lines 4789 4847 +58
==========================================
+ Hits 3896 3954 +58
Misses 893 893 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
topolarity
reviewed
Jul 13, 2026
topolarity
left a comment
There was a problem hiding this comment.
Nice! This ended up even simpler than I hoped 👍
This seems like the better path to me. Something like JuliaLang/julia#62191 is possible, but it requires a more significant refactor to give any assurances that it's complete. This is complete by design, assuming it works, so that's quite nice.
Only concern is Bool, which might be worthy of more test coverage. Some notes inline.
vchuravy
reviewed
Jul 14, 2026
Since JuliaLang/julia#55045 (1.14.0-DEV.1348), small isbits unions built from constants stay fully boxed, so `julia.constgv` slots may now be dereferenced on device. Instead of baking the host address, emit a constant replica of the box (header word + payload bytes) and point the slot at its payload; LLVM folds the loads. Ghosts, Bools and non-isbits objects keep their identity via baked addresses. `relocate_gvs!` now reports whether the module remained session-portable. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Materialized constgv slots (with smalltag headers) contain no session data, so smalltag-only kernels can stay in package images. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
maleadt
force-pushed
the
tb/materialize-boxed-constants
branch
from
July 14, 2026 09:24
738528a to
74386f6
Compare
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.
Since JuliaLang/julia#55045 (1.14.0-DEV.1348), small isbits unions built from
constants are kept fully boxed: codegen emits a
julia.constgvslot holding apointer to the host box, which device code then dereferences for the payload
or type tag.
relocate_gvs!used to bake that host address into the IR, so anysuch kernel reads host memory →
ERROR_ILLEGAL_ADDRESS.Fixing this upstream was rejected (JuliaLang/julia#62191): inline storage is a
host-side de-optimization, and flag-guarding every eager-box site doesn't
scale. Instead, this implements @topolarity's suggestion on the GPUCompiler
side, where the GC-related objections don't apply.
relocate_gvs!now inspects the object behind each constgv slot. Non-ghost,non-
Boolisbits objects are materialized: a private constant replica ofthe box (header word + payload bytes, heap-compatible layout and alignment) is
emitted into the module and the slot points at its payload. Everything else —
types, symbols, singletons,
Bools, mutable objects — keeps the baked address;those are only ever used as identity tokens.
Notes:
typeof/isa(smalltag immediate or type pointer), and===on isbitsfalls back to bits comparison, so no identity-sensitive behavior changes.
optimize!, so payload and tag loads constant-fold;the device code ends up identical to what inline union storage produced
before #55045. No de-optimization, host codegen untouched.
literal_pointer_val_slot, sofuture upstream boxing patterns are covered automatically.
relocate_gvs!reports whetherany host address survived (baked slot, or a materialized header carrying a
non-smalltag type pointer). Kernels whose constants are all smalltag
(
Int/UInt/Charetc.) no longer get wiped from package images.Applies to 1.13+ (older versions bake addresses in Julia itself); the union
regression only exists on 1.14.0-DEV.1348+.