Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 79 additions & 34 deletions cpp/include/cudf_test/column_utilities.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2019-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <cudf_test/default_stream.hpp>

#include <cudf/column/column.hpp>
#include <cudf/column/column_view.hpp>
#include <cudf/detail/utilities/vector_factories.hpp>
Expand All @@ -14,6 +16,9 @@
#include <cudf/utilities/default_stream.hpp>
#include <cudf/utilities/error.hpp>
#include <cudf/utilities/export.hpp>
#include <cudf/utilities/memory_resource.hpp>

#include <rmm/cuda_stream_view.hpp>

#include <thrust/host_vector.h>
#include <thrust/iterator/transform_iterator.h>
Expand Down Expand Up @@ -43,12 +48,17 @@ namespace detail {
* @param lhs The first column
* @param rhs The second column
* @param verbosity Level of debug output verbosity
* @param stream CUDA stream used for device memory operations
* @param mr Memory resources used for temporary device allocations
*
* @returns True if the column properties are equal, false otherwise
*/
bool expect_column_properties_equal(cudf::column_view const& lhs,
cudf::column_view const& rhs,
debug_output_level verbosity = debug_output_level::FIRST_ERROR);
bool expect_column_properties_equal(
cudf::column_view const& lhs,
cudf::column_view const& rhs,
debug_output_level verbosity = debug_output_level::FIRST_ERROR,
rmm::cuda_stream_view stream = cudf::test::get_default_stream(),
cudf::memory_resources mr = cudf::get_current_device_resource_ref());

/**
* @brief Verifies the property equivalence of two columns.
Expand All @@ -63,13 +73,17 @@ bool expect_column_properties_equal(cudf::column_view const& lhs,
* @param lhs The first column
* @param rhs The second column
* @param verbosity Level of debug output verbosity
* @param stream CUDA stream used for device memory operations
* @param mr Memory resources used for temporary device allocations
*
* @returns True if the column properties are equivalent, false otherwise
*/
bool expect_column_properties_equivalent(
cudf::column_view const& lhs,
cudf::column_view const& rhs,
debug_output_level verbosity = debug_output_level::FIRST_ERROR);
debug_output_level verbosity = debug_output_level::FIRST_ERROR,
rmm::cuda_stream_view stream = cudf::test::get_default_stream(),
cudf::memory_resources mr = cudf::get_current_device_resource_ref());

/**
* @brief Verifies the element-wise equality of two columns.
Expand All @@ -82,12 +96,16 @@ bool expect_column_properties_equivalent(
* @param lhs The first column
* @param rhs The second column
* @param verbosity Level of debug output verbosity
* @param stream CUDA stream used for device memory operations
* @param mr Memory resources used for temporary device allocations
*
* @returns True if the columns (and their properties) are equal, false otherwise
*/
bool expect_columns_equal(cudf::column_view const& lhs,
cudf::column_view const& rhs,
debug_output_level verbosity = debug_output_level::FIRST_ERROR);
debug_output_level verbosity = debug_output_level::FIRST_ERROR,
rmm::cuda_stream_view stream = cudf::test::get_default_stream(),
cudf::memory_resources mr = cudf::get_current_device_resource_ref());

/**
* @brief Verifies the element-wise equivalence of two columns.
Expand All @@ -103,13 +121,17 @@ bool expect_columns_equal(cudf::column_view const& lhs,
* @param verbosity Level of debug output verbosity
* @param fp_ulps # of ulps of tolerance to allow when comparing
* floating point values
* @param stream CUDA stream used for device memory operations
* @param mr Memory resources used for temporary device allocations
*
* @returns True if the columns (and their properties) are equivalent, false otherwise
*/
bool expect_columns_equivalent(cudf::column_view const& lhs,
cudf::column_view const& rhs,
debug_output_level verbosity = debug_output_level::FIRST_ERROR,
size_type fp_ulps = cudf::test::default_ulp);
size_type fp_ulps = cudf::test::default_ulp,
rmm::cuda_stream_view stream = cudf::test::get_default_stream(),
cudf::memory_resources mr = cudf::get_current_device_resource_ref());

