Yes there are several possibilities. The easiest is probably to use the random number generator that is part of GPUArrays
should work on the device. (It isn’t documented well, but it should get you started: https://github.com/JuliaGPU/GPUArrays.jl/blob/master/src/random.jl)
@maleadt wrote this a while back and I don’t think it is part of any repository. It is a xorshift
implementation.
function xorshift(x::UInt32)::UInt32
x = xor(x, x << 13)
x = xor(x, x >> 17)
x = xor(x, x << 5)
return x
end
function gpurand(state::UInt32)::Tuple{Float32,UInt32}
state = xorshift(state)
res = (state >> 9) | reinterpret(UInt32, 1f0)
val = reinterpret(Float32, res) - 1f0
return val, state
end
function gpu_walk_kernel(f, out, N, x, a, b)
idx = (blockIdx().x-UInt32(1)) * blockDim().x + threadIdx().x
# random number generation
_, state = gpurand(idx)
function rand()
let state=state # JuliaLang/julia#15276
val, state = gpurand(state)
return val
end
end
...
end
The last idea is to actually use the device version of CURAND.jl and I attempted that in GitHub - JuliaGPU/CUDAnativelib.jl