YAKL
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
yakl::CSArray< T, rank, D0, D1, D2, D3 > Class Template Reference

C-style array on the stack similar in nature to, e.g., float arr[ny][nx]; More...

#include <YAKL_CSArray.h>

Public Types

typedef std::add_const< type >::type const_value_type
 This is the type T with const added to it (if the original type has volatile, then so will this type). More...
 
typedef std::remove_const< type >::type non_const_value_type
 This is the type T with const removed from it (if the original type has volatile, then so will this type). More...
 
typedef std::remove_cv< T >::type type
 This is the type T without const and volatile modifiers. More...
 
typedef T value_type
 This is the type T exactly as it was defined upon array object creation. More...
 

Public Member Functions

 CSArray ()=default
 
YAKL_INLINE CSArray (T init_fill)
 No constructor arguments allowed. More...
 
 ~CSArray ()=default
 
YAKL_INLINE T * begin () const
 Returns pointer to beginning of the data. More...
 
YAKL_INLINE T * data () const
 Get the underlying raw data pointer. More...
 
YAKL_INLINE T * end () const
 Returns pointer to end of the data. More...
 
YAKL_INLINE T * get_data () const
 Get the underlying raw data pointer. More...
 
YAKL_INLINE CSArray< uint, 1, rank > get_dimensions () const
 Returns the dimensions of this array as a yakl::SArray object. More...
 
YAKL_INLINE CSArray< uint, 1, rank > get_lbounds () const
 Returns the lower bound of each dimension of this array as a yakl::SArray object. More...
 
YAKL_INLINE CSArray< uint, 1, rank > get_ubounds () const
 Returns the upper bound of each dimension of this array as a yakl::SArray object. More...
 
YAKL_INLINE T & operator() (uint const i0) const
 Returns a reference to the indexed element (1-D). More...
 
YAKL_INLINE T & operator() (uint const i0, uint const i1) const
 Returns a reference to the indexed element (2-D). More...
 
YAKL_INLINE T & operator() (uint const i0, uint const i1, uint const i2) const
 Returns a reference to the indexed element (3-D). More...
 
YAKL_INLINE T & operator() (uint const i0, uint const i1, uint const i2, uint const i3) const
 Returns a reference to the indexed element (4-D). More...
 
template<class TLOC , typename std::enable_if< std::is_arithmetic< TLOC >::value, int >::type = 0>
YAKL_INLINE void operator= (TLOC val)
 Assign a single arithmetic value to the entire array. More...
 

Static Public Member Functions

static constexpr unsigned get_elem_count ()
 Get the total number of array elements. More...
 
static constexpr unsigned get_rank ()
 Get the number of dimensions. More...
 
static constexpr unsigned get_totElems ()
 Get the total number of array elements. More...
 
static constexpr bool initialized ()
 Always true. yakl::SArray objects are by default always initialized / allocated. More...
 
static constexpr unsigned size ()
 Get the total number of array elements. More...
 
static constexpr bool span_is_contiguous ()
 Always true. All YAKL arrays are contiguous with no padding. More...
 
static constexpr unsigned totElems ()
 Get the total number of array elements. More...
 

Friends

std::ostream & operator<< (std::ostream &os, CSArray< T, rank, D0, D1, D2, D3 > const &v)
 Print out the contents of this array. This should be called only from the host. More...
 

Detailed Description

template<class T, int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
class yakl::CSArray< T, rank, D0, D1, D2, D3 >

C-style array on the stack similar in nature to, e.g., float arr[ny][nx];

This creates a C-style "Stack Array" (CSArray) class, which is typedefined to yakl::SArray. It should be thought of as very similar to a C-style multi-dimensional array, float arr[n1][n2][n3];. That array as an SArray object would be created as yakl::SArray<float,3,n1,n2,n3> arr;, and it would be indexed as arr(i1,i2,i3);. For bounds checking, define the CPP macro YAKL_DEBUG. Dimensions sizes must be known at compile time, and data is placed on the stack of whatever context it is declared. When declared in a device parallel_for kernel, it is a thread-private array, meaning every thread has a separate copy of the array.

Parameters
TType of the yakl::SArray object
rankNumber of dimensions
D[0-3]Dimensions sizes. D1, D2, and D3 are optional template parameters

Creating these arrays is very cheap, but copying them does a deep copy every time and can be expensive. yakl::SArray objects should be indexed with zero-based indices in row-major order (right-most index varies the fastest)

Member Typedef Documentation

◆ const_value_type

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
typedef std::add_const<type>::type yakl::CSArray< T, rank, D0, D1, D2, D3 >::const_value_type

This is the type T with const added to it (if the original type has volatile, then so will this type).

◆ non_const_value_type

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
typedef std::remove_const<type>::type yakl::CSArray< T, rank, D0, D1, D2, D3 >::non_const_value_type

This is the type T with const removed from it (if the original type has volatile, then so will this type).

◆ type

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
typedef std::remove_cv<T>::type yakl::CSArray< T, rank, D0, D1, D2, D3 >::type

This is the type T without const and volatile modifiers.

◆ value_type

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
typedef T yakl::CSArray< T, rank, D0, D1, D2, D3 >::value_type

This is the type T exactly as it was defined upon array object creation.

Constructor & Destructor Documentation

◆ CSArray() [1/2]

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
YAKL_INLINE yakl::CSArray< T, rank, D0, D1, D2, D3 >::CSArray ( init_fill)
inline

No constructor arguments allowed.

◆ CSArray() [2/2]

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
yakl::CSArray< T, rank, D0, D1, D2, D3 >::CSArray ( )
default

◆ ~CSArray()

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
yakl::CSArray< T, rank, D0, D1, D2, D3 >::~CSArray ( )
default