/**
* @brief Verifies the bitwise equality of two device memory buffers.
Expand All @@ -119,8 +141,14 @@ bool expect_columns_equivalent(cudf::column_view const& lhs,
* @param lhs The first buffer
* @param rhs The second buffer
* @param size_bytes The number of bytes to check for equality
* @param stream CUDA stream used for device memory operations
* @param mr Memory resources used for temporary device allocations
*/
void expect_equal_buffers(void const* lhs, void const* rhs, std::size_t size_bytes);
void expect_equal_buffers(void const* lhs,
void const* rhs,
std::size_t size_bytes,
rmm::cuda_stream_view stream = cudf::test::get_default_stream(),
cudf::memory_resources mr = cudf::get_current_device_resource_ref());

} // namespace detail

Expand All @@ -135,9 +163,14 @@ void expect_column_empty(cudf::column_view const& col);
* @brief Copy the null bitmask from a column view to a host vector
*
* @param c The column view
* @param stream CUDA stream used for device memory operations
* @param mr Memory resources used for temporary device allocations
* @returns Vector of bitmask_type elements
*/
std::vector<bitmask_type> bitmask_to_host(cudf::column_view const& c);
std::vector<bitmask_type> bitmask_to_host(
cudf::column_view const& c,
rmm::cuda_stream_view stream = cudf::test::get_default_stream(),
cudf::memory_resources mr = cudf::get_current_device_resource_ref());

/**
* @brief Validates bitmask situated in host as per `number_of_elements`
Expand All @@ -159,15 +192,20 @@ bool validate_host_masks(std::vector<bitmask_type> const& expected_mask,
*
* @tparam T The data type of the elements of the `column_view`
* @param c the `column_view` to copy from
* @param stream CUDA stream used for device memory operations
* @param mr Memory resources used for temporary device allocations
* @return std::pair<thrust::host_vector<T>, std::vector<bitmask_type>> first is the
* `column_view`'s data, and second is the column's bitmask.
*/
template <typename T, std::enable_if_t<not cudf::is_fixed_point<T>()>* = nullptr>
std::pair<thrust::host_vector<T>, std::vector<bitmask_type>> to_host(column_view c)
std::pair<thrust::host_vector<T>, std::vector<bitmask_type>> to_host(
column_view c,
rmm::cuda_stream_view stream = cudf::test::get_default_stream(),
cudf::memory_resources mr = cudf::get_current_device_resource_ref())
{
auto col_span = cudf::device_span<T const>(c.data<T>(), c.size());
auto host_data = cudf::detail::make_host_vector(col_span, cudf::get_default_stream());
return {std::move(host_data), bitmask_to_host(c)};
auto host_data = cudf::detail::make_host_vector(col_span, stream);
return {std::move(host_data), bitmask_to_host(c, stream, mr)};
}

// This signature is identical to the above overload apart from SFINAE so
Expand All @@ -181,11 +219,16 @@ std::pair<thrust::host_vector<T>, std::vector<bitmask_type>> to_host(column_view
*
* @tparam T The data type of the elements of the `column_view`
* @param c the `column_view` to copy from
* @param stream CUDA stream used for device memory operations
* @param mr Memory resources used for temporary device allocations
Comment thread
nirandaperera marked this conversation as resolved.
Resolved
* @return std::pair<thrust::host_vector<T>, std::vector<bitmask_type>> first is the
* `column_view`'s data, and second is the column's bitmask.
*/
template <typename T, std::enable_if_t<cudf::is_fixed_point<T>()>* = nullptr>
CUDF_EXPORT std::pair<thrust::host_vector<T>, std::vector<bitmask_type>> to_host(column_view c);
CUDF_EXPORT std::pair<thrust::host_vector<T>, std::vector<bitmask_type>> to_host(
column_view c,
rmm::cuda_stream_view stream = cudf::test::get_default_stream(),
cudf::memory_resources mr = cudf::get_current_device_resource_ref());

/**
* @brief Copies the data and bitmask of a `column_view` of strings
Expand All @@ -194,12 +237,14 @@ CUDF_EXPORT std::pair<thrust::host_vector<T>, std::vector<bitmask_type>> to_host
* @throw cudf::logic_error if c is not strings column.
*
* @param c the `column_view` of strings to copy from
* @param stream CUDA stream used for device memory operations
* @param mr Memory resources used for temporary device allocations
* @return std::pair first is `std::vector` of `std::string`
* and second is the column's bitmask.
*/
template <>
CUDF_EXPORT std::pair<thrust::host_vector<std::string>, std::vector<bitmask_type>> to_host(
column_view c);
column_view c, rmm::cuda_stream_view stream, cudf::memory_resources mr);
//! @endcond

