-
Notifications
You must be signed in to change notification settings - Fork 988
batched_memset to use a host_span arg instead of std::vector
#19020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rapids-bot
merged 4 commits into
rapidsai:branch-25.08
from
mhaseeb123:improve/batched-memset
May 29, 2025
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6935f8e
Use a `host_span` as argument to batched_memset utility
mhaseeb123 cf4ba96
Merge branch 'branch-25.08' into improve/batched-memset
mhaseeb123 84f009d
style fix
mhaseeb123 60e3516
Merge branch 'branch-25.08' into improve/batched-memset
mhaseeb123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1561,7 +1561,7 @@ void reader::impl::allocate_columns(read_mode mode, size_t skip_rows, size_t num | |
| // if we have any list columns that need further processing. | ||
| bool has_lists = false; | ||
| // Casting to std::byte since data buffer pointer is void * | ||
| std::vector<cudf::device_span<std::byte>> memset_bufs; | ||
| std::vector<cudf::device_span<cuda::std::byte>> memset_bufs; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
| // Validity Buffer is a uint32_t pointer | ||
| std::vector<cudf::device_span<cudf::bitmask_type>> nullmask_bufs; | ||
|
|
||
|
|
@@ -1589,7 +1589,7 @@ void reader::impl::allocate_columns(read_mode mode, size_t skip_rows, size_t num | |
| std::overflow_error); | ||
| out_buf.create_with_mask( | ||
| out_buf_size, cudf::mask_state::UNINITIALIZED, false, _stream, _mr); | ||
| memset_bufs.emplace_back(static_cast<std::byte*>(out_buf.data()), out_buf.data_size()); | ||
| memset_bufs.emplace_back(static_cast<cuda::std::byte*>(out_buf.data()), out_buf.data_size()); | ||
| nullmask_bufs.emplace_back( | ||
| out_buf.null_mask(), | ||
| cudf::util::round_up_safe(out_buf.null_mask_size(), sizeof(cudf::bitmask_type)) / | ||
|
|
@@ -1704,7 +1704,7 @@ void reader::impl::allocate_columns(read_mode mode, size_t skip_rows, size_t num | |
| // we're going to start null mask as all valid and then turn bits off if necessary | ||
| out_buf.create_with_mask( | ||
| buffer_size, cudf::mask_state::UNINITIALIZED, false, _stream, _mr); | ||
| memset_bufs.emplace_back(static_cast<std::byte*>(out_buf.data()), out_buf.data_size()); | ||
| memset_bufs.emplace_back(static_cast<cuda::std::byte*>(out_buf.data()), out_buf.data_size()); | ||
| nullmask_bufs.emplace_back( | ||
| out_buf.null_mask(), | ||
| cudf::util::round_up_safe(out_buf.null_mask_size(), sizeof(cudf::bitmask_type)) / | ||
|
|
@@ -1714,9 +1714,10 @@ void reader::impl::allocate_columns(read_mode mode, size_t skip_rows, size_t num | |
| } | ||
| } | ||
|
|
||
| cudf::detail::batched_memset(memset_bufs, static_cast<std::byte>(0), _stream); | ||
| cudf::detail::batched_memset<cuda::std::byte>( | ||
| memset_bufs, static_cast<cuda::std::byte>(0), _stream); | ||
| // Need to set null mask bufs to all high bits | ||
| cudf::detail::batched_memset( | ||
| cudf::detail::batched_memset<cudf::bitmask_type>( | ||
| nullmask_bufs, std::numeric_limits<cudf::bitmask_type>::max(), _stream); | ||
| } | ||
|
|
||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ struct MultiBufferTestIntegral : public cudf::test::BaseFixture {}; | |
|
|
||
| TEST(MultiBufferTestIntegral, BasicTest1) | ||
| { | ||
| std::vector<size_t> const BUF_SIZES{ | ||
| std::vector<size_t> const buffer_sizes{ | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style |
||
| 50000, 4, 1000, 0, 250000, 1, 100, 8000, 0, 1, 100, 1000, 10000, 100000, 0, 1, 100000}; | ||
|
|
||
| // Device init | ||
|
|
@@ -46,52 +46,54 @@ TEST(MultiBufferTestIntegral, BasicTest1) | |
|
|
||
| // Creating base vector for data and setting it to all 0xFF | ||
| std::vector<std::vector<uint64_t>> expected; | ||
| std::transform(BUF_SIZES.begin(), BUF_SIZES.end(), std::back_inserter(expected), [](auto size) { | ||
| return std::vector<uint64_t>(size + 2000, std::numeric_limits<uint64_t>::max()); | ||
| }); | ||
| std::transform( | ||
| buffer_sizes.begin(), buffer_sizes.end(), std::back_inserter(expected), [](auto size) { | ||
| return std::vector<uint64_t>(size + 2000, std::numeric_limits<uint64_t>::max()); | ||
| }); | ||
|
|
||
| // set buffer region to other value | ||
| std::for_each(thrust::make_zip_iterator(thrust::make_tuple(expected.begin(), BUF_SIZES.begin())), | ||
| thrust::make_zip_iterator(thrust::make_tuple(expected.end(), BUF_SIZES.end())), | ||
| [](auto elem) { | ||
| std::fill_n( | ||
| thrust::get<0>(elem).begin() + 1000, thrust::get<1>(elem), 0xEEEEEEEEEEEEEEEE); | ||
| }); | ||
| std::for_each( | ||
| thrust::make_zip_iterator(thrust::make_tuple(expected.begin(), buffer_sizes.begin())), | ||
| thrust::make_zip_iterator(thrust::make_tuple(expected.end(), buffer_sizes.end())), | ||
| [](auto elem) { | ||
| std::fill_n(thrust::get<0>(elem).begin() + 1000, thrust::get<1>(elem), 0xEEEEEEEEEEEEEEEE); | ||
| }); | ||
|
|
||
| // Copy host vector data to device | ||
| std::vector<rmm::device_uvector<uint64_t>> device_bufs; | ||
| std::vector<rmm::device_uvector<uint64_t>> device_buffers; | ||
| std::transform(expected.begin(), | ||
| expected.end(), | ||
| std::back_inserter(device_bufs), | ||
| std::back_inserter(device_buffers), | ||
| [stream, mr](auto const& vec) { | ||
| return cudf::detail::make_device_uvector_async(vec, stream, mr); | ||
| }); | ||
|
|
||
| // Initialize device buffers for memset | ||
| std::vector<cudf::device_span<uint64_t>> memset_bufs; | ||
| auto buffers = | ||
| cudf::detail::make_host_vector<cudf::device_span<uint64_t>>(device_buffers.size(), stream); | ||
| std::transform( | ||
| thrust::make_zip_iterator(thrust::make_tuple(device_bufs.begin(), BUF_SIZES.begin())), | ||
| thrust::make_zip_iterator(thrust::make_tuple(device_bufs.end(), BUF_SIZES.end())), | ||
| std::back_inserter(memset_bufs), | ||
| thrust::make_zip_iterator(thrust::make_tuple(device_buffers.begin(), buffer_sizes.begin())), | ||
| thrust::make_zip_iterator(thrust::make_tuple(device_buffers.end(), buffer_sizes.end())), | ||
| buffers.begin(), | ||
| [](auto const& elem) { | ||
| return cudf::device_span<uint64_t>(thrust::get<0>(elem).data() + 1000, thrust::get<1>(elem)); | ||
| }); | ||
|
|
||
| // Function Call | ||
| cudf::detail::batched_memset(memset_bufs, uint64_t{0}, stream); | ||
| // Function call | ||
| cudf::detail::batched_memset<uint64_t>(buffers, uint64_t{0}, stream); | ||
|
|
||
| // Set all buffer regions to 0 for expected comparison | ||
| std::for_each( | ||
| thrust::make_zip_iterator(thrust::make_tuple(expected.begin(), BUF_SIZES.begin())), | ||
| thrust::make_zip_iterator(thrust::make_tuple(expected.end(), BUF_SIZES.end())), | ||
| thrust::make_zip_iterator(thrust::make_tuple(expected.begin(), buffer_sizes.begin())), | ||
| thrust::make_zip_iterator(thrust::make_tuple(expected.end(), buffer_sizes.end())), | ||
| [](auto elem) { std::fill_n(thrust::get<0>(elem).begin() + 1000, thrust::get<1>(elem), 0UL); }); | ||
|
|
||
| // Compare to see that only given buffers are zeroed out | ||
| std::for_each( | ||
| thrust::make_zip_iterator(thrust::make_tuple(device_bufs.begin(), expected.begin())), | ||
| thrust::make_zip_iterator(thrust::make_tuple(device_bufs.end(), expected.end())), | ||
| thrust::make_zip_iterator(thrust::make_tuple(device_buffers.begin(), expected.begin())), | ||
| thrust::make_zip_iterator(thrust::make_tuple(device_buffers.end(), expected.end())), | ||
| [stream](auto const& elem) { | ||
| auto after_memset = cudf::detail::make_std_vector_async(thrust::get<0>(elem), stream); | ||
| auto const after_memset = cudf::detail::make_host_vector(thrust::get<0>(elem), stream); | ||
| EXPECT_TRUE( | ||
| std::equal(thrust::get<1>(elem).begin(), thrust::get<1>(elem).end(), after_memset.begin())); | ||
| }); | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor improvement to docstring here