Skip to content

Allow public tuning of cub::DeviceSelect (without UniqueByKey) and cub::DevicePartition (without three-way) - #9316

Merged
gonidelis merged 11 commits into
NVIDIA:mainfrom
bernhardmgruber:tune_select
Jun 12, 2026
Merged

gonidelis merged 11 commits into
NVIDIA:mainfrom
bernhardmgruber:tune_select

Conversation

@bernhardmgruber

Copy link
Copy Markdown
Contributor

Fixes: #8583
Fixes: #8575

@bernhardmgruber
bernhardmgruber requested review from a team as code owners June 9, 2026 08:53
@bernhardmgruber
bernhardmgruber requested a review from shwina June 9, 2026 08:53
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jun 9, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jun 9, 2026
@coderabbitai

coderabbitai Bot commented Jun 9, 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

important:

Walkthrough

Public SelectPolicy and PartitionPolicy types added; agent select-if policy internals moved to detail::agent_select_if_policy with deprecated alias; tuning helpers, policy hub, and dispatch paths updated to use SelectPolicy; DevicePartition adds PartitionPolicy and adapter; benchmarks, tests, docs, and libc++ dispatch calls updated; DispatchSelectIf deprecated.

Changes

SelectPolicy Tuning Type Productization

Layer / File(s) Summary
SelectPolicy struct and SM branches
cub/cub/device/dispatch/tuning/tuning_select_if.cuh
Introduces SelectPolicy and updates SM80/SM90/SM100 tuning helpers and branches to construct/return SelectPolicy.
Policy hub, defaults, and selector call-ops
cub/cub/device/dispatch/tuning/tuning_select_if.cuh
Policy hub and selection helpers updated; policy_selector::operator() and policy_selector_from_types::operator() now return SelectPolicy and concept constraints updated.
AgentSelectIfPolicy refactor
cub/cub/agent/agent_select_if.cuh, cub/cub/device/dispatch/tuning/tuning_select_if.cuh
Moves agent policy to detail::agent_select_if_policy and preserves a deprecated public alias template AgentSelectIfPolicy.
DispatchSelectIf integration and deprecation
cub/cub/device/dispatch/dispatch_select_if.cuh, libcudacxx/include/cuda/std/__pstl/cuda/unique.h
Dispatch wiring now uses SelectPolicy and detail::agent_select_if_policy; DispatchSelectIf is marked deprecated; libc++ dispatch usages updated to call detail::select::dispatch<Select>.
PartitionPolicy and DevicePartition adapter
cub/cub/device/device_partition.cuh
Adds PartitionPolicy struct, documentation @par Tuning, and __policy_selector_adapter converting PartitionPolicy → SelectPolicy; env-based DevicePartition selectors are routed through adapter.
DeviceSelect documentation
cub/cub/device/device_select.cuh
Adds @par Tuning section and example references demonstrating env-based tuning selectors.
Benchmark policy selectors
cub/benchmarks/bench/partition/*, cub/benchmarks/bench/select/*
Benchmark selector functors updated to return public cub::SelectPolicy / cub::PartitionPolicy.
Tests and CMake
cub/test/*, cub/test/CMakeLists.txt
Tests updated to use public policy selectors, add execution::tune tests and SelectPolicy trait checks, add CCCL_IGNORE_DEPRECATED_API in one test, and extend CMake warning-suppression pattern.

Assessment against linked issues

Objective Addressed Explanation
Productize cub::DeviceSelect tuning API [#8583] ✅
Productize cub::DevicePartition tuning API [#8575] ✅

possibly related PRs

  • NVIDIA/cccl#8880: Overlaps with SelectPolicy selector return-type changes in benchmark files and tuning-API refactor.
  • NVIDIA/cccl#8853: Related agent/lookback-delay and dispatch wiring changes affecting select-if dispatch.

suggested reviewers

  • shwina
  • NaderAlAwar
  • wmaxey

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
cub/cub/device/dispatch/tuning/tuning_select_if.cuh (1)

37-38: ⚡ Quick win

suggestion: Replace this struct doc opening with an explicit //! @brief ... form so it is consistently consumed by the Doxygen pipeline.
As per coding guidelines, "Use Doxygen-style //! comments with @brief tags for documentation."

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e5ed72c3-b50e-42d5-b5d3-764f59808ff2

📥 Commits

Reviewing files that changed from the base of the PR and between 03e7b55 and c2b8f7a.

📒 Files selected for processing (15)
  • cub/benchmarks/bench/partition/flagged.cu
  • cub/benchmarks/bench/partition/if.cu
  • cub/benchmarks/bench/select/flagged.cu
  • cub/benchmarks/bench/select/if.cu
  • cub/benchmarks/bench/select/unique.cu
  • cub/cub/agent/agent_select_if.cuh
  • cub/cub/device/device_partition.cuh
  • cub/cub/device/device_select.cuh
  • cub/cub/device/dispatch/dispatch_select_if.cuh
  • cub/cub/device/dispatch/tuning/tuning_select_if.cuh
  • cub/test/catch2_test_device_partition_env.cu
  • cub/test/catch2_test_device_partition_env_api.cu
  • cub/test/catch2_test_device_select_env.cu
  • cub/test/catch2_test_device_select_env_api.cu
  • cub/test/catch2_test_device_select_if_custom_policy_hub.cu

Comment on lines +435 to +437
[] __host__ __device__(int v) {
return v < 5;
},

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.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -nP '\[\]\s*__host__\s*__device__' cub/test/catch2_test_device_select_env_api.cu

Repository: NVIDIA/cccl

Length of output: 95


🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="cub/test/catch2_test_device_select_env_api.cu"

# Inspect context around the reported lambda
sed -n '380,470p' "$file" | nl -ba | sed -n '1,120p'

# Find other host-device lambdas in cub/test
rg -nP '\[\]\s*__host__\s*__device__' cub/test | head -n 50

# Find other host-device lambdas in cub (broader)
rg -nP '\[\]\s*__host__\s*__device__' cub | head -n 50

Repository: NVIDIA/cccl

Length of output: 98


🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="cub/test/catch2_test_device_select_env_api.cu"

# Show surrounding code with line numbers (no nl dependency)
sed -n '400,465p' "$file" | cat -n

# Search for other host-device lambdas in nearby tests (limit output)
rg -nP '\[\]\s*__host__\s*__device__' cub/test | head -n 50

# Broader search within cub (limit output)
rg -nP '\[\]\s*__host__\s*__device__' cub | head -n 50

Repository: NVIDIA/cccl

Length of output: 3392


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Search for the guideline wording (or close variants)
rg -n --hidden --no-ignore-vcs "Never allow.*lambda|lambda expression|host__device.*lambda|__host__ __device.*lambda" . | head -n 50

# Inspect a couple other occurrences for style consistency
for f in \
  cub/test/catch2_test_device_partition_env_api.cu \
  cub/test/catch2_test_device_find_env_api.cu \
  cub/test/catch2_test_device_segmented_scan_api.cu
do
  echo "---- $f"
  rg -nP '\[\]\s*__host__\s*__device__\b' "$f" | head -n 5
done

Repository: NVIDIA/cccl

Length of output: 1337


🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="cub/test/catch2_test_device_select_env_api.cu"
sed -n '420,450p' "$file" | cat -n

echo "---- skills: libcudacxx-style/SKILL.md ----"
sed -n '70,130p' .agent/skills/libcudacxx-style/SKILL.md | cat -n

echo "---- skills: libcudacxx-test/SKILL.md ----"
sed -n '30,80p' .agent/skills/libcudacxx-test/SKILL.md | cat -n

Repository: NVIDIA/cccl

Length of output: 6740


important: Replace the [] __host__ __device__(int v) predicate in the tuned cub::DeviceSelect::If call with a named functor (cub/test/catch2_test_device_select_env_api.cu, lines 435-437) to follow CCCL’s device-code/lambda constraints (e.g., struct Pred { __host__ __device__ bool operator()(int v) const { return v < 5; } };).

Source: Coding guidelines


#include <thrust/device_vector.h>

#include <cuda/__execution/tune.h>

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.

Question: This currently uses a non-exposed header. If we productize this which header should a user include?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#include <cuda/execution.tune.h> if they want to, but it also just works with just <cub/device/device_select.cuh>

@bernhardmgruber
bernhardmgruber requested a review from a team as a code owner June 9, 2026 09:20
@bernhardmgruber
bernhardmgruber requested a review from wmaxey June 9, 2026 09:20
@bernhardmgruber bernhardmgruber changed the title Productize the cub::DeviceSelect (without UniqueByKey) and cub::DevicePartition (without three-way) tuning API Allow public tuning of cub::DeviceSelect (without UniqueByKey) and cub::DevicePartition (without three-way) Jun 9, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@bernhardmgruber

Copy link
Copy Markdown
Contributor Author
/home/coder/cccl/lib/cmake/libcudacxx/../../../libcudacxx/include/cuda/std/__pstl/cuda/unique.h:83:55: error: ‘template<class InputIteratorT, class FlagsInputIteratorT, class SelectedOutputIteratorT, class NumSelectedIteratorT, class SelectOpT, class EqualityOpT, class OffsetT, cub::_V_300500_SM_750_800_900::SelectImpl SelectionOpt, class PolicyHub> struct cub::_V_300500_SM_750_800_900::DispatchSelectIf’ is deprecated [-Werror=deprecated-declarations]
       using DispatchUnique = CUB_NS_QUALIFIER::DispatchSelectIf<
                                                         ^~~~~~~~        
  /home/coder/cccl/lib/cmake/cub/../../../cub/cub/device/dispatch/dispatch_select_if.cuh:457:80: note: declared here
   struct CCCL_DEPRECATED_BECAUSE("Please use DeviceSelect or DevicePartition") DispatchSelectIf
                                                                                  ^~~~~~~~~~~~~~  

@miscco that's on you :) Do you need to use the Dispatch struct because of temporary storage query again?

@bernhardmgruber
bernhardmgruber requested a review from a team as a code owner June 9, 2026 16:33
@github-actions

This comment has been minimized.

@bernhardmgruber
bernhardmgruber force-pushed the tune_select branch 2 times, most recently from 803b740 to 65625a6 Compare June 9, 2026 23:17
@github-actions

This comment has been minimized.

@miscco

miscco commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

If I remember correctly this was because of SelectImpl::SelectPotentiallyInPlace but I am not sure whether this is something we actually need anymore

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

// example-begin partition-if-policy-selector
struct PartitionPolicySelector
{
__host__ __device__ constexpr auto operator()(cuda::compute_capability cc) const -> cub::PartitionPolicy

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tiny nit: is there a reason for not using the less verbal

  __host__ __device__ constexpr cub::PartitionPolicy operator()(cuda::compute_capability cc) const

?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Personal preference. I find it more readable.

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

benchmarks look good

@github-actions

This comment has been minimized.

@gonidelis
gonidelis enabled auto-merge (squash) June 12, 2026 00:27
@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2d 00h: Pass: 100%/343 | Total: 12d 08h | Max: 2h 20m | Hits: 36%/1334368

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.

Productize the cub::DeviceSelect (without UniqueByKey) tuning API Productize the cub::DevicePartition (without three-way) tuning API

4 participants