3

I was reading the CURAND Library API and I am a newbie in CUDA and I wanted to see if someone could actually show me a simple code that uses the CURAND Library to generate random numbers. I am looking into generating a large amount of number to use with Discrete Event Simulation. My task is just to develop the algorithms to use GPGPU's to speed up the random number generation. I have implemented the LCG, Multiplicative, and Fibonacci methods in standard C Language Programming. However I want to "port" those codes into CUDA and take advantage of threads and blocks to speed up the process of generating random numbers.

Link 1: http://adnanboz.wordpress.com/tag/nvidia-curand/

That person has two of the methods I will need (LCG and Mersenne Twister) but the codes do not provide much detail. I was wondering if anyone could expand on those initial implementations to actually point me in the right direction on how to use them properly.

Thanks!

Wilo Maldonado
  • 551
  • 2
  • 11
  • 22
  • There should be a Monte Carlo estimation of PI among the SDK example programs which demonstrated simple CURAND usage. E.g. EstimatePiP under MonteCarloCURAND. Have you have a chance to look at that? – njuffa Jul 30 '12 at 22:04
  • Yeah I looked at it. However I am looking for a mere example of a Random Number Generator. I will edit my question to post a code I developed that I am having trouble working on. – Wilo Maldonado Jul 31 '12 at 00:57
  • @njuffa Anyone wanna share/elaborate on this? – Wilo Maldonado Aug 01 '12 at 18:05

1 Answers1

5

Your question is misleading - you say "Use the cuRAND Library for Dummies" but you don't actually want to use cuRAND. If I understand correctly, you actually want to implement your own RNG from scratch rather than use the optimised RNGs available in cuRAND.

  1. First recommendation is to revisit your decision to use your own RNG, why not use cuRAND? If the statistical properties are suitable for your application then you would be much better off using cuRAND in the knowledge that it is tuned for all generations of the GPU. It includes Marsaglia's XORWOW, l'Ecuyer's MRG32k3a, and the MTGP32 Mersenne Twister (as well as Sobol' for Quasi-RNG).
  2. You could also look at Thrust, which has some simple RNGs, for an example see the Monte Carlo sample.
  3. If you really need to create your own generator, then there's some useful techniques in GPU Computing Gems (Emerald Edition, Chapter 16: Parallelization Techniques for Random Number Generators).

As a side note, remember that while a simple LCG is fast and easy to skip-ahead, they typically have fairly poor statistical properties especially when using large quantities of draws. When you say you will need "Mersenne Twister" I assume you mean MT19937. The referenced Gems book talks about parallelising MT19937 but the original developers created the MTGP generators (also referenced above) since MT19937 is fairly complex to implement skip-ahead.

Also as another side note, just using a different seed to achieve parallelisation is usually a bad idea, statistically you are not assured of the independence. You either need to skip-ahead or leap-frog, or else use some other technique (e.g. DCMT) for ensuring there is no correlation between sequences.

Tom
  • 20,852
  • 4
  • 42
  • 54