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
8 changes: 3 additions & 5 deletions cpp/include/cudf/detail/utilities/cuda_memcpy.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down Expand Up @@ -28,10 +28,8 @@ void cuda_memcpy_async_impl(
* satisfied, but for host memory the caller must ensure the source is not freed before the stream
* is synchronized.
*
* All copies share a single attribute entry (`cudaMemcpySrcAccessOrderStream` +
* `cudaMemcpyFlagPreferOverlapWithCompute`). Per-copy attributes are not supported by this
* wrapper; callers requiring different attributes per copy should call `cudaMemcpyBatchAsync`
* directly.
* A batch uses `cudaMemcpyFlagPreferOverlapWithCompute` when every copy is 128 KiB or less. If
* any copy is larger, the batch uses `cudaMemcpyFlagDefault`.
*
* @param dsts Host pointer to a list of destination pointers.
* @param srcs Host pointer to a list of source pointers.
Expand Down
14 changes: 10 additions & 4 deletions cpp/src/utilities/cuda_memcpy.cu
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace cudf::detail {

namespace {

constexpr std::size_t prefer_overlap_threshold = 128 * 1024;

// Simple kernel to copy between device buffers
CUDF_KERNEL void copy_kernel(char const* __restrict__ src, char* __restrict__ dst, size_t n)
{
Expand Down Expand Up @@ -90,10 +92,14 @@ cudaError_t memcpy_batch_async(void* const* dsts,
count = valid_dsts.size();
}

cudaMemcpyAttributes attrs = {.srcAccessOrder = cudaMemcpySrcAccessOrderStream,
.flags = cudaMemcpyFlagPreferOverlapWithCompute};
std::size_t attrs_idxs = 0;
return cudaMemcpyBatchAsync(dsts, srcs, sizes, count, &attrs, &attrs_idxs, 1, stream.value());
auto const flags =
std::ranges::any_of(std::ranges::views::iota(std::size_t{0}, count),
Comment thread
bdice marked this conversation as resolved.
Resolved
[&](auto i) { return sizes[i] > prefer_overlap_threshold; })
Comment thread
bdice marked this conversation as resolved.
Resolved
? cudaMemcpyFlagDefault
: cudaMemcpyFlagPreferOverlapWithCompute;
cudaMemcpyAttributes attrs = {.srcAccessOrder = cudaMemcpySrcAccessOrderStream, .flags = flags};
std::size_t attrs_idx = 0;
return cudaMemcpyBatchAsync(dsts, srcs, sizes, count, &attrs, &attrs_idx, 1, stream.value());
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
#endif // CUDART_VERSION >= 13000
for (std::size_t i = 0; i < count; ++i) {
Expand Down
Loading