-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rmm::prefetch() and DeviceBuffer.prefetch() (#1573)
This adds two `rmm::prefetch()` functions in C++. 1. `rmm::prefetch(void *ptr, size_t bytes, device, stream)` 2. `rmm::prefetch<T>(cuda::std::span<T> data, device, stream)` Item 2 enables prefetching the containers that RMM provides (`device_uvector`, `device_scalar`) that support conversion to `cuda::std::span`. In order to enable that, `device_scalar::size()` is added. Note that `device_buffer`s must be prefetched using item 1 because you can't create a `span<void>`. In Python, this adds `DeviceBuffer.prefetch()` because that's really the only RMM Python data type to prefetch. There is *one* Cython use of `device_uvector` in cuDF `join` that we might need to add prefetch support for later. `prefetch` is a no-op on non-managed memory. Rather than querying the type of memory, it just catches `cudaErrorInvalidValue` from `cudaMemPrefetchAsync`. Authors: - Mark Harris (https://github.com/harrism) Approvers: - Lawrence Mitchell (https://github.com/wence-) - Rong Ou (https://github.com/rongou) - Jake Hemstad (https://github.com/jrhemstad) - Michael Schellenberger Costa (https://github.com/miscco) - Vyas Ramasubramani (https://github.com/vyasr) URL: #1573
- Loading branch information
Showing
10 changed files
with
320 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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 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,77 @@ | ||
/* | ||
* Copyright (c) 2024, 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 <rmm/cuda_device.hpp> | ||
#include <rmm/cuda_stream_view.hpp> | ||
#include <rmm/error.hpp> | ||
|
||
#include <cuda/std/span> | ||
|
||
namespace rmm { | ||
|
||
/** | ||
* @addtogroup utilities | ||
* @{ | ||
* @file | ||
*/ | ||
|
||
/** | ||
* @brief Prefetch memory to the specified device on the specified stream. | ||
* | ||
* This function is a no-op if the pointer is not to CUDA managed memory. | ||
* | ||
* @throw rmm::cuda_error if the prefetch fails. | ||
* | ||
* @param ptr The pointer to the memory to prefetch | ||
* @param size The number of bytes to prefetch | ||
* @param device The device to prefetch to | ||
* @param stream The stream to use for the prefetch | ||
*/ | ||
void prefetch(void const* ptr, | ||
std::size_t size, | ||
rmm::cuda_device_id device, | ||
rmm::cuda_stream_view stream) | ||
{ | ||
auto result = cudaMemPrefetchAsync(ptr, size, device.value(), stream.value()); | ||
// InvalidValue error is raised when non-managed memory is passed to cudaMemPrefetchAsync | ||
// We should treat this as a no-op | ||
if (result != cudaErrorInvalidValue && result != cudaSuccess) { RMM_CUDA_TRY(result); } | ||
} | ||
|
||
/** | ||
* @brief Prefetch a span of memory to the specified device on the specified stream. | ||
* | ||
* This function is a no-op if the buffer is not backed by CUDA managed memory. | ||
* | ||
* @throw rmm::cuda_error if the prefetch fails. | ||
* | ||
* @param data The span to prefetch | ||
* @param device The device to prefetch to | ||
* @param stream The stream to use for the prefetch | ||
*/ | ||
template <typename T> | ||
void prefetch(cuda::std::span<T const> data, | ||
rmm::cuda_device_id device, | ||
rmm::cuda_stream_view stream) | ||
{ | ||
prefetch(data.data(), data.size_bytes(), device, stream); | ||
} | ||
|
||
/** @} */ // end of group | ||
|
||
} // namespace rmm |
This file contains 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 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 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 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 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 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.