lundi 10 juillet 2017

understanding curand_init parameters

I am trying to generate random numbers in cuda kernels. I found that curand's documentation is relatively long compared to a c++ program, which seems reasonable. But there I found terminologies that I couldn't understand even with google. I continue my question by containing some minimal code examples. In c++ I can generate uniform-distribution random numbers with these lines:

std::random_device rd;
std::default_random_engine generator( rd() );
std::uniform_real_distribution<double> unif( 0, 1 );
double x = unif( generator );

We see that parameters are clear. rd() gives a random value as a seed for generator. generator uses a specific function to generate sequence of random numbers. and uniform_real_distribution adjusts the probability distribution.


But my problem is with curand...

I have simplified one of the examples in the curand docs: in an init kernel:

curand_init(sobolDirectionVectors + VECTOR_SIZE*dim, 
                sobolScrambleConstants[dim], 
                1234, 
                &state); 

in a generator kernel:

double x = curand_uniform_double(&state);

this is the curand_init signature:

__device__ void curand_init ( 
     unsigned long long seed,
     unsigned long long sequence,
     unsigned long long offset,
     curandState_t *state
)

my questions are:

  1. What is sequence? How does it affect random-number generation?
  2. What is offset, and why are they giving a constant (1234) number to it in every invocation? How does it affect random-number generation?
  3. Is the documentation ambiguous or those terminologies are fairly popular among programmers? Any reference for learning them is appreciated.



Aucun commentaire:

Enregistrer un commentaire