Skip to content

[CUB] Refactor cub::DeviceSelect::If to always take an environment - #9456

Merged
miscco merged 1 commit into
mainfrom
device_select_env
Jun 25, 2026
Merged

miscco merged 1 commit into
mainfrom
device_select_env

Conversation

@miscco

@miscco miscco commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Description

closes

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@copy-pr-bot

copy-pr-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Progress in CCCL Jun 15, 2026
@miscco
miscco force-pushed the device_select_env branch from a0bb633 to ff89356 Compare June 15, 2026 08:28
@miscco
miscco force-pushed the device_select_env branch 2 times, most recently from 5042f64 to fcd3004 Compare June 15, 2026 09:19
@miscco
miscco force-pushed the device_select_env branch from fcd3004 to ae24f0a Compare June 15, 2026 12:38
@github-project-automation github-project-automation Bot moved this from In Progress to In Review in CCCL Jun 15, 2026
@miscco
miscco force-pushed the device_select_env branch from ae24f0a to bcd1fd6 Compare June 16, 2026 10:49
Base automatically changed from device_select_flagged to main June 22, 2026 10:17
@miscco
miscco force-pushed the device_select_env branch from bcd1fd6 to a8906a9 Compare June 22, 2026 10:17
@copy-pr-bot

copy-pr-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@miscco
miscco marked this pull request as ready for review June 22, 2026 10:17
@miscco
miscco requested review from a team as code owners June 22, 2026 10:17
@miscco
miscco requested review from pauleonix and wmaxey June 22, 2026 10:17
@coderabbitai

coderabbitai Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 433ab92b-629f-4049-88b2-ade305e0df8b

📥 Commits

Reviewing files that changed from the base of the PR and between 55d861f and 1749bea.

📒 Files selected for processing (6)
  • cub/cub/device/device_select.cuh
  • cub/test/catch2_test_device_select_if.cu
  • libcudacxx/include/cuda/std/__pstl/cuda/copy_if.h
  • libcudacxx/include/cuda/std/__pstl/cuda/remove_if.h
  • libcudacxx/test/libcudacxx/std/algorithms/alg.modifying/alg.remove/pstl_remove.cu
  • libcudacxx/test/libcudacxx/std/algorithms/alg.modifying/alg.remove/pstl_remove_copy.cu
🚧 Files skipped from review as they are similar to previous changes (4)
  • libcudacxx/include/cuda/std/__pstl/cuda/remove_if.h
  • libcudacxx/include/cuda/std/__pstl/cuda/copy_if.h
  • cub/test/catch2_test_device_select_if.cu
  • cub/cub/device/device_select.cuh

Note: CodeRabbit is enabled on this repository as a convenience for maintainers
and contributors. Use your best judgment when considering its review comments and
suggestions — a suggested change may be inadequate, unnecessary, or safe to ignore.
Contributors are not expected to address every comment. Human reviews are what
ultimately matter for merging.

Overview

This pull request refactors cub::DeviceSelect::If to consistently take an explicit execution environment (env) instead of stream-based execution, so policy/tuning can be propagated through CUB’s dispatch machinery.

Changes by File

Core API Changes: cub/cub/device/device_select.cuh

  • Updated environment-based If overloads to take env by const-reference (const EnvT& env = {}) instead of pass-by-value (EnvT env = {}) for overloads without user-provided temp storage.
  • Replaced stream-based device-storage overloads with environment-based overloads:
    • Removed cudaStream_t stream = nullptr
    • Added EnvT template parameter and const EnvT& env = {}
  • Updated implementations to route through detail::dispatch_with_env_and_tuning using the provided env, and to dispatch detail::select::dispatch using the stream obtained internally (rather than threading a cudaStream_t argument directly).

Lines changed: +67/-42

Tests: cub/test/catch2_test_device_select_if.cu

  • Added CUDA includes needed for execution/environment coverage:
    • <cuda/devices>
    • <cuda/std/execution>
  • Added a new #if TEST_LAUNCH == 0 block with two C2H_TEST cases:
    • DeviceSelect::If works with user provided memory and environment
    • DeviceSelect::If works in place with user provided memory and environment
  • The tests validate sizing with nullptr temp storage, then re-run with user-provided temp storage across multiple execution environment variants (e.g., stream/stream-ref and cuda::std::execution / cuda::execution forms), and check both the selected prefix correctness and that the remainder is unchanged.

Lines changed: +185/-0

libcudacxx PSTL Integration: libcudacxx/include/cuda/std/__pstl/cuda/copy_if.h

  • Updated __pstl_cuda_select_if to match the new CUB env-based DeviceSelect::If API:
    • Uses DeviceSelect::If(..., nullptr, __policy) for device-storage sizing (no explicit stream passed)
    • Switches temp-storage pointer plumbing from __get_ptr<0>() to __get_raw_ptr<0>()
    • Uses __policy instead of passing a stream handle into CUB during the kernel-launch path

Lines changed: +6/-7

libcudacxx PSTL Integration: libcudacxx/include/cuda/std/__pstl/cuda/remove_if.h

  • Applied the same __pstl_cuda_select_if updates as in copy_if:
    • Passes __policy (not a stream handle) to DeviceSelect::If
    • Switches temp-storage pointer usage to __storage.__get_raw_ptr<0>()

Lines changed: +6/-7

