9 #include <rmm/detail/error.hpp>
10 #include <rmm/detail/export.hpp>
11 #include <rmm/detail/runtime_capabilities.hpp>
15 #include <cuda/std/type_traits>
16 #include <cuda_runtime_api.h>
22 namespace RMM_NAMESPACE {
50 RMM_EXPECTS(rmm::detail::runtime_async_managed_alloc::is_supported(),
51 "cuda_async_managed_memory_resource requires CUDA 13.0 or higher");
53 #if defined(CUDA_VERSION) && CUDA_VERSION >= RMM_MIN_ASYNC_MANAGED_ALLOC_CUDA_VERSION
54 cudaMemPool_t managed_pool_handle{};
55 cudaMemLocation location{.type = cudaMemLocationTypeDevice,
58 cudaMemGetDefaultMemPool(&managed_pool_handle, &location, cudaMemAllocationTypeManaged));
68 [[nodiscard]] cudaMemPool_t
pool_handle() const noexcept {
return pool_.pool_handle(); }
71 cuda_async_managed_memory_resource(cuda_async_managed_memory_resource
const&) =
delete;
72 cuda_async_managed_memory_resource(cuda_async_managed_memory_resource&&) =
delete;
73 cuda_async_managed_memory_resource& operator=(cuda_async_managed_memory_resource
const&) =
delete;
74 cuda_async_managed_memory_resource& operator=(cuda_async_managed_memory_resource&&) =
delete;
77 cuda_async_view_memory_resource pool_{};
90 return pool_.
allocate(stream, bytes);
103 pool_.deallocate(stream, ptr, bytes);
113 [[nodiscard]]
bool do_is_equal(device_memory_resource
const& other)
const noexcept
override
115 auto const* async_mr =
dynamic_cast<cuda_async_managed_memory_resource const*
>(&other);
116 return (async_mr !=
nullptr) && (this->pool_handle() == async_mr->pool_handle());
121 static_assert(rmm::detail::polyfill::resource<cuda_async_managed_memory_resource>);
122 static_assert(rmm::detail::polyfill::async_resource<cuda_async_managed_memory_resource>);
123 static_assert(rmm::detail::polyfill::resource_with<cuda_async_managed_memory_resource,
124 cuda::mr::device_accessible>);
125 static_assert(rmm::detail::polyfill::async_resource_with<cuda_async_managed_memory_resource,
126 cuda::mr::device_accessible>);
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:28
device_memory_resource derived class that uses cudaMallocFromPoolAsync/cudaFreeFromPoolAsync with a m...
Definition: cuda_async_managed_memory_resource.hpp:35
cuda_async_managed_memory_resource()
Constructs a cuda_async_managed_memory_resource with the default managed memory pool for the current ...
Definition: cuda_async_managed_memory_resource.hpp:47
cudaMemPool_t pool_handle() const noexcept
Returns the underlying native handle to the CUDA pool.
Definition: cuda_async_managed_memory_resource.hpp:68
device_memory_resource derived class that uses cudaMallocAsync/cudaFreeAsync for allocation/deallocat...
Definition: cuda_async_view_memory_resource.hpp:29
Base class for all librmm device memory allocation.
Definition: device_memory_resource.hpp:82
void * allocate(cuda_stream_view stream, std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates memory of size at least bytes on the specified stream.
Definition: device_memory_resource.hpp:152
cuda_device_id get_current_cuda_device()
Returns a cuda_device_id for the current device.
constexpr value_type value() const noexcept
The wrapped integer value.
Definition: cuda_device.hpp:43