Public Types | Public Member Functions | List of all members
rmm::mr::polymorphic_allocator< T > Class Template Reference

A stream ordered Allocator using a rmm::mr::device_memory_resource to satisfy (de)allocations. More...

#include <polymorphic_allocator.hpp>

Public Types

using value_type = T
 

Public Member Functions

 polymorphic_allocator ()=default
 Construct a polymorphic_allocator using the return value of rmm::mr::get_current_device_resource() as the underlying memory resource.
 
 polymorphic_allocator (polymorphic_allocator< T > const &other)=default
 Construct a polymorphic_allocator using other.resource() as the underlying memory resource. More...
 
 polymorphic_allocator (device_memory_resource *mr)
 Construct a polymorphic_allocator using the provided memory resource. More...
 
template<typename U >
 polymorphic_allocator (polymorphic_allocator< U > const &other) noexcept
 Construct a polymorphic_allocator using other.resource() as the underlying memory resource. More...
 
value_type * allocate (std::size_t n, cuda_stream_view stream)
 Allocates storage for n objects of type T using the underlying memory resource. More...
 
void deallocate (value_type *p, std::size_t n, cuda_stream_view stream)
 Deallocates storage pointed to by p. More...
 
device_memory_resourceresource () const noexcept
 Returns pointer to the underlying rmm::mr::device_memory_resource. More...
 

Detailed Description

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

A stream ordered Allocator using a rmm::mr::device_memory_resource to satisfy (de)allocations.

Similar to std::pmr::polymorphic_allocator, uses the runtime polymorphism of device_memory_resource to allow containers with polymorphic_allocator as their static allocator type to be interoperable, but exhibit different behavior depending on resource used.

Unlike STL allocators, polymorphic_allocator's allocate and deallocate functions are stream ordered. Use stream_allocator_adaptor to allow interoperability with interfaces that require standard, non stream-ordered Allocator interfaces.

Template Parameters
TThe allocators value type.

Constructor & Destructor Documentation

◆ polymorphic_allocator() [1/3]

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

Construct a polymorphic_allocator using other.resource() as the underlying memory resource.

Parameters
otherThe polymorphic_resource whose resource() will be used as the underlying resource of the new polymorphic_allocator.

◆ polymorphic_allocator() [2/3]

template<typename T >
rmm::mr::polymorphic_allocator< T >::polymorphic_allocator ( device_memory_resource mr)
inline

Construct a polymorphic_allocator using the provided memory resource.

This constructor provides an implicit conversion from memory_resource*.

Parameters
mrThe device_memory_resource to use as the underlying resource.

◆ polymorphic_allocator() [3/3]

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

Construct a polymorphic_allocator using other.resource() as the underlying memory resource.

Parameters
otherThe polymorphic_resource whose resource() will be used as the underlying resource of the new polymorphic_allocator.

Member Function Documentation

◆ allocate()

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

Allocates storage for n objects of type T using the underlying memory resource.

Parameters
nThe number of objects to allocate storage for
streamThe stream on which to perform the allocation
Returns
Pointer to the allocated storage

◆ deallocate()

template<typename T >
void rmm::mr::polymorphic_allocator< T >::deallocate ( value_type *  p,
std::size_t  n,
cuda_stream_view  stream 
)
inline

Deallocates storage pointed to by p.

p must have been allocated from a rmm::mr::device_memory_resource r that compares equal to *resource() using r.allocate(n * sizeof(T)).

Parameters
pPointer to memory to deallocate
nNumber of objects originally allocated
streamStream on which to perform the deallocation

◆ resource()

template<typename T >
device_memory_resource* rmm::mr::polymorphic_allocator< T >::resource ( ) const
inlinenoexcept

Returns pointer to the underlying rmm::mr::device_memory_resource.

Returns
Pointer to the underlying resource.

The documentation for this class was generated from the following file: