Skip to content

Commit

Permalink
Replace more deprecated CUB functors (#18119)
Browse files Browse the repository at this point in the history
They will be removed in a future CCCL release

Authors:
  - Michael Schellenberger Costa (https://github.com/miscco)
  - Bradley Dice (https://github.com/bdice)
  - Vyas Ramasubramani (https://github.com/vyasr)

Approvers:
  - David Wendt (https://github.com/davidwendt)
  - Nghia Truong (https://github.com/ttnghia)
  - Bradley Dice (https://github.com/bdice)

URL: #18119
  • Loading branch information
miscco authored Mar 4, 2025
1 parent 43bbd7f commit 3636040
Show file tree
Hide file tree
Showing 36 changed files with 160 additions and 87 deletions.
2 changes: 1 addition & 1 deletion cpp/benchmarks/common/generate_input.cu
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ std::unique_ptr<cudf::column> create_random_utf8_string_column(data_profile cons
null_mask.begin(),
lengths.begin(),
cuda::proclaim_return_type<cudf::size_type>([] __device__(auto) { return 0; }),
thrust::logical_not<bool>{});
cuda::std::logical_not<bool>{});
auto valid_lengths = thrust::make_transform_iterator(
thrust::make_zip_iterator(thrust::make_tuple(lengths.begin(), null_mask.begin())),
valid_or_zero{});
Expand Down
31 changes: 31 additions & 0 deletions cpp/include/cudf/detail/utilities/functional.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include <cuda/functional>
#include <thrust/functional.h>

namespace cudf::detail {

#if CCCL_MAJOR_VERSION >= 3
using cuda::maximum;
using cuda::minimum;
#else
using thrust::maximum;
using thrust::minimum;
#endif

} // namespace cudf::detail
7 changes: 4 additions & 3 deletions cpp/include/cudf/table/experimental/row_operators.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2024, NVIDIA CORPORATION.
* Copyright (c) 2022-2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,6 +33,7 @@
#include <cudf/utilities/traits.hpp>
#include <cudf/utilities/type_dispatcher.hpp>

#include <cuda/std/functional>
#include <cuda/std/limits>
#include <cuda/std/optional>
#include <cuda/std/tuple>
Expand Down Expand Up @@ -1466,9 +1467,9 @@ class device_row_comparator {
auto rvalid = detail::make_validity_iterator<true>(rcol);
if (nulls_are_equal == null_equality::UNEQUAL) {
if (thrust::any_of(
thrust::seq, lvalid, lvalid + lcol.size(), thrust::logical_not<bool>()) or
thrust::seq, lvalid, lvalid + lcol.size(), cuda::std::logical_not<bool>()) or
thrust::any_of(
thrust::seq, rvalid, rvalid + rcol.size(), thrust::logical_not<bool>())) {
thrust::seq, rvalid, rvalid + rcol.size(), cuda::std::logical_not<bool>())) {
return false;
}
} else {
Expand Down
7 changes: 4 additions & 3 deletions cpp/src/binaryop/compiled/binary_ops.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2024, NVIDIA CORPORATION.
* Copyright (c) 2019-2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,7 @@
#include <cudf/column/column_device_view.cuh>
#include <cudf/column/column_factories.hpp>
#include <cudf/detail/structs/utilities.hpp>
#include <cudf/detail/utilities/functional.hpp>
#include <cudf/scalar/scalar_device_view.cuh>
#include <cudf/strings/detail/strings_children.cuh>
#include <cudf/utilities/memory_resource.hpp>
Expand Down Expand Up @@ -241,8 +242,8 @@ struct null_considering_binop {
return invalid_str;
else if (lhs_valid && rhs_valid) {
return (op == binary_operator::NULL_MAX)
? thrust::maximum<cudf::string_view>()(lhs_value, rhs_value)
: thrust::minimum<cudf::string_view>()(lhs_value, rhs_value);
? cudf::detail::maximum<cudf::string_view>()(lhs_value, rhs_value)
: cudf::detail::minimum<cudf::string_view>()(lhs_value, rhs_value);
} else if (lhs_valid)
return lhs_value;
else
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/filling/repeat.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2024, NVIDIA CORPORATION.
* Copyright (c) 2019-2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@
#include <cudf/detail/gather.cuh>
#include <cudf/detail/nvtx/ranges.hpp>
#include <cudf/detail/repeat.hpp>
#include <cudf/detail/utilities/functional.hpp>
#include <cudf/filling.hpp>
#include <cudf/scalar/scalar.hpp>
#include <cudf/table/table.hpp>
Expand Down Expand Up @@ -81,7 +82,7 @@ struct count_checker {
if (static_cast<int64_t>(std::numeric_limits<T>::max()) >
std::numeric_limits<cudf::size_type>::max()) {
auto max = thrust::reduce(
rmm::exec_policy(stream), count.begin<T>(), count.end<T>(), 0, thrust::maximum<T>());
rmm::exec_policy(stream), count.begin<T>(), count.end<T>(), 0, cudf::detail::maximum<T>());
CUDF_EXPECTS(max <= std::numeric_limits<cudf::size_type>::max(),
"count exceeds the column size limit",
std::overflow_error);
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/groupby/sort/group_rank_scan.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2024, NVIDIA CORPORATION.
* Copyright (c) 2021-2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,6 +29,7 @@
#include <rmm/cuda_stream_view.hpp>
#include <rmm/exec_policy.hpp>

#include <cuda/std/functional>
#include <cuda/std/limits>
#include <thrust/functional.h>
#include <thrust/iterator/reverse_iterator.h>
Expand Down Expand Up @@ -146,7 +147,7 @@ std::unique_ptr<column> rank_generator(column_view const& grouped_values,
group_labels_begin + group_labels.size(),
mutable_rank_begin,
mutable_rank_begin,
thrust::equal_to{},
cuda::std::equal_to{},
scan_op);
return ranks;
}
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/groupby/sort/group_replace_nulls.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2024, NVIDIA CORPORATION.
* Copyright (c) 2021-2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,6 +23,7 @@

#include <rmm/device_uvector.hpp>

#include <cuda/std/functional>
#include <thrust/functional.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/discard_iterator.h>
Expand Down Expand Up @@ -55,7 +56,7 @@ std::unique_ptr<column> group_replace_nulls(cudf::column_view const& grouped_val
thrust::make_tuple(gather_map.begin(), thrust::make_discard_iterator()));

auto func = cudf::detail::replace_policy_functor();
thrust::equal_to<cudf::size_type> eq;
cuda::std::equal_to<cudf::size_type> eq;
if (replace_policy == cudf::replace_policy::PRECEDING) {
thrust::inclusive_scan_by_key(rmm::exec_policy(stream),
group_labels.begin(),
Expand Down
7 changes: 4 additions & 3 deletions cpp/src/groupby/sort/group_scan_util.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <rmm/device_uvector.hpp>
#include <rmm/exec_policy.hpp>

#include <cuda/std/functional>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/transform_iterator.h>
#include <thrust/scan.h>
Expand Down Expand Up @@ -122,7 +123,7 @@ struct group_scan_functor<K, T, std::enable_if_t<is_group_scan_supported<K, T>()
group_labels.end(),
inp_iter,
out_iter,
thrust::equal_to{},
cuda::std::equal_to{},
binop);
};

Expand Down Expand Up @@ -167,7 +168,7 @@ struct group_scan_functor<K,
group_labels.end(),
inp_iter,
out_iter,
thrust::equal_to{},
cuda::std::equal_to{},
binop);
};

Expand Down Expand Up @@ -209,7 +210,7 @@ struct group_scan_functor<K,
group_labels.end(),
thrust::make_counting_iterator<size_type>(0),
gather_map.begin(),
thrust::equal_to{},
cuda::std::equal_to{},
binop_generator.binop());

//
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/groupby/sort/group_single_pass_reduction_util.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ struct group_reduction_functor<
inp_iter,
thrust::make_discard_iterator(),
out_iter,
thrust::equal_to{},
cuda::std::equal_to{},
binop);
};

Expand All @@ -201,7 +201,7 @@ struct group_reduction_functor<
rmm::device_uvector<bool> validity(num_groups, stream);
do_reduction(cudf::detail::make_validity_iterator(*d_values_ptr),
validity.begin(),
thrust::logical_or{});
cuda::std::logical_or{});

auto [null_mask, null_count] =
cudf::detail::valid_if(validity.begin(), validity.end(), cuda::std::identity{}, stream, mr);
Expand Down Expand Up @@ -238,7 +238,7 @@ struct group_reduction_functor<
inp_iter,
thrust::make_discard_iterator(),
out_iter,
thrust::equal_to{},
cuda::std::equal_to{},
binop);
};

