Random Numbers

In-kernel rand, randn and randexp are Base/Random functions that cuTile overlays; their usage is documented in the Random Numbers manual page. The entries below are the cuTile-specific stream types.

Streams

cuTile.DeviceRNGType
cuTile.DeviceRNG()
Random.default_rng()   # inside a kernel

Kernel-scope RNG. Two ways to obtain one:

  • DeviceRNG() — opens a fresh independent stream. Distinct construction sites yield streams with their own (counter, seed) slots. Use this when you want multiple uncorrelated RNGs in a kernel.
  • Random.default_rng() — returns the shared default stream. All default_rng() call sites in a kernel share one (counter, seed) pair, matching the CPU Random convention that bare rand() uses an implicit global RNG.

Seeding one DeviceRNG does not affect another.

a = cuTile.DeviceRNG()
b = cuTile.DeviceRNG()
Random.seed!(a, 1); Random.seed!(b, 2)
x = rand(a, Float32, (16,))
y = rand(b, Float32, (16,))   # uncorrelated with x

The wrapped stream::Int is an opaque compile-time ID: 0 for the default stream, 1..N assigned by rng_assign_ids_pass! per call site. Codegen is unaware of RNG semantics — the state intrinsics lower to plain arithmetic on integer-keyed state slots, nothing else.

source
cuTile.RNGType
cuTile.RNG([seed::Integer])
cuTile.RNG(seed::UInt32, counter::UInt32)

Host-side handle for generating random numbers on the device via the cuTile Philox2x32-7 implementation. Mirrors Random.AbstractRNG — use with Random.rand! / Random.rand or the cuTile.rand / cuTile.rand! helpers.

At launch time the fill kernel calls Random.seed!(Random.default_rng(), seed) and advances the threaded counter by counter, so two RNGs with different seeds produce uncorrelated Philox streams. The counter is auto-advanced by length(A) after each rand! call, giving disjoint streams across consecutive calls on the same RNG.

source