LvArray
Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
LvArray::ChaiBuffer< T > Class Template Reference

Implements the Buffer interface using CHAI. More...

#include <ChaiBuffer.hpp>

Public Types

using value_type = T
 Alias for T used used in the bufferManipulation functions.
 
using T_non_const = std::remove_const_t< T >
 An alias for the non const version of T.
 

Public Member Functions

LVARRAY_HOST_DEVICE constexpr ChaiBuffer ()
 Default constructor, creates an uninitialized ChaiBuffer. More...
 
LVARRAY_HOST_DEVICE ChaiBuffer (bool)
 Constructor for creating an empty Buffer. More...
 
LVARRAY_HOST_DEVICE ChaiBuffer (std::initializer_list< MemorySpace > const &spaces, std::initializer_list< umpire::Allocator > const &allocators)
 Construct a ChaiBuffer which uses the specific allocator for each space. More...
 
LVARRAY_HOST_DEVICE ChaiBuffer (ChaiBuffer const &src)
 Copy constructor. More...
 
LVARRAY_HOST_DEVICE ChaiBuffer (ChaiBuffer const &src, std::ptrdiff_t const size)
 Copy constructor. More...
 
LVARRAY_HOST_DEVICE constexpr ChaiBuffer (ChaiBuffer &&src)
 Move constructor. More...
 
template<typename U >
LVARRAY_HOST_DEVICE constexpr ChaiBuffer (ChaiBuffer< U > const &src)
 Create a shallow copy of src but with a different type. More...
 
LVARRAY_HOST_DEVICE LVARRAY_INTEL_CONSTEXPR ChaiBufferoperator= (ChaiBuffer const &src)
 Copy assignment operator. More...
 
LVARRAY_HOST_DEVICE LVARRAY_INTEL_CONSTEXPR ChaiBufferoperator= (ChaiBuffer &&src)
 Move assignment operator. More...
 
LVARRAY_HOST_DEVICE void reallocate (std::ptrdiff_t const size, MemorySpace const space, std::ptrdiff_t const newCapacity)
 Reallocate the buffer to the new capacity. More...
 
LVARRAY_HOST_DEVICE void free ()
 Free the data in the buffer but does not destroy any values. More...
 
LVARRAY_HOST_DEVICE constexpr std::ptrdiff_t capacity () const
 
LVARRAY_HOST_DEVICE constexpr T * data () const
 
LVARRAY_HOST_DEVICE constexpr chai::PointerRecord & pointerRecord () const
 Return a reference to the associated CHAI PointerRecord. More...
 
template<typename INDEX_TYPE >
LVARRAY_HOST_DEVICE constexpr T & operator[] (INDEX_TYPE const i) const
 
void moveNested (MemorySpace const space, std::ptrdiff_t const size, bool const touch) const
 Move the buffer to the given execution space, optionally touching it. More...
 
void move (MemorySpace const space, bool const touch) const
 Move the buffer to the given execution space, optionally touching it. More...
 
MemorySpace getPreviousSpace () const
 
constexpr void registerTouch (MemorySpace const space) const
 Touch the buffer in the given space. More...
 
template<typename U = ChaiBuffer< T >>
void setName (std::string const &name)
 Set the name associated with this buffer which is used in the chai callback. More...
 

Static Public Attributes

static constexpr bool hasShallowCopy = true
 A flag indicating that the ChaiBuffer's copy semantics are shallow.
 

Private Member Functions

template<typename U = T_non_const>
std::enable_if_t< bufferManipulation::HasMemberFunction_move< U > > moveInnerData (MemorySpace const space, std::ptrdiff_t const size, bool const touch) const
 Move inner allocations to the memory space space. More...
 
template<typename U = T_non_const>
std::enable_if_t< !bufferManipulation::HasMemberFunction_move< U > > moveInnerData (MemorySpace const, std::ptrdiff_t const, bool const) const
 Move inner allocations to the memory space space. More...
 

Private Attributes

T *LVARRAY_RESTRICT m_pointer = nullptr
 A pointer to the data.
 
std::ptrdiff_t m_capacity = 0
 The size of the allocation.
 
chai::PointerRecord * m_pointerRecord = nullptr
 A pointer to the chai PointerRecord, keeps track of the memory space information.
 

Detailed Description

template<typename T>
class LvArray::ChaiBuffer< T >

Implements the Buffer interface using CHAI.

Template Parameters
Ttype of data that is contained in the buffer.

