公共类型 | 公共成员函数 | 所有成员列表
rmm::mr::polymorphic_allocator< T > 类模板参考

一个流序分配器 (stream ordered Allocator),使用一个 rmm::mr::device_memory_resource 来满足分配 (allocations) 和释放 (deallocations)。更多...

#include <polymorphic_allocator.hpp>

公共类型

using value_type = T
 T,此分配器分配的对象的值类型。
 

公共成员函数

 polymorphic_allocator ()=default
 构造一个 polymorphic_allocator,使用 rmm::mr::get_current_device_resource_ref() 的返回值作为底层内存资源。
 
 polymorphic_allocator (device_async_resource_ref mr)
 使用提供的内存资源构造一个 polymorphic_allocator更多...
 
template<typename U >
 polymorphic_allocator (polymorphic_allocator< U > const &other) noexcept
 使用 other 的底层内存资源构造一个 polymorphic_allocator更多...
 
value_typeallocate (std::size_t num, cuda_stream_view stream)
 使用底层内存资源为 num 个类型为 T 的对象分配存储空间。更多...
 
void deallocate (value_type *ptr, std::size_t num, cuda_stream_view stream)
 释放由 ptr 指向的存储空间。更多...
 
rmm::device_async_resource_ref get_upstream_resource () const noexcept
 指向所用上游资源的 rmm::device_async_resource_ref。更多...
 

详细描述

template<typename T>
class rmm::mr::polymorphic_allocator< T >

一个流序分配器 (stream ordered Allocator),使用一个 rmm::mr::device_memory_resource 来满足分配 (allocations) 和释放 (deallocations)。

类似于 std::pmr::polymorphic_allocator,它利用 device_memory_resource 的运行时多态性 (runtime polymorphism),使得使用 polymorphic_allocator 作为其静态分配器类型 (static allocator type) 的容器能够互操作 (interoperable),但根据所使用的资源表现出不同的行为。

与 STL 分配器不同,polymorphic_allocatorallocatedeallocate 函数是流序的 (stream ordered)。使用 stream_allocator_adaptor 来实现与需要标准、非流序 (non stream-ordered) Allocator 接口的接口的互操作性。

模板参数
T分配器的值类型。

构造函数和析构函数文档

◆ polymorphic_allocator() [1/2]

使用提供的内存资源构造一个 polymorphic_allocator

此构造函数提供了从 device_async_resource_ref 的隐式转换 (implicit conversion)。

参数
mr用于分配的上游内存资源 (upstream memory resource)。

◆ polymorphic_allocator() [2/2]

template<typename T >
template<typename U >
rmm::mr::polymorphic_allocator< T >::polymorphic_allocator ( polymorphic_allocator< U > const &  other)
inlinenoexcept

使用 other 的底层内存资源 (underlying memory resource) 构造一个 polymorphic_allocator

参数
other将其内存资源用作新的 polymorphic_allocator 的底层资源 (underlying resource) 的 polymorphic_allocator

成员函数文档

◆ allocate()

template<typename T >
value_type* rmm::mr::polymorphic_allocator< T >::allocate ( std::size_t  num,
cuda_stream_view  stream 
)
inline

使用底层内存资源为 num 个类型为 T 的对象分配存储空间。

参数
num要为其分配存储空间的对象数量
stream执行分配操作的流 (stream)
返回
指向已分配存储空间的指针

◆ deallocate()

template<typename T >
void rmm::mr::polymorphic__allocator< T >::deallocate ( value_type ptr,
std::size_t  num,
cuda_stream_view  stream 
)
inline

释放由 ptr 指向的存储空间。

ptr 必须是从一个内存资源 r 分配而来,且该资源与使用 r.allocate(n * sizeof(T))get_upstream_resource() 比较相等 (compares equal to)。

参数
ptr指向要释放内存的指针
num最初分配的对象数量
stream执行释放操作的流 (Stream)

◆ get_upstream_resource()

template<typename T >
rmm::device_async_resource_ref rmm::mr::polymorphic__allocator< T >::get_upstream_resource ( ) const
inlinenoexcept

指向所用上游资源的 rmm::device_async_resource_ref

返回
指向所用上游资源的 rmm::device_async_resource_ref

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