Hi,
I need to generate discrete random variables from a numerically specified distribution function (histogram) on the device. I can see two options:
-
On the device: have an array which holds cumulative probabilities, draw a uniform variable from curand, do a first occurrence search for this uniform variable in the array (potentially slow as the search will likely create divergence problems)
-
Utilise undocumented API in curand: Create a curandDiscreteDistribution_t histogram on the host (how?), from the device use the api curand_discrete to generate a random variable. Clean up with curandDestroyDistribution
Clearly 2) is the superior approach and Nvidia have undoubtedly put lots of thought into making curand_discrete efficient.
The relevant help documentation is below:
curandStatus_t
curandCreatePoissonDistribution(
double lambda,
curandDiscreteDistribution_t *discrete_distribution)
The curandCreatePoissonDistribution() function is used to create a histogram for the
Poisson distribution with the given lambda.
__device__ unsigned int
curand_discrete (
curandState_t *state,
curandDiscreteDistribution_t discrete_distribution)
This function returns a single discrete distributed unsigned int based on a distribution for
the given discrete distribution histogram.
curandStatus_t
curandDestroyDistribution(
curandDiscreteDistribution_t discrete_distribution)
Is the source code for curandCreatePoissonDistribution available somewhere? This would help me understand how to create my own curandDiscreteDistribution_t *discrete_distribution for my own histogram.
Thanks!