Repository navigation
[CUB] Refactor cub::DeviceFor to always take an environment - #11013
Conversation
There was a problem hiding this comment.
Pull request overview
This PR continues the CUB device-scope API migration away from a trailing cudaStream_t parameter by refactoring cub::DeviceFor to consistently accept an execution environment (const Env&) for both single-phase and two-phase overloads. It also tightens environment/stream querying behavior to avoid silent fallback to the default stream for env types that are only non-const convertible to cudaStream_t, and fixes ForEachInExtents behavior for empty extents plus a mislabeled NVTX range.
Changes:
- Replaced
cudaStream_tparameters inDeviceFortwo-phase overloads withconst Env&, and removed the bare-stream single-phase overloads/SFINAE. - Added a compile-time guard to reject env types whose stream conversion cannot be queried through a
const&(preventing silent default-stream launches). - Fixed
ForEachInExtentsempty-extent handling (avoidsfast_div_modassertion) and corrected theForEachInLayoutNVTX range name; expanded/updated Catch2 coverage accordingly.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
cub/cub/device/device_for.cuh |
Refactors DeviceFor APIs to use environments everywhere, adds const-query static_assert guard, fixes empty-extents path, and corrects NVTX labeling/docs. |
cub/test/catch2_test_device_for_env.cu |
Adds broad environment-kind acceptance tests, stream-routing verification, and two-phase tuning propagation coverage for the updated env-based APIs. |
cub/test/catch2_test_device_for_api.cu |
Updates unambiguity guard tests and adds size-query guards for extents/layout plus a runtime test for empty-extents handling. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
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:
📝 SummarySummary by CodeRabbit
WalkthroughChangesDeviceFor operations now use execution environments for stream selection. Legacy ChangesDeviceFor execution environments
Suggested reviewers: Merge Risk: 🟡 Moderate · up to The PR changes DeviceFor stream selection to use execution environments, but mutable-only wrappers may now run on the default CUDA stream instead of their represented stream, potentially breaking synchronization or capture assumptions. A multi-GPU test can also target the wrong device, and a test const-correctness issue remains open; these should be fixed or explicitly accepted before merging. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cub/cub/device/device_for.cuh (1)
1278-1289: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winsuggestion:
extents,shape,sub_sizes_div_array,extents_div_array, andop_wrapperare never modified after initialization. Declare themconst.- auto extents = layout_mapping.extents(); + const auto extents = layout_mapping.extents(); using ShapeT = implicit_prom_t<extent_index_type>; - auto shape = static_cast<ShapeT>(cub::detail::size(extents)); + const auto shape = static_cast<ShapeT>(cub::detail::size(extents)); // must precede the fast_div_mod arrays below, whose constructor asserts a positive divisor if (shape == 0) { return cudaSuccess; } - fast_mod_array_t sub_sizes_div_array = cub::detail::sub_sizes_fast_div_mod<is_layout_right>(extents, seq); - fast_mod_array_t extents_div_array = cub::detail::extents_fast_div_mod(extents, seq); - for_each::op_wrapper_extents_t<OpType, extents_type, is_layout_right, fast_mod_array_t> op_wrapper{ + const fast_mod_array_t sub_sizes_div_array = cub::detail::sub_sizes_fast_div_mod<is_layout_right>(extents, seq); + const fast_mod_array_t extents_div_array = cub::detail::extents_fast_div_mod(extents, seq); + const for_each::op_wrapper_extents_t<OpType, extents_type, is_layout_right, fast_mod_array_t> op_wrapper{ op, extents, sub_sizes_div_array, extents_div_array};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
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 38b95cf6-a477-4750-b9e7-9fe3ee2c9994
📒 Files selected for processing (3)
cub/cub/device/device_for.cuhcub/test/catch2_test_device_for_api.cucub/test/catch2_test_device_for_env.cu
Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: cbd4e601-3346-4d85-9f7c-1677215a9eb4
📒 Files selected for processing (2)
cub/cub/device/device_for.cuhcub/test/catch2_test_device_for_env.cu
Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.
7a96f60 to
ff3305c
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: ae10d251-70a3-4255-abc6-116817670d95
📒 Files selected for processing (3)
cub/cub/device/device_for.cuhcub/test/catch2_test_device_for_api.cucub/test/catch2_test_device_for_env.cu
🚧 Files skipped from review as they are similar to previous changes (2)
- cub/test/catch2_test_device_for_api.cu
- cub/cub/device/device_for.cuh
Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
|
/ok to test c4ee8bd |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
/ok to test b2006d0 |
This comment has been minimized.
This comment has been minimized.
|
/ok to test aa20309 |
🥳 CI Workflow Results🟩 Finished in 2h 55m: Pass: 100%/176 | Total: 8d 14h | Max: 2h 55m | Hits: 33%/569347See results here. |
|
Thank you for your contribution! 🎉 |
|
Thanks for the feedback everyone! |
…#11013) * [CUB] Refactor `cub::DeviceFor` to always take an environment * Address PR comments * Update __for_each_n, remove static assert, and add test case for __for_each_n * Address code-rabbit comments re const and additional device-ref comment * Suppress MSVC C4127 on the empty-extent check, which is constant for fully static extents * Fix graph race condition in threads_multiple_graphs test case * Revert "Fix graph race condition in threads_multiple_graphs test case" This reverts commit 6a8e638. * Use lambdas inside test body and move utility functions to top of file * Use existing block size extracting function
…#11013) * [CUB] Refactor `cub::DeviceFor` to always take an environment * Address PR comments * Update __for_each_n, remove static assert, and add test case for __for_each_n * Address code-rabbit comments re const and additional device-ref comment * Suppress MSVC C4127 on the empty-extent check, which is constant for fully static extents * Fix graph race condition in threads_multiple_graphs test case * Revert "Fix graph race condition in threads_multiple_graphs test case" This reverts commit 6a8e638. * Use lambdas inside test body and move utility functions to top of file * Use existing block size extracting function
Description
Part of #9875 (the DeviceFor row).
Fixes: #11713
Fixes: #11714
Replaces the trailing
cudaStream_tparameter of the two-phaseBulk,ForEachN,ForEach,ForEachCopyN,ForEachCopy,ForEachInExtents, andForEachInLayoutoverloads with an execution environment, and removes the bare-stream single-phase overloads and their SFINAE, which are no longer needed now that environments are taken byconst&(#10105).Notes:
cudaStream_tis not const-qualified — previously served by the removed overloads, these would otherwise silently launch on the default stream. Flagged for discussion: happy to generalize it intocuda::get_stream/env_dispatch.cuhas a follow-up, or drop it for exact parity with the sibling migrations.fast_div_modassertion failure for empty extents inForEachInExtents, the mislabeledForEachInLayoutNVTX range, and its param docs.Checklist