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

A technology agnostic buffer that manages memory on the host, GPUs, and other accelerators. More...

#include <hamr_buffer.h>

Public Types

using allocator = buffer_allocator
 
using transfer = buffer_transfer
 

Public Member Functions

 buffer (allocator alloc, const hamr::stream &strm, transfer sync=transfer::async)
 
 buffer (allocator alloc)
 
 buffer (allocator alloc, const hamr::stream &strm, transfer sync, size_t n_elem)
 
 buffer (allocator alloc, const hamr::stream &strm, size_t n_elem)
 
 buffer (allocator alloc, size_t n_elem)
 
 buffer (allocator alloc, const hamr::stream &strm, transfer sync, size_t n_elem, const T &val)
 
 buffer (allocator alloc, const hamr::stream &strm, size_t n_elem, const T &val)
 
 buffer (allocator alloc, size_t n_elem, const T &val)
 
 buffer (allocator alloc, const hamr::stream &strm, transfer sync, size_t n_elem, const T *vals)
 
 buffer (allocator alloc, const hamr::stream &strm, size_t n_elem, const T *vals)
 
 buffer (allocator alloc, size_t n_elem, const T *vals)
 
template<typename delete_func_t >
 buffer (allocator alloc, const hamr::stream &strm, transfer sync, size_t size, int owner, T *ptr, delete_func_t df)
 
template<typename delete_func_t >
 buffer (allocator alloc, const hamr::stream &strm, size_t size, int owner, T *ptr, delete_func_t df)
 
template<typename delete_func_t >
 buffer (allocator alloc, size_t size, int owner, T *ptr, delete_func_t df)
 
 buffer (allocator alloc, const hamr::stream &strm, transfer sync, size_t size, int owner, T *ptr, int take=1)
 
 buffer (allocator alloc, const hamr::stream &strm, size_t size, int owner, T *ptr)
 
 buffer (allocator alloc, size_t size, int owner, T *ptr)
 
 buffer (allocator alloc, const hamr::stream &strm, transfer sync, size_t size, int owner, const std::shared_ptr< T > &data)
 
 buffer (allocator alloc, const hamr::stream &strm, size_t size, int owner, const std::shared_ptr< T > &data)
 
 buffer (allocator alloc, size_t size, int owner, const std::shared_ptr< T > &data)
 
template<typename U >
 buffer (const buffer< U > &other)
 copy construct from the passed buffer More...
 
 buffer (const buffer< T > &other)
 copy construct from the passed buffer More...
 
template<typename U >
 buffer (allocator alloc, const hamr::stream &strm, transfer sync, const buffer< U > &other)
 
template<typename U >
 buffer (allocator alloc, const hamr::stream &strm, const buffer< U > &other)
 
template<typename U >
 buffer (allocator alloc, const buffer< U > &other)
 
 buffer (buffer< T > &&other)
 Move construct from the passed buffer. More...
 
 buffer (allocator alloc, const hamr::stream &strm, transfer sync, buffer< T > &&other)
 
 buffer (allocator alloc, const hamr::stream &strm, buffer< T > &&other)
 
 buffer (allocator alloc, buffer< T > &&other)
 
void operator= (buffer< T > &&other)
 
template<typename U >
void operator= (const buffer< U > &other)
 
void operator= (const buffer< T > &other)
 
void swap (buffer< T > &other)
 swap the contents of the two buffers More...
 
int move (allocator alloc)
 
int free ()
 free all internal storage More...
 
size_t size () const
 returns the number of elements of storage allocated to the buffer More...
 
std::shared_ptr< const T > get_host_accessible () const
 
int host_accessible () const
 returns true if the data is accessible from codes running on the host More...
 
std::shared_ptr< const T > get_cuda_accessible () const
 
int cuda_accessible () const
 returns true if the data is accessible from CUDA codes More...
 
std::shared_ptr< const T > get_hip_accessible () const
 
int hip_accessible () const
 returns true if the data is accessible from HIP codes More...
 