Expand All @@ -254,7 +254,7 @@ struct group_reduction_functor<
auto validity = rmm::device_uvector<bool>(num_groups, stream);
do_reduction(cudf::detail::make_validity_iterator(*d_values_ptr),
validity.begin(),
thrust::logical_or{});
cuda::std::logical_or{});

auto [null_mask, null_count] =
cudf::detail::valid_if(validity.begin(), validity.end(), cuda::std::identity{}, stream, mr);
Expand Down
7 changes: 5 additions & 2 deletions cpp/src/io/avro/reader_impl.cu
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "io/utilities/hostdevice_vector.hpp"

#include <cudf/detail/null_mask.hpp>
#include <cudf/detail/utilities/functional.hpp>
#include <cudf/detail/utilities/vector_factories.hpp>
#include <cudf/io/datasource.hpp>
#include <cudf/io/detail/avro.hpp>
Expand Down Expand Up @@ -300,8 +301,10 @@ rmm::device_buffer decompress_data(datasource& source,

size_t const uncompressed_data_size =
std::reduce(uncompressed_data_sizes.begin(), uncompressed_data_sizes.end());
size_t const max_uncomp_block_size = std::reduce(
uncompressed_data_sizes.begin(), uncompressed_data_sizes.end(), 0, thrust::maximum<size_t>());
size_t const max_uncomp_block_size = std::reduce(uncompressed_data_sizes.begin(),
uncompressed_data_sizes.end(),
0,
cudf::detail::maximum<size_t>());

size_t temp_size = 0;
status =
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/io/comp/nvcomp_adapter.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2024, NVIDIA CORPORATION.
* Copyright (c) 2022-2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
*/
#include "nvcomp_adapter.cuh"

#include <cudf/detail/utilities/functional.hpp>
#include <cudf/detail/utilities/integer_utils.hpp>

#include <rmm/exec_policy.hpp>
Expand Down Expand Up @@ -122,7 +123,7 @@ std::pair<size_t, size_t> max_chunk_and_total_input_size(device_span<size_t cons
input_sizes.begin(),
input_sizes.end(),
0ul,
thrust::maximum<size_t>());
cudf::detail::maximum<size_t>());
auto const sum = thrust::reduce(rmm::exec_policy(stream), input_sizes.begin(), input_sizes.end());
return {max, sum};
}
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/io/fst/logical_stack.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <rmm/exec_policy.hpp>