libcudacxx Test Fixups (GCC < 8)

  • libcudacxx/test/libcudacxx/std/algorithms/alg.modifying/alg.remove/pstl_remove.cu
    • Guarded the equality-comparability/converting-value remove test cases with #if !TEST_COMPILER(GCC, <, 8).
  • libcudacxx/test/libcudacxx/std/algorithms/alg.modifying/alg.remove/pstl_remove_copy.cu
    • Guarded the corresponding remove_copy converting-value test block with #if !TEST_COMPILER(GCC, <, 8).

Lines changed (each): +2/-0

Impact

All cub::DeviceSelect::If call sites that previously relied on the stream-based device-storage overloads must be updated to pass an appropriate execution environment (env) instead. The change also ensures CUB’s dispatch/tuning path consistently receives the environment/policy.

Walkthrough

DeviceSelect::If now uses env-based dispatch for device-storage overloads and const env references for env-based overloads. libcudacxx PSTL calls switch to policy-based dispatch and raw storage pointers. Tests add multi-environment coverage for user-provided temp storage.

Changes

DeviceSelect::If environment API migration

Layer / File(s) Summary
API and docs updates
cub/cub/device/device_select.cuh
Environment-based overloads change to const EnvT&, and device-storage overloads add EnvT template parameters and matching documentation.
Out-of-place device-storage dispatch
cub/cub/device/device_select.cuh
The out-of-place device-storage overload removes direct stream dispatch and routes through dispatch_with_env_and_tuning before calling detail::select::dispatch from the lambda.
In-place device-storage dispatch
cub/cub/device/device_select.cuh
The potentially in-place device-storage overload removes the stream parameter, adds EnvT plus const EnvT& env, and dispatches through dispatch_with_env_and_tuning to the in-place detail::select::dispatch variant.
PSTL call site updates
libcudacxx/include/cuda/std/__pstl/cuda/copy_if.h, libcudacxx/include/cuda/std/__pstl/cuda/remove_if.h
Sizing calls pass nullptr and __policy; kernel launches use __get_raw_ptr<0>() and pass __policy instead of __stream.get().
User-provided storage tests
cub/test/catch2_test_device_select_if.cu
The test file adds execution-environment includes and two guarded cases covering out-of-place and in-place user-provided storage across multiple environment variants with partition checks.

Suggested reviewers

  • bernhardmgruber
  • elstehle

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

@miscco

miscco commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@copy-pr-bot

copy-pr-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

/ok to test

@miscco, there was an error processing your request: E1

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/1/

@miscco

miscco commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@copy-pr-bot

copy-pr-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

/ok to test

@miscco, there was an error processing your request: E1

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/1/

@miscco
miscco force-pushed the device_select_env branch from a8906a9 to b5e4e2c Compare June 22, 2026 11:15
@miscco

miscco commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@copy-pr-bot

copy-pr-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

/ok to test

@miscco, there was an error processing your request: E1

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/1/

@miscco
miscco force-pushed the device_select_env branch from b5e4e2c to f7de38f Compare June 22, 2026 11:20
@github-actions

This comment has been minimized.

@miscco
miscco force-pushed the device_select_env branch from f7de38f to 68d34fa Compare June 23, 2026 07:21
@github-actions

This comment has been minimized.

@miscco
miscco force-pushed the device_select_env branch from 68d34fa to 55d861f Compare June 25, 2026 08:26

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
cub/test/catch2_test_device_select_if.cu (1)

183-187: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: declare immutable locals as const (le, pointer aliases, temp-storage pointer aliases) to match CCCL const-correctness rules in C++/CUDA files.

As per coding guidelines, “All variables that are not modified must be declared const...”

Also applies to: 202-203, 277-281, 290-291

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 1a214b9a-3480-465a-8e7f-c9ecc5e1bd4d

📥 Commits

Reviewing files that changed from the base of the PR and between 68d34fa and 55d861f.

📒 Files selected for processing (4)
  • cub/cub/device/device_select.cuh
  • cub/test/catch2_test_device_select_if.cu
  • libcudacxx/include/cuda/std/__pstl/cuda/copy_if.h
  • libcudacxx/include/cuda/std/__pstl/cuda/remove_if.h
🚧 Files skipped from review as they are similar to previous changes (3)
  • libcudacxx/include/cuda/std/__pstl/cuda/remove_if.h
  • libcudacxx/include/cuda/std/__pstl/cuda/copy_if.h
  • cub/cub/device/device_select.cuh

Comment on lines +307 to +309
const auto boundary = in.begin() + num_selected_out[0];
REQUIRE(thrust::all_of(c2h::device_policy, in.begin(), boundary, le));
};

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

important: the in-place test assertion is too weak and can miss wrong num_selected_out/boundary results. Add a reference count (or host-side expected partition boundary) and assert num_selected_out[0] matches it before validating the prefix.

As per path instructions, “Focus on algorithm correctness ... and test coverage.”

Source: Path instructions

We want to be able to pass tunings to the APIs that take user provided memory

Make sure we can pass any environment or stream type to them
@miscco
miscco force-pushed the device_select_env branch from 55d861f to 1749bea Compare June 25, 2026 11:01
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 3h 21m: Pass: 100%/345 | Total: 6d 02h | Max: 1h 25m | Hits: 99%/497513

See results here.

@miscco
miscco merged commit 7a72681 into main Jun 25, 2026
719 of 725 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Jun 25, 2026
@miscco
miscco deleted the device_select_env branch June 25, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants