Skip to content

Use the new tuning API internally for detail::select::dispatch and DeviceSelect - #8880

Merged
bernhardmgruber merged 6 commits into
NVIDIA:mainfrom
bernhardmgruber:use_tuning_api_select
May 18, 2026
Merged

bernhardmgruber merged 6 commits into
NVIDIA:mainfrom
bernhardmgruber:use_tuning_api_select

Conversation

@bernhardmgruber

@bernhardmgruber bernhardmgruber commented May 8, 2026 •

Copy link
Copy Markdown
Contributor
  • Add in-place overloads for DeviceSelect::Unique #8896
  • No SASS changes in cub.bench.select.flagged.base on SM75;80;86;90;100
  • No SASS changes in cub.bench.select.if.base on SM75;80;86;90;100
  • No SASS changes in cub.bench.select.unique.base on SM75;80;86;90;100
  • No SASS changes in thrust.test.unique on SM120 (quick sanity check)
  • No SASS changes in thrust.test.copy on SM120 (quick sanity check)

Fixes: #8379

@bernhardmgruber
bernhardmgruber requested review from a team as code owners May 8, 2026 14:55
@bernhardmgruber
bernhardmgruber requested a review from shwina May 8, 2026 14:55
@github-project-automation github-project-automation Bot moved this to Todo in CCCL May 8, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL May 8, 2026
Comment thread cub/benchmarks/bench/select/unique.cu Resolved
@github-actions

This comment has been minimized.

@oleksandr-pavlyk

oleksandr-pavlyk commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Compilation error for some compiler/standard combination:

    /home/coder/cccl/lib/cmake/thrust/../../../thrust/thrust/system/cuda/detail/remove.h:41:13: error: no template named 'copy_if' in namespace 'thrust::cuda_cub::detail'; did you mean simply 'copy_if'?

@bernhardmgruber

Copy link
Copy Markdown
Contributor Author

There are SASS diffs for cub.bench.select.unique.base on all SM versions

@github-actions

This comment has been minimized.

@bernhardmgruber
bernhardmgruber force-pushed the use_tuning_api_select branch from 5dcad17 to a842d5c Compare May 11, 2026 07:30
@bernhardmgruber

Copy link
Copy Markdown
Contributor Author

There are SASS diffs for cub.bench.select.unique.base on all SM versions

They were caused by removing the InPlace benchmarks. I split out the commit dropping them and then diffed that commit with HEAD. No SASS changes now.

@github-actions

This comment has been minimized.

@bernhardmgruber
bernhardmgruber force-pushed the use_tuning_api_select branch from a842d5c to 1dbbe5a Compare May 11, 2026 11:03
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@bernhardmgruber
bernhardmgruber force-pushed the use_tuning_api_select branch from 6e21bf6 to 580d2ef Compare May 12, 2026 07:38
@github-actions

This comment has been minimized.

@bernhardmgruber
bernhardmgruber force-pushed the use_tuning_api_select branch from 580d2ef to 3eda066 Compare May 13, 2026 15:27
@coderabbitai

coderabbitai Bot commented May 13, 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: f78bf436-851f-47c4-989a-874d6b0a8fb3

📥 Commits

Reviewing files that changed from the base of the PR and between 72d92b8 and 3eda066.

📒 Files selected for processing (8)
  • cub/benchmarks/bench/select/flagged.cu
  • cub/benchmarks/bench/select/if.cu
  • cub/benchmarks/bench/select/unique.cu
  • cub/cub/device/device_select.cuh
  • cub/test/catch2_test_device_select_env.cu
  • thrust/thrust/system/cuda/detail/copy_if.h
  • thrust/thrust/system/cuda/detail/remove.h
  • thrust/thrust/system/cuda/detail/unique.h

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • New Features

    • Added tuning support for select and unique benchmark operations.
  • Refactor

    • Simplified benchmark execution paths for select operations (Flagged, If, Unique).
    • Reorganized internal dispatch mechanisms for select and unique device operations.
    • Updated helper utilities to use streamlined algorithm implementations.

Walkthrough

This PR refactors CUB's DeviceSelect environment-based overloads to adopt the new cuda::execution::tune API, replacing the prior dispatch_with_env + tuning-query pattern with dispatch_with_env_and_tuning. Corresponding Thrust algorithms and benchmarks are updated to use the new direct DeviceSelect APIs. Temp-storage overloads are simplified by removing OffsetT type aliases.

Changes

Tuning API adoption for DeviceSelect and Thrust integration