Member Function Documentation

◆ begin()

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
YAKL_INLINE T* yakl::CSArray< T, rank, D0, D1, D2, D3 >::begin ( ) const
inline

Returns pointer to beginning of the data.

◆ data()

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
YAKL_INLINE T* yakl::CSArray< T, rank, D0, D1, D2, D3 >::data ( ) const
inline

Get the underlying raw data pointer.

◆ end()

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
YAKL_INLINE T* yakl::CSArray< T, rank, D0, D1, D2, D3 >::end ( ) const
inline

Returns pointer to end of the data.

◆ get_data()

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
YAKL_INLINE T* yakl::CSArray< T, rank, D0, D1, D2, D3 >::get_data ( ) const
inline

Get the underlying raw data pointer.

◆ get_dimensions()

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
YAKL_INLINE CSArray<uint,1,rank> yakl::CSArray< T, rank, D0, D1, D2, D3 >::get_dimensions ( ) const
inline

Returns the dimensions of this array as a yakl::SArray object.

You should use zero-based indexing on the returned SArray object.

◆ get_elem_count()

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
static constexpr unsigned yakl::CSArray< T, rank, D0, D1, D2, D3 >::get_elem_count ( )
inlinestaticconstexpr

Get the total number of array elements.

◆ get_lbounds()

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
YAKL_INLINE CSArray<uint,1,rank> yakl::CSArray< T, rank, D0, D1, D2, D3 >::get_lbounds ( ) const
inline

Returns the lower bound of each dimension of this array as a yakl::SArray object.

You should use zero-based indexing on the returned yakl::SArray object.

◆ get_rank()

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
static constexpr unsigned yakl::CSArray< T, rank, D0, D1, D2, D3 >::get_rank ( )
inlinestaticconstexpr

Get the number of dimensions.

◆ get_totElems()

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
static constexpr unsigned yakl::CSArray< T, rank, D0, D1, D2, D3 >::get_totElems ( )
inlinestaticconstexpr

Get the total number of array elements.

◆ get_ubounds()

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
YAKL_INLINE CSArray<uint,1,rank> yakl::CSArray< T, rank, D0, D1, D2, D3 >::get_ubounds ( ) const
inline

Returns the upper bound of each dimension of this array as a yakl::SArray object.

You should use zero-based indexing on the returned yakl::SArray object.

◆ initialized()

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
static constexpr bool yakl::CSArray< T, rank, D0, D1, D2, D3 >::initialized ( )
inlinestaticconstexpr

Always true. yakl::SArray objects are by default always initialized / allocated.

◆ operator()() [1/4]

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
YAKL_INLINE T& yakl::CSArray< T, rank, D0, D1, D2, D3 >::operator() ( uint const  i0) const
inline

Returns a reference to the indexed element (1-D).

Number of indices must match the rank of the array object. For bounds checking, define the CPP macro YAKL_DEBUG. Always use zero-based indexing with row-major ordering (right-most index varying the fastest).

◆ operator()() [2/4]

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
YAKL_INLINE T& yakl::CSArray< T, rank, D0, D1, D2, D3 >::operator() ( uint const  i0,
uint const  i1 
) const
inline

Returns a reference to the indexed element (2-D).

Number of indices must match the rank of the array object. For bounds checking, define the CPP macro YAKL_DEBUG. Always use zero-based indexing with row-major ordering (right-most index varying the fastest).

◆ operator()() [3/4]

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
YAKL_INLINE T& yakl::CSArray< T, rank, D0, D1, D2, D3 >::operator() ( uint const  i0,
uint const  i1,
uint const  i2 
) const
inline

Returns a reference to the indexed element (3-D).

Number of indices must match the rank of the array object. For bounds checking, define the CPP macro YAKL_DEBUG. Always use zero-based indexing with row-major ordering (right-most index varying the fastest).

◆ operator()() [4/4]

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
YAKL_INLINE T& yakl::CSArray< T, rank, D0, D1, D2, D3 >::operator() ( uint const  i0,
uint const  i1,
uint const  i2,
uint const  i3 
) const
inline

Returns a reference to the indexed element (4-D).

Number of indices must match the rank of the array object. For bounds checking, define the CPP macro YAKL_DEBUG. Always use zero-based indexing with row-major ordering (right-most index varying the fastest).

◆ operator=()

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
template<class TLOC , typename std::enable_if< std::is_arithmetic< TLOC >::value, int >::type = 0>
YAKL_INLINE void yakl::CSArray< T, rank, D0, D1, D2, D3 >::operator= ( TLOC  val)
inline

Assign a single arithmetic value to the entire array.

◆ size()

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
static constexpr unsigned yakl::CSArray< T, rank, D0, D1, D2, D3 >::size ( )
inlinestaticconstexpr

Get the total number of array elements.

◆ span_is_contiguous()

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
static constexpr bool yakl::CSArray< T, rank, D0, D1, D2, D3 >::span_is_contiguous ( )
inlinestaticconstexpr

Always true. All YAKL arrays are contiguous with no padding.

◆ totElems()

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
static constexpr unsigned yakl::CSArray< T, rank, D0, D1, D2, D3 >::totElems ( )
inlinestaticconstexpr

Get the total number of array elements.

Friends And Related Function Documentation

◆ operator<<

template<class T , int rank, unsigned D0, unsigned D1 = 1, unsigned D2 = 1, unsigned D3 = 1>
std::ostream& operator<< ( std::ostream &  os,
CSArray< T, rank, D0, D1, D2, D3 > const &  v 
)
friend

Print out the contents of this array. This should be called only from the host.


The documentation for this class was generated from the following file: