Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using random numbers with GPUs

Tags:

c

cuda

gpu

gsl

I'm investigating using nvidia GPUs for Monte-Carlo simulations. However, I would like to use the gsl random number generators and also a parallel random number generator such as SPRNG. Does anyone know if this is possible?

Update

I've played about with RNG using GPUs. At present there isn't a nice solution. The Mersenne Twister that comes with the SDK isn't really suitable for (my) Monte-Carlo simulations since it takes an incredibly long time to generate seeds.

The NAG libraries are more promising. You can generate RNs either in batches or in individual threads. However, only a few distributions are currently supported - Uniform, exponential and Normal.

like image 367
csgillespie Avatar asked Jun 26 '10 18:06

csgillespie


People also ask

Can GPU generate random numbers?

Uniformly distributed random numbers are generated on the GPU using either rand , or randi . In performance terms, these two functions behave very similarly and only rand is measured here.

Why random numbers are used in cryptography?

In cryptography randomness is found everywhere, from the generation of keys to encryption systems, even the way in which cryptosystems are attacked. Without randomness, all crypto operations would be predictable and hence insecure.

Why can't computers make random numbers?

The problem modern computers have with randomness is that it doesn't make mathematical sense. You can't program a computer to produce true randomness—wherein no element has any consistent, rule-based relationship to any other element—because then it wouldn't be random.


2 Answers

The GSL manual recommends the Mersenne Twister.

The Mersenne Twister authors have a version for Nvidia GPUs. I looked into porting this to the R package gputools but found that I needed excessively large number of draws (millions, I think) before the combination of 'generate of GPU and make available to R' was faster than just drawing in R (using only the CPU).

It really is a computation / communication tradeoff.

like image 108
Dirk Eddelbuettel Avatar answered Oct 14 '22 00:10

Dirk Eddelbuettel


My colleagues and I have a preprint, to appear in the SC11 conference that revisits an alternative technique for generating random numbers that is well-suited to GPUs. The idea is that the nth random number is:

x_n = f(n) 

In contrast to the conventional approach where

x_n = f(x_{n-1})

Source code is available, which implements several different generators. offering 2^64 or more streams, each with periods of 2^128 or more. All pass a wide assortment of tests (the TestU01 Crush and BigCrush suites) of both intra-stream and inter-stream statistical independence. The library also includes adapters that allow you to use our generators in a GSL framework.

like image 39
jks Avatar answered Oct 14 '22 01:10

jks