int openmp_accessible () const
 returns true if the data is accessible from OpenMP off load codes More...
 
std::shared_ptr< const T > get_device_accessible () const
 
int device_accessible () const
 
allocator get_allocator () const
 
int get_owner () const
 
const hamr::streamget_stream () const
 
hamr::streamget_stream ()
 
void set_stream (const stream &strm, transfer sync=transfer::async)
 
void set_transfer_asynchronous ()
 
void set_transfer_sycnhronous_host ()
 
void set_transfer_sycnhronous ()
 
transfer get_transfer_mode () const
 
int synchronize () const
 
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)
 reserve n_elem of memory and initialize them to val More...
 
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_openmp_accessible
Returns
a read only pointer to the contents of the buffer accessible from the active OpenMP off load device. If the buffer is currently accessible on the active OpenMP off load device then this call is a NOOP. If the buffer is not currently accessible on the active OpenMP off load device then a temporary buffer is allocated and the data is moved. The returned shared_ptr deals with deallocation of the temporary if needed.
std::shared_ptr< const T > get_openmp_accessible () const
 
data
Returns
a writable pointer to the buffer contents. Use this to modify the buffer contents or when you know that the buffer contents are accessible by the code operating on them to save the cost of a std::shared_ptr copy construct.
T * data ()
 
const T * data () const
 return a const pointer to the buffer contents More...
 
pointer
Returns
the smart pointer managing the buffer contents. Use this when you know that the buffer contents are accessible by the code operating on them to save the costs of the logic that determines if a temporary is needed
std::shared_ptr< T > & pointer ()
 
const std::shared_ptr< T > & pointer () 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...
 
int set_owner ()
 
int set_owner (const T *ptr)
 
int get_active_device (int &dev_id)
 get the active device id associated with the current allocator More...
 

Detailed Description

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

A technology agnostic buffer that manages memory on the host, GPUs, and other 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.

Member Typedef Documentation

◆ allocator

template<typename T >
using hamr::buffer< T >::allocator = buffer_allocator

An enumeration for the type of allocator to use for memory allocations. See buffer_allocator.

◆ transfer

template<typename T >
using hamr::buffer< T >::transfer = buffer_transfer

An enumeration for the types of transfer supported. See buffer_transfer

Constructor & Destructor Documentation

◆ buffer() [1/29]

template<typename T >
hamr::buffer< T >::buffer ( allocator  alloc,
const hamr::stream strm,
transfer  sync = transfer::async 
)

Construct an empty buffer.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally
[in]strma ::stream object used to order operations
[in]synca buffer_transfer specifies synchronous or asynchronous behavior.

◆ buffer() [2/29]

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

Construct an empty buffer. This constructor will result in the default stream for the chosen technology with transfer::sync_host mode which synchronizes after data movement from a device to the host.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally

◆ buffer() [3/29]

template<typename T >
hamr::buffer< T >::buffer ( allocator  alloc,
const hamr::stream strm,
transfer  sync,
size_t  n_elem 
)

Construct a buffer with storage allocated but unitialized.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally
[in]strma ::stream object used to order operations
[in]synca buffer_transfer specifies synchronous or asynchronous behavior.
[in]n_elemthe initial size of the new buffer

◆ buffer() [4/29]

template<typename T >
hamr::buffer< T >::buffer ( allocator  alloc,
const hamr::stream strm,
size_t  n_elem 
)
inline

Construct a buffer configured for asynchronous data transfers, with storage allocated, but unitialized.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally
[in]strma ::stream object used to order operations
[in]n_elemthe initial size of the new buffer

◆ buffer() [5/29]

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

Construct a buffer with storage allocated but unitialized. This constructor will result in the default stream for the chosen technology with transfer::sync_host mode which synchronizes after data movement from a device to the host.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally
[in]n_elemthe initial size of the new buffer

◆ buffer() [6/29]

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

Construct a buffer with storage allocated and initialized to a single value.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally
[in]strma ::stream object used to order operations
[in]synca buffer_transfer specifies synchronous or asynchronous behavior.
[in]n_elemthe initial size of the new buffer
[in]valan single value used to initialize the buffer contents

