Skip to content

Commit d6902b0

Browse files
authored
Change copy_if_safe to call thrust instead of the overload function (#15018)
Found while working on large strings where copy-if is called. In places where `copy_if_safe` utility is called the non-stencil overload calls the stencil-ed function by forwarding the `first` iterator as the `stencil` parameter. This works logically because both values will return the same result. Unfortunately, this can be a performance issue if the iterator is complex/slow transform iterator since it would be called twice (an inlined twice). Changing the non-stencil version to call `thrust::copy_if` directly fixes the potential issue. Authors: - David Wendt (https://github.com/davidwendt) Approvers: - Bradley Dice (https://github.com/bdice) - Yunsong Wang (https://github.com/PointKernel) - Mike Wilson (https://github.com/hyperbolic2346) URL: #15018
1 parent d848707 commit d6902b0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cpp/include/cudf/detail/utilities/algorithm.cuh

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022-2023, NVIDIA CORPORATION.
2+
* Copyright (c) 2022-2024, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -89,7 +89,17 @@ OutputIterator copy_if_safe(InputIterator first,
8989
Predicate pred,
9090
rmm::cuda_stream_view stream)
9191
{
92-
return copy_if_safe(first, last, first, result, pred, stream);
92+
auto const copy_size = std::min(static_cast<std::size_t>(std::distance(first, last)),
93+
static_cast<std::size_t>(std::numeric_limits<int>::max()));
94+
95+
auto itr = first;
96+
while (itr != last) {
97+
auto const copy_end =
98+
static_cast<std::size_t>(std::distance(itr, last)) <= copy_size ? last : itr + copy_size;
99+
result = thrust::copy_if(rmm::exec_policy(stream), itr, copy_end, result, pred);
100+
itr = copy_end;
101+
}
102+
return result;
93103
}
94104

95105
} // namespace cudf::detail

0 commit comments

Comments
 (0)