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

assignment changes random seed #1226

Closed
bjarthur opened this issue Nov 1, 2021 · 4 comments
Closed

assignment changes random seed #1226

bjarthur opened this issue Nov 1, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@bjarthur
Copy link
Contributor

bjarthur commented Nov 1, 2021

on the CPU:

julia> using Random

julia> foo = Vector{Float64}(undef, 1000);

julia> Random.seed!(1)
TaskLocalRNG()

julia> rand(3)
3-element Vector{Float64}:
 0.07336635446929285
 0.34924148955718615
 0.6988266836914685

julia> foo[1:3] .= 4;

julia> rand(3)
3-element Vector{Float64}:
 0.6282647403425017
 0.9149290036628314
 0.19280811624587546

same on the GPU. notice the first set of random numbers is the same as above. the second are different.

julia> using Random, CUDA

julia> foo = CuVector{Float64}(undef, 1000);

julia> Random.seed!(1)
TaskLocalRNG()

julia> rand(3)
3-element Vector{Float64}:
 0.07336635446929285
 0.34924148955718615
 0.6988266836914685

julia> foo[1:3] .= 4;

julia> rand(3)
3-element Vector{Float64}:
 0.7805192636751863
 0.6702639583444937
 0.16771210647092682

i suppose this could be a bug in the CPU code. let me know if i should refile the issue elsewhere.

@bjarthur bjarthur added the bug Something isn't working label Nov 1, 2021
@bjarthur
Copy link
Contributor Author

bjarthur commented Nov 1, 2021

oh, and this is with julia 1.7.0-rc2, CUDA 3.5.0, and GPUArrays 8.1.2. i did not notice this with julia 1.6 and CUDA 3.4.2

@bjarthur
Copy link
Contributor Author

bjarthur commented Nov 1, 2021

skipping the assignment on the CPU yields the same random numbers the second time, so it seems this is a GPU problem.

julia> using Random

julia> foo = Vector{Float64}(undef, 1000);

julia> Random.seed!(1)
TaskLocalRNG()

julia> rand(3)
3-element Vector{Float64}:
 0.07336635446929285
 0.34924148955718615
 0.6988266836914685

julia> rand(3)
3-element Vector{Float64}:
 0.6282647403425017
 0.9149290036628314
 0.19280811624587546

@bjarthur bjarthur changed the title assignment changes random seed on GPU assignment changes random seed Nov 1, 2021
@maleadt
Copy link
Member

maleadt commented Nov 9, 2021

This seems caused by task switches, so better file this upstream:

julia> Random.seed!(1); rand(); rand()
0.34924148955718615

julia> Random.seed!(1); rand(); rand()
0.34924148955718615

julia> Random.seed!(1); rand(); wait(@async begin end); rand()
0.19280811624587546

@maleadt maleadt closed this as completed Nov 9, 2021
@bjarthur
Copy link
Contributor Author

using the MersenneTwister RNG instead of the default fixes it for my use case. thanks for looking into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants