Skip to content

Commit c704823

Browse files
avik-palchristiangnrd
authored andcommitted
fix: indexing for gpu_rand
1 parent 1901868 commit c704823

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/host/random.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ function Random.randn!(rng::RNG, A::AnyGPUArray{T}) where T <: Number
9797
@kernel function randn!(a, randstates)
9898
i = @index(Global, Linear)
9999
idx = 2*(i - 1) + 1
100-
U1 = gpu_rand(T, i, randstates)
101-
U2 = gpu_rand(T, i, randstates)
100+
threadidx = (i-1)%length(randstates) + 1
101+
U1 = gpu_rand(T, threadidx, randstates)
102+
U2 = gpu_rand(T, threadidx, randstates)
102103
Z0 = sqrt(T(-2.0)*log(U1))*cos(T(2pi)*U2)
103104
Z1 = sqrt(T(-2.0)*log(U1))*sin(T(2pi)*U2)
104105
@inbounds a[idx] = Z0

test/testsuite/random.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
cpu_rng = Random.default_rng()
88

99
@testset "rand" begin # uniform
10-
for T in eltypes, d in (10, (10,10))
10+
for T in eltypes, d in (10, (10,10), (128,128))
1111
A = AT{T}(undef, d)
1212
B = copy(A)
1313
rand!(rng, A)

0 commit comments

Comments
 (0)