19 #include <rmm/detail/aligned.hpp>
20 #include <rmm/detail/error.hpp>
75 return std::make_pair(0, 0);
90 return do_allocate(bytes, alignment);
104 return do_allocate(bytes);
117 do_deallocate(ptr, rmm::detail::align_up(bytes, alignment));
140 void* do_allocate(std::size_t bytes, std::size_t alignment =
alignof(std::max_align_t))
override
143 if (0 == bytes) {
return nullptr; }
146 alignment = (rmm::detail::is_supported_alignment(alignment))
148 : rmm::detail::RMM_DEFAULT_HOST_ALIGNMENT;
150 return rmm::detail::aligned_allocate(bytes, alignment, [](std::size_t size) {
152 auto status = cudaMallocHost(&ptr, size);
153 if (cudaSuccess != status) {
throw std::bad_alloc{}; }
171 void do_deallocate(
void* ptr,
173 std::size_t alignment =
alignof(std::max_align_t))
override
175 if (
nullptr == ptr) {
return; }
176 rmm::detail::aligned_deallocate(
177 ptr, bytes, alignment, [](
void* ptr) { RMM_ASSERT_CUDA_SUCCESS(cudaFreeHost(ptr)); });
180 static_assert(cuda::mr::async_resource_with<pinned_memory_resource,
181 cuda::mr::host_accessible,
182 cuda::mr::device_accessible>);
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:41
Base class for host memory allocation.
Definition: host_memory_resource.hpp:54
A host_memory_resource that uses cudaMallocHost to allocate pinned/page-locked host memory.
Definition: pinned_memory_resource.hpp:39
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:125
void * allocate_async(std::size_t bytes, cuda_stream_view)
Pretend to support the allocate_async interface, falling back to stream 0.
Definition: pinned_memory_resource.hpp:102
pinned_memory_resource & operator=(pinned_memory_resource const &)=default
Default copy assignment operator.
pinned_memory_resource(pinned_memory_resource &&)=default
Default move constructor.
bool supports_streams() const noexcept
Query whether the pinned_memory_resource supports use of non-null CUDA streams for allocation/dealloc...
Definition: pinned_memory_resource.hpp:56
std::pair< std::size_t, std::size_t > get_mem_info(cuda_stream_view stream) const
Queries the amount of free and total memory for the resource.
Definition: pinned_memory_resource.hpp:73
bool supports_get_mem_info() const noexcept
Query whether the resource supports the get_mem_info API.
Definition: pinned_memory_resource.hpp:63
pinned_memory_resource & operator=(pinned_memory_resource &&)=default
Default move assignment operator.
void * allocate_async(std::size_t bytes, std::size_t alignment, cuda_stream_view)
Pretend to support the allocate_async interface, falling back to stream 0.
Definition: pinned_memory_resource.hpp:88
void deallocate_async(void *ptr, std::size_t bytes, std::size_t alignment, cuda_stream_view)
Pretend to support the deallocate_async interface, falling back to stream 0.
Definition: pinned_memory_resource.hpp:115
pinned_memory_resource(pinned_memory_resource const &)=default
Default copy constructor.