Skip to content

[CUB] Refactor DeviceSelect::Flagged to always take an environment - #9455

Merged
miscco merged 1 commit into
mainfrom
device_select_flagged
Jun 22, 2026
Merged

miscco merged 1 commit into
mainfrom
device_select_flagged

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_flagged branch 4 times, most recently from 412d7d7 to ddfaf0b Compare June 15, 2026 12:38
@miscco
miscco marked this pull request as ready for review June 15, 2026 18:02
@miscco
miscco requested review from a team as code owners June 15, 2026 18:02
@cccl-authenticator-app cccl-authenticator-app Bot moved this from In Progress to In Review in CCCL Jun 15, 2026
@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

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: 797b8e27-c7b9-4e3f-be4f-e4fe5c60d53b

📥 Commits

Reviewing files that changed from the base of the PR and between ddfaf0b and c37c1c1.

📒 Files selected for processing (3)
  • cub/cub/device/device_select.cuh
  • cub/test/catch2_test_device_select_flagged.cu
  • libcudacxx/include/cuda/std/__pstl/cuda/shift_left.h
🚧 Files skipped from review as they are similar to previous changes (3)
  • libcudacxx/include/cuda/std/__pstl/cuda/shift_left.h
  • cub/test/catch2_test_device_select_flagged.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 PR refactors cub::DeviceSelect::Flagged (and the in-place overload) to require an execution environment parameter consistently, enabling tuning/config propagation through APIs that accept user-provided temporary storage.

Key Changes

API Refactoring

cub::DeviceSelect::Flagged now uses environment-based dispatch instead of stream-based dispatch:

  • Temp-storage overloads: removed the cudaStream_t parameter and replaced it with const EnvT& env = {} (with typename EnvT = ::cuda::std::execution::env<>), routing through detail::dispatch_with_env_and_tuning to select a policy and dispatch to the appropriate detail::select::dispatch path.
  • Non-temp-storage overloads (out-of-place and in-place): changed the environment parameter from pass-by-value (EnvT env = {}) to pass-by-reference (const EnvT& env = {}).
  • Documentation: updated/added Doxygen parameter documentation for EnvT.

Test Coverage

Added coverage in cub/test/catch2_test_device_select_flagged.cu to validate behavior with user-provided temp storage across multiple environment variants. The test:

  • Computes expected_allocation_size by calling Flagged with nullptr temp storage,
  • Allocates exactly that temp size,
  • Re-calls Flagged per environment variant and checks CUDA status, allocation-size consistency, num_selected_out, and output values against a host reference.

Environment variants covered include: cudaStream_t, cuda::stream, cuda::stream_ref, cuda::std::execution::env, cuda::execution::gpu, and cuda::execution::gpu with an attached stream.

Downstream Updates

Updated libcudacxx/include/cuda/std/__pstl/cuda/shift_left.h to match the new API:

  • Passes the execution policy (__policy) instead of the raw CUDA stream,
  • Uses the updated temp-storage pointer accessor (__get_raw_ptr),
  • Passes __policy into the DeviceSelect::Flagged calls.

Metrics

  • Code changes: +161 / -44 lines across three files
  • Review effort: High (public API signature + template parameter changes)

Walkthrough

cub::DeviceSelect::Flagged and its in-place variant transition their temp-storage overloads from cudaStream_t-based dispatch to const EnvT&-based dispatch routed through detail::dispatch_with_env_and_tuning. Non-temp-storage overloads fix EnvT by-value to const EnvT&. The shift_left PSTL callsite is updated to match. New tests cover all environment/dispatch variants.

Changes

Environment-based dispatch for DeviceSelect::Flagged

Layer / File(s) Summary
Flagged API signature and docs
cub/cub/device/device_select.cuh
Adds typename EnvT = ::cuda::std::execution::env<> template parameters and const EnvT& env = {} to both Flagged temp-storage overloads; fixes non-temp-storage overloads from EnvT by-value to const EnvT&; adds Doxygen for EnvT in both overload groups.
Flagged env-based dispatch implementation
cub/cub/device/device_select.cuh
Replaces stream-based dispatch bodies in both Flagged temp-storage overloads with environment-based flows using detail::dispatch_with_env_and_tuning and a policy selector.
shift_left PSTL callsite update
libcudacxx/include/cuda/std/__pstl/cuda/shift_left.h
Updates DeviceSelect::Flagged invocations to pass __policy instead of __stream.get() and switches temp-storage accessor to __get_raw_ptr<0>().
Multi-environment Flagged tests
cub/test/catch2_test_device_select_flagged.cu
Adds cuda/devices and cuda/std/execution headers and a TEST_LAUNCH == 0 block validating Flagged with user-supplied temp storage across cudaStream_t, cuda::stream, cuda::stream_ref, cuda::std::execution::env, cuda::execution::gpu, and cuda::execution::gpu with attached stream.

Possibly related PRs

  • NVIDIA/cccl#9316: Directly related — introduces SelectPolicy/PartitionPolicy tuning-policy machinery and public dispatch changes in DeviceSelect/DevicePartition that this PR builds upon when routing Flagged through dispatch_with_env_and_tuning.

Suggested reviewers

  • gevtushenko
  • gonidelis
  • davebayer

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

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

🧹 Nitpick comments (3)
cub/test/catch2_test_device_select_flagged.cu (3)

233-251: ⚡ Quick win

important: make stream propagation observable.

This helper uses cudaDeviceSynchronize(), so the cudaStream_t, cuda::stream, cuda::stream_ref, and gpu.with(cuda::get_stream, stream) sections would still pass if env dispatch fell back to stream 0. Use a non-default/non-blocking stream and synchronize an event recorded on that stream before checking outputs.

Also applies to: 257-293


233-251: ⚡ Quick win

important: cover the in-place temp-storage overload.

The new helper only calls the out-of-place temp-storage signature. The in-place Flagged(temp_storage, bytes, d_data, flags, d_num_selected_out, num_items, env) implementation changed separately, so add a user-provided-memory env case for it too.


276-293: ⚡ Quick win

important: add a tuning-selector case.

These sections pass streams/default policies, but none attach a custom tuning policy selector, so dispatch_with_env_and_tuning could ignore tuning and this test would still pass. Add one env/policy with an observably selected test policy selector.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e1bb85c4-0a24-473b-b862-a4a895712ad8

📥 Commits

Reviewing files that changed from the base of the PR and between c6e14ac and ddfaf0b.

📒 Files selected for processing (3)
  • cub/cub/device/device_select.cuh
  • cub/test/catch2_test_device_select_flagged.cu
  • libcudacxx/include/cuda/std/__pstl/cuda/shift_left.h

@github-actions

This comment has been minimized.

We want to be able to pass tunings  to the APIs that take user provided memory.
@miscco
miscco force-pushed the device_select_flagged branch from ddfaf0b to c37c1c1 Compare June 16, 2026 10:49
@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 27m: Pass: 100%/343 | Total: 13d 13h | Max: 2h 25m | Hits: 37%/1298826

See results here.

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.

2 participants