◆ buffer() [7/29]

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

Construct a buffer configured for asynchronous data movement, with storage allocated, and initialized to a single value.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally
[in]strma ::stream object used to order operations
[in]n_elemthe initial size of the new buffer
[in]valan single value used to initialize the buffer contents

◆ buffer() [8/29]

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

Construct a buffer with storage allocated and initialized to a single value. This constructor will result in the default stream for the chosen technology with transfer::sync_host mode which synchronizes after data movement from a device to the host. For fully asynchronous data transfers one must explicitly prtovide a stream and specify the asynchronous mode.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally
[in]n_elemthe initial size of the new buffer
[in]valan single value used to initialize the buffer contents

◆ buffer() [9/29]

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

Construct a buffer with storage allocated and initialized to the array of values. This array is always assumed to be accessible on the host. Use one of the zero-copy constructors if the data is already accessible on the device.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally
[in]strma ::stream object used to order operations
[in]synca buffer_transfer specifies synchronous or asynchronous behavior.
[in]n_elemthe initial size of the new buffer and number of elements in the array pointed to by vals
[in]valsan array of values accessible on the host used to initialize the buffer contents

◆ buffer() [10/29]

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

Construct a buffer configured for asynchronous data movement, with storage allocated, and initialized to the array of values. This array is always assumed to be accessible on the host. Use one of the zero-copy constructors if the data is already accessible on the device.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally
[in]strma ::stream object used to order operations
[in]n_elemthe initial size of the new buffer and number of elements in the array pointed to by vals
[in]valsan array of values accessible on the host used to initialize the buffer contents

◆ buffer() [11/29]

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

Construct a buffer with storage allocated and initialized to the array of values. This array is always assumed to be accessible on the host. Use one of the zero-copy constructors if the data is already accessible on the device. This constructor will result in the default stream for the chosen technology with transfer::sync_host mode which synchronizes after data movement from a device to the host.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally
[in]n_elemthe initial size of the new buffer and number of elements in the array pointed to by vals
[in]valsan array of values accessible on the host used to initialize the buffer contents

◆ buffer() [12/29]

template<typename T >
template<typename delete_func_t >
hamr::buffer< T >::buffer ( allocator  alloc,
const hamr::stream strm,
transfer  sync,
size_t  size,
int  owner,
T *  ptr,
delete_func_t  df 
)

Construct by directly providing the buffer contents. This can be used for zero-copy transfer of data. One must also name the allocator type and device owning the data. In addition for new allocations the allocator type and owner are used internally to know how to automatically move data during inter technology transfers.

Parameters
[in]alloca buffer_allocator indicating the technology backing the pointer
[in]strma ::stream object used to order operations
[in]synca buffer_transfer specifies synchronous or asynchronous behavior.
[in]sizethe number of elements in the array pointed to by ptr
[in]ownerthe device owning the memory, -1 for host. if the allocator is a GPU allocator and -1 is passed the driver API is used to determine the device that allocated the memory.
[in]ptra pointer to the array
[in]dfa function void df(void*ptr) used to delete the array when this instance is finished.

◆ buffer() [13/29]

template<typename T >
template<typename delete_func_t >
hamr::buffer< T >::buffer ( allocator  alloc,
const hamr::stream strm,
size_t  size,
int  owner,
T *  ptr,
delete_func_t  df 
)
inline

Construct by directly providing the buffer contents. This can be used for zero-copy transfer of data. One must also name the allocator type and device owning the data. In addition for new allocations the allocator type and owner are used internally to know how to automatically move data during inter technology transfers. The buffer is configured for asynchronous data transfers.

Parameters
[in]alloca buffer_allocator indicating the technology backing the pointer
[in]strma ::stream object used to order operations
[in]sizethe number of elements in the array pointed to by ptr
[in]ownerthe device owning the memory, -1 for host. if the allocator is a GPU allocator and -1 is passed the driver API is used to determine the device that allocated the memory.
[in]ptra pointer to the array
[in]dfa function void df(void*ptr) used to delete the array when this instance is finished.

