18 #include <rmm/cuda_device.hpp>
19 #include <rmm/cuda_stream_view.hpp>
20 #include <rmm/detail/cuda_util.hpp>
21 #include <rmm/detail/dynamic_load_runtime.hpp>
22 #include <rmm/detail/error.hpp>
23 #include <rmm/mr/device/device_memory_resource.hpp>
25 #include <thrust/optional.h>
27 #include <cuda_runtime_api.h>
32 #if CUDART_VERSION >= 11020 // 11.2 introduced cudaMallocAsync
33 #define RMM_CUDA_MALLOC_ASYNC_SUPPORT
44 #ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT
56 : cuda_pool_handle_{[valid_pool_handle]() {
57 RMM_EXPECTS(
nullptr != valid_pool_handle,
"Unexpected null pool handle.");
58 return valid_pool_handle;
62 auto const device = rmm::detail::current_device();
63 int cuda_pool_supported{};
65 cudaDeviceGetAttribute(&cuda_pool_supported, cudaDevAttrMemoryPoolsSupported, device.value());
66 RMM_EXPECTS(result == cudaSuccess && cuda_pool_supported,
67 "cudaMallocAsync not supported with this CUDA driver/runtime version");
71 #ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT
76 [[nodiscard]] cudaMemPool_t pool_handle()
const noexcept {
return cuda_pool_handle_; }
101 #ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT
102 cudaMemPool_t cuda_pool_handle_{};
118 #ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT
120 RMM_CUDA_TRY_ALLOC(rmm::detail::async_alloc::cudaMallocFromPoolAsync(
121 &ptr, bytes, pool_handle(), stream.
value()));
139 #ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT
140 if (ptr !=
nullptr) {
141 RMM_ASSERT_CUDA_SUCCESS(rmm::detail::async_alloc::cudaFreeAsync(ptr, stream.
value()));
158 [[nodiscard]]
bool do_is_equal(device_memory_resource
const& other)
const noexcept
override
160 return dynamic_cast<cuda_async_view_memory_resource const*
>(&other) !=
nullptr;
170 [[nodiscard]] std::pair<std::size_t, std::size_t> do_get_mem_info(
173 return std::make_pair(0, 0);