15 #if !defined( NDEBUG ) && !defined( __APPLE__ ) && !defined( __ibmxl__ ) 21 #define DEFINE_GDB_PY_SCRIPT( script_name ) \ 22 asm (".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n \ 24 .asciz \"" script_name "\"\n \ 31 #define DEFINE_GDB_PY_SCRIPT( script_name ) 38 #include "LvArrayConfig.hpp" 48 #ifdef LVARRAY_BOUNDS_CHECK 55 #define ARRAY_SLICE_CHECK_BOUNDS( index ) \ 56 LVARRAY_ERROR_IF( index < 0 || index >= m_dims[ 0 ], \ 57 "Array Bounds Check Failed: index=" << index << " m_dims[0]=" << m_dims[0] ) 59 #else // LVARRAY_BOUNDS_CHECK 66 #define ARRAY_SLICE_CHECK_BOUNDS( index ) 68 #endif // LVARRAY_BOUNDS_CHECK 88 template<
typename T,
int NDIM_TPARAM,
int USD_TPARAM,
typename INDEX_TYPE >
93 static_assert( USD_TPARAM < NDIM_TPARAM,
"USD must be less than NDIM." );
99 static constexpr
int NDIM = NDIM_TPARAM;
102 static constexpr
int USD = USD_TPARAM;
123 INDEX_TYPE
const *
const LVARRAY_RESTRICT inputDimensions,
124 INDEX_TYPE
const *
const LVARRAY_RESTRICT inputStrides ) noexcept:
126 m_dims( inputDimensions ),
129 #if defined(LVARRAY_USE_TOTALVIEW_OUTPUT) && !defined(__CUDA_ARCH__) && defined(LVARRAY_BOUNDS_CHECK) 130 ArraySlice::TV_ttf_display_type(
nullptr );
144 template<
typename U=T >
153 template<
typename U=T >
155 operator std::enable_if_t< !std::is_const< U >::value,
171 INDEX_TYPE
size() const noexcept
173 #if defined( __ibmxl__ ) 176 INDEX_TYPE val =
m_dims[ 0 ];
177 for(
int i = 1; i <
NDIM; ++i )
182 return indexing::multiplyAll< NDIM >(
m_dims );
191 INDEX_TYPE
size(
int dim )
const noexcept
193 #ifdef LVARRAY_BOUNDS_CHECK 204 template<
int _USD = USD >
206 std::enable_if_t< ( _USD >= 0),
bool >
209 if( NDIM == 1 && USD == 0 )
return true;
212 for(
int i = 0; i <
NDIM; ++i )
214 if( i == USD )
continue;
216 for(
int j = 0; j <
NDIM; ++j )
218 if( j != i ) prod *=
m_dims[j];
231 template<
int USD_ = USD >
233 std::enable_if_t< (USD_ < 0), bool >
242 template<
typename ... INDICES >
246 static_assert(
sizeof ... (INDICES) == NDIM,
"number of indices does not match NDIM" );
247 #ifdef LVARRAY_BOUNDS_CHECK 250 return indexing::getLinearIndex< USD >(
m_strides, indices ... );
264 template<
int _NDIM=NDIM,
int _USD=USD >
266 operator std::enable_if_t< _NDIM == 1 && _USD == 0, T * const LVARRAY_RESTRICT >
275 template<
int U=NDIM >
278 operator[]( INDEX_TYPE
const index )
const noexcept
291 template<
int U=NDIM >
293 std::enable_if_t< U == 1, T & >
305 template<
typename ... INDICES >
309 static_assert(
sizeof ... (INDICES) == NDIM,
"number of indices does not match NDIM" );
342 #if defined(LVARRAY_USE_TOTALVIEW_OUTPUT) && !defined(__CUDA_ARCH__) && defined(LVARRAY_BOUNDS_CHECK) 348 static int TV_ttf_display_type(
ArraySlice const * av )
352 int constexpr ndim =
NDIM;
355 TV_ttf_add_row(
"tv(m_data)", totalview::format< T, INDEX_TYPE >( NDIM, av->
m_dims ).c_str(), (av->
m_data) );
356 TV_ttf_add_row(
"m_data", totalview::format< T, INDEX_TYPE >( 1, av->
m_dims ).c_str(), (av->
m_data) );
357 TV_ttf_add_row(
"m_dims", totalview::format< INDEX_TYPE, int >( 1, &ndim ).c_str(), (av->
m_dims) );
358 TV_ttf_add_row(
"m_strides", totalview::format< INDEX_TYPE, int >( 1, &ndim ).c_str(), (av->
m_strides) );
369 INDEX_TYPE
const *
const LVARRAY_RESTRICT
m_dims;
INDEX_TYPE IndexType
The integer type used for indexing.
constexpr std::enable_if_t< U==1, T &> operator[](INDEX_TYPE const index) const noexcept
constexpr ArraySlice< T const, NDIM, USD, INDEX_TYPE > toSliceConst() const noexcept
constexpr INDEX_TYPE size(int dim) const noexcept
#define LVARRAY_ERROR_IF(EXP, MSG)
Abort execution if EXP is true.
constexpr T & operator()(INDICES... indices) const
This class serves to provide a sliced multidimensional interface to the family of LvArray classes...
constexpr INDEX_TYPE linearIndex(INDICES... indices) const
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.
T *const LVARRAY_RESTRICT m_data
pointer to beginning of data for this array, or sub-array.
#define ARRAY_SLICE_CHECK_BOUNDS(index)
Point GDB at the scripts/gdb-printers.py.
#define CONSTEXPR_WITHOUT_BOUNDS_CHECK
Expands to constexpr when array bound checking is disabled.
constexpr std::enable_if_t<(USD_< 0), bool > isContiguous() const
Check if the slice is contiguous in memory.
constexpr T * end() const
constexpr INDEX_TYPE size() const noexcept
constexpr T * begin() const
static constexpr auto multiply(A const a, B const b)
constexpr ArraySlice(T *const LVARRAY_RESTRICT inputData, INDEX_TYPE const *const LVARRAY_RESTRICT inputDimensions, INDEX_TYPE const *const LVARRAY_RESTRICT inputStrides) noexcept
Construct a new ArraySlice.
T ValueType
The type of the value in the ArraySlice.
Contains a bunch of macro definitions.
#define LVARRAY_ERROR_IF_GE(lhs, rhs)
Raise a hard error if one value compares greater than or equal to the other.
INDEX_TYPE const *const LVARRAY_RESTRICT m_dims
pointer to array of length NDIM that contains the lengths of each array dimension ...
constexpr std::enable_if_t<(_USD >=0), bool > isContiguous() const
Check if the slice is contiguous in memory.
static constexpr int USD
The unit stride dimension.
#define DEFINE_GDB_PY_SCRIPT(script_name)
Add GDB pretty printers the given script.
INDEX_TYPE const *const LVARRAY_RESTRICT m_strides
pointer to array of length NDIM that contains the strides of each array dimension ...
static constexpr int NDIM
The number of dimensions.
ArraySlice()=delete
deleted default constructor
Contains functions to aid in multidimensional indexing.
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
T * dataIfContiguous() const