Repository navigation
[CUB] Refactor cub::DeviceMemcpy to always take an environment - #11590
Conversation
Part of NVIDIA#9875. Replaces the trailing cudaStream_t parameter of the two-phase DeviceMemcpy::Batched overload with an execution environment. The overload now dispatches through dispatch_with_env_and_tuning, so cuda::get_stream and cuda::execution::tune are honored like in the single-phase overload, mirroring DeviceCopy::Batched. Passing a cudaStream_t, nullptr or 0 keeps working. Adds env tests for the two-phase overload: 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
ChangesBatched memcpy environment support
Assessment against linked issues
Suggested reviewers: Priority: ⬇️ Low Change: Refactor Merge Risk: 🔵 Low · up to The environment API preserves the inspected dispatch contracts. This is mergeable with a bounded testing follow-up: strengthen the custom-stream test to detect incorrect stream selection. Comment |
The two-phase environment test now goes 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_memcpy_env.cu (1)
218-229: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winsuggestion: Instrument custom-stream dispatch with stream capture.
cuda::get_stream(env)is valid for all helper inputs and returns the default stream for environments without a custom stream. However, synchronization and vector equality do not prove stream placement. Default-stream ordering can make that check pass after a regression.For non-default streams, capture the execution call and require a captured graph node. Keep the existing uncaptured call for the result check.
Suggested fix
REQUIRE(num_bytes == expected_bytes); + auto stream = cuda::get_stream(env).get(); + if (stream != nullptr) { + cudaGraph_t graph{}; + size_t graph_nodes = 0; + REQUIRE(cudaSuccess == cudaStreamBeginCapture(stream, cudaStreamCaptureModeGlobal)); + REQUIRE( + cudaSuccess == cub::DeviceMemcpy::Batched(temp_storage, num_bytes, input_it, output_it, sizes, num_buffers, env)); + REQUIRE(cudaSuccess == cudaStreamEndCapture(stream, &graph)); + REQUIRE(cudaSuccess == cudaGraphGetNodes(graph, nullptr, &graph_nodes)); + REQUIRE(graph_nodes > 0); + REQUIRE(cudaSuccess == cudaGraphDestroy(graph)); + } + REQUIRE( cudaSuccess == cub::DeviceMemcpy::Batched(temp_storage, num_bytes, input_it, output_it, sizes, num_buffers, env));
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: NVIDIA/cccl/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: fdd48610-6cbb-4a1a-97e5-1eb3534abdbb
📒 Files selected for processing (1)
cub/test/catch2_test_device_memcpy_env.cu
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 9 remain after this review.
|
/ok to test 3dacc19 |
This comment has been minimized.
This comment has been minimized.
|
/ok to test 73d2f10 |
🥳 CI Workflow Results🟩 Finished in 2h 59m: Pass: 100%/202 | Total: 7d 05h | Max: 2h 48m | Hits: 45%/642469See results here. |
Description
Part of #9875 (the
DeviceMemcpyrow).Replaces the trailing
cudaStream_tparameter of the two-phaseDeviceMemcpy::Batchedoverload with an execution environment (const EnvT& env = {}). The overload now goes throughdetail::dispatch_with_env_and_tuningwith user-provided storage, so it honorscuda::get_streamandcuda::execution::tunethe same way the single-phase overload does. This mirrors the mergedDeviceCopy::Batchedrefactor (#9416) line by line, and follows #11587 and #11589 forDeviceMergeSortandDeviceMerge.Existing callers keep working: a
cudaStream_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). No caller outside the CUB tests usesDeviceMemcpy::Batchedin this repository.The doxygen block of the two-phase overload now documents
EnvTandenvinstead ofstream.Tests
Added to
cub/test/catch2_test_device_memcpy_env.cu, restricted toTEST_LAUNCH == 0since the two-phase overload does not go through the launch wrappers:DeviceMemcpy::Batched works with user provided memory and environment. It 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 copied buffers.DeviceMemcpy::Batched can be tuned with user provided memory, with two block sizes verified viablock_size_extracting_constant_iterator.DeviceMemcpy::Batched two-phase overload accepts legacy null stream argumentsfornullptrand0.Run locally on an RTX 5070 Ti (SM 120), CUDA 13.2, gcc 13.3, preset
cub-cpp20withCMAKE_CUDA_ARCHITECTURES=120. All of the following passed:cub.test.device.memcpy_env.lid_{0,1,2}cub.test.device.memcpy_batched.lid_{0,1,2}cub.test.device.memcpy_env_api.lid_0In 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.memcpy_env.lid_{0,1,2}andcub.test.device.memcpy_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: #11701