◆ buffer() [14/29]

template<typename T >
template<typename delete_func_t >
hamr::buffer< T >::buffer ( allocator  alloc,
size_t  size,
int  owner,
T *  ptr,
delete_func_t  df 
)
inline

Construct by directly providing the buffer contents. This can be used for zero-copy transfer of data. One must also name the allocator type and device owning the data. In addition for new allocations the allocator type and owner are used internally to know how to automatically move data during inter technology transfers. This constructor will result in the default stream for the chosen technology with transfer::sync_host mode which synchronizes after data movement from a device to the host.

Parameters
[in]alloca buffer_allocator indicating the technology backing the pointer
[in]sizethe number of elements in the array pointed to by ptr
[in]ownerthe device owning the memory, -1 for host. if the allocator is a GPU allocator and -1 is passed the driver API is used to determine the device that allocated the memory.
[in]ptra pointer to the array
[in]dfa function void df(void*ptr) used to delete the array when this instance is finished.

◆ buffer() [15/29]

template<typename T >
hamr::buffer< T >::buffer ( allocator  alloc,
const hamr::stream strm,
transfer  sync,
size_t  size,
int  owner,
T *  ptr,
int  take = 1 
)

Construct by directly providing the buffer contents. This can be used for zero-copy transfer of data. One must also name the allocator type and device owning the data. In addition for new allocations the allocator type and owner are used internally to know how to automatically move data during inter technology transfers. The pass buffer_allocator is used to create the deleter that will be called when this instance is finished with the memeory. Use this constructor to transfer ownership of the array.

Parameters
[in]alloca buffer_allocator indicating the technology backing the pointer
[in]strma ::stream object used to order operations
[in]synca buffer_transfer specifies synchronous or asynchronous behavior.
[in]sizethe number of elements in the array pointed to by ptr
[in]ownerthe device owning the memory, -1 for host. if the allocator is a GPU allocator and -1 is passed the driver API is used to determine the device that allocated the memory.
[in]ptra pointer to the array
[in]takeset non-zero if the buffer should delete the passed memory using the named allocator

◆ buffer() [16/29]

template<typename T >
hamr::buffer< T >::buffer ( allocator  alloc,
const hamr::stream strm,
size_t  size,
int  owner,
T *  ptr 
)
inline

Construct by directly providing the buffer contents. This can be used for zero-copy transfer of data. One must also name the allocator type and device owning the data. In addition for new allocations the allocator type and owner are used internally to know how to automatically move data during inter technology transfers. The pass buffer_allocator is used to create the deleter that will be called when this instance is finished with the memeory. Use this constructor to transfer ownership of the array. The buffer is configured for asynchronous data transfers.

Parameters
[in]alloca buffer_allocator indicating the technology backing the pointer
[in]strma ::stream object used to order operations
[in]sizethe number of elements in the array pointed to by ptr
[in]ownerthe device owning the memory, -1 for host. if the allocator is a GPU allocator and -1 is passed the driver API is used to determine the device that allocated the memory.
[in]ptra pointer to the array

◆ buffer() [17/29]

template<typename T >
hamr::buffer< T >::buffer ( allocator  alloc,
size_t  size,
int  owner,
T *  ptr 
)
inline

construct by directly providing the buffer contents. This can be used for zero-copy transfer of data. One must also name the allocator type and device owning the data. In addition for new allocations the allocator type and owner are used internally to know how to automatically move data during inter technology transfers. The pass buffer_allocator is used to create the deleter that will be called when this instance is finished with the memeory. Use this constructor to transfer ownership of the array. This constructor will result in the default stream for the chosen technology with transfer::sync_host mode which synchronizes after data movement from a device to the host.

Parameters
[in]alloca buffer_allocator indicating the technology backing the pointer
[in]sizethe number of elements in the array pointed to by ptr
[in]ownerthe device owning the memory, -1 for host. if the allocator is a GPU allocator and -1 is passed the driver API is used to determine the device that allocated the memory.
[in]ptra pointer to the array

