column_utilities.hpp
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-2025, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include <cudf/column/column.hpp>
10 #include <cudf/detail/utilities/vector_factories.hpp>
11 #include <cudf/null_mask.hpp>
13 #include <cudf/types.hpp>
15 #include <cudf/utilities/error.hpp>
16 #include <cudf/utilities/export.hpp>
17 
18 #include <thrust/host_vector.h>
19 #include <thrust/iterator/transform_iterator.h>
20 
21 namespace CUDF_EXPORT cudf {
22 namespace test {
23 
27 enum class debug_output_level {
28  FIRST_ERROR = 0, // print first error only
29  ALL_ERRORS, // print all errors
30  QUIET // no debug output
31 };
32 
33 constexpr size_type default_ulp = 4;
34 
35 namespace detail {
36 
49 bool expect_column_properties_equal(cudf::column_view const& lhs,
50  cudf::column_view const& rhs,
51  debug_output_level verbosity = debug_output_level::FIRST_ERROR);
52 
69 bool expect_column_properties_equivalent(
70  cudf::column_view const& lhs,
71  cudf::column_view const& rhs,
72  debug_output_level verbosity = debug_output_level::FIRST_ERROR);
73 
88 bool expect_columns_equal(cudf::column_view const& lhs,
89  cudf::column_view const& rhs,
90  debug_output_level verbosity = debug_output_level::FIRST_ERROR);
91 
109 bool expect_columns_equivalent(cudf::column_view const& lhs,
110  cudf::column_view const& rhs,
111  debug_output_level verbosity = debug_output_level::FIRST_ERROR,
112  size_type fp_ulps = cudf::test::default_ulp);
113 
123 void expect_equal_buffers(void const* lhs, void const* rhs, std::size_t size_bytes);
124 
125 } // namespace detail
126 
132 void expect_column_empty(cudf::column_view const& col);
133 
140 std::vector<bitmask_type> bitmask_to_host(cudf::column_view const& c);
141 
153 bool validate_host_masks(std::vector<bitmask_type> const& expected_mask,
154  std::vector<bitmask_type> const& got_mask_begin,
155  size_type number_of_elements);
156 
165 template <typename T, std::enable_if_t<not cudf::is_fixed_point<T>()>* = nullptr>
166 std::pair<thrust::host_vector<T>, std::vector<bitmask_type>> to_host(column_view c)
167 {
168  auto col_span = cudf::device_span<T const>(c.data<T>(), c.size());
169  auto host_data = cudf::detail::make_host_vector(col_span, cudf::get_default_stream());
170  return {std::move(host_data), bitmask_to_host(c)};
171 }
172 
173 // This signature is identical to the above overload apart from SFINAE so
174 // doxygen sees it as a duplicate.
176 
187 template <typename T, std::enable_if_t<cudf::is_fixed_point<T>()>* = nullptr>
188 CUDF_EXPORT std::pair<thrust::host_vector<T>, std::vector<bitmask_type>> to_host(column_view c);
189 
200 template <>
201 CUDF_EXPORT std::pair<thrust::host_vector<std::string>, std::vector<bitmask_type>> to_host(
202  column_view c);
204 
214  large_strings_enabler(bool default_enable = true);
216 
220  void enable();
221 
225  void disable();
226 };
227 
228 } // namespace test
229 } // namespace CUDF_EXPORT cudf
230 
231 // Macros for showing line of failure.
232 #define CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUAL(lhs, rhs) \
233  do { \
234  SCOPED_TRACE(" <-- line of failure\n"); \
235  cudf::test::detail::expect_column_properties_equal(lhs, rhs); \
236  } while (0)
237 
238 #define CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUIVALENT(lhs, rhs) \
239  do { \
240  SCOPED_TRACE(" <-- line of failure\n"); \
241  cudf::test::detail::expect_column_properties_equivalent(lhs, rhs); \
242  } while (0)
243 
244 #define CUDF_TEST_EXPECT_COLUMNS_EQUAL(lhs, rhs...) \
245  do { \
246  SCOPED_TRACE(" <-- line of failure\n"); \
247  cudf::test::detail::expect_columns_equal(lhs, rhs); \
248  } while (0)
249 
250 #define CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(lhs, rhs...) \
251  do { \
252  SCOPED_TRACE(" <-- line of failure\n"); \
253  cudf::test::detail::expect_columns_equivalent(lhs, rhs); \
254  } while (0)
255 
256 #define CUDF_TEST_EXPECT_EQUAL_BUFFERS(lhs, rhs, size_bytes) \
257  do { \
258  SCOPED_TRACE(" <-- line of failure\n"); \
259  cudf::test::detail::expect_equal_buffers(lhs, rhs, size_bytes); \
260  } while (0)
261 
262 #define CUDF_TEST_ENABLE_LARGE_STRINGS() cudf::test::large_strings_enabler ls___
A non-owning, immutable view of device data as a column of elements, some of which may be null as ind...
Class definition for cudf::column.
column view class definitions
rmm::cuda_stream_view const get_default_stream()
Get the current default stream.
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:84
cuDF interfaces
Definition: host_udf.hpp:26
APIs for managing validity bitmasks.
Class definition for cudf::strings_column_view.
Device version of C++20 std::span with reduced feature set.
Definition: span.hpp:323
For enabling large strings testing in specific tests.
void enable()
Enable large strings support.
void disable()
Disable large strings support.
large_strings_enabler(bool default_enable=true)
Create large strings enable object.
Type declarations for libcudf.