# Is there a way to serialize a CURAND RNG?

**URL:** https://discourse.julialang.org/t/is-there-a-way-to-serialize-a-curand-rng/34493
**Category:** GPU
**Created:** [February 11, 2020, 11:34pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-serialize-a-curand-rng/34493 "2020-02-11T23:34:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)
#### Post date: [February 11, 2020, 11:34pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-serialize-a-curand-rng/34493/1 "2020-02-11T23:34:32Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)
#### Post date: [February 12, 2020, 12:32pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-serialize-a-curand-rng/34493/2 "2020-02-12T12:32:33Z")

</div>

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

---

<div class="post-metadata">

### Author: ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)
#### Post date: [October 11, 2021, 9:15pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-serialize-a-curand-rng/34493/3 "2021-10-11T21:15:16Z")

</div>

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

```julia
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

```
