Skip to content

Improve Random.jl coverage: randn and randexp#204

Merged
maleadt merged 3 commits into
mainfrom
tb/random
Apr 27, 2026
Merged

Improve Random.jl coverage: randn and randexp#204
maleadt merged 3 commits into
mainfrom
tb/random

Conversation

@maleadt
Copy link
Copy Markdown
Member

@maleadt maleadt commented Apr 27, 2026

No description provided.

maleadt added 2 commits April 27, 2026 17:25
Reuses the rand pipeline: a Box-Muller transform on the (c1, c2) pair
each Philox call already emits, so a tile of n Float32 normals costs
n/2 Philox calls (same as `rand(Float32)`). Float64 needs n calls since
each output draws a UInt64 of entropy. Float16/BFloat16 compute the
transform in Float32 and narrow at the end. Same `rand`-style overlay
surface for both the default stream and explicit `DeviceRNG`.

The host-side `cuTile.RNG` gets a parallel `randn!` / `randn` /
`cuTile.randn` aliases via a `randn_fill_kernel` that mirrors
`rand_fill_kernel`'s counter accounting (advance-by-element-count is
T-agnostic, so the host bookkeeping is unchanged).
`randexp` is the simplest of the non-uniform draws: each output is
`-log(U)` where `U` is a uniform sample from the existing rand path.
No Box-Muller, no rejection — one log per element. Same surface
coverage as randn (default-stream + DeviceRNG, scalar/tile/variadic).

This rounds out Random.jl's array-distribution API on cuTile (rand,
randn, randexp); the remaining stdlib `rand*` family is array
permutations / strings, which doesn't fit the GPU element-wise model.

Also collapse the randn and randexp test sections into shared loops.
The two distributions agree on every property tested (typed/untyped
surfaces, in-kernel-seed match, host basics, determinism, T-coverage,
etc.) — only the per-bin probabilities, mean, and in-range predicate
differ. Shared `bin_counts` + a `RAND_DISTS` table replace ~250 lines
of duplicated testset bodies. The rand testset stays separate since
its multi-stream / control-flow tests are unique to it.
@maleadt maleadt marked this pull request as ready for review April 27, 2026 18:43
[ci skip]
@maleadt maleadt merged commit cb51c36 into main Apr 27, 2026
@maleadt maleadt deleted the tb/random branch April 27, 2026 18:45
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.

1 participant