Layer / File(s) Summary
Environment-based DeviceSelect overload refactoring
cub/cub/device/device_select.cuh
Replaces dispatch_with_env + select_impl pattern with dispatch_with_env_and_tuning and explicit default_policy_selector across Flagged (out-of-place and in-place), If, FlaggedIf, and Unique overloads; removes detail::unique_by_key_tuning helper definitions; now passes policy_selector directly to detail::select::dispatch and detail::unique_by_key::dispatch.
Temp-storage overload offset simplification
cub/cub/device/device_select.cuh
Removes OffsetT type alias and static_cast<OffsetT>(num_items) conversions across temp-storage Flagged, If, and FlaggedIf variants; UniqueByKey switches to offset_t = detail::choose_offset_t<NumItemsT> and casts num_items directly; num_items forwarded unmodified to dispatch functions.
Thrust copy_if refactoring with CUB tuning API
thrust/thrust/system/cuda/detail/copy_if.h
Replaces DispatchCopyIf dispatch machinery with copy_if_with_stencil template that calls cub::DeviceSelect::FlaggedIf directly in a two-step workflow (temp-storage query, then execution); allocates temporary storage plus 64-bit selected-count buffer; updates Thrust CDP dispatch paths for both stencil and no-stencil copy_if overloads.
Thrust remove refactoring with copy_if_with_stencil
thrust/thrust/system/cuda/detail/remove.h
Updates both stencil-based and predicate-only remove_if CUDA dispatch paths to call copy_if_with_stencil</* InPlace */ true> instead of dispatch-based copy_if<SelectPotentiallyInPlace>.
Thrust unique refactoring with DeviceSelect::Unique
thrust/thrust/system/cuda/detail/unique.h
Replaces dispatch_select_unique and dispatch-based unique implementation with new select_unique<InPlace> template that calls cub::DeviceSelect::Unique directly with temp-storage query and allocation; updates unique_copy and unique entry points to call select_unique<false> and select_unique<true> respectively.
Tuning API test coverage for DeviceSelect variants
cub/test/catch2_test_device_select_env.cu
Adds includes for raw pointer cast and CUDA execution tuning; introduces predicate functors (less_than_5_t, even_flag_t), tuning-policy factories (select_tuning<BlockThreads>, unique_by_key_tuning<BlockThreads>), and block_sizes type list; adds new C2H_TEST cases exercising If, Flagged, FlaggedIf, Unique, and UniqueByKey with cuda::execution::tune, verifying correctness and expected block-size selection.
Flagged benchmark refactoring to use DeviceSelect::Flagged
cub/benchmarks/bench/select/flagged.cu
Adds bench_policy_selector<InputT> producing select_if_policy; replaces policy_hub_t and dispatch-based implementation with direct cub::DeviceSelect::Flagged call inside state.exec; removes OffsetT template parameter and hardcodes offset_t to int64_t; removes OffsetT axis from benchmark type registration.
Select-If benchmark refactoring to use DeviceSelect::If
cub/benchmarks/bench/select/if.cu
Adds bench_policy_selector<InputT> conditionally mapping tuning parameters to select_if_policy; removes OffsetT template parameter and hardcodes offset_t to int64_t; replaces dispatch-based implementation with direct cub::DeviceSelect::If call using caching allocator and if constexpr branching for in-place vs out-of-place; removes OffsetT axis from benchmark registration.
Unique benchmark refactoring to use DeviceSelect::Unique
cub/benchmarks/bench/select/unique.cu
Adds bench_policy_selector<InputT> producing tuned select_if_policy; replaces policy_hub_t and dispatch-based implementation with direct cub::DeviceSelect::Unique call using cuda::execution::tune; removes OffsetT from function signature, type axes, and axis name registration.

Assessment against linked issues

Objective Addressed Explanation
Use the new tuning API internally for detail::select::dispatch + DeviceSelect [#8379] ✅

Out-of-scope changes

No out-of-scope changes detected. All modifications are directly related to adopting the tuning API for DeviceSelect and integrating it into Thrust algorithms and benchmarks.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 3h 03m: Pass: 100%/340 | Total: 16d 06h | Max: 2h 58m | Hits: 12%/2342155

See results here.

Comment on lines +78 to +88
if constexpr (InPlace::value)
{
_CCCL_TRY_CUDA_API(
cub::DeviceSelect::Flagged,
"DeviceSelect::Flagged failed",
d_in,
d_flags,
d_num_selected,
static_cast<offset_t>(elements),
env);
}

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.

Critical: for all new in place variant benchmarks, the input values will change between runs. This will affect the performance reported. We should maintain the original values and copy them in each iteration. We can use nvbench::exec_tag::timer to avoid timing the copy

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.

That's a valid observation! Now I wonder what the original benchmark's use case was? For the in-place versions it measured the in-place implementation but on distinct input and output ranges, a case not reachable with the public CUB API.

Comment on lines 22 to +34
template <typename InputT>
struct policy_hub_t
struct bench_policy_selector
{
struct policy_t : cub::ChainedPolicy<300, policy_t, policy_t>
[[nodiscard]] _CCCL_API constexpr auto operator()(cuda::compute_capability) const
-> cub::detail::select::select_if_policy
{
using SelectIfPolicyT =
cub::AgentSelectIfPolicy<TUNE_THREADS_PER_BLOCK,
TUNE_ITEMS_PER_THREAD,
TUNE_LOAD_ALGORITHM,
TUNE_LOAD_MODIFIER,
cub::BLOCK_SCAN_WARP_SCANS,
delay_constructor_t>;
};

using MaxPolicy = policy_t;
return {TUNE_THREADS_PER_BLOCK,
TUNE_ITEMS_PER_THREAD,
(TUNE_TRANSPOSE == 0 ? cub::BLOCK_LOAD_DIRECT : cub::BLOCK_LOAD_WARP_TRANSPOSE),
(TUNE_LOAD == 0 ? cub::LOAD_DEFAULT : cub::LOAD_CA),
cub::BLOCK_SCAN_WARP_SCANS,
delay_constructor_policy};
}

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.

I love this

@bernhardmgruber
bernhardmgruber merged commit 0937ec3 into NVIDIA:main May 18, 2026
361 of 362 checks passed
@bernhardmgruber
bernhardmgruber deleted the use_tuning_api_select branch May 18, 2026 10:42
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL May 18, 2026
@coderabbitai coderabbitai Bot mentioned this pull request May 21, 2026
2 tasks done
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.

Use the new tuning API internally for detail::select::dispatch + DeviceSelect

5 participants