Fix RNG type in mtgp32 uniform cuRAND example - #365
Open
jamespud wants to merge 2 commits into
Open
Conversation
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 SummaryThe PR aligns three cuRAND samples’ generator types with the algorithms advertised by their directories and filenames.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Reviews (2): Last reviewed commit: "Fix RNG types in Poisson cuRAND examples" | Re-trigger Greptile |
dorispnvidia
left a comment
Collaborator
There was a problem hiding this comment.
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>
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). |
JanuszL
approved these changes
Aug 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
cuRAND/Host/mtgp32/curand_mtgp32_uniform_example.cppCURAND_RNG_PSEUDO_MRG32K3AcuRAND/Host/mtgp32/curand_mtgp32_poisson_example.cppCURAND_RNG_PSEUDO_MT19937cuRAND/Host/scrambled_sobol32/curand_scrambled_sobol32_poisson_example.cppCURAND_RNG_QUASI_SCRAMBLED_SOBOL64Why 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_poissonchange 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 therngvariable inmain().curand_mtgp32_uniform_example.cpp:MRG32K3A→CURAND_RNG_PSEUDO_MTGP32curand_mtgp32_poisson_example.cpp:MT19937→CURAND_RNG_PSEUDO_MTGP32curand_scrambled_sobol32_poisson_example.cpp:SOBOL64→CURAND_RNG_QUASI_SCRAMBLED_SOBOL32This matches the sibling examples (
curand_mtgp32_normal_example.cpp,curand_mtgp32_lognormal_example.cpp, and the otherscrambled_sobol32samples), which already use the correct generator type in the same three places.Testing
mtgp32examples and thescrambled_sobol32_poissonexample build and run with matching host and device output.