Skip to content

[CUB] Refactor dispatch_streaming_arg_reduce to take a tuning environment - #9660

Merged
bernhardmgruber merged 3 commits into
NVIDIA:mainfrom
miscco:device_reduce_argmin_dispatch
Jul 3, 2026
Merged

bernhardmgruber merged 3 commits into
NVIDIA:mainfrom
miscco:device_reduce_argmin_dispatch

Conversation

@miscco

@miscco miscco commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

We want to put more logic into the dispatch layer where it belongs

@miscco
miscco requested review from a team as code owners July 1, 2026 09:15
@miscco
miscco requested review from elstehle and pciolkosz July 1, 2026 09:15
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jul 1, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jul 1, 2026
@miscco
miscco force-pushed the device_reduce_argmin_dispatch branch from 0102443 to 4f27546 Compare July 1, 2026 09:18
@coderabbitai

coderabbitai Bot commented Jul 1, 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
📝 Walkthrough
📝 Walkthrough

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.

Actionable comments posted: 1

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_reduce.cuh (1)

1692-1714: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

suggestion: Fix the ArgMax convenience overload notes.

Lines 1696 and 1934 say these overloads use cuda::std::less, but Lines 1714 and 1950 pass cuda::std::greater{}. Update the notes to cuda::std::greater.

Also applies to: 1933-1950

🧹 Nitpick comments (3)
cub/cub/device/dispatch/dispatch_streaming_reduce.cuh (2)

177-179: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

suggestion: Declare policy_selector const.

policy_selector is initialized once and only passed onward. Make it const and, if needed, use a non-cv type for policy_selector_t. As per coding guidelines, "All variables that are not modified must be declared const, including cast results, function return values, and loop-invariant computations."

Source: Coding guidelines


160-178: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Add direct includes for the new execution query symbols. This header now uses ::cuda::std::execution::env, ::cuda::std::execution::__query_or, and ::cuda::compute_capability; include <cuda/std/__execution/env.h> and <cuda/__device/compute_capability.h> here instead of relying on transitive includes.

Source: Coding guidelines

cub/test/catch2_test_device_reduce.cu (1)

233-320: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

suggestion: none of the env variants tested (stream, cuda::stream, stream_ref, execution::env{}, cuda::execution::gpu[.with(...)]) exercise a custom tuning query, so the REQUIRE(expected_allocation_size == num_bytes) checks trivially pass with the same default policy every time. The PR's core change is that dispatch_streaming_arg_reduce now derives its policy selector from a tuning environment via __query_or — add a case that supplies a real tuning override (a custom policy_selector/tuning env) to ArgMin/ArgMax and assert it actually changes dispatch behavior (e.g., temp-storage size or a policy-observable effect), otherwise the new tuning-env plumbing added to the dispatch layer has no direct test coverage.

As per path instructions for cub/**/*: "Focus on algorithm correctness, temporary-storage protocol, dispatch/policy selection, ... and test coverage."

Also applies to: 342-429

Source: Path instructions


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 599a73a6-bde3-4d1b-a89f-51d1f69be40b

📥 Commits

Reviewing files that changed from the base of the PR and between f25e0e1 and 0102443.

📒 Files selected for processing (5)
  • cub/cub/device/device_reduce.cuh
  • cub/cub/device/dispatch/dispatch_streaming_reduce.cuh
  • cub/test/catch2_test_device_reduce.cu
  • libcudacxx/include/cuda/std/__pstl/cuda/max_element.h
  • libcudacxx/include/cuda/std/__pstl/cuda/min_element.h

Comment on lines +946 to +947
static_assert(__validate_determinism_streaming_reduce<EnvT>(), "gpu_to_gpu determinism is not supported");

@coderabbitai coderabbitai Bot Jul 1, 2026 •

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

suggestion: Document the gpu_to_gpu rejection in the public ArgMin/ArgMax env docs.

Lines 946 and 1132 reject gpu_to_gpu determinism, but the public env overload docs only say determinism is based on environment requirements. Add a sentence that gpu_to_gpu is unsupported for streaming ArgMin/ArgMax so users do not discover it only through the static assertion.

Also applies to: 1132-1132, 1166-1168, 1863-1865

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.

@bernhardmgruber what do you think about that?

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.

@miscco Noted — I'll wait for bernhardmgruber's input before this suggestion is considered resolved.


🧠 Learnings used
Learnt from: sleeepyjack
Repo: NVIDIA/cccl PR: 8857
File: cudax/include/cuda/experimental/__cuco/__hyperloglog/default_policy.cuh:92-95
Timestamp: 2026-05-06T23:47:10.296Z
Learning: In this CCCL (CUDA C++ Core Libraries) codebase, do NOT treat `_CCCL_API` as host-only. `_CCCL_API` is defined in `libcudacxx/include/cuda/std/__cccl/visibility.h` and always expands to include `_CCCL_HOST_DEVICE` (possibly alongside `_CCCL_TILE`, `_CCCL_VISIBILITY_HIDDEN`, and `_CCCL_EXCLUDE_FROM_EXPLICIT_INSTANTIATION`). So any function annotated with `_CCCL_API` is already valid for both host and device code; reviewers should not flag it as host-only.

