16 #include "LvArrayConfig.hpp" 35 #if defined(LVARRAY_USE_CUDA) 48 if( space == MemorySpace::NONE )
50 if( space == MemorySpace::CPU )
52 #if defined(LVARRAY_USE_CUDA) 53 if( space == MemorySpace::GPU )
63 namespace bufferManipulation
123 template<
typename=Vo
idBuffer >
136 template<
typename BUFFER >
138 void check( BUFFER
const & buf, std::ptrdiff_t
const size )
140 #ifdef LVARRAY_BOUNDS_CHECK 158 template<
typename BUFFER >
160 void checkInsert( BUFFER
const & buf, std::ptrdiff_t
const size, std::ptrdiff_t
const pos )
162 #ifdef LVARRAY_BOUNDS_CHECK 180 template<
typename BUFFER >
182 void free( BUFFER & buf, std::ptrdiff_t
const size )
184 using T =
typename BUFFER::value_type;
188 if( !std::is_trivially_destructible< T >::value )
190 buf.move( MemorySpace::CPU,
true );
205 template<
typename BUFFER >
207 void setCapacity( BUFFER & buf, std::ptrdiff_t
const size, std::ptrdiff_t
const newCapacity )
210 buf.reallocate( size, newCapacity );
220 template<
typename BUFFER >
222 void reserve( BUFFER & buf, std::ptrdiff_t
const size, std::ptrdiff_t
const newCapacity )
226 if( newCapacity > buf.capacity() )
242 template<
typename BUFFER >
243 void dynamicReserve( BUFFER & buf, std::ptrdiff_t
const size, std::ptrdiff_t
const newCapacity )
247 if( newCapacity > buf.capacity() )
264 template<
typename BUFFER,
typename ... ARGS >
266 void resize( BUFFER & buf, std::ptrdiff_t
const size, std::ptrdiff_t
const newSize, ARGS && ... args )
274 #if !defined(__CUDA_ARCH__) 277 buf.registerTouch( MemorySpace::CPU );
290 template<
typename BUFFER,
typename ... ARGS >
291 void emplaceBack( BUFFER & buf, std::ptrdiff_t
const size, ARGS && ... args )
308 template<
typename BUFFER,
typename ... ARGS >
310 std::ptrdiff_t
const size,
311 std::ptrdiff_t
const pos,
331 template<
typename BUFFER,
typename ITER >
333 std::ptrdiff_t
const size,
334 std::ptrdiff_t
const pos,
352 template<
typename BUFFER >
353 void popBack( BUFFER & buf, std::ptrdiff_t
const size )
366 template<
typename BUFFER >
367 void erase( BUFFER & buf, std::ptrdiff_t
const size, std::ptrdiff_t
const pos )
385 template<
typename DST_BUFFER,
typename SRC_BUFFER >
388 std::ptrdiff_t
const dstSize,
389 SRC_BUFFER
const & src,
390 std::ptrdiff_t
const srcSize )
392 check( dst, dstSize );
393 check( src, srcSize );
395 resize( dst, dstSize, srcSize );
397 using T =
typename DST_BUFFER::value_type;
398 T *
const LVARRAY_RESTRICT dstData = dst.data();
399 T
const *
const LVARRAY_RESTRICT srcData = src.data();
401 for( std::ptrdiff_t i = 0; i < srcSize; ++i )
403 dstData[ i ] = srcData[ i ];
constexpr void check(BUFFER const &buf, std::ptrdiff_t const size)
Check that given Buffer and size are valid.
#define LVARRAY_UNUSED_VARIABLE(X)
Mark X as an unused variable, used to silence compiler warnings.
void emplace(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const pos, ARGS &&... args)
Construct a new value at position pos.
constexpr std::iterator_traits< ITER >::difference_type iterDistance(ITER first, ITER const last, std::input_iterator_tag)
std::ptrdiff_t insert(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const pos, ITER const first, ITER const last)
Insert multiple values into the buffer.
void reserve(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const newCapacity)
Reserve space in the buffer for at least the given capacity.
void emplaceBack(BUFFER &buf, std::ptrdiff_t const size, ARGS &&... args)
Construct a new value at the end of the buffer.
This class implements the default behavior for the Buffer methods related to execution space...
void dynamicReserve(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const newCapacity)
If the buffer's capacity is greater than newCapacity this is a no-op. Otherwise the buffer's capacity...
Contains templates useful for type manipulation.
void setName(std::string const &name)
Set the name associated with this buffer.
#define LVARRAY_ERROR_IF_NE_MSG(lhs, rhs, msg)
Raise a hard error if two values are not equal.
void copyInto(DST_BUFFER &dst, std::ptrdiff_t const dstSize, SRC_BUFFER const &src, std::ptrdiff_t const srcSize)
Copy values from the source buffer into the destination buffer.
void popBack(BUFFER &buf, std::ptrdiff_t const size)
Remove a value from the end of the buffer.
#define CONSTEXPR_WITHOUT_BOUNDS_CHECK
Expands to constexpr when array bound checking is disabled.
void destroy(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size)
Destory the values in the array.
#define LVARRAY_ERROR_IF_GT(lhs, rhs)
Raise a hard error if one value compares greater than the other.
void free(BUFFER &buf, std::ptrdiff_t const size)
Destroy the values in the buffer and free it's memory.
void checkInsert(BUFFER const &buf, std::ptrdiff_t const size, std::ptrdiff_t const pos)
Check that given Buffer, size, and insertion position, are valid.
#define HAS_MEMBER_FUNCTION_NO_RTYPE(NAME,...)
Macro that expands to a static constexpr bool templated on a type that is only true when the type has...
void emplace(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, ARGS &&... args)
Insert into the array constructing the new value in place.
void popBack(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size)
Destroy the value at the end of the array.
Contains functions for manipulating a contiguous array of values.
void move(MemorySpace const space, bool const touch) const
Move the buffer to the given execution space, optionally touching it.
#define LVARRAY_DEBUG_VAR(X)
Mark X as an debug variable, used to silence compiler warnings.
MemorySpace
An enum containing the available memory spaces.
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.
void setCapacity(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const newCapacity)
Set the capacity of the buffer.
void resize(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const newSize, ARGS &&... args)
Resize the give array.
Contains a bunch of macro definitions.
std::ostream & operator<<(std::ostream &os, MemorySpace const space)
Output a MemorySpace enum to a stream.
#define LVARRAY_ERROR_IF_GE(lhs, rhs)
Raise a hard error if one value compares greater than or equal to the other.
void erase(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, std::ptrdiff_t const n=1)
Shift the values in the array at or above the given position down by the given amount overwriting the...
void emplaceBack(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, ARGS &&... args)
Append the to the array constructing the new value in place.
std::string string
String type.
#define DISABLE_HD_WARNING
Disable host device warnings.
void insert(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, ITERATOR first, std::ptrdiff_t const n)
Insert the given values into the array at the given position.
void erase(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const pos)
Erase a value from the buffer.
void registerTouch(MemorySpace const space) const
Touch the buffer in the given space.
void resize(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const newSize, ARGS &&... args)
Resize the buffer to the given size.
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.