Repository navigation
[CUB] Refactor cub::DeviceMerge to always take an environment - #11589
Conversation
Part of NVIDIA#9875. Replaces the trailing cudaStream_t parameter of the two-phase MergeKeys and MergePairs overloads with an execution environment. The two-phase overloads now dispatch through dispatch_with_env_and_tuning, so cuda::get_stream and cuda::execution::tune are honored like in the single-phase overloads. Passing a cudaStream_t, nullptr or 0 keeps working, which covers thrust::merge and thrust::merge_by_key. Adds env tests for the two-phase overloads: per-environment-kind runs with user provided storage that verify the launch stream, tuning extraction with two block sizes, and the legacy null-stream arguments. Developed in combination with Claude Fable 5.1
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configurationConfiguration used: Repository: NVIDIA/cccl/.coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 SummarySummary by CodeRabbit
Walkthrough
ChangesDeviceMerge environment dispatch
Assessment against linked issues
Suggested reviewers: Priority: ⬇️ Low Change: Feature Merge Risk: 🔵 Low · up to The environment-aware merge implementation preserves the inspected compatibility contracts. Merging is reasonable with follow-up to strengthen custom-stream tests, which currently cannot detect execution on the wrong stream. Comment |
bernhardmgruber
left a comment
There was a problem hiding this comment.
Looks mostly good!
| SECTION("default environment") | ||
| { | ||
| run(stdexec::env<>{}, default_stream); | ||
| } | ||
|
|
||
| SECTION("cudaStream_t") | ||
| { | ||
| run(stream.get(), cuda::stream_ref{stream}); | ||
| } | ||
|
|
||
| SECTION("cuda::stream") | ||
| { | ||
| run(stream, cuda::stream_ref{stream}); | ||
| } | ||
|
|
||
| SECTION("cuda::stream_ref") | ||
| { | ||
| run(cuda::stream_ref{stream}, cuda::stream_ref{stream}); | ||
| } | ||
|
|
||
| SECTION("environment with stream") | ||
| { | ||
| run(stdexec::env{cuda::stream_ref{stream}}, cuda::stream_ref{stream}); | ||
| } | ||
|
|
||
| SECTION("cuda::execution::gpu") | ||
| { | ||
| run(cuda::execution::gpu, default_stream); | ||
| } | ||
|
|
||
| SECTION("cuda::execution::gpu with stream") | ||
| { | ||
| run(cuda::execution::gpu.with(cuda::get_stream, cuda::stream_ref{stream}), cuda::stream_ref{stream}); | ||
| } |
There was a problem hiding this comment.
Important: I added a helper test_with_custom_streams(TestFunc&& test_func) to catch2_test_custom_streams.cuh that should automate the various stream types. Please use it here.
There was a problem hiding this comment.
Done in 3afb25e: both two-phase tests now use test_with_custom_streams.
| { | ||
| auto keys1 = c2h::device_vector<int>{0, 2, 5}; | ||
| auto keys2 = c2h::device_vector<int>{0, 3, 3, 4}; | ||
| auto result = c2h::device_vector<int>(7); |
There was a problem hiding this comment.
Important: Please use thrust::no_init for any result vectors.
@CodeRabbit why did you not flag this?
There was a problem hiding this comment.
📌 Tracking this review finding. CodeRabbit will verify future changes against the original feedback and will only mark it fixed when the code satisfies it.
There was a problem hiding this comment.
I'll remember that next time. Should be fixed in 3afb25e: all result vectors use thrust::no_init.
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!
|
/ok to test 9767af2 |
This comment has been minimized.
This comment has been minimized.
The two-phase environment tests now go through the shared test_with_custom_streams helper instead of a local sweep over stream kinds, and result vectors are created with thrust::no_init.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cub/test/catch2_test_device_merge_env.cu (1)
396-452: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winsuggestion: Scope stream-bearing custom-stream sections.
launch_envactivatesstream_scope, but the direct two-phase MergeKeys and MergePairs tests bypasslaunch_env. The shared stream helper also leavesm_streamunset, so a default-stream launch can pass the current synchronization and output checks.#include <c2h/catch2_test_helper.h> #include <c2h/device_and_stream.h> +#include "stream_registry_factory.h" @@ void test_with_custom_streams(TestFunc&& test_func, const cuda::stream& stream) { + const stream_scope scope{stream.get()}; + SECTION("works with cudaStream_t")The scope ends before the streamless sections in the overload without an explicit stream.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: NVIDIA/cccl/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: e5a59cc7-77e3-48ce-b471-74424dad5c54
📒 Files selected for processing (1)
cub/test/catch2_test_device_merge_env.cu
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.
|
/ok to test 3afb25e |
This comment has been minimized.
This comment has been minimized.
|
/ok to test 97be89f |
This comment has been minimized.
This comment has been minimized.
|
/ok to test f64a5fb |
🥳 CI Workflow Results🟩 Finished in 4h 20m: Pass: 100%/202 | Total: 14d 18h | Max: 3h 58m | Hits: 37%/1746664See results here. AI failure analysis1. RAFT compilation cannot find rmm/cuda_stream_view.hpp · 2 jobsExplanation: Both jobs checked out the same RMM and RAFT main revisions, built RMM successfully, and then failed while compiling RAFT with the RMM include directory configured. This indicates incompatible upstream RMM/RAFT revisions; the logs do not contain upstream file history showing whether RMM removed the header or RAFT has not yet migrated from it. Evidence: Copy this prompt into a coding agentJobs: 2. RAPIDS environment creation times out downloading rapidsai-nightly repodata · 2 jobsExplanation: Both jobs stopped during conda environment creation before any project compilation because libmamba could not load rapidsai-nightly channel metadata. The cuopt job's subsequent report that RAPIDS packages do not exist is derivative of the failed metadata download, not evidence of an independent dependency specification error. Evidence: Copy this prompt into a coding agentJobs: |
Description
Part of #9875 (the
DeviceMergerow).Replaces the trailing
cudaStream_tparameter of the two-phaseMergeKeysandMergePairsoverloads with an execution environment (const EnvT& env = {}). The two-phase overloads now go throughdetail::dispatch_with_env_and_tuningwith user-provided storage, so they honorcuda::get_streamandcuda::execution::tunethe same way the single-phase overloads do. This follows the pattern of the merged sibling refactors (#9416, #9455 to #9459, #9463, #9464, #9552 to #9555, #11013) and of #11587 forDeviceMergeSort.The overload sets keep their previous shape, so the existing
enable_ifguards on the single-phase overloads still separate the two families at the one overlapping arity. Existing callers keep working: acudaStream_t,nullptror literal0passed in the last position is accepted (cuda::get_streamhandles the first two, the third falls back to the default stream as before). Callers checked:thrust::mergeandthrust::merge_by_key(thrust/system/cuda/detail/merge.h) call the two-phase overloads with the policy'scudaStream_t, from host code and under CDP. The Thrust merge tests pass with this change.cuda::std::__pstlmerge and the cudax multi-GPU HSS k-way merge use the single-phase overloads and are unaffected.The doxygen blocks of the two-phase overloads now document
EnvTandenvinstead ofstream.Tests
Added to
cub/test/catch2_test_device_merge_env.cu, restricted toTEST_LAUNCH == 0since the two-phase overloads do not go through the launch wrappers:DeviceMerge::MergeKeys works with user provided memory and environmentand theMergePairscounterpart. Each runs throughtest_with_custom_streamsfor every stream and environment kind the helper covers, checks that the storage query matches the legacy overload, and verifies the merged output.DeviceMerge::MergeKeys can be tuned with user provided memoryand theMergePairscounterpart, with two block sizes verified viablock_size_extracting_op.DeviceMerge two-phase overloads accept legacy null stream argumentsfornullptrand0.Run locally on an RTX 5070 Ti (SM 120), CUDA 13.2, gcc 13.3, presets
cub-cpp20andthrust-cpp20withCMAKE_CUDA_ARCHITECTURES=120. All of the following passed:cub.test.device.merge_env.lid_{0,1,2}cub.test.device.merge.lid_{0,1,2}cub.test.device.merge_no_unroll.lid_{0,1,2}cub.test.device.merge_api.lid_0,cub.test.device.merge_env_api.lid_0thrust.cpp.cuda.test.merge,thrust.cpp.cuda.test.merge_by_key,thrust.cpp.cuda.test.merge_key_valueIn addition, the same tree builds with clang 21 as the host compiler under C++17 (preset
cub-cpp17,-Werror -Wall -Wextra) with zero warnings, andcub.test.device.merge_env.lid_{0,1,2},cub.test.device.merge_api.lid_0andcub.test.device.merge_env_api.lid_0pass in that configuration too.pre-commitpasses on the changed files. I could not build the MSVC or NVHPC configurations locally.Checklist
Developed with Claude Fable 5.1
Fixes: #11700