The ChaiBuffer's allocation can exist in multiple memory spaces. If the chai execution space is set the copy constructor will ensure that the newly constructed ChaiBuffer's pointer points to memory in that space. If the memory does exist it will be allocated and the data copied over. If the memory exists but the data has been touched (modified) in the current space it will be copied over. The data is touched in the new space if T is non const and is not touched if T is const.

Note
Both the copy constructor and copy assignment constructor perform a shallow copy of the source. Similarly the destructor does not free the allocation.

Constructor & Destructor Documentation

◆ ChaiBuffer() [1/7]

template<typename T>
LVARRAY_HOST_DEVICE constexpr LvArray::ChaiBuffer< T >::ChaiBuffer ( )
inline

Default constructor, creates an uninitialized ChaiBuffer.

An uninitialized ChaiBuffer is an undefined state and may only be assigned to. An uninitialized ChaiBuffer holds no recources and does not need to be free'd.

◆ ChaiBuffer() [2/7]

template<typename T>
LVARRAY_HOST_DEVICE LvArray::ChaiBuffer< T >::ChaiBuffer ( bool  )
inline

Constructor for creating an empty Buffer.

An empty buffer may hold resources and needs to be free'd.

Note
The unused boolean parameter is to distinguish this from default constructor.
Although it is marked as a host-device method, this is only valid to call from the host.

◆ ChaiBuffer() [3/7]

template<typename T>
LVARRAY_HOST_DEVICE LvArray::ChaiBuffer< T >::ChaiBuffer ( std::initializer_list< MemorySpace > const &  spaces,
std::initializer_list< umpire::Allocator > const &  allocators 
)
inline

Construct a ChaiBuffer which uses the specific allocator for each space.

Parameters
spacesThe list of spaces.
allocatorsThe allocators, must be the same length as spaces.
allocator[ i ]

is used for the memory space

spaces[ i ]

.

Note
Although it is marked as a host-device method, this is only valid to call from the host.

◆ ChaiBuffer() [4/7]

template<typename T>
LVARRAY_HOST_DEVICE LvArray::ChaiBuffer< T >::ChaiBuffer ( ChaiBuffer< T > const &  src)
inline

Copy constructor.

Parameters
srcThe buffer to copy.

In addition to performing a shallow copy of src if the chai execution space is set *this will contain a pointer the the allocation in that space.

◆ ChaiBuffer() [5/7]

template<typename T>
LVARRAY_HOST_DEVICE LvArray::ChaiBuffer< T >::ChaiBuffer ( ChaiBuffer< T > const &  src,
std::ptrdiff_t const  size 
)
inline

Copy constructor.

Parameters
srcThe buffer to copy.

In addition to performing a shallow copy of src if the chai execution space is set *this will contain a pointer the the allocation in that space.

Parameters
sizeThe number of values in the allocation.
Note
In addition to performing a shallow copy of src if the chai execution space is set *this will contain a pointer the the allocation in that space. It will also move any nested objects.

◆ ChaiBuffer() [6/7]

template<typename T>
LVARRAY_HOST_DEVICE constexpr LvArray::ChaiBuffer< T >::ChaiBuffer ( ChaiBuffer< T > &&  src)
inline

Move constructor.

Parameters
srcThe ChaiBuffer to be moved from, is uninitialized after this call.

◆ ChaiBuffer() [7/7]

template<typename T>
template<typename U >
LVARRAY_HOST_DEVICE constexpr LvArray::ChaiBuffer< T >::ChaiBuffer ( ChaiBuffer< U > const &  src)
inline

Create a shallow copy of src but with a different type.

Template Parameters
UThe type to convert from.
Parameters
srcThe buffer to copy.

Member Function Documentation

◆ capacity()

template<typename T>
LVARRAY_HOST_DEVICE constexpr std::ptrdiff_t LvArray::ChaiBuffer< T >::capacity ( ) const
inline
Returns
Return the capacity of the buffer.

◆ data()

template<typename T>
LVARRAY_HOST_DEVICE constexpr T* LvArray::ChaiBuffer< T >::data ( ) const
inline
Returns
Return a pointer to the beginning of the buffer.

◆ free()

template<typename T>
LVARRAY_HOST_DEVICE void LvArray::ChaiBuffer< T >::free ( )
inline

Free the data in the buffer but does not destroy any values.

Note
To destroy the values and free the data call bufferManipulation::free.
Although it is marked as a host-device method, this is only valid to call from the host.

◆ getPreviousSpace()

template<typename T>
MemorySpace LvArray::ChaiBuffer< T >::getPreviousSpace ( ) const
inline
Returns
The last space the ChaiBuffer was moved to.

◆ move()

template<typename T>
void LvArray::ChaiBuffer< T >::move ( MemorySpace const  space,
bool const  touch 
) const
inline

