Repository navigation
[CUB] Refactor DevicePartition::If to always take an environment - #9464
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
89ae2b2 to
b6d1633
Compare
48a510a to
bd7b7d9
Compare
bd7b7d9 to
1fd1bb1
Compare
1fd1bb1 to
459699b
Compare
459699b to
4e582bc
Compare
This comment has been minimized.
This comment has been minimized.
4e582bc to
1abbfcf
Compare
1abbfcf to
d1954a8
Compare
|
|
||
| // Copy the result back from storage | ||
| _CCCL_TRY_CUDA_API( | ||
| ::cudaMemcpyAsync, |
There was a problem hiding this comment.
Unrelated to the current PR, but we should try and use the driver wherever possible so that we are explicit about the CUDA contexts. Especially for multi-GPU, the fact that runtime API leaves its the context on the stack is very problematic because some APIs (like cuMemcpy() actually) will behave differently if there is a context on the stack already.
This comment has been minimized.
This comment has been minimized.
d200e8a to
c381575
Compare
This comment has been minimized.
This comment has been minimized.
c381575 to
b858f79
Compare
This comment has been minimized.
This comment has been minimized.
b858f79 to
6c749a9
Compare
This comment has been minimized.
This comment has been minimized.
We want to be able to pass tunings to the APIs that take user provided memory Make sure we can pass any environment or stream type to them
6c749a9 to
66eeb73
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughSummary by CodeRabbit
WalkthroughChanges
DevicePartition environment support
Possibly related PRs
Suggested reviewers: Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
cub/test/catch2_test_device_partition_if.cu (1)
186-215: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winimportant: declare immutable local bindings
const.le,d_first_num_selected_out,temp_storage, andtest_partition_ifare never reassigned. As per coding guidelines, “All variables that are not modified must be declaredconst.”Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: e415d8ba-c558-4809-aed6-c7b4ef95d496
📒 Files selected for processing (5)
cub/cub/device/device_partition.cuhcub/test/catch2_test_device_partition_if.culibcudacxx/include/cuda/std/__pstl/cuda/partition.hlibcudacxx/include/cuda/std/__pstl/cuda/partition_copy.hlibcudacxx/include/cuda/std/__pstl/cuda/stable_partition.h
| #if TEST_LAUNCH == 0 | ||
| C2H_TEST("DevicePartition::If works with user provided memory and environment", "[device][partition_if]", types) | ||
| { | ||
| using type = typename c2h::get<0, TestType>; | ||
|
|
||
| const int num_items = GENERATE_COPY(take(2, random(1, 1000000))); | ||
| c2h::device_vector<type> in(num_items, thrust::default_init); | ||
| c2h::device_vector<type> out(num_items, thrust::default_init); | ||
| c2h::gen(C2H_SEED(2), in); | ||
|
|
||
| // just pick one of the input elements as boundary | ||
| less_than_t<type> le{in[num_items / 2]}; | ||
|
|
||
| // Needs to be device accessible | ||
| c2h::device_vector<int> num_selected_out(1, 0); | ||
| int* d_first_num_selected_out = thrust::raw_pointer_cast(num_selected_out.data()); | ||
|
|
||
| // Ensure that we create the same output as std | ||
| c2h::host_vector<type> reference = in; | ||
| // The main difference between stable_partition and DevicePartition::If is that the false partition is in reverse | ||
| // order | ||
| const auto boundary = std::stable_partition(reference.begin(), reference.end(), le); | ||
| std::reverse(boundary, reference.end()); | ||
|
|
||
| size_t expected_allocation_size = 0; | ||
| auto error = cub::DevicePartition::If( | ||
| static_cast<void*>(nullptr), | ||
| expected_allocation_size, | ||
| in.begin(), | ||
| out.begin(), | ||
| d_first_num_selected_out, | ||
| num_items, | ||
| le); | ||
| REQUIRE(error == cudaSuccess); | ||
| REQUIRE(cudaSuccess == cudaPeekAtLastError()); | ||
| REQUIRE(cudaSuccess == cudaDeviceSynchronize()); | ||
|
|
||
| auto d_temp = c2h::device_vector<uint8_t>(expected_allocation_size, thrust::no_init); | ||
| void* temp_storage = thrust::raw_pointer_cast(d_temp.data()); | ||
|
|
||
| auto test_partition_if = [&](const auto& env) { | ||
| size_t num_bytes = 0; | ||
| error = cub::DevicePartition::If( | ||
| static_cast<void*>(nullptr), num_bytes, in.begin(), out.begin(), d_first_num_selected_out, num_items, le, env); | ||
| REQUIRE(error == cudaSuccess); | ||
| REQUIRE(cudaSuccess == cudaPeekAtLastError()); | ||
| REQUIRE(cudaSuccess == cudaDeviceSynchronize()); | ||
| REQUIRE(expected_allocation_size == num_bytes); | ||
|
|
||
| error = cub::DevicePartition::If( | ||
| temp_storage, num_bytes, in.begin(), out.begin(), d_first_num_selected_out, num_items, le, env); | ||
| REQUIRE(error == cudaSuccess); | ||
| REQUIRE(cudaSuccess == cudaPeekAtLastError()); | ||
| REQUIRE(cudaSuccess == cudaDeviceSynchronize()); | ||
|
|
||
| REQUIRE(num_selected_out[0] == cuda::std::distance(reference.begin(), boundary)); | ||
| REQUIRE(reference == out); | ||
| }; | ||
|
|
||
| int current_device; | ||
| error = cudaGetDevice(¤t_device); | ||
| REQUIRE(error == cudaSuccess); | ||
|
|
||
| SECTION("DevicePartition::If works with cudaStream_t") | ||
| { | ||
| cuda::stream stream{cuda::devices[current_device]}; | ||
| test_partition_if(stream.get()); | ||
| } | ||
|
|
||
| SECTION("DevicePartition::If works with cuda::stream") | ||
| { | ||
| cuda::stream stream{cuda::devices[current_device]}; | ||
| test_partition_if(stream); | ||
| } | ||
|
|
||
| SECTION("DevicePartition::If works with cuda::stream_ref") | ||
| { | ||
| cuda::stream stream{cuda::devices[current_device]}; | ||
| cuda::stream_ref stream_ref{stream}; | ||
| test_partition_if(stream_ref); | ||
| } | ||
|
|
||
| SECTION("DevicePartition::If works with cuda::std::execution::env") | ||
| { | ||
| cuda::std::execution::env env{}; | ||
| test_partition_if(env); | ||
| } | ||
|
|
||
| SECTION("DevicePartition::If works with cuda::execution::gpu") | ||
| { | ||
| const auto policy = cuda::execution::gpu; | ||
| test_partition_if(policy); | ||
| } | ||
|
|
||
| SECTION("DevicePartition::If works with cuda::execution::gpu with stream") | ||
| { | ||
| cuda::stream stream{cuda::devices[current_device]}; | ||
| const auto policy = cuda::execution::gpu.with(cuda::get_stream, stream); | ||
| test_partition_if(policy); | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
important: add a user-provided-storage case with a custom PartitionPolicy selector or tuning environment. These sections only vary stream/environment representations, so they do not exercise the tuning contract introduced by this PR or catch a selector-type regression in the temporary-storage overload. As per path instructions, CUB reviews must focus on algorithm correctness and test coverage.
Source: Path instructions
This comment has been minimized.
This comment has been minimized.
🥳 CI Workflow Results🟩 Finished in 10h 09m: Pass: 100%/345 | Total: 8d 09h | Max: 1h 33m | Hits: 66%/786879See results here. |
…VIDIA#9464) We want to be able to pass tunings to the APIs that take user provided memory Make sure we can pass any environment or stream type to them Co-authored-by: Bernhard Manfred Gruber <[email protected]>
Description
closes
Checklist