◆ buffer() [18/29]

template<typename T >
hamr::buffer< T >::buffer ( allocator  alloc,
const hamr::stream strm,
transfer  sync,
size_t  size,
int  owner,
const std::shared_ptr< T > &  data 
)

Construct by directly providing the buffer contents. This can be used for zero-copy transfer of data. One must also name the allocator type and device owning the data. In addition for new allocations the allocator type and owner are used internally to know how to automatically move data during inter technology transfers.

Parameters
[in]alloca buffer_allocator indicating the technology backing the pointer
[in]strma ::stream object used to order operations
[in]synca buffer_transfer specifies synchronous or asynchronous behavior.
[in]sizethe number of elements in the array pointed to by ptr
[in]ownerthe device owning the memory, -1 for host. if the allocator is a GPU allocator and -1 is passed the driver API is used to determine the device that allocated the memory.
[in]dataa shared pointer managing the data

◆ buffer() [19/29]

template<typename T >
hamr::buffer< T >::buffer ( allocator  alloc,
const hamr::stream strm,
size_t  size,
int  owner,
const std::shared_ptr< T > &  data 
)
inline

Construct by directly providing the buffer contents. This can be used for zero-copy transfer of data. One must also name the allocator type and device owning the data. In addition for new allocations the allocator type and owner are used internally to know how to automatically move data during inter technology transfers. The buffer is configured for asynchronous data transfers.

Parameters
[in]alloca buffer_allocator indicating the technology backing the pointer
[in]strma ::stream object used to order operations
[in]sizethe number of elements in the array pointed to by ptr
[in]ownerthe device owning the memory, -1 for host. if the allocator is a GPU allocator and -1 is passed the driver API is used to determine the device that allocated the memory.
[in]dataa shared pointer managing the data

◆ buffer() [20/29]

template<typename T >
hamr::buffer< T >::buffer ( allocator  alloc,
size_t  size,
int  owner,
const std::shared_ptr< T > &  data 
)
inline

Construct by directly providing the buffer contents. This can be used for zero-copy transfer of data. One must also name the allocator type and device owning the data. In addition for new allocations the allocator type and owner are used internally to know how to automatically move data during inter technology transfers. This constructor will result in the default stream for the chosen technology with transfer::sync_host mode which synchronizes after data movement from a device to the host.

Parameters
[in]alloca buffer_allocator indicating the technology backing the pointer
[in]sizethe number of elements in the array pointed to by ptr
[in]ownerthe device owning the memory, -1 for host. if the allocator is a GPU allocator and -1 is passed the driver API is used to determine the device that allocated the memory.
[in]dataa shared pointer managing the data

◆ buffer() [21/29]

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

copy construct from the passed buffer

◆ buffer() [22/29]

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

copy construct from the passed buffer

◆ buffer() [23/29]

template<typename T >
template<typename U >
hamr::buffer< T >::buffer ( allocator  alloc,
const hamr::stream strm,
transfer  sync,
const buffer< U > &  other 
)

Copy construct from the passed buffer, while specifying a potentially different allocator, stream, and synchronization behavior.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally
[in]strma ::stream object used to order operations
[in]synca buffer_transfer specifies synchronous or asynchronous behavior.

◆ buffer() [24/29]

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

Copy construct from the passed buffer, while specifying a potentially different allocator, stream, and synchronization behavior. The buffer is configured for asynchronous data transfers.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally
[in]strma ::stream object used to order operations

◆ buffer() [25/29]

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

Copy construct from the passed buffer, while specifying a potentially different allocator, stream, and synchronization behavior. This constructor will result in the default stream for the chosen technology with transfer::sync_host mode which synchronizes after data movement from a device to the host.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally
[in]strma ::stream object used to order operations
[in]synca buffer_transfer specifies synchronous or asynchronous behavior.

◆ buffer() [26/29]

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

Move construct from the passed buffer.

◆ buffer() [27/29]

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

