Random numbers in GPU


I’m using the standard random number generator to generate n (~10**5) double precision random numbers between 0 and 1 each step, but this routine is the slowest part of the code (and the only one which runs on CPU) due to the communication between host and device.

Could you reccomend me another way to generate random numbers?

I think I could send the seed to the GPU and the generate all the numbers in GPU but I don’t know how to do it.

Simplest implementation of my code bellow:

for(int i=0; i<n; i++) Ran[i] = RND1; //n double precision random number in CPU

cudaMemcpy(Ran_d,Ran,nsizeof(double),cudaMemcpyHostToDevice) //Sending n double random number to GPU

Thanks, this is my first post

NVIDIA provides a library for random number generation on the GPU, called curand.

The documentation is here:


There are also curand sample codes in the cuda toolkit distribution, and many curand questions here on these forums as well as all over the web discussing how to use it.

Thrust also has a random number generation facility, and there are probably many other ways to generate random numbers on the GPU.