8 #include <rmm/detail/error.hpp>
9 #include <rmm/detail/export.hpp>
10 #include <rmm/detail/runtime_capabilities.hpp>
12 #include <cuda/memory_resource>
13 #include <cuda/stream_ref>
14 #include <cuda_runtime_api.h>
18 namespace RMM_NAMESPACE {
43 : cuda_pool_handle_{[pool_handle]() {
44 RMM_EXPECTS(
nullptr != pool_handle,
"Unexpected null pool handle.");
49 RMM_EXPECTS(rmm::detail::runtime_async_alloc::is_supported(),
50 "cudaMallocAsync not supported with this CUDA driver/runtime version");
58 [[nodiscard]] cudaMemPool_t
pool_handle() const noexcept {
return cuda_pool_handle_; }
87 RMM_CUDA_TRY_ALLOC(cudaMallocFromPoolAsync(&ptr, bytes, pool_handle(), stream.get()), bytes);
103 [[maybe_unused]] std::size_t bytes,
106 if (ptr !=
nullptr) { RMM_ASSERT_CUDA_SUCCESS_SAFE_SHUTDOWN(cudaFreeAsync(ptr, stream.get())); }
118 auto* ptr = allocate(cuda::stream_ref{cudaStream_t{
nullptr}}, bytes, alignment);
119 RMM_CUDA_TRY(cudaStreamSynchronize(cudaStream_t{
nullptr}));
134 deallocate(cuda::stream_ref{cudaStream_t{
nullptr}}, ptr, bytes, alignment);
146 return pool_handle() == other.pool_handle();
164 cuda::mr::device_accessible) noexcept
169 cudaMemPool_t cuda_pool_handle_{};
173 static_assert(cuda::mr::synchronous_resource<cuda_async_view_memory_resource>);
174 static_assert(cuda::mr::resource<cuda_async_view_memory_resource>);
175 static_assert(cuda::mr::synchronous_resource_with<cuda_async_view_memory_resource,
176 cuda::mr::device_accessible>);
178 cuda::mr::resource_with<cuda_async_view_memory_resource, cuda::mr::device_accessible>);
Memory resource that uses cudaMallocAsync/cudaFreeAsync for allocation/deallocation.
Definition: cuda_async_view_memory_resource.hpp:30
void deallocate(cuda::stream_ref stream, void *ptr, [[maybe_unused]] std::size_t bytes, [[maybe_unused]] std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept
Deallocate memory pointed to by ptr.
Definition: cuda_async_view_memory_resource.hpp:101
bool operator!=(cuda_async_view_memory_resource const &other) const noexcept
Compare this resource to another.
Definition: cuda_async_view_memory_resource.hpp:152
cuda_async_view_memory_resource & operator=(cuda_async_view_memory_resource &&)=default
Default move assignment operator.
void deallocate_sync(void *ptr, std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept
Deallocate memory pointed to by ptr synchronously.
Definition: cuda_async_view_memory_resource.hpp:130
cuda_async_view_memory_resource(cuda_async_view_memory_resource &&)=default
Default move constructor.
cudaMemPool_t pool_handle() const noexcept
Returns the underlying native handle to the CUDA pool.
Definition: cuda_async_view_memory_resource.hpp:58
void * allocate(cuda::stream_ref stream, std::size_t bytes, [[maybe_unused]] std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates memory of size at least bytes.
Definition: cuda_async_view_memory_resource.hpp:81
void * allocate_sync(std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates memory of size at least bytes synchronously.
Definition: cuda_async_view_memory_resource.hpp:116
cuda_async_view_memory_resource(cudaMemPool_t pool_handle)
Constructs a cuda_async_view_memory_resource which uses an existing CUDA memory pool....
Definition: cuda_async_view_memory_resource.hpp:42
bool operator==(cuda_async_view_memory_resource const &other) const noexcept
Compare this resource to another.
Definition: cuda_async_view_memory_resource.hpp:144
cuda_async_view_memory_resource(cuda_async_view_memory_resource const &)=default
Default copy constructor.
friend void get_property(cuda_async_view_memory_resource const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition: cuda_async_view_memory_resource.hpp:163
cuda_async_view_memory_resource & operator=(cuda_async_view_memory_resource const &)=default
Default copy assignment operator.
bool operator==(cuda_stream_view lhs, cuda_stream_view rhs)
Equality comparison operator for streams.
static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT
Default alignment used for CUDA memory allocation.
Definition: aligned.hpp:25