Skip to content
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

Fix AllocateLikeTest gtests reading uninitialized null-mask #12643

Merged
merged 3 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions cpp/src/copying/copy.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022, NVIDIA CORPORATION.
* Copyright (c) 2019-2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -125,16 +125,11 @@ std::unique_ptr<column> allocate_like(column_view const& input,
CUDF_EXPECTS(is_fixed_width(input.type()), "Expects only fixed-width type column");
mask_state allocate_mask = should_allocate_mask(mask_alloc, input.nullable());

auto op = [&](auto const& child) { return allocate_like(child, size, mask_alloc, stream, mr); };
auto begin = thrust::make_transform_iterator(input.child_begin(), op);
std::vector<std::unique_ptr<column>> children(begin, begin + input.num_children());

return std::make_unique<column>(input.type(),
size,
rmm::device_buffer(size * size_of(input.type()), stream, mr),
detail::create_null_mask(size, allocate_mask, stream, mr),
state_null_count(allocate_mask, input.size()),
std::move(children));
state_null_count(allocate_mask, input.size()));
}

} // namespace detail
Expand Down
50 changes: 38 additions & 12 deletions cpp/tests/copying/utility_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022, NVIDIA CORPORATION.
* Copyright (c) 2019-2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -192,26 +192,52 @@ TYPED_TEST_SUITE(AllocateLikeTest, numeric_types);
TYPED_TEST(AllocateLikeTest, ColumnNumericTestSameSize)
{
// For same size as input
cudf::size_type size = 10;
cudf::mask_state state = cudf::mask_state::ALL_VALID;
auto input = make_numeric_column(cudf::data_type{cudf::type_to_id<TypeParam>()}, size, state);
auto expected = make_numeric_column(
cudf::data_type{cudf::type_to_id<TypeParam>()}, size, cudf::mask_state::ALL_VALID);
cudf::size_type size = 10;

auto input = make_numeric_column(
cudf::data_type{cudf::type_to_id<TypeParam>()}, size, cudf::mask_state::UNALLOCATED);
auto got = cudf::allocate_like(input->view());
CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUAL(*expected, *got);
CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUAL(*input, *got);

input = make_numeric_column(
cudf::data_type{cudf::type_to_id<TypeParam>()}, size, cudf::mask_state::ALL_VALID);
got = cudf::allocate_like(input->view());
EXPECT_EQ(input->type(), got->type());
EXPECT_EQ(input->size(), got->size());
EXPECT_EQ(input->nullable(), got->nullable());
EXPECT_EQ(input->num_children(), got->num_children());
// CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUAL includes checking the null-count property.
// This value will be incorrect since the null mask will contain uninitialized bits
// and the null-count set to UNKNOWN_NULL_COUNT on return from allocate_like().
// This means any subsequent call to null_count() will try to compute the null-count
// using the uninitialized null-mask.
}

TYPED_TEST(AllocateLikeTest, ColumnNumericTestSpecifiedSize)
{
// For same size as input
// For different size as input
cudf::size_type size = 10;
cudf::size_type specified_size = 5;
cudf::mask_state state = cudf::mask_state::ALL_VALID;
auto input = make_numeric_column(cudf::data_type{cudf::type_to_id<TypeParam>()}, size, state);
auto expected = make_numeric_column(
cudf::data_type{cudf::type_to_id<TypeParam>()}, specified_size, cudf::mask_state::ALL_VALID);

auto state = cudf::mask_state::UNALLOCATED;
auto input = make_numeric_column(cudf::data_type{cudf::type_to_id<TypeParam>()}, size, state);
auto expected =
make_numeric_column(cudf::data_type{cudf::type_to_id<TypeParam>()}, specified_size, state);
auto got = cudf::allocate_like(input->view(), specified_size);
CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUAL(*expected, *got);

input = make_numeric_column(
cudf::data_type{cudf::type_to_id<TypeParam>()}, size, cudf::mask_state::ALL_VALID);
got = cudf::allocate_like(input->view(), specified_size);
EXPECT_EQ(input->type(), got->type());
EXPECT_EQ(specified_size, got->size());
EXPECT_EQ(input->nullable(), got->nullable());
EXPECT_EQ(input->num_children(), got->num_children());
// CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUAL includes checking the null-count property.
// This value will be incorrect since the null mask will contain uninitialized bits
// and the null-count set to UNKNOWN_NULL_COUNT on return from allocate_like().
// This means any subsequent call to null_count() will try to compute the null-count
// using the uninitialized null-mask.
}

CUDF_TEST_PROGRAM_MAIN()