16 #include "LvArrayConfig.hpp" 22 #include <camp/resource.hpp> 41 if( space == MemorySpace::undefined )
42 return os <<
"undefined";
43 if( space == MemorySpace::host )
45 if( space == MemorySpace::cuda )
47 if( space == MemorySpace::omp_target )
48 return os <<
"omp_target";
49 if( space == MemorySpace::hip )
51 if( space == MemorySpace::sycl )
54 LVARRAY_ERROR(
"Unrecognized memory space " << static_cast< int >( space ) );
62 namespace bufferManipulation
113 {
return MemorySpace::host; }
129 template<
typename=Vo
idBuffer >
142 template<
typename BUFFER >
144 void check( BUFFER
const & buf, std::ptrdiff_t
const size )
146 #ifdef LVARRAY_BOUNDS_CHECK 164 template<
typename BUFFER >
166 void checkInsert( BUFFER
const & buf, std::ptrdiff_t
const size, std::ptrdiff_t
const pos )
168 #ifdef LVARRAY_BOUNDS_CHECK 186 template<
typename BUFFER >
188 void free( BUFFER & buf, std::ptrdiff_t
const size )
190 using T =
typename BUFFER::value_type;
194 if( !std::is_trivially_destructible< T >::value )
196 buf.move( MemorySpace::host,
true );
212 template<
typename BUFFER >
217 buf.reallocate( size, space, newCapacity );
228 template<
typename BUFFER >
230 void reserve( BUFFER & buf, std::ptrdiff_t
const size,
MemorySpace const space, std::ptrdiff_t
const newCapacity )
234 if( newCapacity > buf.capacity() )
250 template<
typename BUFFER >
251 void dynamicReserve( BUFFER & buf, std::ptrdiff_t
const size, std::ptrdiff_t
const newCapacity )
255 if( newCapacity > buf.capacity() )
257 setCapacity( buf, size, MemorySpace::host, 2 * newCapacity );
270 template<
typename BUFFER,
typename ... ARGS >
272 void resize( BUFFER & buf, std::ptrdiff_t
const size, std::ptrdiff_t
const newSize, ARGS && ... args )
276 reserve( buf, size, MemorySpace::host, newSize );
280 #if !defined(LVARRAY_DEVICE_COMPILE) 283 buf.registerTouch( MemorySpace::host );
296 template<
typename BUFFER,
typename ... ARGS >
297 void emplaceBack( BUFFER & buf, std::ptrdiff_t
const size, ARGS && ... args )
314 template<
typename BUFFER,
typename ... ARGS >
316 std::ptrdiff_t
const size,
317 std::ptrdiff_t
const pos,
337 template<
typename BUFFER,
typename ITER >
339 std::ptrdiff_t
const size,
340 std::ptrdiff_t
const pos,
358 template<
typename BUFFER >
359 void popBack( BUFFER & buf, std::ptrdiff_t
const size )
372 template<
typename BUFFER >
373 void erase( BUFFER & buf, std::ptrdiff_t
const size, std::ptrdiff_t
const pos )
391 template<
typename DST_BUFFER,
typename SRC_BUFFER >
394 std::ptrdiff_t
const dstSize,
395 SRC_BUFFER
const & src,
396 std::ptrdiff_t
const srcSize )
398 check( dst, dstSize );
399 check( src, srcSize );
401 resize( dst, dstSize, srcSize );
403 using T =
typename DST_BUFFER::value_type;
404 T *
const LVARRAY_RESTRICT dstData = dst.data();
405 T
const *
const LVARRAY_RESTRICT srcData = src.data();
407 for( std::ptrdiff_t i = 0; i < srcSize; ++i )
409 dstData[ i ] = srcData[ i ];
#define LVARRAY_UNUSED_VARIABLE(X)
Mark X as an unused variable, used to silence compiler warnings.
Definition: Macros.hpp:79
LVARRAY_HOST_DEVICE void resize(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const newSize, ARGS &&... args)
Resize the buffer to the given size.
Definition: bufferManipulation.hpp:272
void emplace(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const pos, ARGS &&... args)
Construct a new value at position pos.
Definition: bufferManipulation.hpp:315
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.
Definition: bufferManipulation.hpp:338
void emplaceBack(BUFFER &buf, std::ptrdiff_t const size, ARGS &&... args)
Construct a new value at the end of the buffer.
Definition: bufferManipulation.hpp:297
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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.
Definition: arrayManipulation.hpp:425
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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.
Definition: arrayManipulation.hpp:505
LVARRAY_HOST_DEVICE void setName(std::string const &name)
Set the name associated with this buffer.
Definition: bufferManipulation.hpp:131
This class implements the default behavior for the Buffer methods related to execution space...
Definition: bufferManipulation.hpp:78
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...
Definition: bufferManipulation.hpp:251
Contains templates useful for type manipulation.
#define LVARRAY_ERROR_IF_NE_MSG(lhs, rhs, msg)
Raise a hard error if two values are not equal.
Definition: Macros.hpp:344
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void resize(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const newSize, ARGS &&... args)
Resize the give array.
Definition: arrayManipulation.hpp:283
void popBack(BUFFER &buf, std::ptrdiff_t const size)
Remove a value from the end of the buffer.
Definition: bufferManipulation.hpp:359
#define CONSTEXPR_WITHOUT_BOUNDS_CHECK
Expands to constexpr when array bound checking is disabled.
Definition: Macros.hpp:662
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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...
Definition: arrayManipulation.hpp:396
#define LVARRAY_ERROR_IF_GT(lhs, rhs)
Raise a hard error if one value compares greater than the other.
Definition: Macros.hpp:392
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.
Definition: bufferManipulation.hpp:166
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK void check(BUFFER const &buf, std::ptrdiff_t const size)
Check that given Buffer and size are valid.
Definition: bufferManipulation.hpp:144
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void popBack(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size)
Destroy the value at the end of the array.
Definition: arrayManipulation.hpp:533
#define LVARRAY_ERROR(MSG)
Abort execution.
Definition: Macros.hpp:176
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void free(BUFFER &buf, std::ptrdiff_t const size)
Destroy the values in the buffer and free it's memory.
Definition: bufferManipulation.hpp:188
camp::resources::Platform MemorySpace
an alias for camp::resources::Platform.
Definition: bufferManipulation.hpp:31
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.
Definition: bufferManipulation.hpp:102
#define LVARRAY_DEBUG_VAR(X)
Mark X as an debug variable, used to silence compiler warnings.
Definition: Macros.hpp:85
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.
Definition: bufferManipulation.hpp:88
The top level namespace.
Definition: Array.hpp:24
LVARRAY_HOST_DEVICE void reserve(BUFFER &buf, std::ptrdiff_t const size, MemorySpace const space, std::ptrdiff_t const newCapacity)
Reserve space in the buffer for at least the given capacity.
Definition: bufferManipulation.hpp:230
Contains a bunch of macro definitions.
std::ostream & operator<<(std::ostream &os, MemorySpace const space)
Output a Platform enum to a stream.
Definition: bufferManipulation.hpp:39
#define LVARRAY_ERROR_IF_GE(lhs, rhs)
Raise a hard error if one value compares greater than or equal to the other.
Definition: Macros.hpp:424
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void destroy(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size)
Destory the values in the array.
Definition: arrayManipulation.hpp:152
MemorySpace getPreviousSpace() const
Definition: bufferManipulation.hpp:112
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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.
Definition: bufferManipulation.hpp:393
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void setCapacity(BUFFER &buf, std::ptrdiff_t const size, MemorySpace const space, std::ptrdiff_t const newCapacity)
Set the capacity of the buffer.
Definition: bufferManipulation.hpp:214
#define DISABLE_HD_WARNING
Disable host device warnings.
Definition: Macros.hpp:614
HAS_MEMBER_FUNCTION_NO_RTYPE(move, MemorySpace::host, true)
Defines a static constexpr bool HasMemberFunction_move< CLASS > that is true iff the class has a meth...
DISABLE_HD_WARNING constexpr LVARRAY_HOST_DEVICE std::iterator_traits< ITER >::difference_type iterDistance(ITER first, ITER const last, std::input_iterator_tag)
Definition: arrayManipulation.hpp:105
void erase(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const pos)
Erase a value from the buffer.
Definition: bufferManipulation.hpp:373
void registerTouch(MemorySpace const space) const
Touch the buffer in the given space.
Definition: bufferManipulation.hpp:121
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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.
Definition: arrayManipulation.hpp:478
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
Definition: Macros.hpp:600