pinned_host_memory_resource.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #pragma once
6 
7 #include <rmm/aligned.hpp>
8 #include <rmm/detail/export.hpp>
9 
10 #include <cuda/memory_resource>
11 #include <cuda/stream_ref>
12 #include <cuda_runtime_api.h>
13 
14 #include <cstddef>
15 
16 namespace RMM_NAMESPACE {
17 namespace mr {
18 
32 class RMM_EXPORT pinned_host_memory_resource final {
33  public:
34  pinned_host_memory_resource() = default;
35  ~pinned_host_memory_resource() = default;
37  default;
39  default;
41  default;
43  default;
44 
61  void* allocate([[maybe_unused]] cuda::stream_ref stream,
62  std::size_t bytes,
63  std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT);
64 
76  void deallocate([[maybe_unused]] cuda::stream_ref stream,
77  void* ptr,
78  std::size_t bytes,
79  std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept;
80 
88  void* allocate_sync(std::size_t bytes, std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT);
89 
97  void deallocate_sync(void* ptr,
98  std::size_t bytes,
99  std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept;
100 
106  RMM_CONSTEXPR_FRIEND void get_property(pinned_host_memory_resource const&,
107  cuda::mr::device_accessible) noexcept
108  {
109  }
110 
116  RMM_CONSTEXPR_FRIEND void get_property(pinned_host_memory_resource const&,
117  cuda::mr::host_accessible) noexcept
118  {
119  }
120 
128  [[nodiscard]] bool operator==(pinned_host_memory_resource const&) const noexcept;
129 
133  [[nodiscard]] bool operator!=(pinned_host_memory_resource const&) const noexcept;
134 };
135 
136 // static property checks
137 static_assert(cuda::mr::synchronous_resource<pinned_host_memory_resource>);
138 static_assert(cuda::mr::resource<pinned_host_memory_resource>);
139 static_assert(
140  cuda::mr::synchronous_resource_with<pinned_host_memory_resource, cuda::mr::device_accessible>);
141 static_assert(
142  cuda::mr::synchronous_resource_with<pinned_host_memory_resource, cuda::mr::host_accessible>);
143 static_assert(cuda::mr::resource_with<pinned_host_memory_resource, cuda::mr::device_accessible>);
144 static_assert(cuda::mr::resource_with<pinned_host_memory_resource, cuda::mr::host_accessible>);
145  // end of group
147 } // namespace mr
148 } // namespace RMM_NAMESPACE
Memory resource class for allocating pinned host memory.
Definition: pinned_host_memory_resource.hpp:32
bool operator==(pinned_host_memory_resource const &) const noexcept
Compare this resource to another.
bool operator!=(pinned_host_memory_resource const &) const noexcept
Compare this resource to another.
void deallocate([[maybe_unused]] cuda::stream_ref stream, void *ptr, std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept
Deallocate memory pointed to by ptr.
pinned_host_memory_resource(pinned_host_memory_resource &&)=default
Default move constructor.
friend void get_property(pinned_host_memory_resource const &, cuda::mr::host_accessible) noexcept
Enables the cuda::mr::host_accessible property.
Definition: pinned_host_memory_resource.hpp:116
void * allocate_sync(std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates pinned host memory of size at least bytes bytes synchronously.
pinned_host_memory_resource & operator=(pinned_host_memory_resource &&)=default
Default move assignment operator.
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.
pinned_host_memory_resource(pinned_host_memory_resource const &)=default
Default copy constructor.
friend void get_property(pinned_host_memory_resource const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition: pinned_host_memory_resource.hpp:106
pinned_host_memory_resource & operator=(pinned_host_memory_resource const &)=default
Default copy assignment operator.
void * allocate([[maybe_unused]] cuda::stream_ref stream, std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates pinned host memory of size at least bytes bytes.
static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT
Default alignment used for CUDA memory allocation.
Definition: aligned.hpp:25