Skip to content

Add dpnp.random.Generator on the oneMKL device RNG API - #3157

Open
ndgrigorian wants to merge 1 commit into
masterfrom
feature/device-rng-generator
Open

ndgrigorian wants to merge 1 commit into
masterfrom
feature/device-rng-generator

Conversation

@ndgrigorian

@ndgrigorian ndgrigorian commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

This PR is the first of a series splitting #3147 into smaller pieces. It adds the new framework for device-side random number generation and NumPy's Generator API, with only the base distributions

The new dpnp.libtensor._rng_impl extension samples on the device using the oneMKL device RNG API (header-only, so no oneMKL RNG library is linked). A bit generator keeps its state on the host, and each kernel launch rebuilds its engines from that state, so sampling never waits on the device and the values depend only on the seed and the output size, not on the device

Adds

  • dpnp.random.Generator with random, uniform, standard_normal, normal and spawn, and default_rng
  • dpnp.random.BitGenerator (with random_raw, spawn, state and lock), SeedSequence (NumPy's) and the Philox4x3210 bit generator on oneMKL's device philox4x32x10
  • Strided and blocked sample layouts; the blocked layout generates the words of a work-item in one engine call and is used on GPUs, giving the same values

The legacy RandomState and the module-level functions are untouched until later in the series

Series:

  1. Add dpnp.random.Generator on the oneMKL device RNG API #3157 (this PR): framework, Philox4x3210 and the base distributions
  2. Add continuous distributions to dpnp.random.Generator #3158: Continuous distributions
  3. Add discrete distributions to dpnp.random.Generator #3159: Discrete distributions
  4. Add multivariate distributions and permutations to dpnp.random.Generator #3160: Multivariate distributions and permutations
  5. Add PCG64DXSM and MRG32k3a bit generators to dpnp.random #3161: PCG64DXSM and MRG32k3a bit generators
  6. Reimplement dpnp.random.RandomState on the device RNG #3162: RandomState and the module functions on the device RNG
  7. Remove the legacy backend RNG #3163: Removal of the legacy backend RNG
  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

Add the dpnp.libtensor._rng_impl extension, which samples on the device
from oneMKL's device philox4x32x10 engine, and the Generator API of
NumPy on top of it: BitGenerator, Philox4x3210, SeedSequence (NumPy's),
default_rng, and the random, uniform, standard_normal and normal methods.

A bit generator keeps its state on the host and every launch rebuilds
its engines from it, so the values depend only on the seed and the
output size, not on the device. The legacy RandomState and module
functions are unchanged.
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/3157/index.html

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.22.0dev0=np2py314h8d9cdd5_27 ran successfully.
Passed: 1491
Failed: 0
Skipped: 6

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 84.209% (-0.2%) from 84.396% — feature/device-rng-generator into master

This branch has not been deployed

No deployments
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.

2 participants