Skip to content

Commit

Permalink
Add anonymous namespace to libcudf test source (#17529)
Browse files Browse the repository at this point in the history
Uses anonymous namespace declaration on internal only functions and structures in the libcudf gtest source. This helps prevent odd nvcc compile errors like the one described in #17432 

Closes #17432

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

Approvers:
  - Vyas Ramasubramani (https://github.com/vyasr)
  - Karthikeyan (https://github.com/karthikeyann)

URL: #17529
  • Loading branch information
davidwendt authored Dec 12, 2024
1 parent 00ed1f2 commit 98d9856
Show file tree
Hide file tree
Showing 19 changed files with 54 additions and 30 deletions.
9 changes: 2 additions & 7 deletions cpp/tests/bitmask/set_nullmask_tests.cu
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,15 @@
#include <algorithm>
#include <iostream>

namespace {
struct valid_bit_functor {
cudf::bitmask_type const* _null_mask;
__device__ bool operator()(cudf::size_type element_index) const noexcept
{
return cudf::bit_is_set(_null_mask, element_index);
}
};

std::ostream& operator<<(std::ostream& stream, thrust::host_vector<bool> const& bits)
{
for (auto _bit : bits)
stream << int(_bit);
return stream;
}
} // namespace

struct SetBitmaskTest : public cudf::test::BaseFixture {
void expect_bitmask_equal(cudf::bitmask_type const* bitmask, // Device Ptr
Expand Down
2 changes: 2 additions & 0 deletions cpp/tests/bitmask/valid_if_tests.cu
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

struct ValidIfTest : public cudf::test::BaseFixture {};

namespace {
struct odds_valid {
__host__ __device__ bool operator()(cudf::size_type i) { return i % 2; }
};
Expand All @@ -37,6 +38,7 @@ struct all_valid {
struct all_null {
__host__ __device__ bool operator()(cudf::size_type i) { return false; }
};
} // namespace

TEST_F(ValidIfTest, EmptyRange)
{
Expand Down
4 changes: 4 additions & 0 deletions cpp/tests/column/bit_cast_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <thrust/iterator/counting_iterator.h>

namespace {
template <typename T, typename T2 = void>
struct rep_type_impl {
using type = void;
Expand All @@ -47,12 +48,14 @@ struct rep_type_impl<T, std::enable_if_t<cudf::is_fixed_point<T>()>> {

template <typename T>
using rep_type_t = typename rep_type_impl<T>::type;
} // namespace

template <typename T>
struct ColumnViewAllTypesTests : public cudf::test::BaseFixture {};

TYPED_TEST_SUITE(ColumnViewAllTypesTests, cudf::test::FixedWidthTypes);

namespace {
template <typename FromType, typename ToType, typename Iterator>
void do_bit_cast(cudf::column_view const& column_view, Iterator begin, Iterator end)
{
Expand Down Expand Up @@ -102,6 +105,7 @@ void do_bit_cast(cudf::column_view const& column_view, Iterator begin, Iterator
}
}
}
} // namespace

TYPED_TEST(ColumnViewAllTypesTests, BitCast)
{
Expand Down
2 changes: 2 additions & 0 deletions cpp/tests/column/compound_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

struct CompoundColumnTest : public cudf::test::BaseFixture {};

namespace {
template <typename ColumnDeviceView>
struct checker_for_level1 {
ColumnDeviceView d_column;
Expand Down Expand Up @@ -62,6 +63,7 @@ struct checker_for_level2 {
return bcheck;
}
};
} // namespace

TEST_F(CompoundColumnTest, ChildrenLevel1)
{
Expand Down
2 changes: 2 additions & 0 deletions cpp/tests/device_atomics/device_atomics_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <algorithm>

namespace {
template <typename T>
CUDF_KERNEL void gpu_atomic_test(T* result, T* data, size_t size)
{
Expand Down Expand Up @@ -109,6 +110,7 @@ std::enable_if_t<cudf::is_timestamp<T>(), T> accumulate(cudf::host_span<T const>
xs.begin(), xs.end(), ys.begin(), [](T const& ts) { return ts.time_since_epoch().count(); });
return T{typename T::duration{std::accumulate(ys.begin(), ys.end(), 0)}};
}
} // namespace

template <typename T>
struct AtomicsTest : public cudf::test::BaseFixture {
Expand Down
2 changes: 2 additions & 0 deletions cpp/tests/fixed_point/fixed_point_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,12 @@ TEST_F(FixedPointTest, Decimal32FloatVector)
float_vector_test(0.15, 20, -2, std::multiplies<>());
}

namespace {
struct cast_to_int32_fn {
using decimal32 = fixed_point<int32_t, Radix::BASE_10>;
int32_t __host__ __device__ operator()(decimal32 fp) { return static_cast<int32_t>(fp); }
};
} // namespace

TYPED_TEST(FixedPointTestAllReps, FixedPointColumnWrapper)
{
Expand Down
2 changes: 2 additions & 0 deletions cpp/tests/fixed_point/fixed_point_tests.cu
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ TYPED_TEST(FixedPointTestAllReps, DecimalXXThrust)
EXPECT_EQ(vec2, vec3);
}

namespace {
struct cast_to_int32_fn {
using decimal32 = fixed_point<int32_t, Radix::BASE_10>;
int32_t __host__ __device__ operator()(decimal32 fp) { return static_cast<int32_t>(fp); }
};
} // namespace

TEST_F(FixedPointTest, DecimalXXThrustOnDevice)
{
Expand Down
4 changes: 4 additions & 0 deletions cpp/tests/groupby/tdigest_tests.cu
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <thrust/fill.h>
#include <thrust/iterator/counting_iterator.h>

namespace {
/**
* @brief Functor to generate a tdigest by key.
*
Expand Down Expand Up @@ -116,6 +117,7 @@ struct tdigest_groupby_simple_merge_op {
return std::move(result.second[0].results[0]);
}
};
} // namespace

template <typename T>
struct TDigestAllTypes : public cudf::test::BaseFixture {};
Expand Down Expand Up @@ -508,6 +510,7 @@ TEST_F(TDigestMergeTest, EmptyGroups)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*expected, *result.second[0].results[0]);
}

namespace {
std::unique_ptr<cudf::table> do_agg(
cudf::column_view key,
cudf::column_view val,
Expand Down Expand Up @@ -537,6 +540,7 @@ std::unique_ptr<cudf::table> do_agg(

return std::make_unique<cudf::table>(std::move(result_columns));
}
} // namespace

TEST_F(TDigestMergeTest, AllValuesAreNull)
{
Expand Down
2 changes: 2 additions & 0 deletions cpp/tests/interop/dlpack_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <dlpack/dlpack.h>

namespace {
struct dlpack_deleter {
void operator()(DLManagedTensor* tensor) { tensor->deleter(tensor); }
};
Expand Down Expand Up @@ -60,6 +61,7 @@ void validate_dtype(DLDataType const& dtype)
EXPECT_EQ(1, dtype.lanes);
EXPECT_EQ(sizeof(T) * 8, dtype.bits);
}
} // namespace

class DLPackUntypedTests : public cudf::test::BaseFixture {};

Expand Down
4 changes: 2 additions & 2 deletions cpp/tests/io/json/json_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

namespace cuio_json = cudf::io::json;

namespace {

// Host copy of tree_meta_t
struct tree_meta_t2 {
std::vector<cuio_json::NodeT> node_categories;
Expand All @@ -43,8 +45,6 @@ struct tree_meta_t2 {
std::vector<cuio_json::SymbolOffsetT> node_range_end;
};

namespace {

tree_meta_t2 to_cpu_tree(cuio_json::tree_meta_t const& d_value, rmm::cuda_stream_view stream)
{
return {cudf::detail::make_std_vector_async(d_value.node_categories, stream),
Expand Down
3 changes: 3 additions & 0 deletions cpp/tests/io/json/json_tree_csr.cu
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

namespace cuio_json = cudf::io::json;

namespace {

struct h_tree_meta_t {
std::vector<cuio_json::NodeT> node_categories;
std::vector<cuio_json::NodeIndexT> parent_node_ids;
Expand Down Expand Up @@ -222,6 +224,7 @@ void run_test(std::string const& input, bool enable_lines = true)
// assert equality between csr and meta formats
ASSERT_TRUE(iseq);
}
} // namespace

struct JsonColumnTreeTests : public cudf::test::BaseFixture {};

Expand Down
10 changes: 10 additions & 0 deletions cpp/tests/io/parquet_chunked_reader_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,7 @@ TEST_F(ParquetChunkedReaderTest, TestChunkedReadNullCount)
} while (reader.has_next());
}

namespace {
constexpr size_t input_limit_expected_file_count = 4;

std::vector<std::string> input_limit_get_test_names(std::string const& base_filename)
Expand Down Expand Up @@ -1133,6 +1134,7 @@ void input_limit_test_read(std::vector<std::string> const& test_filenames,
CUDF_TEST_EXPECT_TABLES_EQUIVALENT(*result.first, t);
}
}
} // namespace

struct ParquetChunkedReaderInputLimitConstrainedTest : public cudf::test::BaseFixture {};

Expand Down Expand Up @@ -1189,6 +1191,7 @@ TEST_F(ParquetChunkedReaderInputLimitConstrainedTest, MixedColumns)

struct ParquetChunkedReaderInputLimitTest : public cudf::test::BaseFixture {};

namespace {
struct offset_gen {
int const group_size;
__device__ int operator()(int i) { return i * group_size; }
Expand All @@ -1198,6 +1201,8 @@ template <typename T>
struct value_gen {
__device__ T operator()(int i) { return i % 1024; }
};
} // namespace

TEST_F(ParquetChunkedReaderInputLimitTest, List)
{
auto base_path = temp_env->get_temp_filepath("list");
Expand Down Expand Up @@ -1263,6 +1268,7 @@ TEST_F(ParquetChunkedReaderInputLimitTest, List)
input_limit_test_read(test_filenames, tbl, 32 * 1024 * 1024, 64 * 1024 * 1024, expected_c);
}

namespace {
void tiny_list_rowgroup_test(bool just_list_col)
{
auto iter = thrust::make_counting_iterator(0);
Expand Down Expand Up @@ -1320,6 +1326,7 @@ void tiny_list_rowgroup_test(bool just_list_col)

CUDF_TEST_EXPECT_TABLES_EQUAL(*expected, *(result.first));
}
} // namespace

TEST_F(ParquetChunkedReaderInputLimitTest, TinyListRowGroupsSingle)
{
Expand All @@ -1333,6 +1340,7 @@ TEST_F(ParquetChunkedReaderInputLimitTest, TinyListRowGroupsMixed)
tiny_list_rowgroup_test(false);
}

namespace {
struct char_values {
__device__ int8_t operator()(int i)
{
Expand All @@ -1341,6 +1349,8 @@ struct char_values {
return index == 0 ? 'a' : (index == 1 ? 'b' : 'c');
}
};
} // namespace

TEST_F(ParquetChunkedReaderInputLimitTest, Mixed)
{
auto base_path = temp_env->get_temp_filepath("mixed_types");
Expand Down
12 changes: 2 additions & 10 deletions cpp/tests/iterator/optional_iterator_test_numeric.cu
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@

using TestingTypes = cudf::test::NumericTypes;

namespace cudf {
// To print meanvar for debug.
// Needs to be in the cudf namespace for ADL
template <typename T>
std::ostream& operator<<(std::ostream& os, cudf::meanvar<T> const& rhs)
{
return os << "[" << rhs.value << ", " << rhs.value_squared << ", " << rhs.count << "] ";
};
} // namespace cudf

template <typename T>
struct NumericOptionalIteratorTest : public IteratorTest<T> {};

Expand All @@ -46,6 +36,7 @@ TYPED_TEST(NumericOptionalIteratorTest, nonull_optional_iterator)
}
TYPED_TEST(NumericOptionalIteratorTest, null_optional_iterator) { null_optional_iterator(*this); }

namespace {
// Transformers and Operators for optional_iterator test
template <typename ElementType>
struct transformer_optional_meanvar {
Expand All @@ -65,6 +56,7 @@ template <typename T>
struct optional_to_meanvar {
CUDF_HOST_DEVICE inline T operator()(cuda::std::optional<T> const& v) { return v.value_or(T{0}); }
};
} // namespace

// TODO: enable this test also at __CUDACC_DEBUG__
// This test causes fatal compilation error only at device debug mode.
Expand Down
12 changes: 2 additions & 10 deletions cpp/tests/iterator/pair_iterator_test_numeric.cu
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@

using TestingTypes = cudf::test::NumericTypes;

namespace cudf {
// To print meanvar for debug.
// Needs to be in the cudf namespace for ADL
template <typename T>
std::ostream& operator<<(std::ostream& os, cudf::meanvar<T> const& rhs)
{
return os << "[" << rhs.value << ", " << rhs.value_squared << ", " << rhs.count << "] ";
};
} // namespace cudf

template <typename T>
struct NumericPairIteratorTest : public IteratorTest<T> {};

Expand All @@ -53,6 +43,7 @@ struct transformer_pair_meanvar {
};
};

namespace {
struct sum_if_not_null {
template <typename T>
CUDF_HOST_DEVICE inline thrust::pair<T, bool> operator()(thrust::pair<T, bool> const& lhs,
Expand All @@ -66,6 +57,7 @@ struct sum_if_not_null {
return {rhs};
}
};
} // namespace

// TODO: enable this test also at __CUDACC_DEBUG__
// This test causes fatal compilation error only at device debug mode.
Expand Down
2 changes: 2 additions & 0 deletions cpp/tests/quantiles/percentile_approx_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <arrow/util/tdigest.h>

namespace {
std::unique_ptr<cudf::column> arrow_percentile_approx(cudf::column_view const& _values,
int delta,
std::vector<double> const& percentages)
Expand Down Expand Up @@ -315,6 +316,7 @@ cudf::data_type get_appropriate_type()
if constexpr (cudf::is_fixed_point<T>()) { return cudf::data_type{cudf::type_to_id<T>(), -7}; }
return cudf::data_type{cudf::type_to_id<T>()};
}
} // namespace

using PercentileApproxTypes =
cudf::test::Concat<cudf::test::NumericTypes, cudf::test::FixedPointTypes>;
Expand Down
4 changes: 3 additions & 1 deletion cpp/tests/reductions/tdigest_tests.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023, NVIDIA CORPORATION.
* Copyright (c) 2022-2024, 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 All @@ -25,6 +25,7 @@ template <typename T>
struct ReductionTDigestAllTypes : public cudf::test::BaseFixture {};
TYPED_TEST_SUITE(ReductionTDigestAllTypes, cudf::test::NumericTypes);

namespace {
struct reduce_op {
std::unique_ptr<cudf::column> operator()(cudf::column_view const& values, int delta) const
{
Expand Down Expand Up @@ -60,6 +61,7 @@ struct reduce_merge_op {
return cudf::make_structs_column(tbl.num_rows(), std::move(cols), 0, rmm::device_buffer());
}
};
} // namespace

TYPED_TEST(ReductionTDigestAllTypes, Simple)
{
Expand Down
2 changes: 2 additions & 0 deletions cpp/tests/streams/interop_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@

#include <dlpack/dlpack.h>

namespace {
struct dlpack_deleter {
void operator()(DLManagedTensor* tensor) { tensor->deleter(tensor); }
};
} // namespace

struct DLPackTest : public cudf::test::BaseFixture {};

Expand Down
Loading

0 comments on commit 98d9856

Please sign in to comment.