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,
54 RMM_CUDA_TRY_ALLOC(cudaMalloc(&ptr, bytes), bytes);
69 void deallocate([[maybe_unused]] cuda::stream_ref stream,
71 [[maybe_unused]] std::size_t bytes,
74 RMM_ASSERT_CUDA_SUCCESS_SAFE_SHUTDOWN(cudaFree(ptr));
86 auto* ptr = allocate(cuda::stream_ref{cudaStream_t{
nullptr}}, bytes, alignment);
87 RMM_CUDA_TRY(cudaStreamSynchronize(cudaStream_t{
nullptr}));
102 deallocate(cuda::stream_ref{cudaStream_t{
nullptr}}, ptr, bytes, alignment);
111 cuda::mr::device_accessible) noexcept
131 static_assert(cuda::mr::synchronous_resource<cuda_memory_resource>);
132 static_assert(cuda::mr::resource<cuda_memory_resource>);
134 cuda::mr::synchronous_resource_with<cuda_memory_resource, cuda::mr::device_accessible>);
135 static_assert(cuda::mr::resource_with<cuda_memory_resource, cuda::mr::device_accessible>);
Memory resource that uses cudaMalloc/Free for allocation/deallocation.
Definition: cuda_memory_resource.hpp:26
cuda_memory_resource(cuda_memory_resource const &)=default
Default copy constructor.
friend void get_property(cuda_memory_resource const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition: cuda_memory_resource.hpp:110
cuda_memory_resource & operator=(cuda_memory_resource const &)=default
Default copy assignment operator.
cuda_memory_resource & operator=(cuda_memory_resource &&)=default
Default move 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: cuda_memory_resource.hpp:69
bool operator==(cuda_memory_resource const &) const noexcept
Compare this resource to another.
Definition: cuda_memory_resource.hpp:122
cuda_memory_resource(cuda_memory_resource &&)=default
Default move constructor.
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_memory_resource.hpp:98
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: cuda_memory_resource.hpp:49
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_memory_resource.hpp:84
bool operator!=(cuda_memory_resource const &) const noexcept
Compare this resource to another.
Definition: cuda_memory_resource.hpp:127
static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT
Default alignment used for CUDA memory allocation.
Definition: aligned.hpp:25