Repository navigation
[CUB] Refactor dispatch_streaming_arg_reduce to take a tuning environment - #9660
Conversation
0102443 to
4f27546
Compare
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 Walkthrough📝 WalkthroughComment |
There was a problem hiding this comment.
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 winsuggestion: Fix the ArgMax convenience overload notes.
Lines 1696 and 1934 say these overloads use
cuda::std::less, but Lines 1714 and 1950 passcuda::std::greater{}. Update the notes tocuda::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 valuesuggestion: Declare
policy_selectorconst.
policy_selectoris initialized once and only passed onward. Make itconstand, if needed, use a non-cv type forpolicy_selector_t. As per coding guidelines, "All variables that are not modified must be declaredconst, including cast results, function return values, and loop-invariant computations."Source: Coding guidelines
160-178: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winsuggestion: 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 liftsuggestion: none of the env variants tested (stream,
cuda::stream,stream_ref,execution::env{},cuda::execution::gpu[.with(...)]) exercise a custom tuning query, so theREQUIRE(expected_allocation_size == num_bytes)checks trivially pass with the same default policy every time. The PR's core change is thatdispatch_streaming_arg_reducenow derives its policy selector from a tuning environment via__query_or— add a case that supplies a real tuning override (a custompolicy_selector/tuning env) toArgMin/ArgMaxand 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
📒 Files selected for processing (5)
cub/cub/device/device_reduce.cuhcub/cub/device/dispatch/dispatch_streaming_reduce.cuhcub/test/catch2_test_device_reduce.culibcudacxx/include/cuda/std/__pstl/cuda/max_element.hlibcudacxx/include/cuda/std/__pstl/cuda/min_element.h
| static_assert(__validate_determinism_streaming_reduce<EnvT>(), "gpu_to_gpu determinism is not supported"); | ||
|
|
There was a problem hiding this comment.
📐 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
There was a problem hiding this comment.
@bernhardmgruber what do you think about that?
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
If we document it, then as a separate PR.
There was a problem hiding this comment.
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!
This comment has been minimized.
This comment has been minimized.
4f27546 to
6bc3503
Compare
This comment has been minimized.
This comment has been minimized.
…onment We want to put more logic into the dispatch layer where it belongs
6bc3503 to
cb77763
Compare
This comment has been minimized.
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{})); |
There was a problem hiding this comment.
Important: unused, please delete
| using default_policy_t = decltype(default_policy_selector_t{}(::cuda::compute_capability{})); |
| static_assert(__validate_determinism_streaming_reduce<EnvT>(), "gpu_to_gpu determinism is not supported"); | ||
|
|
There was a problem hiding this comment.
If we document it, then as a separate PR.
🥳 CI Workflow Results🟩 Finished in 2h 44m: Pass: 100%/287 | Total: 13d 11h | Max: 2h 43m | Hits: 17%/1222119See results here. |
We want to put more logic into the dispatch layer where it belongs