/**
Expand Down Expand Up @@ -229,34 +274,34 @@ struct large_strings_enabler {
} // namespace CUDF_EXPORT cudf

// Macros for showing line of failure.
#define CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUAL(lhs, rhs) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cudf::test::detail::expect_column_properties_equal(lhs, rhs); \
#define CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUAL(lhs, rhs, ...) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cudf::test::detail::expect_column_properties_equal(lhs, rhs __VA_OPT__(, ) __VA_ARGS__); \
} while (0)

#define CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUIVALENT(lhs, rhs) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cudf::test::detail::expect_column_properties_equivalent(lhs, rhs); \
#define CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUIVALENT(lhs, rhs, ...) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cudf::test::detail::expect_column_properties_equivalent(lhs, rhs __VA_OPT__(, ) __VA_ARGS__); \
} while (0)

#define CUDF_TEST_EXPECT_COLUMNS_EQUAL(lhs, rhs...) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cudf::test::detail::expect_columns_equal(lhs, rhs); \
#define CUDF_TEST_EXPECT_COLUMNS_EQUAL(lhs, rhs, ...) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cudf::test::detail::expect_columns_equal(lhs, rhs __VA_OPT__(, ) __VA_ARGS__); \
} while (0)

#define CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(lhs, rhs...) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cudf::test::detail::expect_columns_equivalent(lhs, rhs); \
#define CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(lhs, rhs, ...) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cudf::test::detail::expect_columns_equivalent(lhs, rhs __VA_OPT__(, ) __VA_ARGS__); \
} while (0)

#define CUDF_TEST_EXPECT_EQUAL_BUFFERS(lhs, rhs, size_bytes) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cudf::test::detail::expect_equal_buffers(lhs, rhs, size_bytes); \
#define CUDF_TEST_EXPECT_EQUAL_BUFFERS(lhs, rhs, size_bytes, ...) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cudf::test::detail::expect_equal_buffers(lhs, rhs, size_bytes __VA_OPT__(, ) __VA_ARGS__); \
} while (0)

#define CUDF_TEST_ENABLE_LARGE_STRINGS() cudf::test::large_strings_enabler ls___
28 changes: 24 additions & 4 deletions cpp/include/cudf_test/debug_utilities.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2020-2024, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <cudf_test/default_stream.hpp>

#include <cudf/column/column_view.hpp>
#include <cudf/null_mask.hpp>
#include <cudf/utilities/export.hpp>
#include <cudf/utilities/memory_resource.hpp>

#include <rmm/cuda_stream_view.hpp>

namespace CUDF_EXPORT cudf {
namespace test {
Expand All @@ -17,23 +22,38 @@ namespace test {
*
* @param col The input column view
* @param delimiter The delimiter to put between strings
* @param stream CUDA stream used for device memory operations
* @param mr Memory resources used for temporary device allocations
*/
std::string to_string(cudf::column_view const& col, std::string const& delimiter);
std::string to_string(cudf::column_view const& col,
std::string const& delimiter,
rmm::cuda_stream_view stream = cudf::test::get_default_stream(),
cudf::memory_resources mr = cudf::get_current_device_resource_ref());

