Skip to content

Add PCG64DXSM and MRG32k3a bit generators to dpnp.random - #3161

Open
ndgrigorian wants to merge 17 commits into
feature/device-rng-multivariatefrom
feature/device-rng-bit-generators
Open

ndgrigorian wants to merge 17 commits into
feature/device-rng-multivariatefrom
feature/device-rng-bit-generators

Conversation

@ndgrigorian

@ndgrigorian ndgrigorian commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

This PR adds two more bit generators to dpnp.random, as part of the series splitting #3147. It is stacked on #3160

  • PCG64DXSM, a custom engine (oneMKL's pcg64_dxsm has a hard-coded increment) that is bit-identical with NumPy's for random_raw, random (f32/f64), uniform and bytes, and exchanges states with numpy.random.PCG64DXSM. The samplers taking a fixed number of draws per element use a new sequential layout, which reproduces NumPy's stream order; the others give work-item w the stream of NumPy's jumped(w)
  • MRG32k3a, on oneMKL's device mrg32k3a, where work-item w draws from substream w. Each work-item produces 128 elements, since moving to a substream costs a matrix product per digit, and 8 elements per work-item were 2x (GPU) to 10x (CPU) slower than Philox

items_per_work_item is now a per-engine trait, exposed to Python as _rng_impl.items_per_work_item

  • 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?

@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-multivariate branch from be00c84 to 742674f Compare November 4, 2026 19:47
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-bit-generators branch 2 times, most recently from 3565820 to e06fd8c Compare November 4, 2026 19:50
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-multivariate branch from 742674f to 9c726f8 Compare November 4, 2026 19:50
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/3161/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.0dev2=np2py314h8d9cdd5_98 ran successfully.
Passed: 1491
Failed: 0
Skipped: 6

@coveralls

coveralls commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Status

Coverage is 84.783% — feature/device-rng-bit-generators into feature/device-rng-multivariate. No base build found for feature/device-rng-multivariate.

@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-multivariate branch from 9c726f8 to 2c9b5f0 Compare November 6, 2026 17:55
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-bit-generators branch from e06fd8c to c5182f4 Compare November 6, 2026 17:55
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-multivariate branch from bf0b546 to 9dab4d3 Compare November 8, 2026 21:54
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-bit-generators branch from acc7ffe to 25ebfd8 Compare November 8, 2026 21:54
Comment thread dpnp/random/_bit_generator.py Resolved
Comment thread dpnp/random/_bit_generator.py Resolved
Comment thread dpnp/random/_bit_generator.py Resolved
Comment thread dpnp/random/_bit_generator.py Resolved
Comment thread dpnp/random/_bit_generator.py Resolved
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-bit-generators branch from 25ebfd8 to ed4d347 Compare November 13, 2026 20:06
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-multivariate branch from 9dab4d3 to ebeb60b Compare November 13, 2026 20:06
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-bit-generators branch from ed4d347 to a59e76d Compare November 13, 2026 22:41
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-multivariate branch 2 times, most recently from 9b8329f to f8e50e8 Compare November 16, 2026 15:57
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-bit-generators branch from a59e76d to a04ffb8 Compare November 16, 2026 15:57
Comment thread dpnp/random/_bit_generator.py Resolved
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-multivariate branch from f8e50e8 to c91c3c8 Compare November 17, 2026 21:13
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-bit-generators branch from a04ffb8 to 8694043 Compare November 17, 2026 21:13

@vlad-perevezentsev vlad-perevezentsev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the new changes on GPU and CPU here, on an Alder Lake iGPU without fp64, on Windows with an Arc GPU, and with free-threaded Python 3.14t: the streams match everywhere, threads are safe, and the earlier comments are fixed. But the new test_state_errors fails on Linux with Python 3.13 and newer, see below.

Comment thread dpnp/random/_bit_generator.py Resolved
Comment thread dpnp/random/_bit_generator.py Resolved
PCG64DXSM is a custom engine bit-identical with NumPy's for raw values,
random, uniform and bytes, drawn in a sequential layout for the samplers
taking a fixed number of draws. MRG32k3a uses oneMKL's device engine,
with work-item w on substream w.

sycl::mul_hi is replaced with a limb-based umul_hi, as DPC++ 2026.2
miscompiles it on Intel GPUs.
Use the dpnp.empty text for their device and sycl_queue, add the
reference line to PCG64DXSM, list its advance and jumped methods in
the docs, and make the thread of their lock test a daemon.
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-bit-generators branch from 8694043 to eef4522 Compare November 20, 2026 01:26
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-multivariate branch from c91c3c8 to fb583eb Compare November 20, 2026 01:26

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.

3 participants