OpenCL中的高斯分布随机数

时间:2021-01-03 11:37:01

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.

我使用OpenCL在GPU上运行计算成本高昂的任务。此任务需要在每个工作人员中生成许多随机数。这些随机数中的一些应该在一定间隔内均匀生成,但是其他一些随机数必须围绕(变化)值高斯分布。

  1. Is there any library for this?
  2. 这有什么图书馆吗?
  3. If not, what's an easy way to implement such a thing?
  4. 如果没有,实现这样的事情的简单方法是什么?

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).

到目前为止,我一直在python中创建随机数,并将它们传递给OpenCL。然而,现在的瓶颈是那些随机数的转移(至少比实际计算慢一个数量级)。

3 个解决方案

#1


1  

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.

Box-Muller变换是一种易于并行化的方法,用于将均匀随机变量转换为正态分布变换。我已经将它与ddemidov提到的Random123库结合使用。

#2


1  

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

VexCL库提供来自Random123套件的基于计数器的随机数生成器(免责声明:我是该库的开发人员)。

Also check Boost.compute and ViennaCL libraries.

还要检查Boost.compute和ViennaCL库。

#3


0  

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.

Boost.Compute库提供了normal_distribution类以及几个随机数生成器(mersenne_twister_engine和linear_congruential_engine)。这些可以一起用于在设备上产生正常(也称为高斯)分布式随机值。

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

例如,要生成以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);

#1


1  

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.

Box-Muller变换是一种易于并行化的方法,用于将均匀随机变量转换为正态分布变换。我已经将它与ddemidov提到的Random123库结合使用。

#2


1  

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

VexCL库提供来自Random123套件的基于计数器的随机数生成器(免责声明:我是该库的开发人员)。

Also check Boost.compute and ViennaCL libraries.

还要检查Boost.compute和ViennaCL库。

#3


0  

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.

Boost.Compute库提供了normal_distribution类以及几个随机数生成器(mersenne_twister_engine和linear_congruential_engine)。这些可以一起用于在设备上产生正常(也称为高斯)分布式随机值。

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

例如,要生成以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);