column_utilities.hpp
1 /*
2  * Copyright (c) 2019-2024, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cudf/column/column.hpp>
21 #include <cudf/detail/utilities/vector_factories.hpp>
22 #include <cudf/null_mask.hpp>
24 #include <cudf/types.hpp>
26 #include <cudf/utilities/error.hpp>
27 #include <cudf/utilities/export.hpp>
28 
29 #include <thrust/host_vector.h>
30 #include <thrust/iterator/transform_iterator.h>
31 
32 namespace CUDF_EXPORT cudf {
33 namespace test {
34 
38 enum class debug_output_level {
39  FIRST_ERROR = 0, // print first error only
40  ALL_ERRORS, // print all errors
41  QUIET // no debug output
42 };
43 
44 constexpr size_type default_ulp = 4;
45 
46 namespace detail {
47 
60 bool expect_column_properties_equal(cudf::column_view const& lhs,
61  cudf::column_view const& rhs,
62  debug_output_level verbosity = debug_output_level::FIRST_ERROR);
63 
80 bool expect_column_properties_equivalent(
81  cudf::column_view const& lhs,
82  cudf::column_view const& rhs,
83  debug_output_level verbosity = debug_output_level::FIRST_ERROR);
84 
99 bool expect_columns_equal(cudf::column_view const& lhs,
100  cudf::column_view const& rhs,
101  debug_output_level verbosity = debug_output_level::FIRST_ERROR);
102 
120 bool expect_columns_equivalent(cudf::column_view const& lhs,
121  cudf::column_view const& rhs,
122  debug_output_level verbosity = debug_output_level::FIRST_ERROR,
123  size_type fp_ulps = cudf::test::default_ulp);
124 
134 void expect_equal_buffers(void const* lhs, void const* rhs, std::size_t size_bytes);
135 
136 } // namespace detail
137 
143 void expect_column_empty(cudf::column_view const& col);
144 
151 std::vector<bitmask_type> bitmask_to_host(cudf::column_view const& c);
152 
164 bool validate_host_masks(std::vector<bitmask_type> const& expected_mask,
165  std::vector<bitmask_type> const& got_mask_begin,
166  size_type number_of_elements);
167 
176 template <typename T, std::enable_if_t<not cudf::is_fixed_point<T>()>* = nullptr>
177 std::pair<thrust::host_vector<T>, std::vector<bitmask_type>> to_host(column_view c)
178 {
179  auto col_span = cudf::device_span<T const>(c.data<T>(), c.size());
180  auto host_data = cudf::detail::make_host_vector_sync(col_span, cudf::get_default_stream());
181  return {std::move(host_data), bitmask_to_host(c)};
182 }
183 
184 // This signature is identical to the above overload apart from SFINAE so
185 // doxygen sees it as a duplicate.
187 
198 template <typename T, std::enable_if_t<cudf::is_fixed_point<T>()>* = nullptr>
199 CUDF_EXPORT std::pair<thrust::host_vector<T>, std::vector<bitmask_type>> to_host(column_view c);
200 
211 template <>
212 CUDF_EXPORT std::pair<thrust::host_vector<std::string>, std::vector<bitmask_type>> to_host(
213  column_view c);
215 
225  large_strings_enabler(bool default_enable = true);
227 
231  void enable();
232 
236  void disable();
237 };
238 
239 } // namespace test
240 } // namespace CUDF_EXPORT cudf
241 
242 // Macros for showing line of failure.
243 #define CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUAL(lhs, rhs) \
244  do { \
245  SCOPED_TRACE(" <-- line of failure\n"); \
246  cudf::test::detail::expect_column_properties_equal(lhs, rhs); \
247  } while (0)
248 
249 #define CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUIVALENT(lhs, rhs) \
250  do { \
251  SCOPED_TRACE(" <-- line of failure\n"); \
252  cudf::test::detail::expect_column_properties_equivalent(lhs, rhs); \
253  } while (0)
254 
255 #define CUDF_TEST_EXPECT_COLUMNS_EQUAL(lhs, rhs...) \
256  do { \
257  SCOPED_TRACE(" <-- line of failure\n"); \
258  cudf::test::detail::expect_columns_equal(lhs, rhs); \
259  } while (0)
260 
261 #define CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(lhs, rhs...) \
262  do { \
263  SCOPED_TRACE(" <-- line of failure\n"); \
264  cudf::test::detail::expect_columns_equivalent(lhs, rhs); \
265  } while (0)
266 
267 #define CUDF_TEST_EXPECT_EQUAL_BUFFERS(lhs, rhs, size_bytes) \
268  do { \
269  SCOPED_TRACE(" <-- line of failure\n"); \
270  cudf::test::detail::expect_equal_buffers(lhs, rhs, size_bytes); \
271  } while (0)
272 
273 #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:95
cuDF interfaces
Definition: aggregation.hpp:35
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:338
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.