Skip to content

Update PhiloxRNG.jl to v1.1.1 and fix counter overflow with UInt64#717

Merged
maleadt merged 3 commits into
JuliaGPU:mainfrom
nhz2:nz/rng-update
May 14, 2026
Merged

Update PhiloxRNG.jl to v1.1.1 and fix counter overflow with UInt64#717
maleadt merged 3 commits into
JuliaGPU:mainfrom
nhz2:nz/rng-update

Conversation

@nhz2
Copy link
Copy Markdown
Contributor

@nhz2 nhz2 commented Apr 28, 2026

Fixes #713
This PR uses the following scheme to avoid rng stream collisions.

Philox4x32-10 takes a 128-bit counter (ctr0, ctr1) and a 64-bit key. The scheme is:

  • key = the 64-bit seed (identifies the RNG instance).
  • ctr1 = a 64-bit per-launch counter, incremented host-side after each kernel that consumes the RNG.
  • ctr0 = a 64-bit counter gid + nthreads * localcounter, varying inside the kernel: gid partitions across threads, localcounter increments per Philox call from that thread. This allows for over 2^32 threads with fewer Philox calls per thread, or over 2^32 Philox calls per thread with fewer threads without having a collision.

ctr1 is also randomized when seeding from a RandomDevice to make collisions less likely.

CC @maleadt

@nhz2 nhz2 marked this pull request as ready for review April 28, 2026 19:24
Comment thread src/host/random.jl Outdated
Comment thread src/host/random.jl
@maleadt maleadt merged commit d65ce69 into JuliaGPU:main May 14, 2026
1 check passed
@nhz2 nhz2 deleted the nz/rng-update branch May 14, 2026 14:52
@nhz2 nhz2 restored the nz/rng-update branch May 15, 2026 13:36
@nhz2 nhz2 deleted the nz/rng-update branch May 15, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrap around in rand_batched_kernel! can lead to repeating patterns

2 participants