21 #include <RAJA/RAJA.hpp> 36 template<
bool B_IS_ONE >
46 template<
typename A,
typename B >
65 template<
typename A,
typename B >
76 template<
int SIZE,
typename T >
78 std::enable_if_t< (SIZE == 1), T >
80 {
return values[ 0 ]; }
88 template<
int SIZE,
typename T >
90 std::enable_if_t< (SIZE > 1), T >
92 {
return values[ 0 ] *
multiplyAll< SIZE - 1 >( values + 1 ); }
104 template<
int USD,
typename INDEX_TYPE,
typename INDEX >
106 INDEX_TYPE
getLinearIndex( INDEX_TYPE
const *
const LVARRAY_RESTRICT strides, INDEX
const index )
121 template<
int USD,
typename INDEX_TYPE,
typename INDEX,
typename ... REMAINING_INDICES >
123 INDEX_TYPE
getLinearIndex( INDEX_TYPE
const *
const LVARRAY_RESTRICT strides, INDEX
const index, REMAINING_INDICES
const ... indices )
126 getLinearIndex< USD - 1, INDEX_TYPE, REMAINING_INDICES... >( strides + 1, indices ... );
141 template<
typename INDEX,
typename ... REMAINING_INDICES >
142 std::string
getIndexString( INDEX
const index, REMAINING_INDICES
const ... indices )
144 std::ostringstream oss;
146 oss <<
"{ " << index;
147 using expander =
int[];
148 (void) expander{ 0, ( void (oss <<
", " << indices ), 0 )... };
161 template<
typename INDEX_TYPE,
typename ... INDICES >
162 std::string
printDimsAndIndices( INDEX_TYPE
const *
const LVARRAY_RESTRICT dims, INDICES
const... indices )
164 constexpr
int NDIM =
sizeof ... (INDICES);
165 std::ostringstream oss;
166 oss <<
"dimensions = { " << dims[ 0 ];
167 for(
int i = 1; i < NDIM; ++i )
169 oss <<
", " << dims[ i ];
184 template<
typename INDEX_TYPE,
typename ... INDICES >
186 bool invalidIndices( INDEX_TYPE
const *
const LVARRAY_RESTRICT dims, INDICES
const ... indices )
189 bool invalid =
false;
192 invalid = invalid || ( index < 0 ) || ( index >= dims[ curDim ] );
206 template<
typename INDEX_TYPE,
typename ... INDICES >
208 void checkIndices( INDEX_TYPE
const *
const LVARRAY_RESTRICT dims, INDICES
const ... indices )
220 template<
typename PERMUTATION,
typename INDEX_TYPE, camp::
idx_t NDIM >
225 INDEX_TYPE foldedStrides[ NDIM ];
227 for(
int i = 0; i < NDIM; ++i )
229 foldedStrides[ i ] = 1;
230 for(
int j = i + 1; j < NDIM; ++j )
232 foldedStrides[ i ] *= dims[ perm[ j ] ];
237 for(
int i = 0; i < NDIM; ++i )
239 strides[ perm[ i ] ] = foldedStrides[ i ];
LVARRAY_HOST_DEVICE constexpr bool invalidIndices(INDEX_TYPE const *const LVARRAY_RESTRICT dims, INDICES const ... indices)
Definition: indexing.hpp:186
LVARRAY_HOST_DEVICE constexpr std::enable_if_t<(SIZE==1), T > multiplyAll(T const *const LVARRAY_RESTRICT values)
Definition: indexing.hpp:79
static LVARRAY_HOST_DEVICE constexpr A multiply(A const a, B const &)
Definition: indexing.hpp:66
std::string getIndexString()
Definition: indexing.hpp:131
LVARRAY_HOST_DEVICE constexpr CArray< camp::idx_t, sizeof...(INDICES) > asArray(camp::idx_seq< INDICES... >)
Definition: typeManipulation.hpp:549
#define LVARRAY_ERROR_IF(EXP, MSG)
Abort execution if EXP is true.
Definition: Macros.hpp:155
LVARRAY_HOST_DEVICE typeManipulation::CArray< INDEX_TYPE, NDIM > calculateStrides(typeManipulation::CArray< INDEX_TYPE, NDIM > const &dims)
Calculate the strides given the dimensions and permutation.
Definition: indexing.hpp:222
Contains templates useful for type manipulation.
Contains portable access to std::numeric_limits and functions for converting between integral types...
DISABLE_HD_WARNING constexpr LVARRAY_HOST_DEVICE void forEachArg(F &&f)
The recursive base case where no argument is provided.
Definition: typeManipulation.hpp:129
static LVARRAY_HOST_DEVICE constexpr auto multiply(A const a, B const b)
Definition: indexing.hpp:47
LVARRAY_HOST_DEVICE void checkIndices(INDEX_TYPE const *const LVARRAY_RESTRICT dims, INDICES const ... indices)
Check that the indices are with dims , if not the program is aborted.
Definition: indexing.hpp:208
A helper struct to multiply two numbers.
Definition: indexing.hpp:37
The top level namespace.
Definition: Array.hpp:24
std::string printDimsAndIndices(INDEX_TYPE const *const LVARRAY_RESTRICT dims, INDICES const ... indices)
Definition: indexing.hpp:162
Contains a bunch of macro definitions.
LVARRAY_HOST_DEVICE constexpr INDEX_TYPE getLinearIndex(INDEX_TYPE const *const LVARRAY_RESTRICT strides, INDEX const index)
Get the index into a one dimensional space.
Definition: indexing.hpp:106
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
Definition: Macros.hpp:600