Move construct from the passed buffer, while specifying a potentially different allocator, owner, stream, and synchronization behavior. The move occurs only if the allocators and owners match, otherwise a copy is made. For non-host allocators, the active device is used to set the owner of the new object prior to the atempted move.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally
[in]strma ::stream object used to order operations
[in]synca buffer_transfer specifies synchronous or asynchronous behavior.

◆ buffer() [28/29]

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

Move construct from the passed buffer, while specifying a potentially different allocator, owner, stream, and synchronization behavior. The move occurs only if the allocators and owners match, otherwise a copy is made. For non-host allocators, the active device is used to set the owner of the new object prior to the atempted move. The buffer is configured for asynchronous data transfers.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally
[in]strma ::stream object used to order operations

◆ buffer() [29/29]

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

Move construct from the passed buffer, while specifying a potentially different allocator, owner, stream, and synchronization behavior. The move occurs only if the allocators and owners match, otherwise a copy is made. For non-host allocators, the active device is used to set the owner of the new object prior to the atempted move. This constructor will result in the default stream for the chosen technology with transfer::sync_host mode which synchronizes after data movement from a device to the host.

Parameters
[in]alloca buffer_allocator indicates what technology manages the data internally

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 host)

◆ 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 host)

◆ cuda_accessible()

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

returns true if the data is accessible from CUDA codes

◆ data() [1/2]

template<typename T >
T* hamr::buffer< T >::data ( )
inline

return a pointer to the buffer contents

◆ data() [2/2]

template<typename T >
const T* hamr::buffer< T >::data ( ) const
inline

return a const pointer to the buffer contents

◆ device_accessible()

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

returns true if the data is accessible from device codes using the technology most suitable with the current build configuration.

◆ 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 host)

◆ get_active_device()

template<typename T >
int hamr::buffer< T >::get_active_device ( int &  dev_id)
protected

get the active device id associated with the current allocator

◆ get_allocator()

template<typename T >
allocator hamr::buffer< T >::get_allocator ( ) const
inline
Returns
the allocator type enum

◆ get_cuda_accessible()

template<typename T >
std::shared_ptr< const T > hamr::buffer< T >::get_cuda_accessible
Returns
a read only pointer to the contents of the buffer accessible from the active CUDA device. If the buffer is currently accessible on the active CUDA device then this call is a NOOP. If the buffer is not currently accessible on the active CUDA device then a temporary buffer is allocated and the data is moved. The returned shared_ptr deals with deallocation of the temporary if needed.

◆ get_device_accessible()

template<typename T >
std::shared_ptr< const T > hamr::buffer< T >::get_device_accessible
Returns
a read only pointer to the contents of the buffer accessible from the active device using the technology most suitable witht he current build configuration. If the buffer is currently accessible on the active device then this call is a NOOP. If the buffer is not currently accessible on the active device then a temporary buffer is allocated and the data is moved. The returned shared_ptr deals with deallocation of the temporary if needed.

◆ get_hip_accessible()

template<typename T >
std::shared_ptr< const T > hamr::buffer< T >::get_hip_accessible
Returns
a read only pointer to the contents of the buffer accessible from the active HIP device. If the buffer is currently accessible on the active HIP device then this call is a NOOP. If the buffer is not currently accessible on the active HIP device then a temporary buffer is allocated and the data is moved. The returned shared_ptr deals with deallocation of the temporary if needed.

◆ get_host_accessible()

template<typename T >
std::shared_ptr< const T > hamr::buffer< T >::get_host_accessible
Returns
a read only pointer to the contents of the buffer accessible on the host. If the buffer is currently accessible by codes running on the host then this call is a NOOP. If the buffer is not currently accessible by codes running on the host then a temporary buffer is allocated and the data is moved to the host. The returned shared_ptr deals with deallocation of the temporary if needed.

◆ get_openmp_accessible()

template<typename T >
std::shared_ptr< const T > hamr::buffer< T >::get_openmp_accessible

returns a pointer to the contents of the buffer accessible from within OpenMP off load

