GPU programs often use separate stateful random-number generators for every thread, requiring each thread to read and update its state in video memory. Because GPU memory capacity and bandwidth are limited, those operations can slow workloads and consume space better used for model parameters or simulation data. A counter-based generator avoids persistent state: it combines a seed with a thread identifier and counter, then applies a hash-like transformation to produce random bits. Each thread can therefore compute its own portion of a sequence without allocating or accessing memory for RNG state. Philox and Threefry use this approach, now supported by tools including PyTorch, JAX and cuRANDDx; the idea was made practical for parallel computing by Salmon and colleagues in 2011.
Three WebGPU demonstrations compare stateful XORWOW, counter-based Philox with its counter stored in memory, and Philox without stored state. On the author’s laptop, stateless Philox runs about 70% faster for estimating pi with random darts and 75% faster for simulating diffusing ink, both of which use many random values but little other computation. In a path tracer, which does more work per random value, XORWOW performs best. Results vary by hardware and browser; in WGSL, Philox’s 64-bit arithmetic is especially costly to emulate. Counter-based methods are most attractive when memory is the bottleneck, not computation. They also require callers to provide distinct inputs for distinct draws: repeating the same seed, thread identifier and counter reproduces the same value.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.