Repository navigation
Conversation
|
Documentation preview: https://juliagpu.github.io/GPUToolbox.jl/previews/PR50/ |
maleadt
added a commit
to JuliaGPU/GPUCompiler.jl
that referenced
this pull request
Dec 3, 2026
Julia 1.11+ installs it through `[sources]`. Julia 1.10 ignores those, so CI adds it by URL and runs the tests in the test environment there. To be dropped once JuliaGPU/GPUToolbox.jl#50 is merged and registered.
maleadt
force-pushed
the
tb/binding-overlays
branch
from
December 3, 2026 15:11
1b2bce9 to
d03e499
Compare
maleadt
added a commit
to JuliaGPU/GPUCompiler.jl
that referenced
this pull request
Dec 3, 2026
Julia 1.11+ installs it through `[sources]`. Julia 1.10 ignores those, so CI adds it by URL and runs the tests in the test environment there. To be dropped once JuliaGPU/GPUToolbox.jl#50 is merged and registered.
maleadt
added a commit
to JuliaGPU/GPUCompiler.jl
that referenced
this pull request
Dec 3, 2026
Julia 1.11+ installs it through `[sources]`. Julia 1.10 ignores those, so CI adds it by URL and runs the tests in the test environment there. To be dropped once JuliaGPU/GPUToolbox.jl#50 is merged and registered.
maleadt
added a commit
to JuliaGPU/GPUCompiler.jl
that referenced
this pull request
Dec 3, 2026
Julia 1.11+ installs it through `[sources]`. Julia 1.10 ignores those, so CI adds it by URL and runs the tests in the test environment there. To be dropped once JuliaGPU/GPUToolbox.jl#50 is merged and registered.
maleadt
added a commit
to JuliaGPU/GPUCompiler.jl
that referenced
this pull request
Dec 3, 2026
Julia 1.11+ installs it through `[sources]`. Julia 1.10 ignores those, so CI adds it by URL and runs the tests in the test environment there. To be dropped once JuliaGPU/GPUToolbox.jl#50 is merged and registered.
maleadt
added a commit
to JuliaGPU/GPUCompiler.jl
that referenced
this pull request
Dec 3, 2026
Julia 1.11+ installs it through `[sources]`. Julia 1.10 ignores those, so CI adds it by URL and runs the tests in the test environment there. To be dropped once JuliaGPU/GPUToolbox.jl#50 is merged and registered.
maleadt
added a commit
to JuliaGPU/GPUCompiler.jl
that referenced
this pull request
Dec 3, 2026
Julia 1.11+ installs it through `[sources]`. Julia 1.10 ignores those, so CI adds it by URL and runs the tests in the test environment there. To be dropped once JuliaGPU/GPUToolbox.jl#50 is merged and registered.
A Base method can be unsuited for a device because of a global it reads: `print(xs...)` reads `stdout`, `ndigits` and Random's samplers read lookup tables that are kept in `Vector`s. Back-ends have to replace such methods as a whole, with overlays that hide other methods or copy Base's code. `Overlays.@binding_overlay table Mod.name = value` declares that code compiled with a method table reads `value` where it reads the binding. A declaration is an overlay method of `Overlays.binding_overlay` in that table, with the value in a constant of the declaring module. That makes binding overlays behave like method overlays without support of their own: they are stacked with the tables, have a world age, are part of the declaring package's image, and declaring or deleting one is a method insertion or deletion, which compilers invalidate code on. A declaration is identified by the declaring module, the table and the source binding, which the method's signature encodes; evaluating it again, however it is spelled, replaces it. Replacing the value needs Julia 1.12, where code depends on the constants it reads. The table is checked before the value is evaluated, as anything but a `@MethodTable` would make the declaration an ordinary method. The binding has to be a global, or a constant that holds a mutable object: compiled code depends on which global it loads from, but only on the value of a constant, so other constants can't be told apart from equal ones. The value has to be of a global's declared type. Compilers find the declarations of a table with `binding_overlay_signature`, and decode them with `binding_overlay_refs`; that interface is stable across GPUToolbox 3.x. The feature itself is experimental. GPUCompiler implements the reads.
`Overlays.lookup_table_overrides` is a method table with binding overlays that make `Base.powers_of_ten` and Random's Ziggurat tables (`ki`, `wi`, `fi`, `ke`, `we`, `fe`) constant tuples in device code. With it stacked, Base's `ndigits` and Random's `randn`/`randexp` samplers compile in kernels of back-ends that provide a random number generator, instead of back-ends keeping copies of those methods with tables of their own. This adds a dependency on Random, which is part of Julia's system image.
maleadt
force-pushed
the
tb/binding-overlays
branch
from
December 3, 2026 20:06
d03e499 to
80f283b
Compare
maleadt
added a commit
to JuliaGPU/GPUCompiler.jl
that referenced
this pull request
Dec 3, 2026
Julia 1.11+ installs it through `[sources]`. Julia 1.10 ignores those, so CI adds it by URL and runs the tests in the test environment there. To be dropped once JuliaGPU/GPUToolbox.jl#50 is merged and registered.
maleadt
added a commit
to JuliaGPU/GPUCompiler.jl
that referenced
this pull request
Dec 3, 2026
Julia 1.11+ installs it through `[sources]`. Julia 1.10 ignores those, so CI adds it by URL and runs the tests in the test environment there. To be dropped once JuliaGPU/GPUToolbox.jl#50 is merged and registered.
This branch has not been deployed
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.
Base's
print(xs...) = print(stdout, xs...)reads the globalBase.stdout, which device code can't load.ndigitsreadsBase.powers_of_ten, and Random'srandn/randexpread their Ziggurat tables, allVectors. Today a back-end has to replace such methods as a whole: CUDA.jl's device printing overlays the IO-lessprint/println/showwith a restricted first-argument type that hides user methods, four back-ends carry copies of Random's samplers with anllvmcallhelper for the tables, andndigitssimply doesn't compile in kernels.This adds a way to replace the binding instead of the methods that read it:
In code compiled with
method_table, a read of the binding reads the given constant. It is to bindings whatBase.Experimental.@overlayis to methods, and is declared in the same tables. The compiler side is in GPUCompiler (JuliaGPU/GPUCompiler.jl#1147); GPUToolbox holds the declarations so that packages can declare overlays without depending on GPUCompiler.A declaration is an overlay method of an internal function in that table, whose signature encodes the table, the declaring module, the source binding and the constant that holds the value. That gives binding overlays the properties of method overlays without machinery of their own: they are stacked with the tables, have a world age, are saved in the declaring package's image, a package can add one to another package's table, and declaring or deleting one is a method insertion or deletion, which compilers invalidate code on. A declaration is identified by (declaring module, table, source binding), so evaluating it again, also spelled differently or by Revise, replaces it.
The binding has to be a global, or a constant that holds a mutable object. Compiled code depends on which global it loads from, but for a constant only on the value, so a constant like
const N = 64can't be told apart from other constants that equal 64. The value has to be of a global's declared type (stdout::IO); for a constant the type is free, since replacing aVectorby a tuple is the point. The table is checked before the value is evaluated: anything but a@MethodTablewould make the declaration an ordinary method.The second commit adds
Overlays.lookup_table_overrides, a table with the overlays forBase.powers_of_tenand Random's Ziggurat tables, next tothrow_overridesandint128_overrides. GPUToolbox now depends on Random, which is in the system image.The semantics are documented as experimental. What compilers use,
binding_overlay_signature(the lookup signature for a table),binding_overlay_refs(source and target of a declaration) andhas_identity, is promised stable across GPUToolbox 3.x, so that GPUCompiler can requireGPUToolbox = "3.9".Tested on Julia 1.10, 1.12, 1.13 and nightly: declarations, redeclarations under other spellings, the checks, and the lookup-table declarations. With GPUCompiler#1147 and CUDA.jl on an RTX 5080,
ndigits, Base'srandexpand Random's Zigguratrandnwork in kernels with this table stacked (2^22 samples: mean, variance and tail probabilities match).