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 &a, cuda_stream_view stream)
 Construct a stream_allocator_adaptor using a as the underlying allocator. More...
 
 stream_allocator_adaptor (stream_allocator_adaptor< Allocator > const &other)=default
 Construct a stream_allocator_adaptor using other.underlying_allocator() and other.stream() as the underlying allocator and stream. 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_type * allocate (std::size_t n)
 Allocates storage for n objects of type T using the underlying allocator on stream(). More...
 
void deallocate (value_type *p, std::size_t n)
 Deallocates storage pointed to by p using the underlying allocator on stream(). More...
 
cuda_stream_view stream () const noexcept
 Returns the underlying stream on which calls to the underlying allocator are made.
 
Allocator underlying_allocator () const noexcept
 Returns the underlying stream-ordered allocator.
 

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:

{c++}
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);
Template Parameters
AllocatorStream ordered allocator type to adapt

Constructor & Destructor Documentation

◆ stream_allocator_adaptor() [1/3]

template<typename Allocator >
rmm::mr::stream_allocator_adaptor< Allocator >::stream_allocator_adaptor ( Allocator const &  a,
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
aThe stream ordered allocator to use as the underlying allocator
streamThe stream used with the underlying allocator

◆ stream_allocator_adaptor() [2/3]

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

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

Parameters
otherThe other stream_allocator_adaptor whose underlying allocator and stream will be copied

◆ stream_allocator_adaptor() [3/3]

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  n)
inline

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

Parameters
nThe 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 *  p,
std::size_t  n 
)
inline

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

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

Parameters
pPointer to memory to deallocate
nNumber of objects originally allocated

The documentation for this class was generated from the following file:
rmm::mr::stream_allocator_adaptor::allocate
value_type * allocate(std::size_t n)
Allocates storage for n objects of type T using the underlying allocator on stream().
Definition: polymorphic_allocator.hpp:219