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(LVARRAY_DEVICE_COMPILE) && defined(LVARRAY_BOUNDS_CHECK) 130 ArraySlice::TV_ttf_display_type(
nullptr );
152 template<
typename U=T >
154 operator std::enable_if_t< !std::is_const< U >::value,
170 INDEX_TYPE
size() const noexcept
172 #if defined( __ibmxl__ ) 175 INDEX_TYPE val =
m_dims[ 0 ];
176 for(
int i = 1; i <
NDIM; ++i )
181 return indexing::multiplyAll< NDIM >(
m_dims );
190 INDEX_TYPE
size(
int const dim )
const noexcept
192 #ifdef LVARRAY_BOUNDS_CHECK 203 INDEX_TYPE
stride(
int const dim )
const noexcept
205 #ifdef LVARRAY_BOUNDS_CHECK 218 if( USD < 0 )
return false;
219 if( NDIM == 1 && USD == 0 )
return true;
222 for(
int i = 0; i <
NDIM; ++i )
224 if( i == USD )
continue;
226 for(
int j = 0; j <
NDIM; ++j )
228 if( j != i ) prod *=
m_dims[j];
240 template<
typename ... INDICES >
244 static_assert(
sizeof ... (INDICES) == NDIM,
"number of indices does not match NDIM" );
245 #ifdef LVARRAY_BOUNDS_CHECK 248 return indexing::getLinearIndex< USD >(
m_strides, indices ... );
262 template<
int NDIM_=NDIM,
int USD_=USD >
264 operator std::enable_if_t< NDIM_ == 1 && USD_ == 0, T * const LVARRAY_RESTRICT >
273 template<
int U=NDIM >
276 operator[]( INDEX_TYPE
const index )
const noexcept
289 template<
int U=NDIM >
291 std::enable_if_t< U == 1, T & >
303 template<
typename ... INDICES >
307 static_assert(
sizeof ... (INDICES) == NDIM,
"number of indices does not match NDIM" );
316 template<
int USD_ = USD >
321 static_assert( USD_ >= 0,
"Direct data access not supported for non-contiguous slices" );
344 #if defined(LVARRAY_USE_TOTALVIEW_OUTPUT) && !defined(LVARRAY_DEVICE_COMPILE) && defined(LVARRAY_BOUNDS_CHECK) 350 static int TV_ttf_display_type(
ArraySlice const * av )
354 int constexpr ndim =
NDIM;
357 TV_ttf_add_row(
"tv(m_data)", totalview::format< T, INDEX_TYPE >( NDIM, av->
m_dims ).c_str(), (av->
m_data) );
358 TV_ttf_add_row(
"m_data", totalview::format< T, INDEX_TYPE >( 1, av->
m_dims ).c_str(), (av->
m_data) );
359 TV_ttf_add_row(
"m_dims", totalview::format< INDEX_TYPE, int >( 1, &ndim ).c_str(), (av->
m_dims) );
360 TV_ttf_add_row(
"m_strides", totalview::format< INDEX_TYPE, int >( 1, &ndim ).c_str(), (av->
m_strides) );
371 INDEX_TYPE
const *
const LVARRAY_RESTRICT
m_dims;
INDEX_TYPE IndexType
The integer type used for indexing.
Definition: ArraySlice.hpp:105
LVARRAY_HOST_DEVICE T * dataIfContiguous() const
Definition: ArraySlice.hpp:318
#define LVARRAY_ERROR_IF(EXP, MSG)
Abort execution if EXP is true.
Definition: Macros.hpp:155
This class serves to provide a sliced multidimensional interface to the family of LvArray classes...
Definition: ArraySlice.hpp:89
LVARRAY_HOST_DEVICE constexpr INDEX_TYPE size() const noexcept
Definition: ArraySlice.hpp:170
LVARRAY_HOST_DEVICE constexpr T * begin() const
Definition: ArraySlice.hpp:331
T *const LVARRAY_RESTRICT m_data
pointer to beginning of data for this array, or sub-array.
Definition: ArraySlice.hpp:368
#define ARRAY_SLICE_CHECK_BOUNDS(index)
Point GDB at the scripts/gdb-printers.py.
Definition: ArraySlice.hpp:66
#define CONSTEXPR_WITHOUT_BOUNDS_CHECK
Expands to constexpr when array bound checking is disabled.
Definition: Macros.hpp:662
LVARRAY_HOST_DEVICE constexpr bool isContiguous() const
Check if the slice is contiguous in memory.
Definition: ArraySlice.hpp:216
LVARRAY_HOST_DEVICE constexpr ArraySlice< T const, NDIM, USD, INDEX_TYPE > toSliceConst() const noexcept
Definition: ArraySlice.hpp:146
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK INDEX_TYPE linearIndex(INDICES... indices) const
Definition: ArraySlice.hpp:242
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK INDEX_TYPE stride(int const dim) const noexcept
Definition: ArraySlice.hpp:203
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
The top level namespace.
Definition: Array.hpp:24
T ValueType
The type of the value in the ArraySlice.
Definition: ArraySlice.hpp:96
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.
Definition: Macros.hpp:424
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK std::enable_if_t< U==1, T &> operator[](INDEX_TYPE const index) const noexcept
Definition: ArraySlice.hpp:292
INDEX_TYPE const *const LVARRAY_RESTRICT m_dims
pointer to array of length NDIM that contains the lengths of each array dimension ...
Definition: ArraySlice.hpp:371
LVARRAY_HOST_DEVICE constexpr T & operator()(INDICES... indices) const
Definition: ArraySlice.hpp:305
static constexpr int USD
The unit stride dimension.
Definition: ArraySlice.hpp:102
#define DEFINE_GDB_PY_SCRIPT(script_name)
Add GDB pretty printers the given script.
Definition: ArraySlice.hpp:21
INDEX_TYPE const *const LVARRAY_RESTRICT m_strides
pointer to array of length NDIM that contains the strides of each array dimension ...
Definition: ArraySlice.hpp:374
static constexpr int NDIM
The number of dimensions.
Definition: ArraySlice.hpp:99
LVARRAY_HOST_DEVICE constexpr T * end() const
Definition: ArraySlice.hpp:339
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK 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.
Definition: ArraySlice.hpp:122
ArraySlice()=delete
deleted default constructor
Contains functions to aid in multidimensional indexing.
LVARRAY_HOST_DEVICE CONSTEXPR_WITHOUT_BOUNDS_CHECK INDEX_TYPE size(int const dim) const noexcept
Definition: ArraySlice.hpp:190
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
Definition: Macros.hpp:600