如何在cuda中生成伪随机数
我正在尝试使用 CUDA 构建一个粒子系统来完成繁重的工作。我想随机化一些粒子的初始值,例如速度和寿命。随机数不必是超级随机,因为它只是为了视觉效果。我发现这篇文章解决了同一主题:
Random Number Generation in CUDA
线性同余是要走的路。看起来它应该很容易实现,但我无法获得对我的实现有用的任何东西。任何人都可以提供一些将在设备中运行的代码吗?
我在 Windows 7 64 位上使用 CUDA 和 VC++。
I am attempting to build a particle system utilizing CUDA to do the heavy lifting. I want to randomize some of the particles' initial values like velocity and life span. The random numbers don't have to be super random since it's just for visual effect. I found this post that addresses the same subject:
Random Number Generation in CUDA
That suggests a linear congruential is the way to go. It seems like it should be simple to implement, but I am having trouble getting anything useful of my implementation. Can anyone provide some code that will run in the device?
I am using CUDA with VC++ on Windows 7 64bit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CUDA 伪随机数生成器
C/src/MersenneTwister/
和C/src/quasirandomGenerator
作为单独的论文和来源提供:
2.a 兰登的论文 和 Langdon 的源代码< /a>
2.b 梅森GPU 上的 Twister
CUDA pseudo random number generators are
included in the NVidia SDK eg
C/src/MersenneTwister/
andC/src/quasirandomGenerator
available as separate papers and source:
2.a Langdon's paper and Langdon's source code
2.b Mersenne Twister on GPU
根据您的要求,有许多开源选项。还有一些商业选项,例如已实施 l'Ecuyer 的 MRG32k3a 的 NAG。如果您需要确保流不相关,请谨慎使用 LCG - 您可以使用蛙跳/分割,但需要很长的时间!
如果您想要开源,那么您绝对应该考虑使用 thrust,因为它很简单。 NVIDIA SDK 中还有一些 RNG,包括 Mersenne Twister PRNG 示例(论坛上有 MT607、MT19937)以及 Sobol 和 Niederreiter QRNG。
最后,CUDPP还有一个随机数生成器。
Depending on your requirements there are a number of open source options. There are also several commercial options such as NAG who have implemented l'Ecuyer's MRG32k3a. Be wary of using an LCG if you need to ensure that your streams are not correlated - you can use leapfrog/splitting but you'll need a very long period!
If you want to go open source then you should definitely consider using thrust for it's simplicity. There are also some RNGs in the NVIDIA SDK, including the Mersenne Twister PRNG sample (MT607, MT19937 is on the forums) and the Sobol and Niederreiter QRNGs.
Finally, CUDPP also has a random number generator.