8 #include <rmm/detail/error.hpp>
9 #include <rmm/detail/export.hpp>
11 #include <cuda/memory_resource>
12 #include <cuda/stream_ref>
16 namespace RMM_NAMESPACE {
49 void*
allocate([[maybe_unused]] cuda::stream_ref stream,
55 if (bytes == 0) {
return nullptr; }
58 RMM_CUDA_TRY_ALLOC(cudaMallocManaged(&ptr, bytes), bytes);
73 void deallocate([[maybe_unused]] cuda::stream_ref stream,
75 [[maybe_unused]] std::size_t bytes,
78 RMM_ASSERT_CUDA_SUCCESS_SAFE_SHUTDOWN(cudaFree(ptr));
90 auto* ptr = allocate(cuda::stream_ref{cudaStream_t{
nullptr}}, bytes, alignment);
91 RMM_CUDA_TRY(cudaStreamSynchronize(cudaStream_t{
nullptr}));
106 deallocate(cuda::stream_ref{cudaStream_t{
nullptr}}, ptr, bytes, alignment);
115 cuda::mr::device_accessible) noexcept
125 cuda::mr::host_accessible) noexcept
145 static_assert(cuda::mr::synchronous_resource<managed_memory_resource>);
146 static_assert(cuda::mr::resource<managed_memory_resource>);
148 cuda::mr::synchronous_resource_with<managed_memory_resource, cuda::mr::device_accessible>);
150 cuda::mr::synchronous_resource_with<managed_memory_resource, cuda::mr::host_accessible>);
151 static_assert(cuda::mr::resource_with<managed_memory_resource, cuda::mr::device_accessible>);
152 static_assert(cuda::mr::resource_with<managed_memory_resource, cuda::mr::host_accessible>);
Memory resource that uses cudaMallocManaged/Free for allocation/deallocation.
Definition: managed_memory_resource.hpp:26
managed_memory_resource(managed_memory_resource &&)=default
Default move constructor.
void * allocate_sync(std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates memory of size at least bytes synchronously.
Definition: managed_memory_resource.hpp:88
bool operator==(managed_memory_resource const &) const noexcept
Compare this resource to another.
Definition: managed_memory_resource.hpp:136
friend void get_property(managed_memory_resource const &, cuda::mr::host_accessible) noexcept
Enables the cuda::mr::host_accessible property.
Definition: managed_memory_resource.hpp:124
void * allocate([[maybe_unused]] 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: managed_memory_resource.hpp:49
friend void get_property(managed_memory_resource const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition: managed_memory_resource.hpp:114
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: managed_memory_resource.hpp:102
managed_memory_resource & operator=(managed_memory_resource &&)=default
Default move assignment operator.
managed_memory_resource & operator=(managed_memory_resource const &)=default
Default copy assignment operator.
void deallocate([[maybe_unused]] 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: managed_memory_resource.hpp:73
bool operator!=(managed_memory_resource const &) const noexcept
Compare this resource to another.
Definition: managed_memory_resource.hpp:141
managed_memory_resource(managed_memory_resource const &)=default
Default copy constructor.
static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT
Default alignment used for CUDA memory allocation.
Definition: aligned.hpp:25