9 #include <rmm/detail/aligned.hpp>
10 #include <rmm/detail/error.hpp>
11 #include <rmm/detail/export.hpp>
12 #include <rmm/error.hpp>
17 namespace RMM_NAMESPACE {
48 #ifdef RMM_ENABLE_LEGACY_MR_INTERFACE
59 [[nodiscard]]
void* allocate_async(std::size_t bytes, std::size_t alignment,
cuda_stream_view)
61 return do_allocate(bytes, alignment);
75 return do_allocate(bytes);
86 void deallocate_async(
void* ptr,
88 std::size_t alignment,
91 do_deallocate(ptr, bytes);
97 using host_memory_resource::allocate;
98 using host_memory_resource::deallocate;
116 return do_allocate(bytes, alignment);
133 return do_deallocate(ptr, bytes, alignment);
156 void* do_allocate(std::size_t bytes,
160 if (0 == bytes) {
return nullptr; }
163 "Allocation alignment is not a power of 2.",
166 return rmm::detail::aligned_host_allocate(bytes, alignment, [](std::size_t size) {
168 RMM_CUDA_TRY_ALLOC(cudaMallocHost(&ptr, size), size);
186 void do_deallocate(
void* ptr,
190 if (
nullptr == ptr) {
return; }
191 rmm::detail::aligned_host_deallocate(
192 ptr, bytes, alignment, [](
void* ptr) { RMM_ASSERT_CUDA_SUCCESS(cudaFreeHost(ptr)); });
197 static_assert(rmm::detail::polyfill::async_resource_with<pinned_memory_resource,
198 cuda::mr::host_accessible,
199 cuda::mr::device_accessible>);
Exception thrown when an RMM allocation fails.
Definition: error.hpp:44
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:28
Base class for host memory allocation.
Definition: host_memory_resource.hpp:48
Memory resource class for allocating pinned host memory.
Definition: pinned_host_memory_resource.hpp:37
A host_memory_resource that uses cudaMallocHost to allocate pinned/page-locked host memory.
Definition: pinned_memory_resource.hpp:37
friend void get_property(pinned_memory_resource const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition: pinned_memory_resource.hpp:141
pinned_memory_resource & operator=(pinned_memory_resource const &)=default
Default copy assignment operator.
void * allocate(cuda_stream_view stream, std::size_t bytes, std::size_t alignment=rmm::RMM_DEFAULT_HOST_ALIGNMENT)
Pretend to support the allocate_async interface, falling back to stream 0.
Definition: pinned_memory_resource.hpp:112
pinned_memory_resource(pinned_memory_resource &&)=default
Default move constructor.
pinned_memory_resource & operator=(pinned_memory_resource &&)=default
Default move assignment operator.
void deallocate(cuda_stream_view stream, void *ptr, std::size_t bytes, std::size_t alignment=rmm::RMM_DEFAULT_HOST_ALIGNMENT) noexcept
Pretend to support the deallocate_async interface, falling back to stream 0.
Definition: pinned_memory_resource.hpp:128
pinned_memory_resource(pinned_memory_resource const &)=default
Default copy constructor.
bool is_supported_alignment(std::size_t alignment) noexcept
Returns whether or not alignment is a valid memory alignment.
static constexpr std::size_t RMM_DEFAULT_HOST_ALIGNMENT
Default alignment used for host memory allocated by RMM.
Definition: aligned.hpp:25