Skip to content

Fix RNG type in mtgp32 uniform cuRAND example - #365

Open
jamespud wants to merge 2 commits into
NVIDIA:mainfrom
jamespud:codex/fix-mtgp32-uniform-rng
Open

Fix RNG type in mtgp32 uniform cuRAND example#365
jamespud wants to merge 2 commits into
NVIDIA:mainfrom
jamespud:codex/fix-mtgp32-uniform-rng

Conversation

@jamespud

@jamespud jamespud commented Aug 13, 2026

Copy link
Copy Markdown

Fixes #146

Summary

Three cuRAND Host API examples create a generator type that does not match the generator they are documented to demonstrate. Each one runs without error because the substituted generator is valid for the requested distribution, but the mismatch is invisible at runtime and silently misleads anyone who copies the example.

File Documented generator Was using
cuRAND/Host/mtgp32/curand_mtgp32_uniform_example.cpp MTGP32 CURAND_RNG_PSEUDO_MRG32K3A
cuRAND/Host/mtgp32/curand_mtgp32_poisson_example.cpp MTGP32 CURAND_RNG_PSEUDO_MT19937
cuRAND/Host/scrambled_sobol32/curand_scrambled_sobol32_poisson_example.cpp scrambled Sobol32 CURAND_RNG_QUASI_SCRAMBLED_SOBOL64

Why this is a bug

The documented intent comes from three places for every file: the file name, the folder README (e.g. "generate MTGP32 pseudorandom generated numbers"), and the cuRAND index (e.g. "uniform mtgp32 pseudorandom generation using Host API"). Because the wrongly used generators are still valid and produce the same distribution shape, the samples build and run cleanly — this is the same class of issue as #146, where the maintainer asked "MRG32K3A is a valid generator type, what is the issue?" and the reporter had to clarify that the sample is named mtgp32.

The mtgp32_poisson change was requested in the review of this PR.

Change

For each file, all three generator-construction sites are updated consistently: the device path (curandCreateGenerator), the host path (curandCreateGeneratorHost), and the rng variable in main().

  • curand_mtgp32_uniform_example.cpp: MRG32K3ACURAND_RNG_PSEUDO_MTGP32
  • curand_mtgp32_poisson_example.cpp: MT19937CURAND_RNG_PSEUDO_MTGP32
  • curand_scrambled_sobol32_poisson_example.cpp: SOBOL64CURAND_RNG_QUASI_SCRAMBLED_SOBOL32

This matches the sibling examples (curand_mtgp32_normal_example.cpp, curand_mtgp32_lognormal_example.cpp, and the other scrambled_sobol32 samples), which already use the correct generator type in the same three places.

Testing

  • Built with CUDA 13.2 on Linux x86_64.
  • Ran on NVIDIA GeForce RTX 4060 Laptop GPU (sm_89).
  • All four mtgp32 examples and the scrambled_sobol32_poisson example build and run with matching host and device output.
  • Before the change, the SOBOL64 + Poisson combination was run as a baseline to confirm the quasi-random + Poisson path is supported.

The mtgp32 uniform example is advertised as demonstrating the MTGP32 host API (by its file name, folder README, and the cuRAND index), but it created an MRG32K3A generator instead. MRG32K3A is a valid generator and also produces uniform floats, so the sample runs without error and the mismatch is easy to miss. However, anyone copying this example to learn the MTGP32 API silently gets the wrong generator.

The sibling normal and lognormal examples already use CURAND_RNG_PSEUDO_MTGP32 in the same three places, so this change makes the uniform example consistent with them and with its documented purpose.

Fixes NVIDIA#146

Signed-off-by: spud <92900806+jamespud@users.noreply.github.com>
@greptile-apps

greptile-apps Bot commented Aug 13, 2026

Copy link
Copy Markdown

Greptile Summary

The PR aligns three cuRAND samples’ generator types with the algorithms advertised by their directories and filenames.

  • Changes the MTGP32 uniform sample from MRG32K3A to MTGP32.
  • Changes the MTGP32 Poisson sample from MT19937 to MTGP32.
  • Changes the scrambled Sobol32 Poisson sample from scrambled Sobol64 to scrambled Sobol32.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
cuRAND/Host/mtgp32/curand_mtgp32_poisson_example.cpp Updates device, host, and main generator-type constants to MTGP32 without introducing a supported-path failure.
cuRAND/Host/mtgp32/curand_mtgp32_uniform_example.cpp Replaces MRG32K3A with MTGP32 consistently across both execution paths and the main configuration.
cuRAND/Host/scrambled_sobol32/curand_scrambled_sobol32_poisson_example.cpp Corrects all three generator-type constants to scrambled Sobol32 while preserving valid dimensions, offset, and output handling.

Reviews (2): Last reviewed commit: "Fix RNG types in Poisson cuRAND examples" | Re-trigger Greptile

@dorispnvidia dorispnvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you also add the changes to curand_mtgp32_poisson_example.cpp please? It looks like the wrong generator is also used in this file. Thanks.

The mtgp32 Poisson example used MT19937 and the scrambled_sobol32 Poisson example used SOBOL64, while both samples are documented as demonstrating MTGP32 and scrambled Sobol32 respectively. This is the same class of issue as the mtgp32 uniform example fixed earlier in this PR: the substituted generator is valid and produces the requested distribution, so the sample runs without error while silently demonstrating the wrong generator type.

Each file has the three generator-construction sites updated consistently: the device path, the host path, and the rng variable in main(). The mtgp32 change was requested in the maintainer review of this PR.

Verified with CUDA 13.2 on an RTX 4060 Laptop GPU (sm_89): both examples build and run with matching host and device output.

Signed-off-by: spud <92900806+jamespud@users.noreply.github.com>
@jamespud

Copy link
Copy Markdown
Author

Thanks @dorispnvidia — added the MTGP32 fix to curand_mtgp32_poisson_example.cpp, and while scanning the family I also fixed the same class of bug in curand_scrambled_sobol32_poisson_example.cpp (SOBOL64 → SOBOL32).

@dorispnvidia dorispnvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CURAND_RNG_PSEUDO_MRG32K3A in curand_mtgp32_uniform_example.cpp

3 participants