HAMR
The Heterogeneous Accelerator Memory Resource
hamr::buffer< T > Class Template Reference

A technology agnostic buffer that manages memory on CPUs, GPUs, and accelerators. More...

#include <hamr_buffer.h>

Public Types

using allocator = buffer_allocator
 

Public Member Functions

 buffer (allocator alloc)
 construct an empty buffer that will use the passed allocator type More...
 
 buffer (allocator alloc, size_t n_elem)
 construct a buffer with n_elem size using the passed allocator type More...
 
 buffer (allocator alloc, size_t n_elem, const T &val)
 
 buffer (allocator alloc, size_t n_elem, const T *vals)
 
 buffer (const buffer< T > &other)
 copy construct from the passed buffer More...
 
 buffer (allocator alloc, const buffer< T > &other)
 copy construct from the passed buffer, using the passed allocator type. More...
 
 buffer (buffer< T > &&other)
 move construct from the passed buffer More...
 
template<typename U >
void operator= (const buffer< U > &other)
 
template<typename U >
void operator= (buffer< U > &&other)
 
void swap (buffer< T > &other)
 swap the contents of the two buffers More...
 
int free ()
 free all internal storage More...
 
size_t size () const
 returns the number of elements of storage allocated to the buffer More...
 
allocator get_allocator () const
 returns the allocator type enum More...
 
int cuda_accessible () const
 returns true if the data is accessible from CUDA codes More...
 
int cpu_accessible () const
 returns true if the data is accessible from codes running on the CPU More...
 
int print () const
 prints the contents to the stderr stream More...
 
reserve

allocates space for n_elems of data

int reserve (size_t n_elem)
 
int reserve (size_t n_elem, const T &val)
 
resize

resizes storage for n_elems of data

int resize (size_t n_elem)
 
int resize (size_t n_elem, const T &val)
 
assign

Copies data into the buffer resizing the buffer.

template<typename U >
int assign (const U *src, size_t src_start, size_t n_vals)
 
template<typename U >
int assign (const buffer< U > &src, size_t src_start, size_t n_vals)
 assign the range from the passed buffer More...
 
template<typename U >
int assign (const buffer< U > &src)
 assign the passed buffer More...
 
append

insert values at the back of the buffer, growing as needed

template<typename U >
int append (const U *src, size_t src_start, size_t n_vals)
 
template<typename U >
int append (const buffer< U > &src, size_t src_start, size_t n_vals)
 
template<typename U >
int append (const buffer< U > &src)
 
set

sets a range of elements in the buffer

template<typename U >
int set (size_t dest_start, const U *src, size_t src_start, size_t n_vals)
 
template<typename U >
int set (const buffer< U > &src)
 
template<typename U >
int set (size_t dest_start, const buffer< U > &src, size_t src_start, size_t n_vals)
 
get

gets a range of values from the buffer

template<typename U >
int get (size_t src_start, U *dest, size_t dest_start, size_t n_vals) const
 
template<typename U >
int get (size_t src_start, buffer< U > &dest, size_t dest_start, size_t n_vals) const
 
template<typename U >
int get (buffer< U > &dest) const
 
get_accessible

get a pointer to the data that is accessible in the given technology

std::shared_ptr< T > get_cpu_accessible ()
 
std::shared_ptr< const T > get_cpu_accessible () const
 
std::shared_ptr< T > get_cuda_accessible ()
 
std::shared_ptr< const T > get_cuda_accessible () const
 

Protected Member Functions

int reserve_for_append (size_t n_vals)
 grow the buffer if needed. doubles in size More...
 
std::shared_ptr< T > allocate (size_t n_elem)
 allocate space for n_elem More...
 
std::shared_ptr< T > allocate (size_t n_elem, const T &val)
 allocate space for n_elem initialized to val More...
 
template<typename U >
std::shared_ptr< T > allocate (size_t n_elem, const U *vals)
 allocate space for n_elem initialized with an array of values More...
 
template<typename U >
std::shared_ptr< T > allocate (const buffer< U > &vals)
 allocate space for n_elem initialized with an array of values More...
 

Static Protected Member Functions

static const char * get_allocator_name (allocator alloc)
 return the human readable name of the allocator More...
 

Detailed Description

template<typename T>
class hamr::buffer< T >

