Add env DeviceMemcpy::Batched and tests#7966
Open
gonidelis wants to merge 1 commit intoNVIDIA:mainfrom
Open
Conversation
This comment has been minimized.
This comment has been minimized.
Contributor
🥳 CI Workflow Results🟩 Finished in 5h 37m: Pass: 100%/249 | Total: 1d 22h | Max: 1h 03m | Hits: 98%/156109See results here. |
| { | ||
| // 3 buffers: [10, 20], [30, 40, 50], [60] | ||
| auto d_src = c2h::device_vector<int>{10, 20, 30, 40, 50, 60}; | ||
| auto d_dst = c2h::device_vector<int>(6, 0); |
Contributor
There was a problem hiding this comment.
Suggestion:
Suggested change
| auto d_dst = c2h::device_vector<int>(6, 0); | |
| auto d_dst = c2h::device_vector<int>(6); |
|
|
||
| int num_buffers = 3; | ||
|
|
||
| thrust::counting_iterator<int> iota(0); |
Contributor
There was a problem hiding this comment.
Important: Please prefer cuda iterators over thrust iterators.
Comment on lines
+116
to
+117
| cudaStream_t custom_stream; | ||
| REQUIRE(cudaSuccess == cudaStreamCreate(&custom_stream)); |
Contributor
There was a problem hiding this comment.
Important: Please use cuda::stream to increase its test coverage
| } | ||
| }; | ||
|
|
||
| #if TEST_LAUNCH == 0 |
Contributor
There was a problem hiding this comment.
Q: What prevents us from running the below unit test for launch id 1 and 2?
Comment on lines
+43
to
+68
| // 3 buffers of different sizes: [10, 20], [30, 40, 50], [60] | ||
| auto d_src = thrust::device_vector<int>{10, 20, 30, 40, 50, 60}; | ||
| auto d_dst = thrust::device_vector<int>(6, 0); | ||
| auto d_offsets = thrust::device_vector<int>{0, 2, 5, 6}; | ||
|
|
||
| int num_buffers = 3; | ||
|
|
||
| thrust::counting_iterator<int> iota(0); | ||
| auto input_it = thrust::make_transform_iterator( | ||
| iota, index_to_ptr<const int>{thrust::raw_pointer_cast(d_src.data()), thrust::raw_pointer_cast(d_offsets.data())}); | ||
| auto output_it = thrust::make_transform_iterator( | ||
| iota, index_to_ptr<int>{thrust::raw_pointer_cast(d_dst.data()), thrust::raw_pointer_cast(d_offsets.data())}); | ||
| auto sizes = thrust::make_transform_iterator(iota, get_size{thrust::raw_pointer_cast(d_offsets.data())}); | ||
|
|
||
| cuda::stream stream{cuda::devices[0]}; | ||
| cuda::stream_ref stream_ref{stream}; | ||
| auto env = cuda::std::execution::env{stream_ref}; | ||
|
|
||
| auto error = cub::DeviceMemcpy::Batched(input_it, output_it, sizes, num_buffers, env); | ||
| if (error != cudaSuccess) | ||
| { | ||
| std::cerr << "cub::DeviceMemcpy::Batched failed with status: " << error << std::endl; | ||
| } | ||
|
|
||
| thrust::device_vector<int> expected{10, 20, 30, 40, 50, 60}; | ||
| // example-end memcpy-batched-env |
Contributor
There was a problem hiding this comment.
Suggestion: I don't think this is a great API example. We should focus on the API's design of taking an iterator to pointers. Something like:
auto d_src = thrust::device_vector<int>{10, 20, 30, 40, 50, 60};
auto d_src_pointers = thrust::device_vector<int*>{d_src[0], d_src[2], d_src[5]};- the raw pointer casts. You could even consider writing the results to two different buffers, to highlight the API's flexibility.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #7540
Adds environment overload for the only overload of
DeviceMemcpy,DeviceMemcpy::Batchedthat is.No deterministic guarantees are specified.