host_memory_resource.hpp
前往此文件的文档。
1 /*
2  * Copyright (c) 2020-2025, NVIDIA CORPORATION.
3  *
4  * 根据 Apache 许可证 2.0 版(“许可证”)获得许可;
5  * 除非遵守许可证,否则您不得使用此文件。
6  * 您可以获取许可证副本,地址为
7  *
8  * https://apache.ac.cn/licenses/LICENSE-2.0
9  *
10  * 除非适用法律要求或书面同意,否则软件
11  * 根据许可证分发,按“原样”提供,
12  * 不附带任何形式的明示或暗示保证或条件。
13  * 请参阅许可证,了解管理权限和
14  * 限制的特定语言。
15  */
16 #pragma once
17 
18 #include <rmm/detail/cuda_memory_resource.hpp>
19 #include <rmm/detail/export.hpp>
20 #include <rmm/detail/nvtx/ranges.hpp>
21 
22 #include <cstddef>
23 
24 namespace RMM_NAMESPACE {
25 namespace mr {
57  public
58  host_memory_resource() = default;
59  virtual ~host_memory_resource() = default;
63  default;
64  host_memory_resource& operator=(host_memory_resource&&) noexcept =
65  default;
66 
79  void* allocate(std::size_t bytes, std::size_t alignment = alignof(std::max_align_t))
80  {
81  RMM_FUNC_RANGE();
82  return do_allocate(bytes, alignment);
83  }
84 
98  void deallocate(void* ptr, std::size_t bytes, std::size_t alignment = alignof(std::max_align_t))
99  {
100  RMM_FUNC_RANGE();
101  do_deallocate(ptr, bytes, alignment);
102  }
103 
116  [[nodiscard]] bool is_equal(host_memory_resource const& other) const noexcept
117  {
118  return do_is_equal(other);
119  }
120 
128  [[nodiscard]] bool operator==(host_memory_resource const& other) const noexcept
129  {
130  return do_is_equal(other);
131  }
132 
140  [[nodiscard]] bool operator!=(host_memory_resource const& other) const noexcept
141  {
142  return !do_is_equal(other);
143  }
144 
150  friend void get_property(host_memory_resource const&, cuda::mr::host_accessible) noexcept {}
151 
152  private
165  virtual void* do_allocate(std::size_t bytes,
166  std::size_t alignment = alignof(std::max_align_t)) = 0;
167 
181  virtual void do_deallocate(void* ptr,
182  std::size_t bytes,
183  std::size_t alignment = alignof(std::max_align_t)) = 0;
184 
197  [[nodiscard]] virtual bool do_is_equal(host_memory_resource const& other) const noexcept
198  {
199  return this == &other;
200  }
201 };
202 static_assert(cuda::mr::resource_with<host_memory_resource, cuda::mr::host_accessible>); // end of group
204 
205 } // namespace mr
206 } // namespace RMM_NAMESPACE
主机内存分配的基类。
定义:host_memory_resource.hpp:56
bool is_equal(host_memory_resource const &other) const noexcept
将此资源与另一个资源进行比较。
定义:host_memory_resource.hpp:116
host_memory_resource(host_memory_resource &&) noexcept=default
默认移动构造函数。
host_memory_resource(host_memory_resource const &)=default
默认复制构造函数。
bool operator==(host_memory_resource const &other) const noexcept
与另一个 host_memory_resource 的比较运算符。
定义:host_memory_resource.hpp:128
friend void get_property(host_memory_resource const &, cuda::mr::host_accessible) noexcept
启用 cuda::mr::host_accessible 属性。
定义:host_memory_resource.hpp:150
void deallocate(void *ptr, std::size_t bytes, std::size_t alignment=alignof(std::max_align_t))
解除分配 ptr 指向的内存。
定义:host_memory_resource.hpp:98
bool operator!=(host_memory_resource const &other) const noexcept
与另一个 host_memory_resource 的比较运算符。
定义:host_memory_resource.hpp:140