Learnt from: sleeepyjack
Repo: NVIDIA/cccl PR: 8857
File: cudax/include/cuda/experimental/__cuco/__hyperloglog/hyperloglog_impl.cuh:426-428
Timestamp: 2026-05-06T23:47:17.597Z
Learning: In the CCCL/CUDA C++ Core Libraries codebase (NVIDIA/cccl), treat `_CCCL_API` as host-and-device callable. `_CCCL_API` expands to `_CCCL_HOST_DEVICE` via `libcudacxx/include/cuda/std/__cccl/visibility.h`, so functions marked with `_CCCL_API` may be invoked from both host and device code. When reviewing device-code contexts, do not flag `_CCCL_API`-annotated functions as if they were host-only.

Learnt from: bernhardmgruber
Repo: NVIDIA/cccl PR: 8975
File: cub/cub/device/device_merge_sort.cuh:100-135
Timestamp: 2026-05-13T22:02:02.361Z
Learning: In the NVIDIA/cccl codebase, policy selectors used at the CUB device API layer (the typical CUB device dispatch wrappers such as DeviceMergeSort/DeviceMerge/DeviceAdjacentDifference) are stateless. When passing a policy selector to dispatch from this layer, it is correct to default-construct it (e.g., `policy_selector_t{}`) and pass it along—doing so should not drop any runtime state. Treat runtime/stateful policy selectors as belonging to CCCL.C (not the CUB device API layer).

Learnt from: NaderAlAwar
Repo: NVIDIA/cccl PR: 9171
File: libcudacxx/include/cuda/std/__cccl/diagnostic.h:126-126
Timestamp: 2026-06-03T13:24:36.356Z
Learning: When reviewing code that uses NVIDIA NVCC/NVRTC diagnostic suppression pragmas, treat `nv_diag_suppress` as supporting comma-separated warning numbers in a single directive. For example, `_Pragma("nv_diag_suppress 1444,20199")` (or an equivalent `#pragma nv_diag_suppress 1444,20199`) is valid; do not flag comma-separated warning IDs inside `nv_diag_suppress` pragmas as unsupported.

Learnt from: tpn
Repo: NVIDIA/cccl PR: 9322
File: cub/cub/block/block_reduce_broadcast.cuh:27-29
Timestamp: 2026-06-09T17:12:10.595Z
Learning: In the NVIDIA/cccl repository, apply the libcudacxx `#include` <cuda/std/__cccl/prologue.h> / epilogue.h “bookend” convention only to libcudacxx headers under libcudacxx/include/ and cudax/include/. For CUB headers under cub/cub/ (e.g., cub/cub/**.cuh), do not require prologue.h/epilogue.h includes—CUB intentionally uses its own convention: start with `#pragma` once, then `#include` <cub/config.cuh>, then the implicit system-header pragmas (_CCCL_IMPLICIT_SYSTEM_HEADER_GCC/CLANG/MSVC). Therefore, if a CUB header is missing prologue.h/epilogue.h, do not flag it as an include-convention violation.

Learnt from: shwina
Repo: NVIDIA/cccl PR: 9568
File: c/parallel/src/segmented_reduce.cu:599-643
Timestamp: 2026-06-23T20:49:51.585Z
Learning: When reviewing uses of NVIDIA/cccl AOT serialization, don’t flag a potential mismatch when `cccl::aot::buffer_writer::write_blob` is paired with `cccl::aot::buffer_reader::read_into(void* dest, size_t expected_size)`. The `read_into` implementation reads a length-prefixed blob: it `read_pod`s the stored length, checks it equals `expected_size`, and only then copies that many bytes into `dest`. This behavior is the intended counterpart for `write_blob`, so these pairs should be treated as compatible rather than mismatched.

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.

If we document it, then as a separate PR.

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.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Comment thread cub/cub/device/device_reduce.cuh Resolved
@github-actions

This comment has been minimized.

@miscco
miscco force-pushed the device_reduce_argmin_dispatch branch from 4f27546 to 6bc3503 Compare July 1, 2026 13:29
@github-actions

This comment has been minimized.

…onment

We want to put more logic into the dispatch layer where it belongs
@miscco
miscco force-pushed the device_reduce_argmin_dispatch branch from 6bc3503 to cb77763 Compare July 2, 2026 11:32
@github-actions

This comment has been minimized.

using output_extremum_t = detail::non_void_value_t<ExtremumOutIteratorT, input_value_t>;
using default_policy_selector_t = detail::reduce::
policy_selector_from_types<KeyValuePair<PerPartitionOffsetT, output_extremum_t>, PerPartitionOffsetT, ReductionOpT>;
using default_policy_t = decltype(default_policy_selector_t{}(::cuda::compute_capability{}));

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.

Important: unused, please delete

Suggested change
using default_policy_t = decltype(default_policy_selector_t{}(::cuda::compute_capability{}));

Comment on lines +946 to +947
static_assert(__validate_determinism_streaming_reduce<EnvT>(), "gpu_to_gpu determinism is not supported");

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.

If we document it, then as a separate PR.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 44m: Pass: 100%/287 | Total: 13d 11h | Max: 2h 43m | Hits: 17%/1222119

See results here.

@bernhardmgruber

Copy link
Copy Markdown
Contributor

I asked claude for a SASS diff and it reports:

No SASS differences detected for cub.bench.reduce.arg_extrema.base on SM120 between the baseline (c5318b2 — parent of PR #9660) and the PR head (e9451b0).

@bernhardmgruber
bernhardmgruber merged commit 174a652 into NVIDIA:main Jul 3, 2026
307 of 308 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Jul 3, 2026
@miscco
miscco deleted the device_reduce_argmin_dispatch branch July 23, 2026 12:05
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