JuliaGPU / JuliaGPU/GPUArrays.jl

Add support for rand(rng, n)

Open
#578 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
450
Forks
104
Avg merge
1d 4h
Merged PRs (30d)
10

Description

Currently we have the following error (show for CUDA but the same happens with Metal).
```julia
julia> using GPUArrays, CUDA

julia> rng = GPUArrays.default_rng(CuArray);

julia> rand(rng, 5)
ERROR: MethodError: no method matching rng_native_52(::GPUArrays.RNG)
The function `rng_native_52` exists, but no method is defined for this combination of argument types.

Closest candidates are:
rng_native_52(::Random.MersenneTwister)
@ Random ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/RNGs.jl:439
rng_native_52(::Random.RandomDevice)
@ Random ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/RNGs.jl:36
rng_native_52(::Random.TaskLocalRNG)
@ Random ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Xoshiro.jl:230
...

Stacktrace:
[1] rand(r::GPUArrays.RNG, ::Random.SamplerTrivial{Random.UInt52Raw{UInt64}, UInt64})
@ Random ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/generation.jl:114
[2] rand(rng::GPUArrays.RNG, X::Random.UInt52Raw{UInt64})
@ Random ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:255
[3] rand(r::GPUArrays.RNG, ::Random.SamplerTrivial{Random.UInt52{UInt64}, UInt64})
@ Random ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/generation.jl:125
[4] rand(rng::GPUArrays.RNG, X::Random.UInt52{UInt64})
@ Random ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:255
[5] rand(r::GPUArrays.RNG, ::Random.SamplerTrivial{Random.CloseOpen12{Float64}, Float64})
@ Random ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/generation.jl:32
[6] rand(rng::GPUArrays.RNG, X::Random.CloseOpen12{Float64})
@ Random ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:255
[7] rand(r::GPUArrays.RNG, ::Random.SamplerTrivial{Random.CloseOpen01{Float64}, Float64})
@ Random ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/generation.jl:35
[8] rand!
@ ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:273 [inlined]
[9] rand!
@ ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:269 [inlined]
[10] rand
@ ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:290 [inlined]
[11] rand(r::GPUArrays.RNG, dims::Int64)
@ Random ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:278
[12] top-level scope
@ REPL[17]:1
```
Is there anything blocking an implementation of `rand(rng, n)`? Notice that the following works fine instead:
```julia
julia> rng = CUDA.default_rng()
CUDA.RNG(0xe8e5e5ff, 0x00000029)

julia> rand(rng, 5)
5-element CuArray{Float32, 1, CUDA.DeviceMemory}:
0.45878232
0.55591
0.1085031
0.66130507
0.47421575
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the failure with GPUArrays.default_rng(CuArray) and rand(rng, 5), then compare it with CUDA.default_rng(). Start from the Random rand(rng, dims) stack entries and GPUArrays.RNG; done means rand(rng, n) works for the GPUArrays RNG as it does for CUDA.RNG.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.