Commit a977de2
committed
Make PassthroughRNG dispatch survive overlay method-table shadowing
PassthroughRNG previously defined only the three no-second-arg methods
(rand, randexp, randn). On Julia 1.12+, GPU back ends like CUDA.jl install
device-side overlay tables via Base.Experimental.@consistent_overlay. Julia's
OverlayMethodTable.findall returns overlay matches *without consulting the
base method table* whenever the overlay fully covers the signature, so an
overlay method like CUDA.jl's `@device_override Random.randexp(rng::AbstractRNG)`
shadows our specific `Random.randexp(::PassthroughRNG)` on the device. The
override's body then runs with rng::PassthroughRNG and calls
`Random.rand(rng, UInt52Raw())`. The stdlib Sampler chain for that bottoms out
at `_rand52(r, rng_native_52(r)) → rand(r, UInt64)`; PassthroughRNG had no
`rng_native_52` and no typed-arg rand, so the chain statically reached
`throw(MethodError, ...)`, which GPUCompiler refuses to lower (see
SciML/JumpProcesses.jl#588 for the original repro).
Add minimal forwarding methods so the chain still reaches bare rand(T):
Random.rng_native_52(::PassthroughRNG) = UInt64
Random.rand(rng::PassthroughRNG, ::Type{T}) where {T} = rand(T)
These keep PassthroughRNG's "use whatever default_rng() returns here"
semantics — bare rand(T) goes through default_rng(), which GPU back ends
device-override to their device RNG (Philox2x32 in CUDA.jl). Verified on
Julia 1.12.6 that rand(PassthroughRNG(), UInt52Raw()), rand(PassthroughRNG(),
UInt64), etc. all resolve cleanly after this change. Bump to 0.4.8.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>1 parent c401dab commit a977de2
3 files changed
Lines changed: 26 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
16 | 25 | | |
17 | 26 | | |
18 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
119 | 135 | | |
120 | 136 | | |
121 | 137 | | |
| |||
0 commit comments