◆ get_owner()

template<typename T >
int hamr::buffer< T >::get_owner ( ) const
inline
Returns
the device id where the memory was allocated

◆ get_stream()

template<typename T >
const hamr::stream& hamr::buffer< T >::get_stream ( ) const
inline
Returns
the active stream

◆ get_transfer_mode()

template<typename T >
transfer hamr::buffer< T >::get_transfer_mode ( ) const
inline
Returns
the current buffer_transfer mode

◆ hip_accessible()

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

returns true if the data is accessible from HIP codes

◆ host_accessible()

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

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

◆ move()

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

This is used to change the location of the buffer contents in place. For GPU based allocators, the new allocation is made on the device active at the time the call is made. If the new allocator and owner are the same as the current allocator and owner, then the call is a NOOP. Otherwise the data is reallocated and moved.

Parameters
[in]allocthe new allocator
Returns
zero if the operation was successful

◆ openmp_accessible()

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

returns true if the data is accessible from OpenMP off load codes

◆ operator=() [1/2]

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

move assign from the other buffer. The target buffer's allocator, stream, and device transfer mode are preserved. if this and the passed buffer have the same type, allocator, and owner the passed buffer is moved. If this and the passed buffer have different allocators or owners this allocator is used to allocate space 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)

Allocate space and copy the contents of another buffer. The allocator, owner, stream, and sychronization mode of the receiving object are unmodified by this operation. Thus one may move data around the system using copy assignment.

◆ pointer() [1/2]

template<typename T >
std::shared_ptr<T>& hamr::buffer< T >::pointer ( )
inline
Returns
a pointer to the buffer contents

◆ pointer() [2/2]

template<typename T >
const std::shared_ptr<T>& hamr::buffer< T >::pointer ( ) const
inline
Returns
a const pointer to the buffer contents

◆ print()

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

prints the contents to the stderr stream

◆ reserve() [1/2]

template<typename T >
int hamr::buffer< T >::reserve ( size_t  n_elem)

reserve n_elem of memory

◆ reserve() [2/2]

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

reserve n_elem of memory and initialize them to val

◆ 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

◆ resize() [1/2]

template<typename T >
int hamr::buffer< T >::resize ( size_t  n_elem)

resize the buffer to hold n_elem of memory

◆ resize() [2/2]

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

resize the buffer to hold n_elem of memory and initialize new elements to val

◆ 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 host)

◆ set_owner() [1/2]

template<typename T >
int hamr::buffer< T >::set_owner
protected

set the device where the buffer is located to the active device or the host. The allocator is used to determine which.

Returns
0 if successful.

◆ set_owner() [2/2]

template<typename T >
int hamr::buffer< T >::set_owner ( const T *  ptr)
protected

set the device where the buffer is located by querying the driver API or the host. The allocator is used to determine which.

Returns
0 if successful.

◆ set_stream()

template<typename T >
void hamr::buffer< T >::set_stream ( const stream strm,
transfer  sync = transfer::async 
)
inline

Sets the active stream and data transfer synchrnonization mode. See buffer_transfer.

Parameters
[in]strma ::stream object used to order operations
[in]synca buffer_transfer specifies synchronous or asynchronous behavior.

◆ set_transfer_asynchronous()

template<typename T >
void hamr::buffer< T >::set_transfer_asynchronous ( )
inline

Set the transfer mode to asynchronous. One must manually synchronize before data access when needed. See synchronize

◆ set_transfer_sycnhronous()

template<typename T >
void hamr::buffer< T >::set_transfer_sycnhronous ( )
inline

Set the transfer mode to synchronize every data transfer. This mode should not be used except for debugging.

◆ set_transfer_sycnhronous_host()

template<typename T >
void hamr::buffer< T >::set_transfer_sycnhronous_host ( )
inline

Set the transfer mode to synchronize automatically after data movement from the GPU to the host.

◆ 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

◆ synchronize()

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

synchronizes with the current stream. This ensures that asynchronous data transfers have completed before you access the data.


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