Repository navigation
[CUB] Refactor cub::DeviceRunLengthEncode to always take an environment - #11591
Conversation
Part of NVIDIA#9875. Replaces the trailing cudaStream_t parameter of the two-phase Encode and NonTrivialRuns 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. 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
|
No actionable comments were generated in the recent review. Summary
Change: Refactor Merge Risk:
|
…de env tests 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.
| // Before the environment parameter, the two-phase overloads took `cudaStream_t stream = nullptr`, so callers passing | ||
| // nullptr or a literal 0 for the stream exist. Both must keep compiling and keep running on the default stream. | ||
| CUB_TEST_CASE("DeviceRunLengthEncode two-phase overloads accept legacy null stream arguments", | ||
| "[run_length_encode][device]", | ||
| CUB_SMALL) |
There was a problem hiding this comment.
Remark: We could have this test for DeviceRunLengthEncode::NonTrivialRuns as well, but I generally don't think this test should be required on every algorithm. nullptr and 0 converting to an env and getting handled was demonstrated, so we don't need to prove it for every algorithm.
|
/ok to test 4faed85 |
This comment has been minimized.
This comment has been minimized.
|
/ok to test cd85475 |
This comment has been minimized.
This comment has been minimized.
|
/ok to test 1585629 |
🥳 CI Workflow Results🟩 Finished in 2h 45m: Pass: 100%/214 | Total: 8d 04h | Max: 2h 44m | Hits: 36%/1240913See results here. |
Description
Part of #9875 (the
DeviceRunLengthEncoderow).Replaces the trailing
cudaStream_tparameter of the two-phaseEncodeandNonTrivialRunsoverloads 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, #11589 and #11590 forDeviceMergeSort,DeviceMergeandDeviceMemcpy.The default policy selectors passed by the two-phase overloads are the ones the dispatch layer already defaulted to, so behavior without a tuning in the environment is unchanged. 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). The only caller outside the CUB tests,nvbench_helper/test/gen_entropy.cu, calls the two-phaseEncodewithout a stream argument and is unaffected. TheCustomDeviceRunLengthEncodewrapper in the NonTrivialRuns functional test callsdetail::rle::dispatchdirectly and is unaffected too.The doxygen blocks of the two-phase overloads now document
EnvTandenvinstead ofstream.Tests
Added to
cub/test/catch2_test_device_run_length_encode_env.cu, restricted toTEST_LAUNCH == 0since the two-phase overloads do not go through the launch wrappers:DeviceRunLengthEncode::Encode works with user provided memory and environmentand theNonTrivialRunscounterpart. 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 encoded runs.DeviceRunLengthEncode::Encode can be tuned with user provided memoryand theNonTrivialRunscounterpart, with two block sizes verified viablock_size_extracting_constant_iterator.DeviceRunLengthEncode two-phase overloads accept 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.run_length_encode_env.lid_{0,1,2}cub.test.device.run_length_encode.lid_{0,1,2}cub.test.device.run_length_encode_non_trivial_runs.lid_{0,1,2}cub.test.device.run_length_encode_api.lid_0,cub.test.device.run_length_encode_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.run_length_encode_env.lid_{0,1,2},cub.test.device.run_length_encode_api.lid_0andcub.test.device.run_length_encode_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: #11702