主机内存分配的基类。 更多...
#包含 <host_memory_resource.hpp>
公有成员函数 | |
host_memory_resource (host_memory_resource const &)=default | |
默认拷贝构造函数。 | |
host_memory_resource (host_memory_resource &&) noexcept=default | |
默认移动构造函数。 | |
host_memory_resource & | operator= (host_memory_resource const &)=default |
默认拷贝赋值运算符。 更多... | |
host_memory_resource & | operator= (host_memory_resource &&) noexcept=default |
默认移动赋值运算符。 更多... | |
void * | allocate (std::size_t bytes, std::size_t alignment=alignof(std::max_align_t)) |
在主机上分配至少 bytes 字节大小的内存。 更多... | |
void | deallocate (void *ptr, std::size_t bytes, std::size_t alignment=alignof(std::max_align_t)) |
释放 `ptr` 指向的内存。 更多... | |
bool | is_equal (host_memory_resource const &other) const noexcept |
将此资源与另一个资源进行比较。 更多... | |
bool | operator== (host_memory_resource const &other) const noexcept |
与另一个 host_memory_resource 的比较运算符。 更多... | |
bool | operator!= (host_memory_resource const &other) const noexcept |
与另一个 host_memory_resource 的比较运算符。 更多... | |
友元 | |
void | get_property (host_memory_resource const &, cuda::mr::host_accessible) noexcept |
启用 `cuda::mr::host_accessible` 属性。 更多... | |
主机内存分配的基类。
这基于 `std::pmr::memory_resource`: https://cppreference.cn/w/cpp/memory/memory_resource
当 RMM 可以使用 C++17 时,`rmm::host_memory_resource` 应该继承自 `std::pmr::memory_resource`。
此类用作所有主机内存资源实现必须满足的接口。
所有派生类必须实现两个私有、纯虚函数:`do_allocate` 和 `do_deallocate`。可选地,派生类还可以重写 `is_equal`。默认情况下,`is_equal` 仅执行身份比较。
公有、非虚函数 `allocate`、`deallocate` 和 `is_equal` 仅调用私有虚函数。这样做的原因是允许在基类中实现共享的默认行为。例如,无论使用哪个派生类的实现,基类的 `allocate` 函数都可能记录每次分配。
|
inline |
在主机上分配至少 `bytes` 字节大小的内存。
如果支持,返回的存储区将按照指定的 `alignment` 对齐;否则,将按照 `alignof(std::max_align_t)` 对齐。
std::bad_alloc | 当无法分配请求的 `bytes` 和 `alignment` 时。 |
bytes | 分配的大小 |
alignment | 分配的对齐方式 |
|
inline |
释放 `ptr` 指向的内存。
`ptr` 必须是通过对与 `*this` 比较相等的 host_memory_resource 调用 `allocate(bytes,alignment)` 返回的,并且其指向的存储区必须尚未被释放,否则行为是未定义的。
ptr | 待释放的指针 |
bytes | 分配的字节大小。这必须等于返回 `ptr` 的 `allocate` 调用中传递给 `bytes` 的值。 |
alignment | 分配的对齐方式。这必须等于返回 `ptr` 的 `allocate` 调用中传递给 `alignment` 的值。 |
|
inlinenoexcept |
将此资源与另一个资源进行比较。
当且仅当从一个 host_memory_resource 分配的内存可以从另一个释放,反之亦然时,两个 host_memory_resource 比较相等。
默认情况下,仅检查 `*this` 和 `other` 是否引用同一个对象,即不检查它们是否是同一个类的两个对象。
other | 要比较的另一个资源 |
|
inlinenoexcept |
|
defaultnoexcept |
默认移动赋值运算符。
|
default |
默认拷贝赋值运算符。
|
inlinenoexcept |
|
friend |
启用 `cuda::mr::host_accessible` 属性。
此属性声明 host_memory_resource 提供主机可访问的内存