How to generate pseudo random in cuda

萝らか妹 提交于 2019-12-23 02:36:24

问题


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.


回答1:


CUDA pseudo random number generators are

  1. included in the NVidia SDK eg C/src/MersenneTwister/ and C/src/quasirandomGenerator

  2. available as separate papers and source:

    2.a Langdon's paper and Langdon's source code

    2.b Mersenne Twister on GPU




回答2:


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.



来源:https://stackoverflow.com/questions/2202534/how-to-generate-pseudo-random-in-cuda

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!