公共类型 | 公共成员函数 | 所有成员列表
rmm::mr::failure_callback_resource_adaptor< Upstream, ExceptionType > 类模板参考final

一种设备内存资源,当分配抛出指定的异常类型时会调用回调函数。 更多...

#include <failure_callback_resource_adaptor.hpp>

rmm::mr::failure_callback_resource_adaptor< Upstream, ExceptionType > 的继承图
Inheritance graph
[图例]
rmm::mr::failure_callback_resource_adaptor< Upstream, ExceptionType > 的协作图
Collaboration graph
[图例]

公共类型

using exception_type = ExceptionType
 此对象捕获/抛出的异常类型。
 

公共成员函数

 failure_callback_resource_adaptor (device_async_resource_ref upstream, failure_callback_t callback, void *callback_arg)
 使用 upstream 构造新的 failure_callback_resource_adaptor 以满足分配请求。 更多...
 
 failure_callback_resource_adaptor (Upstream *upstream, failure_callback_t callback, void *callback_arg)
 使用 upstream 构造新的 failure_callback_resource_adaptor 以满足分配请求。 更多...
 
 failure_callback_resource_adaptor (failure_callback_resource_adaptor const &)=delete
 
failure_callback_resource_adaptoroperator= (failure_callback_resource_adaptor const &)=delete
 
 failure_callback_resource_adaptor (failure_callback_resource_adaptor &&) noexcept=default
 默认移动构造函数。
 
failure_callback_resource_adaptoroperator= (failure_callback_resource_adaptor &&) noexcept=default
 默认移动赋值运算符。 更多...
 
rmm::device_async_resource_ref get_upstream_resource () const noexcept
 指向 upstream 资源的 rmm::device_async_resource_ref。 更多...
 
- 继承自 rmm::mr::device_memory_resource 的公共成员函数
 device_memory_resource (device_memory_resource const &)=default
 默认拷贝构造函数。
 
 device_memory_resource (device_memory_resource &&) noexcept=default
 默认移动构造函数。
 
device_memory_resourceoperator= (device_memory_resource const &)=default
 默认拷贝赋值运算符。 更多...
 
device_memory_resourceoperator= (device_memory_resource &&) noexcept=default
 默认移动赋值运算符。 更多...
 
void * allocate (std::size_t bytes, cuda_stream_view stream=cuda_stream_view{})
 分配至少 bytes 大小的内存。 更多...
 
void deallocate (void *ptr, std::size_t bytes, cuda_stream_view stream=cuda_stream_view{})
 释放由 p 指向的内存。 更多...
 
bool is_equal (device_memory_resource const &other) const noexcept
 将此资源与另一个资源进行比较。 更多...
 
void * allocate (std::size_t bytes, std::size_t alignment)
 分配至少 bytes 大小的内存。 更多...
 
void deallocate (void *ptr, std::size_t bytes, std::size_t alignment)
 释放由 p 指向的内存。 更多...
 
void * allocate_async (std::size_t bytes, std::size_t alignment, cuda_stream_view stream)
 分配至少 bytes 大小的内存。 更多...
 
void * allocate_async (std::size_t bytes, cuda_stream_view stream)
 分配至少 bytes 大小的内存。 更多...
 
void deallocate_async (void *ptr, std::size_t bytes, std::size_t alignment, cuda_stream_view stream)
 释放由 p 指向的内存。 更多...
 
void deallocate_async (void *ptr, std::size_t bytes, cuda_stream_view stream)
 释放由 p 指向的内存。 更多...
 
bool operator== (device_memory_resource const &other) const noexcept
 与另一个 device_memory_resource 的比较运算符。 更多...
 
bool operator!= (device_memory_resource const &other) const noexcept
 与另一个 device_memory_resource 的比较运算符。 更多...
 

详细描述

template<typename Upstream, typename ExceptionType = rmm::out_of_memory>
class rmm::mr::failure_callback_resource_adaptor< Upstream, ExceptionType >

一种设备内存资源,当分配抛出指定的异常类型时会调用回调函数。

此资源实例必须使用现有的 upstream 资源构造,以满足分配请求。

回调函数接受分配大小和回调参数,并返回一个 bool 值,表示是否重试分配 (true) 或重新抛出捕获的异常 (false)。

在实现分配重试的回调函数时,必须小心以避免无限循环。以下示例确保只重试分配一次

using failure_callback_adaptor =
bool failure_handler(std::size_t bytes, void* arg)
{
bool& retried = *reinterpret_cast<bool*>(arg);
if (!retried) {
retried = true;
return true; // First time we request an allocation retry
}
return false; // Second time we let the adaptor throw std::bad_alloc
}
int main()
{
bool retried{false};
failure_callback_adaptor mr{
rmm::mr::get_current_device_resource_ref(), failure_handler, &retried
};
}
一种设备内存资源,当分配抛出指定的异常时调用回调函数...
定义: failure_callback_resource_adaptor.hpp:95
device_async_resource_ref set_current_device_resource_ref(device_async_resource_ref new_resource_ref)
设置当前设备的 device_async_resource_ref。
定义: per_device_resource.hpp:437
device_async_resource_ref get_current_device_resource_ref()
获取当前设备的 device_async_resource_ref。
定义: per_device_resource.hpp:411
模板参数
Upstream用于分配/释放的 upstream 资源的类型。
ExceptionType此适配器应响应的异常类型

构造函数和析构函数文档

◆ failure_callback_resource_adaptor() [1/2]

template<typename Upstream , typename ExceptionType = rmm::out_of_memory>
rmm::mr::failure_callback_resource_adaptor< Upstream, ExceptionType >::failure_callback_resource_adaptor ( device_async_resource_ref  upstream,
failure_callback_t  callback,
void *  callback_arg 
)
inline

使用 upstream 构造新的 failure_callback_resource_adaptor 以满足分配请求。

参数
upstream用于分配/释放设备内存的资源
callback回调函数
另请参阅
failure_callback_t
参数
callback_arg传递给 callback 的额外参数

◆ failure_callback_resource_adaptor() [2/2]

template<typename Upstream , typename ExceptionType = rmm::out_of_memory>
rmm::mr::failure_callback_resource_adaptor< Upstream, ExceptionType >::failure_callback_resource_adaptor ( Upstream *  upstream,
failure_callback_t  callback,
void *  callback_arg 
)
inline

使用 upstream 构造新的 failure_callback_resource_adaptor 以满足分配请求。

异常
rmm::logic_error如果 upstream == nullptr
参数
upstream用于分配/释放设备内存的资源
callback回调函数
另请参阅
failure_callback_t
参数
callback_arg传递给 callback 的额外参数

成员函数文档

◆ get_upstream_resource()

template<typename Upstream , typename ExceptionType = rmm::out_of_memory>
rmm::device_async_resource_ref rmm::mr::failure_callback_resource_adaptor< Upstream, ExceptionType >::get_upstream_resource ( ) const
inlinenoexcept

指向 upstream 资源的 rmm::device_async_resource_ref

返回值
指向 upstream 资源的 rmm::device_async_resource_ref

◆ operator=()

template<typename Upstream , typename ExceptionType = rmm::out_of_memory>
failure_callback_resource_adaptor& rmm::mr::failure_callback_resource_adaptor< Upstream, ExceptionType >::operator= ( failure_callback_resource_adaptor< Upstream, ExceptionType > &&  )
defaultnoexcept

默认移动赋值运算符。

返回值
failure_callback_resource_adaptor& 对赋值对象的引用

此类的文档由以下文件生成