Skip to content

Commit

Permalink
Change some .cu gtest files to .cpp (#13155)
Browse files Browse the repository at this point in the history
Changed some libcudf gtests source files from .cu to .cpp by removing the unneeded thrust calls. This also simplified the logic a bit as well.
These were found while working on #13149

Authors:
  - David Wendt (https://github.com/davidwendt)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Robert Maynard (https://github.com/robertmaynard)
  - https://github.com/nvdbaranec

URL: #13155
  • Loading branch information
davidwendt authored Apr 19, 2023
1 parent de676b1 commit 4f85f63
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 101 deletions.
4 changes: 2 additions & 2 deletions cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ConfigureTest(
COLUMN_TEST
column/bit_cast_test.cpp
column/column_device_view_test.cu
column/column_test.cu
column/column_test.cpp
column/column_view_device_span_test.cpp
column/column_view_shallow_test.cpp
column/compound_test.cu
Expand Down Expand Up @@ -306,7 +306,7 @@ ConfigureTest(
# * copying tests ---------------------------------------------------------------------------------
ConfigureTest(
COPYING_TEST
copying/concatenate_tests.cu
copying/concatenate_tests.cpp
copying/copy_if_else_nested_tests.cpp
copying/copy_range_tests.cpp
copying/copy_tests.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,42 @@
* limitations under the License.
*/

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_utilities.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/cudf_gtest.hpp>
#include <cudf_test/type_list_utilities.hpp>
#include <cudf_test/type_lists.hpp>

#include <cudf/column/column.hpp>
#include <cudf/column/column_factories.hpp>
#include <cudf/column/column_view.hpp>
#include <cudf/copying.hpp>
#include <cudf/detail/iterator.cuh>
#include <cudf/detail/utilities/vector_factories.hpp>
#include <cudf/null_mask.hpp>
#include <cudf/transform.hpp>
#include <cudf/types.hpp>
#include <cudf/utilities/default_stream.hpp>
#include <cudf/utilities/type_dispatcher.hpp>
#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_utilities.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/cudf_gtest.hpp>
#include <cudf_test/type_list_utilities.hpp>
#include <cudf_test/type_lists.hpp>

#include <rmm/exec_policy.hpp>

#include <thrust/execution_policy.h>
#include <thrust/sequence.h>
#include <cudf/utilities/error.hpp>

#include <numeric>
#include <random>

template <typename T>
struct TypedColumnTest : public cudf::test::BaseFixture {
cudf::data_type type() { return cudf::data_type{cudf::type_to_id<T>()}; }

TypedColumnTest()
: data{_num_elements * cudf::size_of(type()), cudf::get_default_stream()},
mask{cudf::bitmask_allocation_size_bytes(_num_elements), cudf::get_default_stream()}
TypedColumnTest(rmm::cuda_stream_view stream = cudf::get_default_stream())
: data{_num_elements * cudf::size_of(type()), stream},
mask{cudf::bitmask_allocation_size_bytes(_num_elements), stream}
{
auto typed_data = static_cast<char*>(data.data());
auto typed_mask = static_cast<char*>(mask.data());
thrust::sequence(
rmm::exec_policy(cudf::get_default_stream()), typed_data, typed_data + data.size());
thrust::sequence(
rmm::exec_policy(cudf::get_default_stream()), typed_mask, typed_mask + mask.size());
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; }
Expand Down Expand Up @@ -347,12 +345,11 @@ TYPED_TEST(TypedColumnTest, MoveConstructorWithMask)

TYPED_TEST(TypedColumnTest, DeviceUvectorConstructorNoMask)
{
rmm::device_uvector<TypeParam> original{static_cast<std::size_t>(this->num_elements()),
cudf::get_default_stream()};
thrust::copy(rmm::exec_policy(cudf::get_default_stream()),
static_cast<TypeParam*>(this->data.data()),
static_cast<TypeParam*>(this->data.data()) + this->num_elements(),
original.begin());
auto data = cudf::device_span<TypeParam const>(static_cast<TypeParam*>(this->data.data()),
this->num_elements());

auto original = cudf::detail::make_device_uvector_async(
data, cudf::get_default_stream(), rmm::mr::get_current_device_resource());
auto original_data = original.data();
cudf::column moved_to{std::move(original)};
verify_column_views(moved_to);
Expand All @@ -364,12 +361,11 @@ TYPED_TEST(TypedColumnTest, DeviceUvectorConstructorNoMask)

TYPED_TEST(TypedColumnTest, DeviceUvectorConstructorWithMask)
{
rmm::device_uvector<TypeParam> original{static_cast<std::size_t>(this->num_elements()),
cudf::get_default_stream()};
thrust::copy(rmm::exec_policy(cudf::get_default_stream()),
static_cast<TypeParam*>(this->data.data()),
static_cast<TypeParam*>(this->data.data()) + this->num_elements(),
original.begin());
auto data = cudf::device_span<TypeParam const>(static_cast<TypeParam*>(this->data.data()),
this->num_elements());

auto original = cudf::detail::make_device_uvector_async(
data, cudf::get_default_stream(), rmm::mr::get_current_device_resource());
auto original_data = original.data();
auto original_mask = this->all_valid_mask.data();
cudf::column moved_to{std::move(original), std::move(this->all_valid_mask)};
Expand Down Expand Up @@ -564,8 +560,7 @@ TYPED_TEST(ListsColumnTest, ListsSlicedNestedEmpty)

TYPED_TEST(ListsColumnTest, ListsSlicedZeroSliceLengthNested)
{
using LCW = cudf::test::lists_column_wrapper<TypeParam>;
using FWCW_SZ = cudf::test::fixed_width_column_wrapper<cudf::size_type>;
using LCW = cudf::test::lists_column_wrapper<TypeParam>;

// Column of List<List<int>>, with incomplete hierarchy
LCW list{{LCW{1}, LCW{2}}, {}, {LCW{3}, LCW{4, 5}}};
Expand All @@ -580,8 +575,7 @@ TYPED_TEST(ListsColumnTest, ListsSlicedZeroSliceLengthNested)

TYPED_TEST(ListsColumnTest, ListsSlicedZeroSliceLengthNonNested)
{
using LCW = cudf::test::lists_column_wrapper<TypeParam>;
using FWCW_SZ = cudf::test::fixed_width_column_wrapper<cudf::size_type>;
using LCW = cudf::test::lists_column_wrapper<TypeParam>;

LCW list{{1, 2}, {}, {3, 4}, {8, 9}};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,24 @@
* limitations under the License.
*/

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_utilities.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/table_utilities.hpp>
#include <cudf_test/type_lists.hpp>

#include <cudf/column/column.hpp>
#include <cudf/concatenate.hpp>
#include <cudf/copying.hpp>
#include <cudf/detail/iterator.cuh>
#include <cudf/dictionary/dictionary_column_view.hpp>
#include <cudf/dictionary/encode.hpp>
#include <cudf/filling.hpp>
#include <cudf/fixed_point/fixed_point.hpp>
#include <cudf/table/table.hpp>
#include <cudf/utilities/default_stream.hpp>
#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_utilities.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/table_utilities.hpp>
#include <cudf_test/type_lists.hpp>

#include <rmm/exec_policy.hpp>

#include <thrust/fill.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/scan.h>

#include <numeric>
#include <stdexcept>
Expand Down Expand Up @@ -527,16 +525,9 @@ TEST_F(OverflowTest, Presliced)
constexpr cudf::size_type num_rows = total_chars_size / string_size;

// try and concatenate 4 string columns of with ~1/2 billion chars in each
auto offsets =
cudf::make_fixed_width_column(cudf::data_type{cudf::type_id::INT32}, num_rows + 1);
thrust::fill(rmm::exec_policy(cudf::get_default_stream()),
offsets->mutable_view().begin<cudf::offset_type>(),
offsets->mutable_view().end<cudf::offset_type>(),
string_size);
thrust::exclusive_scan(rmm::exec_policy(cudf::get_default_stream()),
offsets->view().begin<cudf::offset_type>(),
offsets->view().end<cudf::offset_type>(),
offsets->mutable_view().begin<cudf::offset_type>());
auto offsets = cudf::sequence(num_rows + 1,
cudf::numeric_scalar<cudf::size_type>(0),
cudf::numeric_scalar<cudf::size_type>(string_size));
auto many_chars =
cudf::make_fixed_width_column(cudf::data_type{cudf::type_id::INT8}, total_chars_size);
auto col = cudf::make_strings_column(
Expand Down Expand Up @@ -609,16 +600,10 @@ TEST_F(OverflowTest, Presliced)
cudf::make_structs_column(inner_size, std::move(children), 0, rmm::device_buffer{});

// try and concatenate 4 struct columns of with ~1/2 billion elements in each
auto offsets =
cudf::make_fixed_width_column(cudf::data_type{cudf::type_id::INT32}, num_rows + 1);
thrust::fill(rmm::exec_policy(cudf::get_default_stream()),
offsets->mutable_view().begin<cudf::offset_type>(),
offsets->mutable_view().end<cudf::offset_type>(),
list_size);
thrust::exclusive_scan(rmm::exec_policy(cudf::get_default_stream()),
offsets->view().begin<cudf::offset_type>(),
offsets->view().end<cudf::offset_type>(),
offsets->mutable_view().begin<cudf::offset_type>());
auto offsets = cudf::sequence(num_rows + 1,
cudf::numeric_scalar<cudf::size_type>(0),
cudf::numeric_scalar<cudf::size_type>(list_size));

auto col = cudf::make_strings_column(
num_rows, std::move(offsets), std::move(struct_col), 0, rmm::device_buffer{});

Expand Down Expand Up @@ -705,16 +690,9 @@ TEST_F(OverflowTest, BigColumnsSmallSlices)
constexpr cudf::size_type num_rows = 1024;
constexpr cudf::size_type string_size = inner_size / num_rows;

auto offsets =
cudf::make_fixed_width_column(cudf::data_type{cudf::type_id::INT32}, num_rows + 1);
thrust::fill(rmm::exec_policy(cudf::get_default_stream()),
offsets->mutable_view().begin<cudf::offset_type>(),
offsets->mutable_view().end<cudf::offset_type>(),
string_size);
thrust::exclusive_scan(rmm::exec_policy(cudf::get_default_stream()),
offsets->view().begin<cudf::offset_type>(),
offsets->view().end<cudf::offset_type>(),
offsets->mutable_view().begin<cudf::offset_type>());
auto offsets = cudf::sequence(num_rows + 1,
cudf::numeric_scalar<cudf::size_type>(0),
cudf::numeric_scalar<cudf::size_type>(string_size));
auto many_chars =
cudf::make_fixed_width_column(cudf::data_type{cudf::type_id::INT8}, inner_size);
auto col = cudf::make_strings_column(
Expand All @@ -735,16 +713,9 @@ TEST_F(OverflowTest, BigColumnsSmallSlices)
constexpr cudf::size_type num_rows = 1024;
constexpr cudf::size_type list_size = inner_size / num_rows;

auto offsets =
cudf::make_fixed_width_column(cudf::data_type{cudf::type_id::INT32}, num_rows + 1);
thrust::fill(rmm::exec_policy(cudf::get_default_stream()),
offsets->mutable_view().begin<cudf::offset_type>(),
offsets->mutable_view().end<cudf::offset_type>(),
list_size);
thrust::exclusive_scan(rmm::exec_policy(cudf::get_default_stream()),
offsets->view().begin<cudf::offset_type>(),
offsets->view().end<cudf::offset_type>(),
offsets->mutable_view().begin<cudf::offset_type>());
auto offsets = cudf::sequence(num_rows + 1,
cudf::numeric_scalar<cudf::size_type>(0),
cudf::numeric_scalar<cudf::size_type>(list_size));
auto many_chars =
cudf::make_fixed_width_column(cudf::data_type{cudf::type_id::INT8}, inner_size);
auto col = cudf::make_lists_column(
Expand All @@ -765,16 +736,9 @@ TEST_F(OverflowTest, BigColumnsSmallSlices)
constexpr cudf::size_type num_rows = 1024;
constexpr cudf::size_type list_size = inner_size / num_rows;

auto offsets =
cudf::make_fixed_width_column(cudf::data_type{cudf::type_id::INT32}, num_rows + 1);
thrust::fill(rmm::exec_policy(cudf::get_default_stream()),
offsets->mutable_view().begin<cudf::offset_type>(),
offsets->mutable_view().end<cudf::offset_type>(),
list_size);
thrust::exclusive_scan(rmm::exec_policy(cudf::get_default_stream()),
offsets->view().begin<cudf::offset_type>(),
offsets->view().end<cudf::offset_type>(),
offsets->mutable_view().begin<cudf::offset_type>());
auto offsets = cudf::sequence(num_rows + 1,
cudf::numeric_scalar<cudf::size_type>(0),
cudf::numeric_scalar<cudf::size_type>(list_size));
auto many_chars =
cudf::make_fixed_width_column(cudf::data_type{cudf::type_id::INT8}, inner_size);
auto list_col = cudf::make_lists_column(
Expand Down Expand Up @@ -1086,7 +1050,7 @@ TEST_F(ListsColumnTest, ConcatenateEmptyLists)
}

{
cudf::test::lists_column_wrapper<int> a{{LCW{}}};
cudf::test::lists_column_wrapper<int> a{LCW{}};
cudf::test::lists_column_wrapper<int> b{4, 5, 6, 7};
cudf::test::lists_column_wrapper<int> expected{LCW{}, {4, 5, 6, 7}};

Expand All @@ -1096,7 +1060,7 @@ TEST_F(ListsColumnTest, ConcatenateEmptyLists)
}

{
cudf::test::lists_column_wrapper<int> a{{LCW{}}}, b{{LCW{}}}, c{{LCW{}}};
cudf::test::lists_column_wrapper<int> a{LCW{}}, b{LCW{}}, c{LCW{}};
cudf::test::lists_column_wrapper<int> d{4, 5, 6, 7};
cudf::test::lists_column_wrapper<int> expected{LCW{}, LCW{}, LCW{}, {4, 5, 6, 7}};

Expand All @@ -1107,7 +1071,7 @@ TEST_F(ListsColumnTest, ConcatenateEmptyLists)

{
cudf::test::lists_column_wrapper<int> a{1, 2};
cudf::test::lists_column_wrapper<int> b{{LCW{}}}, c{{LCW{}}};
cudf::test::lists_column_wrapper<int> b{LCW{}}, c{LCW{}};
cudf::test::lists_column_wrapper<int> d{4, 5, 6, 7};
cudf::test::lists_column_wrapper<int> expected{{1, 2}, LCW{}, LCW{}, {4, 5, 6, 7}};

Expand Down

0 comments on commit 4f85f63

Please sign in to comment.