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
61 #ifdef RMM_DEPRECATE_LEGACY_MR_INTERFACE
63 "This function is deprecated. Use allocate(cuda_stream_view stream, std::size_t bytes, "
64 "std::size_t alignment) instead.")]]
69 return do_allocate(bytes, alignment);
83 #ifdef RMM_DEPRECATE_LEGACY_MR_INTERFACE
85 "This function is deprecated. Use allocate(cuda_stream_view stream, std::size_t bytes, "
86 "std::size_t alignment) instead.")]]
91 return do_allocate(bytes);
104 #ifdef RMM_DEPRECATE_LEGACY_MR_INTERFACE
106 "This function is deprecated. Use deallocate(cuda_stream_view stream, void* ptr, std::size_t "
107 "bytes, std::size_t alignment) instead.")]]
109 void deallocate_async(
void* ptr,
111 std::size_t alignment,
114 do_deallocate(ptr, bytes);
122 using host_memory_resource::allocate;
123 using host_memory_resource::deallocate;
141 return do_allocate(bytes, alignment);
158 return do_deallocate(ptr, bytes, alignment);
181 void* do_allocate(std::size_t bytes,
185 if (0 == bytes) {
return nullptr; }
188 "Allocation alignment is not a power of 2.",
191 return rmm::detail::aligned_host_allocate(bytes, alignment, [](std::size_t size) {
193 RMM_CUDA_TRY_ALLOC(cudaMallocHost(&ptr, size), size);
211 void do_deallocate(
void* ptr,
215 if (
nullptr == ptr) {
return; }
216 rmm::detail::aligned_host_deallocate(
217 ptr, bytes, alignment, [](
void* ptr) { RMM_ASSERT_CUDA_SUCCESS(cudaFreeHost(ptr)); });
222 static_assert(rmm::detail::polyfill::async_resource_with<pinned_memory_resource,
223 cuda::mr::host_accessible,
224 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:166
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:137
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:153
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:27