Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion cpp/include/cudf/join/key_remapping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,14 @@ class key_remapping {
* and get_max_duplicate_count(). If NO, skip metrics computation for better performance;
* calling get_distinct_count() or get_max_duplicate_count() will throw.
* @param stream CUDA stream used for device memory operations and kernel launches
* @param mr Device memory resource used to allocate the internal hash table
*/
key_remapping(cudf::table_view const& right,
null_equality compare_nulls = null_equality::EQUAL,
cudf::compute_metrics metrics = cudf::compute_metrics::YES,
rmm::cuda_stream_view stream = cudf::get_default_stream());
rmm::cuda_stream_view stream = cudf::get_default_stream(),
cuda::mr::any_resource<cuda::mr::device_accessible> mr =
cudf::get_current_device_resource_ref());

/**
* @brief Remap right keys to integer IDs.
Expand Down
36 changes: 22 additions & 14 deletions cpp/src/join/key_remapping.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down Expand Up @@ -280,7 +280,8 @@ class key_remap_table : public key_remap_table_interface {
RowHasher const& row_hasher,
cudf::null_equality compare_nulls,
bool compute_metrics,
rmm::cuda_stream_view stream)
rmm::cuda_stream_view stream,
cuda::mr::any_resource<cuda::mr::device_accessible> mr)
: _right_has_nested_columns{cudf::has_nested_columns(right)},
_compare_nulls{compare_nulls},
_right{right},
Expand All @@ -293,7 +294,7 @@ class key_remap_table : public key_remap_table_interface {
{},
cuco::thread_scope_device,
cuco_storage_type{},
rmm::mr::polymorphic_allocator<char>{},
rmm::mr::polymorphic_allocator<char>{std::move(mr)},
stream.value()},
_has_metrics{compute_metrics},
_distinct_count{0},
Expand Down Expand Up @@ -489,10 +490,12 @@ class key_remap_table : public key_remap_table_interface {
/**
* @brief Factory function to create a key remap hash table.
*/
std::unique_ptr<key_remap_table_interface> create_key_remap_table(cudf::table_view const& right,
cudf::null_equality compare_nulls,
bool compute_metrics,
rmm::cuda_stream_view stream)
std::unique_ptr<key_remap_table_interface> create_key_remap_table(
cudf::table_view const& right,
cudf::null_equality compare_nulls,
bool compute_metrics,
rmm::cuda_stream_view stream,
cuda::mr::any_resource<cuda::mr::device_accessible> mr)
{
CUDF_FUNC_RANGE();

Expand All @@ -513,7 +516,8 @@ std::unique_ptr<key_remap_table_interface> create_key_remap_table(cudf::table_vi
d_hasher,
compare_nulls,
compute_metrics,
stream);
stream,
std::move(mr));
}

auto const has_nested = cudf::has_nested_columns(right);
Expand All @@ -532,7 +536,8 @@ std::unique_ptr<key_remap_table_interface> create_key_remap_table(cudf::table_vi
d_hasher,
compare_nulls,
compute_metrics,
stream);
stream,
std::move(mr));
} else {
auto const d_equal =
self_equal.equal_to<false>(cudf::nullate::DYNAMIC{HAS_NULLS}, compare_nulls);
Expand All @@ -544,7 +549,8 @@ std::unique_ptr<key_remap_table_interface> create_key_remap_table(cudf::table_vi
d_hasher,
compare_nulls,
compute_metrics,
stream);
stream,
std::move(mr));
}
}

Expand All @@ -560,11 +566,12 @@ class key_remapping_impl {
key_remapping_impl(cudf::table_view const& right,
cudf::null_equality compare_nulls,
bool compute_metrics,
rmm::cuda_stream_view stream)
rmm::cuda_stream_view stream,
cuda::mr::any_resource<cuda::mr::device_accessible> mr)
: _right{right},
_compare_nulls{compare_nulls},
_compute_metrics{compute_metrics},
_table{create_key_remap_table(right, compare_nulls, compute_metrics, stream)}
_table{create_key_remap_table(right, compare_nulls, compute_metrics, stream, std::move(mr))}
{
}

Expand Down Expand Up @@ -631,9 +638,10 @@ class key_remapping_impl {
key_remapping::key_remapping(cudf::table_view const& right,
null_equality compare_nulls,
cudf::compute_metrics metrics,
rmm::cuda_stream_view stream)
rmm::cuda_stream_view stream,
cuda::mr::any_resource<cuda::mr::device_accessible> mr)
: _impl{std::make_unique<detail::key_remapping_impl>(
right, compare_nulls, static_cast<bool>(metrics), stream)}
right, compare_nulls, static_cast<bool>(metrics), stream, std::move(mr))}
{
CUDF_EXPECTS(right.num_columns() > 0, "Right table must have at least one column");
}
Expand Down
27 changes: 26 additions & 1 deletion cpp/tests/join/key_remapping_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -20,6 +20,8 @@
#include <cudf/utilities/default_stream.hpp>
#include <cudf/utilities/span.hpp>

#include <rmm/mr/statistics_resource_adaptor.hpp>

#include <algorithm>
#include <set>
#include <vector>
Expand Down Expand Up @@ -741,6 +743,29 @@ TEST_F(KeyRemappingTest, EmptyLeftSchemaMismatchColumnCount)

// Tests for optional metrics computation

TEST_F(KeyRemappingTest, MemoryResource)
{
column_wrapper<int32_t> right_col{1, 2, 2, 3};
auto right_table = cudf::table_view{{right_col}};

auto mr = rmm::mr::statistics_resource_adaptor(cudf::get_current_device_resource_ref());

cudf::key_remapping remap{right_table,
cudf::null_equality::EQUAL,
cudf::compute_metrics::YES,
cudf::get_default_stream(),
mr};

EXPECT_GT(mr.get_bytes_counter().peak, 0);

auto result = remap.remap_right_keys();
auto ids = to_host<int32_t>(result->view());

EXPECT_EQ(ids[1], ids[2]);
EXPECT_NE(ids[0], ids[1]);
EXPECT_NE(ids[1], ids[3]);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

TEST_F(KeyRemappingTest, MetricsEnabled)
{
column_wrapper<int32_t> right_col{1, 2, 2, 3, 3, 3};
Expand Down
Loading