A technology agnostic buffer that manages memory on CPUs, GPUs, and accelerators.

The buffer mediates between different accelerator and platform portability technologies' memory models. Examples of platform portability technologies are HIP, OpenMP, OpenCL, SYCL, and Kokos, Examples of accelerator technologies are CUDA and ROCm. Other accelerator and platform portability technologies exist and can be supported. Data can be left in place until it is consumed. The consumer of the data can get a pointer that is accessible in the technology that will be used to process the data. If the data is already accessible in that technology access is a NOOP, otherwise the data will be moved such that it is accessible. Smart pointers take care of destruction of temporary buffers if needed.

Constructor & Destructor Documentation

◆ buffer() [1/7]

template<typename T >
hamr::buffer< T >::buffer ( allocator  alloc)

construct an empty buffer that will use the passed allocator type

◆ buffer() [2/7]

template<typename T >
hamr::buffer< T >::buffer ( allocator  alloc,
size_t  n_elem 
)

construct a buffer with n_elem size using the passed allocator type

◆ buffer() [3/7]

template<typename T >
hamr::buffer< T >::buffer ( allocator  alloc,
size_t  n_elem,
const T &  val 
)

construct a buffer with n_elem size initialized to the passed value using the passed allocator type

◆ buffer() [4/7]

template<typename T >
hamr::buffer< T >::buffer ( allocator  alloc,
size_t  n_elem,
const T *  vals 
)

construct a buffer with n_elem size initialized to the passed value using the passed allocator type

◆ buffer() [5/7]

template<typename T >
hamr::buffer< T >::buffer ( const buffer< T > &  other)

copy construct from the passed buffer

◆ buffer() [6/7]

template<typename T >
hamr::buffer< T >::buffer ( allocator  alloc,
const buffer< T > &  other 
)

copy construct from the passed buffer, using the passed allocator type.

◆ buffer() [7/7]

template<typename T >
hamr::buffer< T >::buffer ( buffer< T > &&  other)

move construct from the passed buffer

Member Function Documentation

◆ allocate() [1/4]

template<typename T >
template<typename U >
std::shared_ptr< T > hamr::buffer< T >::allocate ( const buffer< U > &  vals)
protected

allocate space for n_elem initialized with an array of values

◆ allocate() [2/4]

template<typename T >
std::shared_ptr< T > hamr::buffer< T >::allocate ( size_t  n_elem)
protected

allocate space for n_elem

◆ allocate() [3/4]

template<typename T >
std::shared_ptr< T > hamr::buffer< T >::allocate ( size_t  n_elem,
const T &  val 
)
protected

allocate space for n_elem initialized to val

◆ allocate() [4/4]

template<typename T >
template<typename U >
std::shared_ptr< T > hamr::buffer< T >::allocate ( size_t  n_elem,
const U *  vals 
)
protected

allocate space for n_elem initialized with an array of values

◆ append() [1/3]

template<typename T >
template<typename U >
int hamr::buffer< T >::append ( const buffer< U > &  src)

appends to the end of the buffer, extending the buffer as needed.

◆ append() [2/3]

template<typename T >
template<typename U >
int hamr::buffer< T >::append ( const buffer< U > &  src,
size_t  src_start,
size_t  n_vals 
)

appends n_vals from src starting at src_start to the end of the buffer, extending the buffer as needed.

◆ append() [3/3]

template<typename T >
template<typename U >
int hamr::buffer< T >::append ( const U *  src,
size_t  src_start,
size_t  n_vals 
)

appends n_vals from src starting at src_start to the end of the buffer, extending the buffer as needed. (src is always on the CPU)

◆ assign() [1/3]

template<typename T >
template<typename U >
int hamr::buffer< T >::assign ( const buffer< U > &  src)

assign the passed buffer

◆ assign() [2/3]

template<typename T >
template<typename U >
int hamr::buffer< T >::assign ( const buffer< U > &  src,
size_t  src_start,
size_t  n_vals 
)

assign the range from the passed buffer

◆ assign() [3/3]

template<typename T >
template<typename U >
int hamr::buffer< T >::assign ( const U *  src,
size_t  src_start,
size_t  n_vals 
)

assign the range from the passed array (src is always on the CPU)

◆ cpu_accessible()

template<typename T >
int hamr::buffer< T >::cpu_accessible

returns true if the data is accessible from codes running on the CPU

