Skip to content

[cudf] Adding memory_resources support for test utils - #23578

Merged
rapids-bot[bot] merged 6 commits into
NVIDIA:mainfrom
nirandaperera:test-validation-utils-mr
Aug 7, 2026
Merged

[cudf] Adding memory_resources support for test utils#23578
rapids-bot[bot] merged 6 commits into
NVIDIA:mainfrom
nirandaperera:test-validation-utils-mr

Conversation

@nirandaperera

@nirandaperera nirandaperera commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description

A part of #20780.

Adds explicit output/temporary memory-resource routing and a CUDA stream parameter to the cudftestutil validation and debug helpers, so tests can verify (or override) where these utilities allocate. This is part of the ongoing cudf::memory_resources migration (issue #20780) and follows the pattern established by PR #23028 (which added memory_resources to the library-side APIs and the memory_resource_test_harness).

Changes

Public test-utility APIs — new trailing parameters (defaulted for full source-compat):

  • expect_column_properties_equal / expect_column_properties_equivalent
  • expect_columns_equal / expect_columns_equivalent
  • expect_equal_buffers
  • expect_tables_equal / expect_tables_equivalent
  • bitmask_to_host, to_host<T> (numeric, fixed-point, and std::string specialization)
  • to_string, to_strings, print

Each gains:

cpp rmm::cuda_stream_view stream = cudf::test::get_default_stream(), cudf::memory_resources mr = cudf::get_current_device_resource_ref()

Notes

  • All new parameters are defaulted, so existing test call sites compile unchanged.
  • Column-wrapper (fixed_width_column_wrapper etc.) migration is intentionally deferred to a follow-up.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@nirandaperera
nirandaperera requested a review from a team as a code owner August 6, 2026 23:01
@nirandaperera nirandaperera added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 9670f35e-477a-4ede-af42-49d7965fadca

📥 Commits

Reviewing files that changed from the base of the PR and between 4f0d6db and cfe3cf5.

📒 Files selected for processing (1)
  • cpp/include/cudf_test/column_utilities.hpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • cpp/include/cudf_test/column_utilities.hpp

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added optional CUDA stream and memory-resource controls across column, table, buffer comparison, host conversion, and formatting utilities.
    • Existing behavior is preserved through sensible default stream and memory-resource settings.
    • Assertion macros now support optional arguments for more flexible validation.
    • Custom execution and allocation settings can be used consistently across related utilities.
  • Tests

    • Added coverage confirming custom memory-resource usage across comparison, conversion, formatting, and validation workflows.

Walkthrough

Changes

The test utility APIs now accept optional CUDA streams and memory resources. Column and table comparison, host conversion, formatting, nested-column handling, and validation propagate these resources. Tests verify distinct memory-resource usage.

Changes

Resource-aware test utilities

Layer / File(s) Summary
Public API contracts
cpp/include/cudf_test/*_utilities.hpp
Column, table, and debug utility declarations add optional CUDA stream and memory-resource parameters. Assertion macros forward optional arguments.
Column comparison resource propagation
cpp/tests/utilities/column_utilities.cu
Comparison, recursive nested-column processing, diagnostics, buffer comparison, bitmask conversion, and host conversion use supplied resources.
Debug formatting resource propagation
cpp/tests/utilities/debug_utilities.cu
Formatting and recursive list, struct, dictionary, timestamp, duration, and string conversions use supplied resources.
Table integration and resource validation
cpp/tests/utilities/table_utilities.cu, cpp/tests/utilities_tests/column_utilities_tests.cpp
Table helpers forward resources to column comparisons. Tests verify explicit resources and expected output.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • rapidsai/cudf#23028: Introduces the cudf::memory_resources type used by these test utility APIs.
  • rapidsai/cudf#23263: Adds related explicit CUDA memory-resource parameters and custom-resource validation in other APIs.

Suggested reviewers: mattgara, misiugodfrey, vyasr

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the addition of stream and memory-resource support to cudftestutil helpers.
Title check ✅ Passed The title clearly summarizes the main change: adding memory_resources support for test utilities.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
cpp/tests/utilities/debug_utilities.cu (1)

149-152: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Keep stream and mr as the last two parameters.

nested_offsets_to_string places the defaulted delimiter after mr. The coding guidelines require stream before mr as the final two parameters. Move delimiter before stream and pass it explicitly at the single call site on Line 387.

♻️ Proposed signature reorder
 template <typename NestedColumnView>
 std::string nested_offsets_to_string(NestedColumnView const& c,
+                                     std::string const& delimiter,
                                      rmm::cuda_stream_view stream,
-                                     cudf::memory_resources mr,
-                                     std::string const& delimiter = ", ")
+                                     cudf::memory_resources mr)

Then update the call site:

-      "Offsets : " + (lcv.size() > 0 ? nested_offsets_to_string(lcv, stream, mr) : "") + "\n" +
+      "Offsets : " + (lcv.size() > 0 ? nested_offsets_to_string(lcv, ", ", stream, mr) : "") +
+      "\n" +

As per coding guidelines: "Keep stream and MR as the final two parameters, with stream before MR; public APIs provide defaults while detail APIs do not."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/tests/utilities/debug_utilities.cu` around lines 149 - 152, Reorder the
parameters of nested_offsets_to_string so delimiter precedes stream, with stream
and mr remaining the final two parameters in that order. Update its single call
site to pass the delimiter explicitly, preserving the existing delimiter
behavior.

Source: Coding guidelines

cpp/include/cudf_test/column_utilities.hpp (1)

222-230: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add the missing @param stream documentation.

Both overloads now take a stream parameter, but the doc blocks only document mr. The //! @cond Doxygen_Suppress region hides this from the doxygen build, so it does not fail docs. Add the line for consistency with the generic to_host at Line 195.

📝 Proposed doc fix
  * `@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

Also applies to: 239-247

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/include/cudf_test/column_utilities.hpp` around lines 222 - 230, Add the
missing `@param` stream documentation to the fixed-point to_host overload and the
corresponding overload near the additional referenced range, matching the
wording and placement used by the generic to_host documentation. Keep the
existing mr documentation unchanged.
cpp/tests/utilities_tests/column_utilities_tests.cpp (1)

149-199: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extend the resource assertions to a nested column.

The test covers fixed-width, string, and decimal columns. The nested paths carry most of the new propagation code: generate_child_row_indices, the recursive column_property_comparator, the recursive column_comparator_impl<list_view>, and the list and struct printers. None of them run in this test, so a missed stream or mr in those paths stays undetected by the harness.

Add one lists_column_wrapper case and one structs_column_wrapper case to the same assertions.

💚 Proposed additional coverage
   cudf::test::fixed_point_column_wrapper<int32_t> decimals({123, 456}, numeric::scale_type{-2});
+  cudf::test::lists_column_wrapper<int32_t> lists{{1, 2}, {3}, {4, 5, 6}};
+  cudf::test::fixed_width_column_wrapper<int32_t> struct_member{1, 2, 3};
+  cudf::test::structs_column_wrapper structs{{struct_member}};
   CUDF_TEST_EXPECT_COLUMNS_EQUAL(lhs, rhs, cudf::test::debug_output_level::QUIET, stream, mr);
+  CUDF_TEST_EXPECT_COLUMNS_EQUAL(lists, lists, cudf::test::debug_output_level::QUIET, stream, mr);
+  CUDF_TEST_EXPECT_COLUMNS_EQUAL(
+    structs, structs, cudf::test::debug_output_level::QUIET, stream, mr);
   static_cast<void>(cudf::test::to_strings(sliced, stream, mr));
+  static_cast<void>(cudf::test::to_strings(lists, stream, mr));
+  static_cast<void>(cudf::test::to_strings(structs, stream, mr));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/tests/utilities_tests/column_utilities_tests.cpp` around lines 149 - 199,
Extend DistinctMemoryResources with lists_column_wrapper and
structs_column_wrapper fixtures, then pass each through the same relevant
property, equality, equivalence, conversion, and printing assertions used for
existing columns. Ensure nested list and struct paths exercise stream and
memory-resource propagation, and retain the existing resource-usage and
no-live-allocation checks.
cpp/tests/utilities/column_utilities.cu (1)

835-948: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Remove defaults from the detail debug helpers. cudf::test::detail::to_string and to_strings still default to the default stream and current memory resource. Keep defaults only on public overloads, so omitted arguments cannot bypass the caller’s stream and memory resource.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/tests/utilities/column_utilities.cu` around lines 835 - 948, Remove the
default stream and memory-resource arguments from the detail helpers
cudf::test::detail::to_string and to_strings. Require callers of these detail
functions to pass both explicitly, while preserving defaults only on the
corresponding public overloads so omitted arguments cannot bypass the caller’s
resources.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cpp/tests/utilities_tests/column_utilities_tests.cpp`:
- Around line 339-340: Update all make_null_mask calls in the column utilities
tests to pass only the validity range arguments, removing
cudf::get_current_device_resource_ref() and any other third argument while
preserving the existing begin/end iterators.

---

Nitpick comments:
In `@cpp/include/cudf_test/column_utilities.hpp`:
- Around line 222-230: Add the missing `@param` stream documentation to the
fixed-point to_host overload and the corresponding overload near the additional
referenced range, matching the wording and placement used by the generic to_host
documentation. Keep the existing mr documentation unchanged.

In `@cpp/tests/utilities_tests/column_utilities_tests.cpp`:
- Around line 149-199: Extend DistinctMemoryResources with lists_column_wrapper
and structs_column_wrapper fixtures, then pass each through the same relevant
property, equality, equivalence, conversion, and printing assertions used for
existing columns. Ensure nested list and struct paths exercise stream and
memory-resource propagation, and retain the existing resource-usage and
no-live-allocation checks.

In `@cpp/tests/utilities/column_utilities.cu`:
- Around line 835-948: Remove the default stream and memory-resource arguments
from the detail helpers cudf::test::detail::to_string and to_strings. Require
callers of these detail functions to pass both explicitly, while preserving
defaults only on the corresponding public overloads so omitted arguments cannot
bypass the caller’s resources.

In `@cpp/tests/utilities/debug_utilities.cu`:
- Around line 149-152: Reorder the parameters of nested_offsets_to_string so
delimiter precedes stream, with stream and mr remaining the final two parameters
in that order. Update its single call site to pass the delimiter explicitly,
preserving the existing delimiter behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2ebfc3c2-4d89-44b1-b1b9-939cd9f9cced

📥 Commits

Reviewing files that changed from the base of the PR and between 8bf8473 and cb4331d.

📒 Files selected for processing (7)
  • cpp/include/cudf_test/column_utilities.hpp
  • cpp/include/cudf_test/debug_utilities.hpp
  • cpp/include/cudf_test/table_utilities.hpp
  • cpp/tests/utilities/column_utilities.cu
  • cpp/tests/utilities/debug_utilities.cu
  • cpp/tests/utilities/table_utilities.cu
  • cpp/tests/utilities_tests/column_utilities_tests.cpp

Comment thread cpp/tests/utilities_tests/column_utilities_tests.cpp Outdated
The validation-utils port incorrectly passed a memory resource to
make_null_mask, which still only accepts begin/end on this branch.
@github-actions github-actions Bot added the libcudf Affects libcudf (C++/CUDA) code. label Aug 6, 2026
@copy-pr-bot

copy-pr-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@nirandaperera

Copy link
Copy Markdown
Contributor Author

/ok to test d32da77

Signed-off-by: niranda perera <niranda.perera@gmail.com>
@nirandaperera

Copy link
Copy Markdown
Contributor Author

/ok to test 4f0d6db

Comment thread cpp/include/cudf_test/column_utilities.hpp
@nirandaperera

Copy link
Copy Markdown
Contributor Author

/ok to test cfe3cf5

requires(is_numeric<Element>())
{
auto h_data = cudf::test::to_host<Element>(col);
auto h_data = cudf::test::to_host<Element>(col, stream, mr);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general design question: should we remove the default arguments for stream and mr to help prevent misuse? One common way to end up with the wrong stream or mr is that the code builds and runs fine with the defaults, so users may not stop to consider whether the appropriate values are being passed. Requiring them explicitly would force users to make that decision at each call site and could significantly reduce accidental misuse.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PointKernel I thought about this too. But this will be a major breaking change. Maybe once we merge this, I can do this as a follow up.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me. This isn’t a change request for the current effort. I’m just putting the idea out there as something that may be worth considering and getting feedback on from others.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, for this PR, we could simply add new overloads that take stream and mr, and deprecate the existing APIs. Not a hard request though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think cudf_test isnt really public, isnt it? So, this will all be impl detail anyways. Following would be the scope of changes. I will follow it up once this PR goes in.

Macro Call sites Files
CUDF_TEST_EXPECT_COLUMNS_EQUAL 3317 208
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT 1132 100
CUDF_TEST_EXPECT_TABLES_EQUAL 934 64
CUDF_TEST_EXPECT_TABLES_EQUIVALENT 239 40
CUDF_TEST_EXPECT_EQUAL_BUFFERS 25 6
CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUAL 9 3
CUDF_TEST_EXPECT_COLUMN_PROPERTIES_EQUIVALENT 5 2
Total ~5661 ~284

requires(is_numeric<Element>())
{
auto h_data = cudf::test::to_host<Element>(col);
auto h_data = cudf::test::to_host<Element>(col, stream, mr);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me. This isn’t a change request for the current effort. I’m just putting the idea out there as something that may be worth considering and getting feedback on from others.

@nirandaperera

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot
rapids-bot Bot merged commit 9fed14e into NVIDIA:main Aug 7, 2026
140 checks passed
rapids-bot Bot pushed a commit that referenced this pull request Aug 14, 2026
Depends on #23578

A part of #20780.

Port column wrappers to accept memory_resources and stream

Adds defaulted stream and memory_resources parameters to cudftestutil
column wrappers and helpers so tests can control allocation and stream
routing. Includes MR tests for wrappers and timestamp generators.

Authors:
  - Niranda Perera (https://github.com/nirandaperera)
  - Bradley Dice (https://github.com/bdice)

Approvers:
  - Basit Ayantunde (https://github.com/lamarrr)
  - Bradley Dice (https://github.com/bdice)

URL: #23581
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improvement / enhancement to an existing function libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants