-
Notifications
You must be signed in to change notification settings - Fork 927
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose stream-ordering in column view APIs (#17434)
Adds stream parameter to ``` cudf::detail::column_view_base::null_count(begin, end) cudf::detail::column_view_base::has_nulls(begin, end) ``` Note: Since stream-ordered prefetching is [back-logged](#17434 (comment)), we defer modifying the `get_data` member functions to accept a stream parameter for now. Reference: 1. #13744 2. #16251 (comment) Authors: - Shruti Shivakumar (https://github.com/shrshi) Approvers: - Nghia Truong (https://github.com/ttnghia) - Bradley Dice (https://github.com/bdice) URL: #17434
- Loading branch information
Showing
6 changed files
with
129 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright (c) 2025, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <cudf_test/base_fixture.hpp> | ||
#include <cudf_test/column_wrapper.hpp> | ||
#include <cudf_test/default_stream.hpp> | ||
#include <cudf_test/type_lists.hpp> | ||
|
||
#include <cudf/column/column_view.hpp> | ||
#include <cudf/null_mask.hpp> | ||
#include <cudf/transform.hpp> | ||
|
||
#include <random> | ||
#include <vector> | ||
|
||
template <typename T> | ||
struct TypedColumnTest : public cudf::test::BaseFixture { | ||
cudf::data_type type() { return cudf::data_type{cudf::type_to_id<T>()}; } | ||
|
||
TypedColumnTest(rmm::cuda_stream_view stream = cudf::test::get_default_stream()) | ||
: data{_num_elements * cudf::size_of(type()), stream}, | ||
mask{cudf::bitmask_allocation_size_bytes(_num_elements), stream} | ||
{ | ||
std::vector<char> h_data(std::max(data.size(), mask.size())); | ||
std::iota(h_data.begin(), h_data.end(), 0); | ||
CUDF_CUDA_TRY( | ||
cudaMemcpyAsync(data.data(), h_data.data(), data.size(), cudaMemcpyDefault, stream.value())); | ||
CUDF_CUDA_TRY( | ||
cudaMemcpyAsync(mask.data(), h_data.data(), mask.size(), cudaMemcpyDefault, stream.value())); | ||
} | ||
|
||
cudf::size_type num_elements() { return _num_elements; } | ||
|
||
std::random_device r; | ||
std::default_random_engine generator{r()}; | ||
std::uniform_int_distribution<cudf::size_type> distribution{200, 1000}; | ||
cudf::size_type _num_elements{distribution(generator)}; | ||
rmm::device_buffer data{}; | ||
rmm::device_buffer mask{}; | ||
rmm::device_buffer all_valid_mask{create_null_mask( | ||
num_elements(), cudf::mask_state::ALL_VALID, cudf::test::get_default_stream())}; | ||
rmm::device_buffer all_null_mask{ | ||
create_null_mask(num_elements(), cudf::mask_state::ALL_NULL, cudf::test::get_default_stream())}; | ||
}; | ||
|
||
TYPED_TEST_SUITE(TypedColumnTest, cudf::test::Types<int32_t>); | ||
|
||
/** | ||
* @brief Verifies equality of the properties and data of a `column`'s views. | ||
* | ||
* @param col The `column` to verify | ||
*/ | ||
void verify_column_views(cudf::column& col) | ||
{ | ||
cudf::column_view view = col; | ||
cudf::mutable_column_view mutable_view = col; | ||
EXPECT_EQ(col.type(), view.type()); | ||
EXPECT_EQ(col.type(), mutable_view.type()); | ||
EXPECT_EQ(col.size(), view.size()); | ||
EXPECT_EQ(col.size(), mutable_view.size()); | ||
EXPECT_EQ(col.null_count(), view.null_count()); | ||
EXPECT_EQ(col.null_count(), mutable_view.null_count()); | ||
EXPECT_EQ(view.null_count(0, col.size(), cudf::test::get_default_stream()), | ||
mutable_view.null_count(0, col.size(), cudf::test::get_default_stream())); | ||
EXPECT_EQ(view.has_nulls(0, col.size(), cudf::test::get_default_stream()), | ||
mutable_view.has_nulls(0, col.size(), cudf::test::get_default_stream())); | ||
EXPECT_EQ(col.null_count(), mutable_view.null_count()); | ||
EXPECT_EQ(col.nullable(), view.nullable()); | ||
EXPECT_EQ(col.nullable(), mutable_view.nullable()); | ||
EXPECT_EQ(col.num_children(), view.num_children()); | ||
EXPECT_EQ(col.num_children(), mutable_view.num_children()); | ||
EXPECT_EQ(view.head(), mutable_view.head()); | ||
EXPECT_EQ(view.data<char>(), mutable_view.data<char>()); | ||
EXPECT_EQ(view.offset(), mutable_view.offset()); | ||
} | ||
|
||
TYPED_TEST(TypedColumnTest, CopyConstructorWithMask) | ||
{ | ||
cudf::column original{ | ||
this->type(), this->num_elements(), std::move(this->data), std::move(this->all_valid_mask), 0}; | ||
cudf::column copy{original, cudf::test::get_default_stream()}; | ||
verify_column_views(copy); | ||
CUDF_TEST_EXPECT_COLUMNS_EQUAL(original, copy); | ||
|
||
// Verify deep copy | ||
cudf::column_view original_view = original; | ||
cudf::column_view copy_view = copy; | ||
EXPECT_NE(original_view.head(), copy_view.head()); | ||
EXPECT_NE(original_view.null_mask(), copy_view.null_mask()); | ||
} |