Is there a way to serialize a CURAND RNG?

With Base, I can take the RNG returned by Random.default_rng(), write it to file with eg JLD2, then later reload it and reproduce my random number sequence from that point.

Is something like this possible with CURAND? I know I can do e.g. CURAND.seed!(0) and always get same random sequence after that, but I can’t figure out how to just save the current random state.

The CURAND API doesn’t seem to offer a way to get the current seed and offset, so no,

1 Like

serializing RNGs seems to work fine with the new CUDA.RNG:

julia> using CUDA, JLD2

julia> rng = CUDA.RNG()
CUDA.RNG(0x0372dcb6, 0x00000000)

julia> jldsave("rng.jld2"; rng)

julia> rand(rng, 3)
3-element CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}:
 0.29187703
 0.54524505
 0.7788844

julia> rand(rng, 3)
3-element CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}:
 0.3157618
 0.10146761
 0.30569053

julia> rng = load("rng.jld2")["rng"]
CUDA.RNG(0x0372dcb6, 0x00000003)

julia> rand(rng, 3)
3-element CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}:
 0.29187703
 0.54524505
 0.7788844
1 Like