Save current states of the CURAND random number generator on a file and retrieve back

Hi,

I have to use in my program random numbers and the number of random numbers generated by each thread is different. In the end of the program I want to save the state of the random number generator in order to use as a start in a new simulation.

I have tried to save the states to a file, i.e, the structure of the curandStates in the curand_kernel.h is
struct curandStateXORWOW {
unsigned int d, v[5];
int boxmuller_flag;
float boxmuller_extra;
double boxmuller_extra_double;
};

When I read back and use this states in the random number generator in a new simulation (with the curandStates in the file), this doesn’t work.
There another way to save the state and then use as the start for the random number generator?
The worst way is to count in each kernel the number of random numbers generated by each thread, but then I have to read the actual number from the global memory, sum and then save again for each thread. However, this affects the performance.

Best regards,
Nuno

Sorry, problem solved. It is possible.

What solution did you use, ultimately?

There are not currently any functions for saving and restoring the generator state in the host API or the device API. But the strategy you’re using should be OK, writing/reading the data from the generator struct. Be aware, though, that the struct is not guaranteed to remain fixed between CUDA Toolkit releases.