◆ cuda_accessible()

template<typename T >
int hamr::buffer< T >::cuda_accessible

returns true if the data is accessible from CUDA codes

◆ free()

template<typename T >
int hamr::buffer< T >::free

free all internal storage

◆ get() [1/3]

template<typename T >
template<typename U >
int hamr::buffer< T >::get ( buffer< U > &  dest) const
inline

gets n_vals elements starting at src_start into the passed buffer's elements starting at dest_start

◆ get() [2/3]

template<typename T >
template<typename U >
int hamr::buffer< T >::get ( size_t  src_start,
buffer< U > &  dest,
size_t  dest_start,
size_t  n_vals 
) const

gets n_vals elements starting at src_start into the passed buffer's elements starting at dest_start

◆ get() [3/3]

template<typename T >
template<typename U >
int hamr::buffer< T >::get ( size_t  src_start,
U *  dest,
size_t  dest_start,
size_t  n_vals 
) const

gets n_vals elements starting at src_start into the passed array elements starting at dest_start (dest is always on the CPU)

◆ get_allocator()

template<typename T >
allocator hamr::buffer< T >::get_allocator ( ) const
inline

returns the allocator type enum

◆ get_allocator_name()

template<typename T >
const char * hamr::buffer< T >::get_allocator_name ( allocator  alloc)
staticprotected

return the human readable name of the allocator

◆ get_cpu_accessible()

template<typename T >
std::shared_ptr< T > hamr::buffer< T >::get_cpu_accessible

returns a pointer to the contents of the buffer accessible on the CPU if the buffer is currently accessible by codes running on the CPU then this call is a NOOP. If the buffer is not currently accessible by codes running on the CPU then a temporary buffer is allocated and the data is moved to the CPU. The returned shared_ptr deals with deallocation of the temporary if needed.

◆ get_cuda_accessible()

template<typename T >
std::shared_ptr< T > hamr::buffer< T >::get_cuda_accessible

returns a pointer to the contents of the buffer accessible on the CUDA if the buffer is currently accessible by codes running on the CUDA then this call is a NOOP. If the buffer is not currently accessible by codes running on the CUDA then a temporary buffer is allocated and the data is moved to the CUDA. The returned shared_ptr deals with deallocation of the temporary if needed.

◆ operator=() [1/2]

template<typename T >
template<typename U >
void hamr::buffer< T >::operator= ( buffer< U > &&  other)

move assign from the other buffer. if this and the passed buffer have the same type and allocator the passed buffer is moved. if this and the passed buffer have different allocators this allocator is used and the data will be copied. if this and the passed buffer have different types elements are cast to this type as they are copied.

◆ operator=() [2/2]

template<typename T >
template<typename U >
void hamr::buffer< T >::operator= ( const buffer< U > &  other)

assign from the other buffer. if this and the passed buffer have different allocators this allocator is used and the data will be copied. if this and the passed buffer have different types elements are cast to this type as they are copied.

◆ print()

template<typename T >
int hamr::buffer< T >::print

prints the contents to the stderr stream

◆ reserve_for_append()

template<typename T >
int hamr::buffer< T >::reserve_for_append ( size_t  n_vals)
protected

grow the buffer if needed. doubles in size

◆ set() [1/3]

template<typename T >
template<typename U >
int hamr::buffer< T >::set ( const buffer< U > &  src)
inline

sets n_vals elements starting at dest_start from the passed buffer's elements starting at src_start

◆ set() [2/3]

template<typename T >
template<typename U >
int hamr::buffer< T >::set ( size_t  dest_start,
const buffer< U > &  src,
size_t  src_start,
size_t  n_vals 
)

sets n_vals elements starting at dest_start from the passed buffer's elements starting at src_start

◆ set() [3/3]

template<typename T >
template<typename U >
int hamr::buffer< T >::set ( size_t  dest_start,
const U *  src,
size_t  src_start,
size_t  n_vals 
)

sets n_vals elements starting at dest_start from the passed buffer's elements starting at src_start (src is always on the CPU)

◆ size()

template<typename T >
size_t hamr::buffer< T >::size ( ) const
inline

returns the number of elements of storage allocated to the buffer

◆ swap()

template<typename T >
void hamr::buffer< T >::swap ( buffer< T > &  other)

swap the contents of the two buffers


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