Skip to content

[CUB] Refactor DevicePartition::Flagged to always take an environment - #9396

Closed
miscco wants to merge 1 commit into
NVIDIA:mainfrom
miscco:test_device_partition_flagged
Closed

miscco wants to merge 1 commit into
NVIDIA:mainfrom
miscco:test_device_partition_flagged

Conversation

@miscco

@miscco miscco commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

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

Also update the PSTL algorithms to take advantage of that

@miscco
miscco requested review from a team as code owners June 11, 2026 09:04
@miscco
miscco requested review from ericniebler and pauleonix June 11, 2026 09:04
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jun 11, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jun 11, 2026
@coderabbitai

coderabbitai Bot commented Jun 11, 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: 1dd66760-8512-4477-bfa0-4ece34b47d23

📥 Commits

Reviewing files that changed from the base of the PR and between eac7282 and 45705b3.

📒 Files selected for processing (4)
  • cub/cub/device/device_partition.cuh
  • cub/test/catch2_test_device_partition_flagged.cu
  • libcudacxx/include/cuda/std/__pstl/cuda/rotate.h
  • libcudacxx/include/cuda/std/__pstl/cuda/rotate_copy.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • libcudacxx/include/cuda/std/__pstl/cuda/rotate_copy.h

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::DevicePartition::Flagged to always take an execution environment, so tunings/stream information can be carried through APIs that operate on user-provided device memory. It also updates PSTL CUDA backends to use the new environment-based overloads, and adds tests covering multiple environment/stream types.

Changes

Core API refactor

cub/cub/device/device_partition.cuh

  • Added/standardized an EnvT template parameter (defaulting to cuda::std::execution::env<>) for DevicePartition::Flagged.
  • Updated the d_temp_storage overload to replace the cudaStream_t parameter with const EnvT& env.
  • Updated the non-d_temp_storage overload to take const EnvT& env (instead of pass-by-value).
  • Switched the dispatch path to environment-aware dispatch (dispatch_with_env_and_tuning), extracting the stream/selector behavior from the environment and type-derived policy selector.
  • Updated Doxygen to document the new EnvT/env parameters.

Test coverage

cub/test/catch2_test_device_partition_flagged.cu

  • Added a parameterized Catch2 test (DevicePartition::Flagged works with user provided memory and environment).
  • Verifies correctness and sizing by:
    • computing a host reference,
    • querying required temporary storage size via nullptr,
    • allocating device temp storage,
    • running DevicePartition::Flagged across multiple environment forms: cudaStream_t, cuda::stream, cuda::stream_ref, cuda::std::execution::env, and cuda::execution::gpu (with and without an explicit stream).

PSTL CUDA backend updates

libcudacxx/include/cuda/std/__pstl/cuda/rotate.h and .../rotate_copy.h

  • Updated the CUDA dispatch implementations to pass the execution policy (__policy) into cub::DevicePartition::Flagged (instead of passing an explicit stream argument / nullptr pattern).
  • Adjusted the temporary-storage raw pointer usage in rotate.h to align with the refactored Flagged environment overload.
  • rotate_copy.h updates similarly to forward the policy as the environment argument for both storage sizing and kernel launch.

Walkthrough

DevicePartition::Flagged migrates from explicit stream-based to environment-based execution dispatch. The API adds an EnvT template parameter and const-ref env parameter, dispatching via dispatch_with_env_and_tuning with computed policy selectors. Tests exercise sizing and multi-environment execution. PSTL rotate backends updated to pass execution policies.

Changes

DevicePartition::Flagged Environment-Based Dispatch

Layer / File(s) Summary
DevicePartition::Flagged API and documentation
cub/cub/device/device_partition.cuh
Flagged overload with d_temp_storage adds EnvT template parameter (default cuda::std::execution::env<>) and replaces cudaStream_t stream with const EnvT& env. Non-storage overload changes env from pass-by-value to const-ref. Doxygen updated.
DevicePartition::Flagged environment dispatch implementation
cub/cub/device/device_partition.cuh
Flagged implementation with d_temp_storage switches to dispatch_with_env_and_tuning, computes policy_selector_from_types for Partition, and forwards environment-derived stream and policy_selector into detail::select::dispatch.
Test infrastructure and multi-environment coverage
cub/test/catch2_test_device_partition_flagged.cu
Test adds cuda/devices and cuda/std/execution headers. New parameterized test queries temp-storage size with nullptr, allocates device storage, executes Flagged across multiple environment forms (cudaStream_t, cuda::stream, cuda::stream_ref, cuda::std::execution::env, cuda::execution::gpu variants), validating selected counts and output.
PSTL rotate and rotate_copy backend updates
libcudacxx/include/cuda/std/__pstl/cuda/rotate.h, libcudacxx/include/cuda/std/__pstl/cuda/rotate_copy.h
rotate.h and rotate_copy.h CUDA backends pass __policy as final argument to DevicePartition::Flagged for both temp-storage sizing (replacing nullptr) and kernel launch (replacing __stream.get()). rotate.h adjusts raw storage pointer index from __get_raw_ptr<1>() to __get_raw_ptr<0>().

Possibly related PRs

  • NVIDIA/cccl#9316: Introduces and publicizes PartitionPolicy and tuning/policy-selector adapter logic that DevicePartition::Flagged now depends on for dispatch_with_env_and_tuning.

Suggested reviewers

  • pauleonix
  • gonidelis
  • davebayer
  • gevtushenko

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 (1)
cub/cub/device/device_partition.cuh (1)

545-545: 💤 Low value

suggestion: The env-based If overloads (lines 545 and 927) still use pass-by-value EnvT env = {}, while Flagged now uses const EnvT& env = {}. Consider aligning them in a follow-up for consistency.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8ef08ec8-6918-47b2-9f80-cdd4d119a9a0

📥 Commits

Reviewing files that changed from the base of the PR and between d2a0a8a and afb5cb0.

📒 Files selected for processing (8)
  • cub/cub/detail/env_dispatch.cuh
  • cub/cub/device/device_find.cuh
  • cub/cub/device/device_partition.cuh
  • cub/test/catch2_test_device_find_env.cu
  • cub/test/catch2_test_device_partition_flagged.cu
  • libcudacxx/include/cuda/std/__pstl/cuda/find_if.h
  • libcudacxx/include/cuda/std/__pstl/cuda/rotate.h
  • libcudacxx/include/cuda/std/__pstl/cuda/rotate_copy.h

@github-actions

This comment has been minimized.

@miscco
miscco force-pushed the test_device_partition_flagged branch 2 times, most recently from 38e7d7c to eac7282 Compare June 12, 2026 11:14
@github-actions

This comment has been minimized.

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 test_device_partition_flagged branch from eac7282 to 45705b3 Compare June 15, 2026 09:25
@miscco miscco closed this Jun 15, 2026
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Jun 15, 2026
@miscco
miscco deleted the test_device_partition_flagged branch June 15, 2026 09:34
@github-actions

Copy link
Copy Markdown
Contributor

😬 CI Workflow Results

🟥 Finished in 1h 32m: Pass: 81%/343 | Total: 5d 17h | Max: 1h 27m | Hits: 71%/660674

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.

1 participant