CUDA.rand() returns duplicate columns

CUDA.rand() appears to return duplicate columns of complex numbers:

julia> CUDA.rand(ComplexF32, 512, 3)
512×3 CuArray{ComplexF32, 2}:
 0.831271+0.460309im    0.831271+0.460309im    0.831271+0.460309im
 0.0160654+0.0647557im  0.0160654+0.0647557im  0.0160654+0.0647557im
 0.457093+0.979712im    0.457093+0.979712im    0.457093+0.979712im
 0.586642+0.25824im     0.586642+0.25824im     0.586642+0.25824im
 0.0836292+0.925833im   0.0836292+0.925833im   0.0836292+0.925833im
 0.816079+0.822063im    0.816079+0.822063im    0.816079+0.822063im
...

I did not observe this behavior when using real numbers.
I am running julia 1.6.1, CUDA.jl v3.3.1, and CUDA 11.4

I have the same problem on Windows 10.

  • Julia v1.8.0-DEV.94
  • CUDA v3.3.2
  • CUDA driver 11.2.0
  • NVIDIA driver 462.31.0
  • GeForce GTX 1650 Ti
julia> a = CUDA.rand(ComplexF32, 1024);

julia> minimum(k for k in 1:1023 if a[1] == a[1+k])
256

julia> [a[1+256k] for k in 0:3]
4-element Vector{ComplexF32}:
 0.3636915f0 + 0.4992487f0im
 0.3636915f0 + 0.4992487f0im
 0.3636915f0 + 0.4992487f0im
 0.3636915f0 + 0.4992487f0im

julia> all(all(a[i] == a[i+256k] for k in 1:3) for i in 1:256)
true

The period is 2^8.

Looks like a bug in the GPUArrays RNG – for reals CURAND is used. Please file an issue, we might be able to use the new CUDA RNG for this (CUDA.RNG()), which is built on RandomNumber.jl. But from a quick glance ComplexF32 numbers aren’t supported by that package out of the box.

1 Like