/**
* @brief Convert column values to a host vector of strings
*
* @param col The input column view
* @param stream CUDA stream used for device memory operations
* @param mr Memory resources used for temporary device allocations
*/
std::vector<std::string> to_strings(cudf::column_view const& col);
std::vector<std::string> to_strings(
cudf::column_view const& col,
rmm::cuda_stream_view stream = cudf::test::get_default_stream(),
cudf::memory_resources mr = cudf::get_current_device_resource_ref());

/**
* @brief Print a column view to an ostream
*
* @param col The input column view
* @param os The output stream
* @param stream CUDA stream used for device memory operations
* @param mr Memory resources used for temporary device allocations
*/
void print(cudf::column_view const& col, std::ostream& os = std::cout);
void print(cudf::column_view const& col,
std::ostream& os = std::cout,
rmm::cuda_stream_view stream = cudf::test::get_default_stream(),
cudf::memory_resources mr = cudf::get_current_device_resource_ref());

} // namespace test
} // namespace CUDF_EXPORT cudf
37 changes: 26 additions & 11 deletions cpp/include/cudf_test/table_utilities.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2019-2024, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <cudf_test/default_stream.hpp>

#include <cudf/table/table_view.hpp>
#include <cudf/types.hpp>
#include <cudf/utilities/export.hpp>
#include <cudf/utilities/memory_resource.hpp>

#include <rmm/cuda_stream_view.hpp>

namespace CUDF_EXPORT cudf {
namespace test::detail {
Expand All @@ -31,8 +36,13 @@ void expect_table_properties_equal(cudf::table_view lhs, cudf::table_view rhs);
*
* @param lhs The first table
* @param rhs The second table
* @param stream CUDA stream used for device memory operations
* @param mr Memory resources used for temporary device allocations
*/
void expect_tables_equal(cudf::table_view lhs, cudf::table_view rhs);
void expect_tables_equal(cudf::table_view lhs,
cudf::table_view rhs,
rmm::cuda_stream_view stream = cudf::test::get_default_stream(),
cudf::memory_resources mr = cudf::get_current_device_resource_ref());

/**
* @brief Verifies the equivalency of two tables.
Expand All @@ -45,8 +55,13 @@ void expect_tables_equal(cudf::table_view lhs, cudf::table_view rhs);
*
* @param lhs The first table
* @param rhs The second table
* @param stream CUDA stream used for device memory operations
* @param mr Memory resources used for temporary device allocations
*/
void expect_tables_equivalent(cudf::table_view lhs, cudf::table_view rhs);
void expect_tables_equivalent(cudf::table_view lhs,
cudf::table_view rhs,
rmm::cuda_stream_view stream = cudf::test::get_default_stream(),
cudf::memory_resources mr = cudf::get_current_device_resource_ref());

} // namespace test::detail
} // namespace CUDF_EXPORT cudf
Expand All @@ -58,14 +73,14 @@ void expect_tables_equivalent(cudf::table_view lhs, cudf::table_view rhs);
cudf::test::detail::expect_table_properties_equal(lhs, rhs); \
} while (0)

#define CUDF_TEST_EXPECT_TABLES_EQUAL(lhs, rhs) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cudf::test::detail::expect_tables_equal(lhs, rhs); \
#define CUDF_TEST_EXPECT_TABLES_EQUAL(lhs, rhs, ...) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cudf::test::detail::expect_tables_equal(lhs, rhs __VA_OPT__(, ) __VA_ARGS__); \
} while (0)

#define CUDF_TEST_EXPECT_TABLES_EQUIVALENT(lhs, rhs) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cudf::test::detail::expect_tables_equivalent(lhs, rhs); \
#define CUDF_TEST_EXPECT_TABLES_EQUIVALENT(lhs, rhs, ...) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cudf::test::detail::expect_tables_equivalent(lhs, rhs __VA_OPT__(, ) __VA_ARGS__); \
} while (0)
Loading
Loading