Question

I am running a computational expensive task on the GPU using OpenCL. This task requires many random numbers generated within each worker. Some of those random numbers are supposed to be uniformly generated within a certain interval, but some others have to be gaussian distributed around a (changing) value.

  1. Is there any library for this?
  2. If not, what's an easy way to implement such a thing?

So far I have been creating the random numbers in python and have them passed to OpenCL. However the bottleneck now is the transfer of those random numbers (at least an order of magnitude slower than the actual computations).

Était-ce utile?

La solution

The Box-Muller transform is an easily parallelized method for transforming uniform random variates into normally distributed ones. I've used it in conjunction with the Random123 library that ddemidov mentioned.

Autres conseils

VexCL library provides counter-based random number generators from Random123 suite (disclaimer: I am the developer of the library).

Also check Boost.compute and ViennaCL libraries.

The Boost.Compute library provides the normal_distribution class along with several random-number generators (mersenne_twister_engine and linear_congruential_engine). These can be used together to produce normally (aka gaussian) distributed random values on the device.

For example, to produce random float values centered at 5.0:

// create a vector of floats on the device
boost::compute::vector<float> vec(1000, context);

// initialize the default random engine
boost::compute::default_random_engine engine(queue);

// setup the normal distribution to produce floats centered at 5
boost::compute::normal_distribution<float> distribution(5.0f, 1.0f);

// generate the random values and store them to 'vec'
distribution.generate(vec.begin(), vec.end(), engine, queue);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top