
GPU random number generation drives some of the heaviest workloads in computing. For example, Monte Carlo simulations price financial products. Likewise, cryptography, procedural generation in games, and noise synthesis depend on it. As a result, the generator itself becomes the limiting factor for large simulations. So when AMD needed a fast GPU random number generation library for its new platform, it asked us to build one. The result is rocRAND, the official random number library of the ROCm stack.
About the customer
AMD develops GPUs and the ROCm software stack around them. ROCm gives scientific and HPC software a home on AMD hardware. Its strategy centers on HIP, a programming language that closely resembles CUDA. Thanks to HIP, porting existing CUDA software to AMD GPUs goes quickly. Even large code-bases take weeks rather than months. However, a language alone is not enough. In addition, every CUDA library a program depends on needs a HIP-equivalent. Otherwise the port stalls on the first missing call. cuRAND, NVIDIA’s random number library, is exactly such a dependency. After all, it appears in scientific software everywhere.
The challenge
AMD needed a random number library that CUDA software could adopt with near-zero effort. To begin with, this set three requirements:
- Compatibility. Many CUDA programs call cuRAND directly. Therefore, the new library had to match its interfaces and offer the same families of generators.
- Coverage. The library had to provide the generators real code uses. As a result, picking the right ones became a research task in itself.
- Performance. A library that slows downported software would block adoption. Above all, it had to match cuRAND, on both AMD and NVIDIA hardware.
Our approach to GPU random number generation
Pick generators from evidence, not habit. To start, we studied what software on GitHub actually uses. Based on that research, the library covers the most-used PRNGs and QRNGs. As a result, every important generator family has a representative: XORWOW, MRG32k3a, MTGP32, Philox (4×32, 10 rounds), and Sobol32. Moreover, several of these also appear in cuRAND, which makes porting straightforward.
Optimize for the hardware, not the algorithm alone. After all, a random number generator on a GPU is only as fast as its memory access allows. Therefore, we profiled how each generator behaves on real hardware and tuned the implementations to it. The gains showed up clearly on AMD GPUs, thanks to their higher-bandwidth memory.
Prove the performance on both platforms. For this purpose, we benchmarked the library on the AMD Radeon Nano and the NVIDIA GTX 1080, against cuRAND on the same GTX 1080. Before the optimization phase, rocRAND was on par with cuRAND. After the optimizations, it came out ahead in most cases. In other words, even on NVIDIA hardware, the library we built for AMD GPUs beats NVIDIA’s own library. Professional-grade GPUs like the AMD MI25 show even larger gains.
Make it verifiable. The library is open source, with benchmark tooling included. Consequently, anyone can reproduce our measurements on their own hardware. One caveat: we tuned it for recent AMD GPUs and NVIDIA GTX GPUs, not for Tesla GPUs. In addition, it does not run on CPUs or Intel GPUs.
Random number generation on GPUs brings its own questions. Previously, we wrote about them here:
- Random numbers in parallel computing: generation and reproducibility, part 1
- Random numbers in parallel computing: generation and reproducibility, part 2
- Porting code that uses random numbers
The result
rocRAND shipped as the official GPU random number generation library of ROCm, AMD’s open source GPU platform. It matches the cuRAND interfaces and covers the generator families that real software uses. Moreover, it outperforms cuRAND in most benchmark cases, on both AMD and NVIDIA hardware. In addition, the hipify tools support it, so CUDA code using cuRAND converts almost automatically. For NVIDIA-only projects it is a viable choice too, given the measured performance.
After the optimizations, AMD GPUs took the lead, thanks to their higher-bandwidth memory:


As you can see, our library was even faster on Nvidia hardware than Nvidia’s own library.
Key takeaway
In short, a porting strategy lives or dies with its libraries. AMD closed one of the biggest gaps, the random number dependency, with an open library that matches cuRAND and beats it in performance. As a result, software depending on cuRAND can now move to AMD hardware in days instead of months. That is what removing a blocking dependency is worth.
Want a tailored RNG?
We delivered rocRAND as a general-purpose library, tuned for generic correctness. However, your project might need more. Get in touch to discuss how we can tune the library further, add special characteristics such as reduced cyclic behavior, or port other PRNGs to the GPU.
Did you enjoy reading about how we helped AMD beat Nvidia on random number generators? You can read about more projects we worked on by checking out our other case studies.
Nice! Why the code doesn’t work on CPUs and Intel GPUs? Because of wavefronts/warps?
P.S. there is mistype in “AMD GTX GPUs”
It’s written for HIP that only works with GPUs supporting ROCm (AMD) and CUDA (Nvidia). Also, for CPUs the design would be slightly different to get maximum performance.
Thanks, fixed it.
Why is it written on HIP not OpenCL? I thought HIP is for porting CUDA applications to newest AMD GPUs but why was it used for new software? Does HIP have any advantages over OpenCL?
HIP and OpenCL both have different goals. For this project the goal was to support (scientific) code that is written in CUDA and should be quickly ported to AMD GPUs. AMD’s Hipify-tools is currently being updated to support this new rocRAND-library.
A good library for OpenCL-code is https://www.thesalmons.org/john/random123/