Skip to content

Use CCCL random for device PRNG draws - #8243

Closed
RAMitchell wants to merge 3 commits into
NVIDIA:mainfrom
RAMitchell:codex/cccl-philox-prng
Closed

Use CCCL random for device PRNG draws#8243
RAMitchell wants to merge 3 commits into
NVIDIA:mainfrom
RAMitchell:codex/cccl-philox-prng

Conversation

@RAMitchell

Copy link
Copy Markdown
Contributor

Start on #8242

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR begins migrating cuML device-side PRNG usage from RAFT/curand-based implementations to CCCL (cuda::std::random), simplifying kernels and moving toward removing curand dependencies (per #8242).

Changes:

  • Replaced RAFT Philox-based integer draws in UMAP optimization kernels with cuda::std::philox4x64 + cuda::std::uniform_int_distribution.
  • Replaced curand usage in KernelSHAP sampling with CCCL random utilities.
  • Replaced RAFT RNG utilities in decision tree sampling kernels and quantile sampling with CCCL random utilities; removed a direct <curand.h> include from UMAP algo header.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cpp/src/umap/simpl_set_embed/optimize_inverse_kernel.cuh Switch negative sampling RNG to cuda::std::random.
cpp/src/umap/simpl_set_embed/optimize_batch_kernel.cuh Switch multiple negative-sampling codepaths to cuda::std::random.
cpp/src/umap/simpl_set_embed/algo.cuh Remove unused curand include.
cpp/src/genetic/genetic.cu Switch tournament selection RNG draws to cuda::std::random.
cpp/src/explainer/kernel_shap.cu Replace curand-based sampling with cuda::std::random.
cpp/src/decisiontree/batched-levelalgo/quantiles.cuh Replace RAFT RNG-based row sampling with cuda::std::random.
cpp/src/decisiontree/batched-levelalgo/kernels/builder_kernels.cuh Replace RAFT RNG utilities with cuda::std::random for feature sampling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cpp/src/decisiontree/batched-levelalgo/kernels/builder_kernels.cuh Outdated
@RAMitchell RAMitchell added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Jun 9, 2026
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 084d6749-0889-468e-acfc-05102cb6d912

📥 Commits

Reviewing files that changed from the base of the PR and between b7703c2 and 0524e20.

📒 Files selected for processing (1)
  • python/cuml/tests/test_random_forest.py

📝 Walkthrough

Summary by CodeRabbit

  • Refactor
    • Modernized device-side random sampling across multiple components to use CUDA C++ standard RNGs; preserved existing behavior and public interfaces.
  • Tests
    • Relaxed tolerance in a random-forest convergence test (slightly higher deviance tolerance) to reduce flaky failures.

Walkthrough

Device-side RNGs in decision tree, explainer, genetic, and UMAP CUDA kernels were migrated from RAFT/CURAND to CUDA C++ cuda::std::philox4x64 engines with cuda::std::uniform_*_distribution draws; headers updated. A Python test tolerance was relaxed. No public APIs changed.

Changes

RNG Implementation Modernization

Layer / File(s) Summary
Includes and header cleanup
cpp/src/decisiontree/batched-levelalgo/kernels/builder_kernels.cuh, cpp/src/decisiontree/batched-levelalgo/quantiles.cuh, cpp/src/explainer/kernel_shap.cu, cpp/src/genetic/genetic.cu, cpp/src/umap/simpl_set_embed/algo.cuh, cpp/src/umap/simpl_set_embed/optimize_batch_kernel.cuh, cpp/src/umap/simpl_set_embed/optimize_inverse_kernel.cuh
Removed RAFT/CURAND device RNG includes and added CUDA C++ standard-library RNG headers (cuda/std/array, cuda/std/random) where needed.
Decision tree builder sampling
cpp/src/decisiontree/batched-levelalgo/kernels/builder_kernels.cuh
excess_sample_with_replacement_kernel, algo_L_sample_kernel, adaptive_sample_kernel now initialize cuda::std::philox4x64 (seed + counter subsequence) and use cuda::std::uniform_real_distribution/cuda::std::uniform_int_distribution for draws.
Decision tree quantiles sampling
cpp/src/decisiontree/batched-levelalgo/quantiles.cuh
sampleOwnedColumnsKernel replaced RAFT PCGenerator + custom_next with cuda::std::philox4x64 (seed + sample_idx counter) and cuda::std::uniform_int_distribution to pick global_row.
Explainer SHAP sampling
cpp/src/explainer/kernel_shap.cu
sampled_rows_kernel migrated from CURAND to cuda::std::philox4x64 keyed by tid and cuda::std::uniform_int_distribution for index selection; collision-avoidance loop preserved.
Genetic tournament kernel
cpp/src/genetic/genetic.cu
batched_tournament_kernel now uses cuda::std::philox4x64 (seed + counter) and cuda::std::uniform_int_distribution<int> to sample candidate indices instead of PhiloxGenerator::next() + modulo.
UMAP optimize batch & sequential kernels
cpp/src/umap/simpl_set_embed/optimize_batch_kernel.cuh
Negative-sampling RNG sites switched to cuda::std::philox4x64 seeded by seed with counters from row/e, sampling t via cuda::std::uniform_int_distribution<int> instead of modulus.
UMAP optimize inverse kernel
cpp/src/umap/simpl_set_embed/optimize_inverse_kernel.cuh
Negative vertex sampling replaced RAFT Philox + modulus with cuda::std::philox4x64 countered by row and uniform int draws in [0, n_vertices-1].
Python test
python/cuml/tests/test_random_forest.py
test_tweedie_convergence tolerance deviance_tolerance increased from 1e-5 to 1e-4.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • rapidsai/cuml#8190: Overlaps on decisiontree/batched-levelalgo/quantiles.cuh sampling logic changes.
  • rapidsai/cuml#8111: Related edits to deterministic uniform row/index sampling in decision tree quantiles.

Suggested reviewers

  • aamijar
  • jcrist
  • csadorf
  • KyleFromNVIDIA
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Use CCCL random for device PRNG draws' directly and accurately summarizes the main change: replacing RAFT/CURAND RNG with CUDA C++ standard library (CCCL) random number generators across multiple device kernels.
Description check ✅ Passed The description 'Start on #8242' is related to the changeset as it references the parent issue tracking this work, though it provides minimal detail about the actual changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cpp/src/decisiontree/batched-levelalgo/kernels/builder_kernels.cuh`:
- Around line 303-304: The uniform_real_distribution uniform01 currently allows
0.0f which can make fp_uniform_val==0 and produce inf/NaN in
algo_L_sample_kernel when computing raft::log(fp_uniform_val) and subsequent
W/log(1-W) math; fix by ensuring fp_uniform_val is strictly positive before any
raft::log call (either initialize uniform01 with a positive lower bound like
std::numeric_limits<float>::min() or clamp fp_uniform_val = max(fp_uniform_val,
eps) immediately before using it), and apply the same guard before computing W
and any raft::log(1 - W) to avoid divide-by-zero/NaN propagation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 834f5f1a-f7c1-4df6-9312-500966d51eb9

📥 Commits

Reviewing files that changed from the base of the PR and between 6956326 and 9112586.

📒 Files selected for processing (7)
  • cpp/src/decisiontree/batched-levelalgo/kernels/builder_kernels.cuh
  • cpp/src/decisiontree/batched-levelalgo/quantiles.cuh
  • cpp/src/explainer/kernel_shap.cu
  • cpp/src/genetic/genetic.cu
  • cpp/src/umap/simpl_set_embed/algo.cuh
  • cpp/src/umap/simpl_set_embed/optimize_batch_kernel.cuh
  • cpp/src/umap/simpl_set_embed/optimize_inverse_kernel.cuh
💤 Files with no reviewable changes (1)
  • cpp/src/umap/simpl_set_embed/algo.cuh

Comment thread cpp/src/decisiontree/batched-levelalgo/kernels/builder_kernels.cuh Outdated
@RAMitchell
RAMitchell force-pushed the codex/cccl-philox-prng branch from 98a18ff to b7703c2 Compare June 9, 2026 12:48
@RAMitchell
RAMitchell requested a review from a team as a code owner June 10, 2026 11:33
@RAMitchell
RAMitchell requested a review from csadorf June 10, 2026 11:33
@github-actions github-actions Bot added the Cython / Python Cython or Python issue label Jun 10, 2026
static_cast<int>(T(epoch - _epoch_of_next_negative_sample) / epochs_per_negative_sample);

raft::random::detail::PhiloxGenerator gen(seed, static_cast<nnz_t>(e), 0);
cuda::std::philox4x64 rng(static_cast<cuda::std::philox4x64::result_type>(seed));

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.

Please wrap this in raft insted of invoking CCCL durectly here.

@RAMitchell RAMitchell closed this Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA/C++ Cython / Python Cython or Python issue improvement Improvement / enhancement to an existing function non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants