libcudf  24.04.00
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 
28 #include <thrust/host_vector.h>
29 #include <thrust/iterator/transform_iterator.h>
30 
31 namespace cudf::test {
32 
36 enum class debug_output_level {
37  FIRST_ERROR = 0, // print first error only
38  ALL_ERRORS, // print all errors
39  QUIET // no debug output
40 };
41 
42 constexpr size_type default_ulp = 4;
43 
44 namespace detail {
45 
58 bool expect_column_properties_equal(cudf::column_view const& lhs,
59  cudf::column_view const& rhs,
60  debug_output_level verbosity = debug_output_level::FIRST_ERROR);
61 
78 bool expect_column_properties_equivalent(
79  cudf::column_view const& lhs,
80  cudf::column_view const& rhs,
81  debug_output_level verbosity = debug_output_level::FIRST_ERROR);
82 
97 bool expect_columns_equal(cudf::column_view const& lhs,
98  cudf::column_view const& rhs,
99  debug_output_level verbosity = debug_output_level::FIRST_ERROR);
100 
118 bool expect_columns_equivalent(cudf::column_view const& lhs,
119  cudf::column_view const& rhs,
120  debug_output_level verbosity = debug_output_level::FIRST_ERROR,
121  size_type fp_ulps = cudf::test::default_ulp);
122 
132 void expect_equal_buffers(void const* lhs, void const* rhs, std::size_t size_bytes);
133 
134 } // namespace detail
135 
141 void expect_column_empty(cudf::column_view const& col);
142 
149 std::vector<bitmask_type> bitmask_to_host(cudf::column_view const& c);
150 
162 bool validate_host_masks(std::vector<bitmask_type> const& expected_mask,
163  std::vector<bitmask_type> const& got_mask_begin,
164  size_type number_of_elements);
165 
174 template <typename T, std::enable_if_t<not cudf::is_fixed_point<T>()>* = nullptr>
175 std::pair<thrust::host_vector<T>, std::vector<bitmask_type>> to_host(column_view c)
176 {
177  auto col_span = cudf::device_span<T const>(c.data<T>(), c.size());
178  auto host_data = cudf::detail::make_host_vector_sync(col_span, cudf::get_default_stream());
179  return {std::move(host_data), bitmask_to_host(c)};
180 }
181 
182 // This signature is identical to the above overload apart from SFINAE so
183 // doxygen sees it as a duplicate.
185 
196 template <typename T, std::enable_if_t<cudf::is_fixed_point<T>()>* = nullptr>
197 std::pair<thrust::host_vector<T>, std::vector<bitmask_type>> to_host(column_view c);
198 
209 template <>
210 std::pair<thrust::host_vector<std::string>, std::vector<bitmask_type>> to_host(column_view c);
212 
213 } // namespace cudf::test
214 
215 // Macros for showing line of failure.
216 #define CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUAL(lhs, rhs) \
217  do { \
218  SCOPED_TRACE(" <-- line of failure\n"); \
219  cudf::test::detail::expect_column_properties_equal(lhs, rhs); \
220  } while (0)
221 
222 #define CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUIVALENT(lhs, rhs) \
223  do { \
224  SCOPED_TRACE(" <-- line of failure\n"); \
225  cudf::test::detail::expect_column_properties_equivalent(lhs, rhs); \
226  } while (0)
227 
228 #define CUDF_TEST_EXPECT_COLUMNS_EQUAL(lhs, rhs...) \
229  do { \
230  SCOPED_TRACE(" <-- line of failure\n"); \
231  cudf::test::detail::expect_columns_equal(lhs, rhs); \
232  } while (0)
233 
234 #define CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(lhs, rhs...) \
235  do { \
236  SCOPED_TRACE(" <-- line of failure\n"); \
237  cudf::test::detail::expect_columns_equivalent(lhs, rhs); \
238  } while (0)
239 
240 #define CUDF_TEST_EXPECT_EQUAL_BUFFERS(lhs, rhs, size_bytes) \
241  do { \
242  SCOPED_TRACE(" <-- line of failure\n"); \
243  cudf::test::detail::expect_equal_buffers(lhs, rhs, size_bytes); \
244  } while (0)
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:93
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:291
Type declarations for libcudf.