20 #include <rmm/detail/cuda_util.hpp>
21 #include <rmm/detail/dynamic_load_runtime.hpp>
22 #include <rmm/detail/error.hpp>
25 #include <rmm/detail/thrust_namespace.h>
26 #include <thrust/optional.h>
28 #include <cuda_runtime_api.h>
33 #if CUDART_VERSION >= 11020
34 #define RMM_CUDA_MALLOC_ASYNC_SUPPORT
50 #ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT
62 : cuda_pool_handle_{[valid_pool_handle]() {
63 RMM_EXPECTS(
nullptr != valid_pool_handle,
"Unexpected null pool handle.");
64 return valid_pool_handle;
69 int cuda_pool_supported{};
71 cudaDeviceGetAttribute(&cuda_pool_supported, cudaDevAttrMemoryPoolsSupported, device.value());
72 RMM_EXPECTS(result == cudaSuccess && cuda_pool_supported,
73 "cudaMallocAsync not supported with this CUDA driver/runtime version");
77 #ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT
82 [[nodiscard]] cudaMemPool_t pool_handle()
const noexcept {
return cuda_pool_handle_; }
111 #ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT
112 cudaMemPool_t cuda_pool_handle_{};
127 #ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT
129 RMM_CUDA_TRY_ALLOC(rmm::detail::async_alloc::cudaMallocFromPoolAsync(
130 &ptr, bytes, pool_handle(), stream.
value()));
147 void do_deallocate(
void* ptr,
148 [[maybe_unused]] std::size_t bytes,
151 #ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT
152 if (ptr !=
nullptr) {
153 RMM_ASSERT_CUDA_SUCCESS(rmm::detail::async_alloc::cudaFreeAsync(ptr, stream.
value()));
169 [[nodiscard]]
bool do_is_equal(device_memory_resource
const& other)
const noexcept
override
171 return dynamic_cast<cuda_async_view_memory_resource const*
>(&other) !=
nullptr;
181 [[nodiscard]] std::pair<std::size_t, std::size_t> do_get_mem_info(
184 return std::make_pair(0, 0);
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:41
constexpr cudaStream_t value() const noexcept
Get the wrapped stream.
Definition: cuda_stream_view.hpp:75
device_memory_resource derived class that uses cudaMallocAsync/cudaFreeAsync for allocation/deallocat...
Definition: cuda_async_view_memory_resource.hpp:48
bool supports_streams() const noexcept override
Query whether the resource supports use of non-null CUDA streams for allocation/deallocation....
Definition: cuda_async_view_memory_resource.hpp:101
bool supports_get_mem_info() const noexcept override
Query whether the resource supports the get_mem_info API.
Definition: cuda_async_view_memory_resource.hpp:108
cuda_async_view_memory_resource & operator=(cuda_async_view_memory_resource &&)=default
Default move assignment operator.
cuda_async_view_memory_resource(cuda_async_view_memory_resource &&)=default
Default move constructor.
cuda_async_view_memory_resource(cuda_async_view_memory_resource const &)=default
Default copy constructor.
cuda_async_view_memory_resource & operator=(cuda_async_view_memory_resource const &)=default
Default copy assignment operator.
Base class for all libcudf device memory allocation.
Definition: device_memory_resource.hpp:89
cuda_device_id get_current_cuda_device()
Returns a cuda_device_id for the current device.
Definition: cuda_device.hpp:86