Skip to content

Take CUB environments by const& - #10105

Merged
miscco merged 1 commit into
NVIDIA:mainfrom
bernhardmgruber:env_const_Ref
Jul 23, 2026
Merged

miscco merged 1 commit into
NVIDIA:mainfrom
bernhardmgruber:env_const_Ref

Conversation

@bernhardmgruber

@bernhardmgruber bernhardmgruber commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

This allows more types to be passed as environments, notably user-defined stream types that are not copyable but convertable to cudaStream_t.

Some work in this direction was already done while working on #9875.

This allows more types to be passed as environments, notably user-defined stream types that are not copyable but convertable to cudaStream_t.
@bernhardmgruber
bernhardmgruber requested review from a team as code owners July 23, 2026 08:24
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jul 23, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • API Improvements

    • Execution environment parameters across device algorithms now use const-reference passing, reducing unnecessary copies while preserving existing behavior.
    • Updated sorting, scanning, reduction, search, merge, top-k, segmented, and memory operation interfaces consistently.
  • Documentation

    • Updated device-scope API examples to reflect the revised environment parameter convention.

Walkthrough

Changes

The PR changes environment parameters across CUB device algorithms and dispatch helpers from pass-by-value to const EnvT&, preserving default {} arguments and existing dispatch behavior. The test helper and device-scope documentation example are updated to match.

Execution environment API updates

Layer / File(s) Summary
Reduction and scan environment flow
cub/cub/device/device_reduce.cuh, cub/cub/device/device_scan.cuh
Reduction and scan internals and environment overloads now pass execution environments by const reference.
Segmented reduction and scan APIs
cub/cub/device/device_segmented_reduce.cuh, cub/cub/device/device_segmented_scan.cuh
Segmented reduction and scan overloads use const-reference environment parameters.
Sorting environment overloads
cub/cub/device/device_merge_sort.cuh, cub/cub/device/device_radix_sort.cuh, cub/cub/device/device_segmented_radix_sort.cuh, cub/cub/device/device_segmented_sort.cuh
Sorting overloads consistently accept environments by const reference across pointer, DoubleBuffer, decomposer, stable, ascending, and descending variants.
Device API and dispatch updates
cub/cub/device/device_find.cuh, cub/cub/device/device_memcpy.cuh, cub/cub/device/device_merge.cuh, cub/cub/device/device_run_length_encode.cuh, cub/cub/device/device_topk.cuh, cub/cub/device/device_batched_topk.cuh, cub/cub/device/dispatch/dispatch_batched_topk.cuh
Additional device APIs and top-k dispatch helpers change environment parameters to const references.
Test helper and documentation alignment
cub/test/catch2_test_env_launch_helper.h, docs/cub/developer/device_scope.rst
The test helper and documented device-scope example use const-reference environment parameters.

Suggested reviewers: ericniebler, miscco


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

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cub/cub/device/device_scan.cuh (1)

1568-1576: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

critical: Add the missing comma after NullType{} at Line 1574. Without it, device_scan.cuh is ill-formed and cannot compile.

🧹 Nitpick comments (2)
cub/cub/device/device_reduce.cuh (1)

599-605: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Add regression coverage for non-copyable environments.

Add a focused test environment with a deleted copy constructor, a get_stream customization, and calls covering these overloads. This verifies the PR’s stated compatibility goal and prevents future reversion to pass-by-value.

As per path instructions, CUB API changes should include coverage for relevant API and compile-time risks.

Also applies to: 676-679, 955-958, 1602-1605, 2240-2243, 2351-2354

Source: Path instructions

cub/cub/device/device_topk.cuh (1)

290-314: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

suggestion: stale ::cuda::std::move(env) calls now meaningless.

dispatch_topk/dispatch_topk_hub take env by const EnvT& (lines 57, 133). Passing ::cuda::std::move(env) at the call sites (e.g. lines 313, 562, 791, 1040, 1252, 1467, 1671, 1886) just binds the const rvalue to the const lvalue-ref parameter — no move occurs. This misleadingly implies move semantics on an env this PR is explicitly making non-owning/const-ref, and could confuse future edits (e.g. if a param type reverts to by-value for a non-movable EnvT). Just pass env directly.

♻️ Example fix (repeat pattern at each call site)
-      detail::identity_decomposer_t{},
-      ::cuda::std::move(env));
+      detail::identity_decomposer_t{},
+      env);

Also applies to: 534-563, 768-792, 1012-1041, 1231-1253, 1441-1468, 1650-1672, 1860-1887


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 06d6d272-4924-4d91-bdea-02f46fd0c7d0

📥 Commits

Reviewing files that changed from the base of the PR and between 49b69bd and e66c2cd.

📒 Files selected for processing (17)
  • cub/cub/device/device_batched_topk.cuh
  • cub/cub/device/device_find.cuh
  • cub/cub/device/device_memcpy.cuh
  • cub/cub/device/device_merge.cuh
  • cub/cub/device/device_merge_sort.cuh
  • cub/cub/device/device_radix_sort.cuh
  • cub/cub/device/device_reduce.cuh
  • cub/cub/device/device_run_length_encode.cuh
  • cub/cub/device/device_scan.cuh
  • cub/cub/device/device_segmented_radix_sort.cuh
  • cub/cub/device/device_segmented_reduce.cuh
  • cub/cub/device/device_segmented_scan.cuh
  • cub/cub/device/device_segmented_sort.cuh
  • cub/cub/device/device_topk.cuh
  • cub/cub/device/dispatch/dispatch_batched_topk.cuh
  • cub/test/catch2_test_env_launch_helper.h
  • docs/cub/developer/device_scope.rst

@bernhardmgruber bernhardmgruber changed the title Take environments by const& Take CUB environments by const& Jul 23, 2026
@bernhardmgruber
bernhardmgruber enabled auto-merge (squash) July 23, 2026 10:26
@miscco

miscco commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

pre-commit.ci autofix

@miscco
miscco disabled auto-merge July 23, 2026 12:34
@miscco
miscco enabled auto-merge (squash) July 23, 2026 12:34
@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 8h 30m: Pass: 100%/287 | Total: 12d 20h | Max: 2h 40m | Hits: 19%/1023852

See results here.

@miscco
miscco merged commit 210d788 into NVIDIA:main Jul 23, 2026
309 of 310 checks passed
@bernhardmgruber
bernhardmgruber deleted the env_const_Ref branch July 28, 2026 22:42
davebayer pushed a commit to davebayer/cccl that referenced this pull request Aug 4, 2026
This allows more types to be passed as environments, notably user-defined stream types that are not copyable but convertable to cudaStream_t.
@pauleonix pauleonix mentioned this pull request Aug 5, 2026
2 tasks
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