-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement equality of two table_views #22319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
60b1c11
Implement equality of two table_views
wence- e23ea20
Use transform then reduce
wence- 8141248
Throw documented exception in two_table_comparator
wence- 4c875d0
More tests
wence- a25682e
Fix traits test
wence- 2d83e62
Add streams test
wence- 92460ad
Merge branch 'main' into wence/fea/table-equal
wence- abce883
Merge branch 'main' into wence/fea/table-equal
wence- d612665
Nodiscard
wence- 983f5a2
Merge branch 'main' into wence/fea/table-equal
mhaseeb123 9523fb5
Merge branch 'main' into wence/fea/table-equal
wence- 615c06a
Merge branch 'main' into wence/fea/table-equal
wence- File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <cudf/table/table_view.hpp> | ||
| #include <cudf/types.hpp> | ||
| #include <cudf/utilities/default_stream.hpp> | ||
| #include <cudf/utilities/memory_resource.hpp> | ||
|
|
||
| #include <rmm/cuda_stream_view.hpp> | ||
| namespace CUDF_EXPORT cudf { | ||
|
|
||
| /** | ||
| * @brief Check if two tables are equal. | ||
| * | ||
| * Returns true if the input tables have the same number of rows, the same number of columns, | ||
| * matching column types, and every row in `left` compares equal to the row at the same index in | ||
| * `right`. Null equality is controlled by `nulls_equal`. Floating point NaN values compare equal. | ||
| * | ||
| * @throws cudf::logic_error if the tables contain `EMPTY` types. | ||
| * | ||
| * @param left The first table to compare | ||
| * @param right The second table to compare | ||
| * @param nulls_equal Flag to denote if null elements should be considered equal | ||
| * @param stream CUDA stream used for device memory operations and kernel launches | ||
| * @return true if the tables are equal, false otherwise | ||
| */ | ||
| [[nodiscard]] bool tables_equal(table_view const& left, | ||
| table_view const& right, | ||
| null_equality nulls_equal = null_equality::EQUAL, | ||
| rmm::cuda_stream_view stream = cudf::get_default_stream()); | ||
|
|
||
| } // namespace CUDF_EXPORT cudf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <cudf/detail/algorithms/reduce.cuh> | ||
| #include <cudf/detail/nvtx/ranges.hpp> | ||
| #include <cudf/detail/row_operator/common_utils.cuh> | ||
| #include <cudf/detail/row_operator/equality.cuh> | ||
| #include <cudf/table/equality.hpp> | ||
| #include <cudf/table/table_view.hpp> | ||
| #include <cudf/utilities/error.hpp> | ||
| #include <cudf/utilities/memory_resource.hpp> | ||
| #include <cudf/utilities/type_checks.hpp> | ||
|
|
||
| #include <rmm/cuda_stream_view.hpp> | ||
| #include <rmm/device_uvector.hpp> | ||
| #include <rmm/exec_policy.hpp> | ||
|
|
||
| #include <cub/device/device_transform.cuh> | ||
| #include <cuda/iterator> | ||
| #include <cuda/std/functional> | ||
|
|
||
| namespace cudf { | ||
| namespace detail { | ||
| namespace { | ||
|
|
||
| template <bool has_nested_columns> | ||
| [[nodiscard]] bool tables_equal(table_view const& left, | ||
| table_view const& right, | ||
| null_equality nulls_equal, | ||
| rmm::cuda_stream_view stream) | ||
| { | ||
| auto const comparator = detail::row::equality::two_table_comparator{left, right, stream}; | ||
| auto const rows_equal = comparator.equal_to<has_nested_columns>( | ||
| nullate::DYNAMIC{has_nested_nulls(left) or has_nested_nulls(right)}, nulls_equal); | ||
| rmm::device_uvector<bool> eq_rows{ | ||
| static_cast<std::size_t>(left.num_rows()), stream, cudf::get_current_device_resource_ref()}; | ||
| CUDF_CUDA_TRY(cub::DeviceTransform::Transform( | ||
| cuda::counting_iterator<size_type>{0}, | ||
| eq_rows.begin(), | ||
| eq_rows.size(), | ||
| [rows_equal] __device__(size_type i) -> bool { | ||
| return rows_equal(detail::row::lhs_index_type{i}, detail::row::rhs_index_type{i}); | ||
| }, | ||
| stream.value())); | ||
| return cudf::detail::reduce( | ||
| eq_rows.begin(), eq_rows.end(), true, cuda::std::logical_and<bool>{}, stream); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| [[nodiscard]] bool tables_equal(table_view const& left, | ||
| table_view const& right, | ||
| null_equality nulls_equal, | ||
| rmm::cuda_stream_view stream) | ||
| { | ||
| if (left.num_rows() != right.num_rows() || left.num_columns() != right.num_columns() || | ||
| !have_same_types(left, right)) { | ||
| return false; | ||
| } else if (left.num_rows() == 0) { | ||
| return true; | ||
| } | ||
|
|
||
| return cudf::has_nested_columns(left) || cudf::has_nested_columns(right) | ||
| ? tables_equal<true>(left, right, nulls_equal, stream) | ||
| : tables_equal<false>(left, right, nulls_equal, stream); | ||
| } | ||
| } // namespace detail | ||
|
|
||
| bool tables_equal(table_view const& left, | ||
| table_view const& right, | ||
| null_equality nulls_equal, | ||
| rmm::cuda_stream_view stream) | ||
| { | ||
| CUDF_FUNC_RANGE(); | ||
| return detail::tables_equal(left, right, nulls_equal, stream); | ||
| } | ||
|
|
||
| } // namespace cudf | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <cudf_test/base_fixture.hpp> | ||
| #include <cudf_test/column_wrapper.hpp> | ||
| #include <cudf_test/default_stream.hpp> | ||
| #include <cudf_test/testing_main.hpp> | ||
|
|
||
| #include <cudf/table/equality.hpp> | ||
| #include <cudf/table/table_view.hpp> | ||
| #include <cudf/types.hpp> | ||
|
|
||
| class TableEqualTest : public cudf::test::BaseFixture {}; | ||
|
|
||
| TEST_F(TableEqualTest, NotEqual) | ||
| { | ||
| cudf::test::fixed_width_column_wrapper<int> left( | ||
| {{0, 0, 0, 0, 0}, {false, false, true, true, true}}); | ||
| cudf::test::fixed_width_column_wrapper<int> right({1, 1, 1, 1, 1}); | ||
| std::ignore = cudf::tables_equal(cudf::table_view{{left}}, | ||
| cudf::table_view{{right}}, | ||
| cudf::null_equality::EQUAL, | ||
| cudf::test::get_default_stream()); | ||
| } | ||
|
|
||
| CUDF_TEST_PROGRAM_MAIN() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.