Move the buffer to the given execution space, optionally touching it.

Parameters
spaceThe space to move the buffer to.
touchIf the buffer should be touched in the new space or not.
Note
This will not move subobjects.

◆ moveInnerData() [1/2]

template<typename T>
template<typename U = T_non_const>
std::enable_if_t< bufferManipulation::HasMemberFunction_move< U > > LvArray::ChaiBuffer< T >::moveInnerData ( MemorySpace const  space,
std::ptrdiff_t const  size,
bool const  touch 
) const
inlineprivate

Move inner allocations to the memory space space.

Template Parameters
UA dummy parameter to enable SFINAE, do not specify.
Parameters
spaceThe memory space to move to.
sizeThe number of values to move.
touchIf the inner values should be touched or not.
Returns
void.
Note
This method is only active when T has a method move( MemorySpace ).

◆ moveInnerData() [2/2]

template<typename T>
template<typename U = T_non_const>
std::enable_if_t< !bufferManipulation::HasMemberFunction_move< U > > LvArray::ChaiBuffer< T >::moveInnerData ( MemorySpace  const,
std::ptrdiff_t  const,
bool  const 
) const
inlineprivate

Move inner allocations to the memory space space.

Template Parameters
UA dummy parameter to enable SFINAE, do not specify.
Returns
void.
Note
This method is only active when T does not have a method move( MemorySpace ).

◆ moveNested()

template<typename T>
void LvArray::ChaiBuffer< T >::moveNested ( MemorySpace const  space,
std::ptrdiff_t const  size,
bool const  touch 
) const
inline

Move the buffer to the given execution space, optionally touching it.

Parameters
spaceThe space to move the buffer to.
sizeThe size of the buffer.
touchIf the buffer should be touched in the new space or not.
Note
If they type T supports it this will call move( space, touch ) on each sub object.

◆ operator=() [1/2]

template<typename T>
LVARRAY_HOST_DEVICE LVARRAY_INTEL_CONSTEXPR ChaiBuffer& LvArray::ChaiBuffer< T >::operator= ( ChaiBuffer< T > const &  src)
inline

Copy assignment operator.

Parameters
srcThe ChaiBuffer to be copied.
Returns
*this.

◆ operator=() [2/2]

template<typename T>
LVARRAY_HOST_DEVICE LVARRAY_INTEL_CONSTEXPR ChaiBuffer& LvArray::ChaiBuffer< T >::operator= ( ChaiBuffer< T > &&  src)
inline

Move assignment operator.

Parameters
srcThe ChaiBuffer to be moved from, is uninitialized after this call.
Returns
*this.

◆ operator[]()

template<typename T>
template<typename INDEX_TYPE >
LVARRAY_HOST_DEVICE constexpr T& LvArray::ChaiBuffer< T >::operator[] ( INDEX_TYPE const  i) const
inline
Template Parameters
INDEX_TYPEthe type used to index into the values.
Returns
The value at position i .
Parameters
iThe position of the value to access.
Note
No bounds checks are performed.

◆ pointerRecord()

template<typename T>
LVARRAY_HOST_DEVICE constexpr chai::PointerRecord& LvArray::ChaiBuffer< T >::pointerRecord ( ) const
inline

Return a reference to the associated CHAI PointerRecord.

Returns
A reference to the associated CHAI PointerRecord.

◆ reallocate()

template<typename T>
LVARRAY_HOST_DEVICE void LvArray::ChaiBuffer< T >::reallocate ( std::ptrdiff_t const  size,
MemorySpace const  space,
std::ptrdiff_t const  newCapacity 
)
inline

Reallocate the buffer to the new capacity.

Parameters
sizethe number of values that are initialized in the buffer. Values between [0, size) are destroyed.
spaceThe space to perform the reallocation in. If space is the CPU then the buffer is reallocated only on the CPU and it is free'd in the other spaces. If the space is the GPU the the current size must be zero.
newCapacitythe new capacity of the buffer.
Note
Although it is marked as a host-device method, this is only valid to call from the host.

◆ registerTouch()

template<typename T>
constexpr void LvArray::ChaiBuffer< T >::registerTouch ( MemorySpace const  space) const
inline

Touch the buffer in the given space.

Parameters
spacethe space to touch.

◆ setName()

template<typename T>
template<typename U = ChaiBuffer< T >>
void LvArray::ChaiBuffer< T >::setName ( std::string const &  name)
inline

Set the name associated with this buffer which is used in the chai callback.

Template Parameters
UThe type of the owning class, will be displayed in the callback.
Parameters
namethe of the buffer.

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