Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for rand(rng, n) #578

Open
CarloLucibello opened this issue Jan 2, 2025 · 1 comment
Open

Add support for rand(rng, n) #578

CarloLucibello opened this issue Jan 2, 2025 · 1 comment

Comments

@CarloLucibello
Copy link

Currently we have the following error (show for CUDA but the same happens with Metal).

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> 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
@maleadt
Copy link
Member

maleadt commented Jan 6, 2025

Is there anything blocking an implementation of rand(rng, n)?

Not really, just somebody improving the current implementation. A literal port of the CUDA.jl RNG is going to be tricky though, as it contains a lot of low-level hackery.

@maleadt maleadt changed the title missing support for rand(rng, n) Add support for rand(rng, n) Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants