Materialize isbits boxed constants as device globals#874
Open
maleadt wants to merge 4 commits into
Open
Conversation
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>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #874 +/- ##
==========================================
+ Coverage 81.37% 81.48% +0.10%
==========================================
Files 25 25
Lines 4769 4806 +37
==========================================
+ Hits 3881 3916 +35
- Misses 888 890 +2 ☔ 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.
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+.