#include <cub/cub.cuh>
#include <cuda/std/functional>
#include <thrust/device_ptr.h>
#include <thrust/execution_policy.h>
#include <thrust/fill.h>
Expand Down Expand Up @@ -400,7 +401,7 @@ void sparse_stack_op_to_top_of_stack(StackSymbolItT d_symbols,
d_kv_operations.Current(),
detail::AddStackLevelFromStackOp<StackSymbolToStackOpTypeT>{symbol_to_stack_op},
num_symbols_in,
cub::Equality{},
cuda::std::equal_to{},
stream));
stack_level_scan_bytes = std::max(gen_segments_scan_bytes, scan_by_key_bytes);
} else {
Expand Down Expand Up @@ -499,7 +500,7 @@ void sparse_stack_op_to_top_of_stack(StackSymbolItT d_symbols,
d_kv_operations.Current(),
detail::AddStackLevelFromStackOp<StackSymbolToStackOpTypeT>{symbol_to_stack_op},
num_symbols_in,
cub::Equality{},
cuda::std::equal_to{},
stream));
} else {
CUDF_CUDA_TRY(cub::DeviceScan::InclusiveScan(
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/io/json/column_tree_construction.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, NVIDIA CORPORATION.
* Copyright (c) 2024-2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
#include "nested_json.hpp"

#include <cudf/detail/nvtx/ranges.hpp>
#include <cudf/detail/utilities/functional.hpp>
#include <cudf/detail/utilities/vector_factories.hpp>
#include <cudf/types.hpp>
#include <cudf/utilities/error.hpp>
Expand Down Expand Up @@ -208,7 +209,7 @@ std::tuple<compressed_sparse_row, column_tree_properties> reduce_to_column_tree(
thrust::make_constant_iterator(1),
non_leaf_nodes.begin(),
non_leaf_nodes_children.begin(),
thrust::equal_to<TreeDepthT>());
cuda::std::equal_to<TreeDepthT>());

thrust::scatter(rmm::exec_policy_nosync(stream),
non_leaf_nodes_children.begin(),
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/io/json/host_tree_algorithms.cu
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <cudf/detail/null_mask.hpp>
#include <cudf/detail/nvtx/ranges.hpp>
#include <cudf/detail/utilities/functional.hpp>
#include <cudf/detail/utilities/vector_factories.hpp>
#include <cudf/detail/utilities/visitor_overload.hpp>
#include <cudf/strings/strings_column_view.hpp>
Expand Down Expand Up @@ -1007,13 +1008,13 @@ void scatter_offsets(tree_meta_t const& tree,
col.string_offsets.begin(),
col.string_offsets.end(),
col.string_offsets.begin(),
thrust::maximum<json_column::row_offset_t>{});
cudf::detail::maximum<json_column::row_offset_t>{});
} else if (col.type == json_col_t::ListColumn) {
thrust::inclusive_scan(rmm::exec_policy_nosync(stream),
col.child_offsets.begin(),
col.child_offsets.end(),
col.child_offsets.begin(),
thrust::maximum<json_column::row_offset_t>{});
cudf::detail::maximum<json_column::row_offset_t>{});
}
}
stream.synchronize();
Expand Down
9 changes: 5 additions & 4 deletions cpp/src/io/json/json_column.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2024, NVIDIA CORPORATION.
* Copyright (c) 2022-2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@
#include <cudf/column/column_factories.hpp>
#include <cudf/detail/null_mask.hpp>
#include <cudf/detail/nvtx/ranges.hpp>
#include <cudf/detail/utilities/functional.hpp>
#include <cudf/detail/utilities/vector_factories.hpp>
#include <cudf/detail/utilities/visitor_overload.hpp>
#include <cudf/io/detail/json.hpp>
Expand Down Expand Up @@ -130,8 +131,8 @@ reduce_to_column_tree(tree_meta_t const& tree,
ordered_row_offsets,
unique_col_ids.begin(),
max_row_offsets.begin(),
thrust::equal_to<size_type>(),
thrust::maximum<size_type>());
cuda::std::equal_to<size_type>(),
cudf::detail::maximum<size_type>());

// 3. reduce_by_key {col_id}, {node_categories} - custom opp (*+v=*, v+v=v, *+#=E)
rmm::device_uvector<NodeT> column_categories(num_columns, stream);
Expand All @@ -142,7 +143,7 @@ reduce_to_column_tree(tree_meta_t const& tree,
thrust::make_permutation_iterator(tree.node_categories.begin(), ordered_node_ids.begin()),
unique_col_ids.begin(),
column_categories.begin(),
thrust::equal_to<size_type>(),
cuda::std::equal_to<size_type>(),
[] __device__(NodeT type_a, NodeT type_b) -> NodeT {
auto is_a_leaf = (type_a == NC_VAL || type_a == NC_STR);
auto is_b_leaf = (type_b == NC_VAL || type_b == NC_STR);
Expand Down
Loading

0 comments on commit 3636040

Please sign in to comment.