This piece has three interactive demos! I’m writing this to tell you about an elegant and simple idea that might make your code go faster. Depending on how you use GPUs, your code might already be using this idea: it has gone mainstream in ML frameworks since I first heard about it and wrote a library ten years ago in 2016. The idea is not mine! I just find it aesthetically pleasing, and so might you.
(Don’t use my old library! It used unsupported internal cuRAND functions. There are better options now, like cuRANDDx.)
Here’s the idea: if you’re generating random numbers on a GPU, by default you should avoid RNGs with internal state that’s updated for every number produced. Instead, prefer a stateless RNG that works by encrypting or hashing a counter. There are some excellent options so you don’t need to roll your own, called Philox and Threefry.…