300 likes | 494 Views
Parallel Algorithms for Pseudorandom Number Generators. CS 387 Se Jun Kim Todd Hartman. Application: Simulation. http://tugtugbug.deviantart.com/art/Epic-Minecraft-Scenery-1680x1050-348488303. Application: Sampling. http://en.wikipedia.org/wiki/File:Pi_30K.gif. Application: Cryptography.
E N D
Parallel Algorithms for Pseudorandom Number Generators CS 387 Se Jun Kim Todd Hartman
Application: Simulation http://tugtugbug.deviantart.com/art/Epic-Minecraft-Scenery-1680x1050-348488303
Application: Sampling http://en.wikipedia.org/wiki/File:Pi_30K.gif
Application: Cryptography http://en.wikipedia.org/wiki/File:Tor-logo-2011-flat.svg
Pseudorandom Numbers What makes a good PRN sequence?
Randomness: Predictability Indistinguishable from Random Discernible Pattern http://www.random.org/analysis/
Randomness: Uniform Distribution http://mathworld.wolfram.com/DiskPointPicking.html
Cryptographically Secure PRNG • Stricter requirements • Next-bit Test • State Compromise Extensions
Linear Congruence Generator • Simple and Fast • Limitations • Period • Distribution http://en.wikipedia.org/wiki/File:Lcg_3d.gif
What is CUDA? • Compute Unified Device Architecture • Parallel Computing on GPUs
Motivation Why PRNG on GPUs? • Use GPU for Monte Carlo integration • Ideal for GPGPU: compute a lot, output a little • Mean, median; uncertainty • Small computation on each thread • RNG on CPU: heavy computation
Constraints • Linear RNGs? • Each thread outputs 1 block from long sequence • Long-range correlation Easy to get burned!
(Combined) Multiple Recursive Generator • Longer periods than LCG • Better uniformity
MRG32k3a: Parallelization • Reproducibility & Skip-Ahead • 3-term Recurrence
MRG32k3a: Parallelization • Matrix multiplication optimization
Mersenne Twister What is it? • A PRNG developed by Matsumoto & Nishimura in 1997 • Produces uniform distribution in [0, 2k-1] Properties • Long Period : 219937-1 • Efficient use of Memory • Good Distribution Properties • High Performance
Mersenne Twister • Based on the recurrence… • 11 parameters ..
Mersenne Twister • Matrix A (w*w) // w = word size • For simple computation.. where
Mersenne Twister • Step 0 • Create a mask for the upper bits and another one for the lower bits. • Step 1 • The x array is initialized with a seed • Step 2 • y is the upper bits of x[i] concatenated with the lower bits of x[i+1].
Mersenne Twister • Step 3 • y * A. • A is chosen carefully so it can be easily calculated with right shift and xor. • Step 4 • Multiply with T (tempering matrix) for better equidistribution and good acurracy. • Steps 5 & 6 • Increment i by 1 and repeat the process
MT19937 on GPUs Why on GPUs? • Uses bitwise arithmetic • Arbitrary amount of memory writes But… • PRNGs are iterative Hard to parallelize single twister state update • GPU needs many(>1000) threads to be fully utilized Simultaneous Mersenne twister processed in Parallel
MT19937 on GPUs Another problem… • Correlated sequences can be generated • Even with “very different” initial state values Each thread has its own parameters (like “seed)
Sources • L. Bassham, “A Statistical Test Suite for Random and Pseudorandom Number Generators for Cryptographic Applications “, National Institute of Standards and Technology, (2010). <http://csrc.nist.gov/groups/ST/toolkit/rng/documents/SP800-22rev1a.pdf> • Wikipedia,< http://en.wikipedia.org> • P. L'Ecuyer, “Combined Multiple Recursive Generators”, Operations Research, 44, 5 (1996), 816--822. <http://www.iro.umontreal.ca/~lecuyer/myftp/papers/combmrg.ps> • P. L'Ecuyer, ``Good Parameter Sets for Combined Multiple Recursive Random Number Generators'', Shorter version in Operations Research, 47, 1 (1999), 159--164. <http://www.iro.umontreal.ca/~lecuyer/myftp/papers/combmrg2.ps> • A. Freeth, "Pseudo-Random Number Generators for Massively Parallel Discrete-Event Simulation", University of Canterbury, (2011). http://www.cosc.canterbury.ac.nz/research/reports/TechReps/2012/tr_1201.pdf • T. Bradley et al, "Parallelisation Techniques for Random Number Generators", (2011). <http://www.nag.com/IndustryArticles/gpu_gems_article.pdf> • Matsumoto, Makoto, and Takuji Nishimura. "Mersenne twister: a 623-dimensionally equidistributed uniform pseudo-random number generator." ACM Transactions on Modeling and Computer Simulation (TOMACS) 8.1 (1998): 3-30. • Podlozhnyuk, Victor. "Parallel Mersenne Twister." NVIDIA white paper(2007).