Classes | Public Types | Public Member Functions | List of all members
rmm::mr::stream_allocator_adaptor< Allocator > Class Template Reference

Adapts a stream ordered allocator to provide a standard Allocator interface. More...

#include <polymorphic_allocator.hpp>

Classes

struct  rebind
 Rebinds the allocator to the specified type. More...
 

Public Types

using value_type = typename std::allocator_traits< Allocator >::value_type
 

Public Member Functions

 stream_allocator_adaptor (Allocator const &allocator, cuda_stream_view stream)
 Construct a stream_allocator_adaptor using a as the underlying allocator. More...
 
template<typename OtherAllocator >
 stream_allocator_adaptor (stream_allocator_adaptor< OtherAllocator > const &other)
 Construct a stream_allocator_adaptor using other.underlying_allocator() and other.stream() as the underlying allocator and stream. More...
 
value_typeallocate (std::size_t num)
 Allocates storage for num objects of type T using the underlying allocator on stream(). More...
 
void deallocate (value_type *ptr, std::size_t num)
 Deallocates storage pointed to by ptr using the underlying allocator on stream(). More...
 
cuda_stream_view stream () const noexcept
 The stream on which calls to the underlying allocator are made. More...
 
Allocator underlying_allocator () const noexcept
 The underlying allocator. More...
 

Detailed Description

template<typename Allocator>
class rmm::mr::stream_allocator_adaptor< Allocator >

Adapts a stream ordered allocator to provide a standard Allocator interface.

A stream-ordered allocator (i.e., allocate/deallocate use a cuda_stream_view) cannot be used in an interface that expects a standard C++ Allocator interface. stream_allocator_adaptor wraps a stream-ordered allocator and a stream to provide a standard Allocator interface. The adaptor uses the wrapped stream in calls to the underlying allocator's allocate and deallocate functions.

Example:

my_stream_ordered_allocator<int> a{...};
cuda_stream_view s = // create stream;
auto adapted = make_stream_allocator_adaptor(a, s);
// Allocates storage for `n` int's on stream `s`
int * p = std::allocator_traits<decltype(adapted)>::allocate(adapted, n);
value_type * allocate(std::size_t num)
Allocates storage for num objects of type T using the underlying allocator on stream().
Definition: polymorphic_allocator.hpp:203
Template Parameters
AllocatorStream ordered allocator type to adapt

Member Typedef Documentation

◆ value_type

template<typename Allocator >
using rmm::mr::stream_allocator_adaptor< Allocator >::value_type = typename std::allocator_traits<Allocator>::value_type

The value type of objects allocated by this allocator

Constructor & Destructor Documentation

◆ stream_allocator_adaptor() [1/2]

template<typename Allocator >
rmm::mr::stream_allocator_adaptor< Allocator >::stream_allocator_adaptor ( Allocator const &  allocator,
cuda_stream_view  stream 
)
inline

Construct a stream_allocator_adaptor using a as the underlying allocator.

Note
: The stream must not be destroyed before the stream_allocator_adaptor, otherwise behavior is undefined.
Parameters
allocatorThe stream ordered allocator to use as the underlying allocator
streamThe stream used with the underlying allocator

◆ stream_allocator_adaptor() [2/2]

template<typename Allocator >
template<typename OtherAllocator >
rmm::mr::stream_allocator_adaptor< Allocator >::stream_allocator_adaptor ( stream_allocator_adaptor< OtherAllocator > const &  other)
inline

Construct a stream_allocator_adaptor using other.underlying_allocator() and other.stream() as the underlying allocator and stream.

Template Parameters
OtherAllocatorType of other's underlying allocator
Parameters
otherThe other stream_allocator_adaptor whose underlying allocator and stream will be copied

Member Function Documentation

◆ allocate()

template<typename Allocator >
value_type* rmm::mr::stream_allocator_adaptor< Allocator >::allocate ( std::size_t  num)
inline

Allocates storage for num objects of type T using the underlying allocator on stream().

Parameters
numThe number of objects to allocate storage for
Returns
Pointer to the allocated storage

◆ deallocate()

template<typename Allocator >
void rmm::mr::stream_allocator_adaptor< Allocator >::deallocate ( value_type ptr,
std::size_t  num 
)
inline

Deallocates storage pointed to by ptr using the underlying allocator on stream().

ptr must have been allocated from by an allocator a that compares equal to underlying_allocator() using a.allocate(n).

Parameters
ptrPointer to memory to deallocate
numNumber of objects originally allocated

◆ stream()

template<typename Allocator >
cuda_stream_view rmm::mr::stream_allocator_adaptor< Allocator >::stream ( ) const
inlinenoexcept

The stream on which calls to the underlying allocator are made.

Returns
The stream on which calls to the underlying allocator are made

◆ underlying_allocator()

template<typename Allocator >
Allocator rmm::mr::stream_allocator_adaptor< Allocator >::underlying_allocator ( ) const
inlinenoexcept

The underlying allocator.

Returns
The underlying allocator

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