|
HAMR
The Heterogeneous Accelerator Memory Resource
|
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... | |
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.
| hamr::buffer< T >::buffer | ( | allocator | alloc | ) |
construct an empty buffer that will use the passed allocator type
| hamr::buffer< T >::buffer | ( | allocator | alloc, |
| size_t | n_elem | ||
| ) |
construct a buffer with n_elem size using the passed allocator type
| 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
| 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
| hamr::buffer< T >::buffer | ( | const buffer< T > & | other | ) |
copy construct from the passed buffer
| hamr::buffer< T >::buffer | ( | allocator | alloc, |
| const buffer< T > & | other | ||
| ) |
copy construct from the passed buffer, using the passed allocator type.
| hamr::buffer< T >::buffer | ( | buffer< T > && | other | ) |
move construct from the passed buffer
|
protected |
allocate space for n_elem initialized with an array of values
|
protected |
allocate space for n_elem
|
protected |
allocate space for n_elem initialized to val
|
protected |
allocate space for n_elem initialized with an array of values
| int hamr::buffer< T >::append | ( | const buffer< U > & | src | ) |
appends to the end of the buffer, extending the buffer as needed.
| 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.
| 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)
| int hamr::buffer< T >::assign | ( | const buffer< U > & | src | ) |
assign the passed buffer
| int hamr::buffer< T >::assign | ( | const buffer< U > & | src, |
| size_t | src_start, | ||
| size_t | n_vals | ||
| ) |
assign the range from the passed buffer
| 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)
| int hamr::buffer< T >::cpu_accessible |
returns true if the data is accessible from codes running on the CPU
| int hamr::buffer< T >::cuda_accessible |
returns true if the data is accessible from CUDA codes
| int hamr::buffer< T >::free |
free all internal storage
|
inline |
gets n_vals elements starting at src_start into the passed buffer's elements starting at dest_start
| 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
| 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)
|
inline |
returns the allocator type enum
|
staticprotected |
return the human readable name of the allocator
| 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.
| 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.
| 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.
| 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.
| int hamr::buffer< T >::print |
prints the contents to the stderr stream
|
protected |
grow the buffer if needed. doubles in size
|
inline |
sets n_vals elements starting at dest_start from the passed buffer's elements starting at src_start
| 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
| 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)
|
inline |
returns the number of elements of storage allocated to the buffer
| void hamr::buffer< T >::swap | ( | buffer< T > & | other | ) |
swap the contents of the two buffers