clProbDist
An OpenCL library for probability distributions
DocsTutorial/example4_kernel.cl

Device code for Example 4: Poisson variate generation on the device

/*
* Authors:
*
* David Munger <mungerd@iro.umontreal.ca> (2015)
* Pierre L'Ecuyer <lecuyer@iro.umontreal.ca> (2015)
*
*/
#include <clRNG/mrg31k3p.clh>
#ifndef NULL
#define NULL ((void*)0)
#endif
double simulateOneRun(__global const clprobdistPoisson* dist, clrngMrg31k3pStream* stream)
{
double output = 0.0;
for (int i = 0; i < 100; i++) {
double u = clrngMrg31k3pRandomU01(stream);
int poisson_variate = clprobdistPoissonInverseCDFWithObject(dist, u, NULL);
// modify output using poisson_variate
output += poisson_variate / (100.0 * clprobdistPoissonMeanWithObject(dist, NULL));
}
return output;
}
__kernel void my_kernel(
__global const clprobdistPoisson* dist,
__global const clrngMrg31k3pHostStream* host_streams,
__global double* output)
{
size_t gid = get_global_id(0);
clrngMrg31k3pStream stream;
clrngMrg31k3pCopyOverStreamsFromGlobal(1, &stream, &host_streams[gid]);
output[gid] = simulateOneRun(dist, &stream);
}