is there a way to generate the same random sequence of numbers on a GPU as on the CPU? i was hoping i could just use rng = Random.default_rng()
as the generator for both GPU and CPU vectors, but while it doesn’t emit an error, it doesn’t give the same sequence. what’s curious is it always works fine for short vectors, but never for long ones.
doesn’t work for long vectors:
julia> using Random, CUDA
julia> CUDA.allowscalar(true)
julia> rng = Random.default_rng()
TaskLocalRNG()
julia> sz=3000
3000
julia> v = Vector{Float64}(undef, sz);
julia> Random.seed!(rng, 1) ### seed
TaskLocalRNG()
julia> randn!(rng, v);
julia> @info v[1:3]
[ Info: [1.3124259911967384, -0.013263403885168697, -1.0268774653294301]
julia> randn!(rng, v);
julia> @info v[1:3]
[ Info: [1.4277456563925504, -1.0891864209485216, -1.29325857771683]
julia> v = CuVector{Float64}(undef, sz);
julia> Random.seed!(rng, 1) ### re-seed
TaskLocalRNG()
julia> randn!(rng, v);
julia> @info v[1:3]
[ Info: [-0.2627388126694136, 0.6279014918085116, 1.0570439330176862]
julia> randn!(rng, v);
julia> @info v[1:3]
[ Info: [0.47525705350476416, -0.8981703138311293, 0.5934767517052868]
but it does for short:
julia> sz=3
3
julia> v = Vector{Float64}(undef, sz);
julia> Random.seed!(rng, 1) ### seed
TaskLocalRNG()
julia> randn!(rng, v);
julia> @info v[1:3]
[ Info: [-0.2627388126694136, 0.6279014918085116, 1.0570439330176862]
julia> randn!(rng, v);
julia> @info v[1:3]
[ Info: [0.05101573888172962, 1.674880612231772, 1.117523429442645]
julia> v = CuVector{Float64}(undef, sz);
julia> Random.seed!(rng, 1) ### re-seed
TaskLocalRNG()
julia> randn!(rng, v);
julia> @info v[1:3]
[ Info: [-0.2627388126694136, 0.6279014918085116, 1.0570439330176862]
julia> randn!(rng, v);
julia> @info v[1:3]
[ Info: [0.05101573888172962, 1.674880612231772, 1.117523429442645]
this is with 1.7-beta4 and 0-day master CUDA.jl