YAKL
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
yakl::FSArray< T, rank, B0, B1, B2, B3 > Class Template Reference

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

#include <YAKL_FSArray.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

 FSArray ()=default
 
YAKL_INLINE FSArray (T init_fill)
 No constructor arguments allowed. More...
 
 ~FSArray ()=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 FSArray< int, 1, SB< rank > > get_dimensions () const
 Returns the dimensions of this array as a yakl::FSArray object. More...
 
YAKL_INLINE FSArray< int, 1, SB< rank > > get_lbounds () const
 Returns the lower bound of each dimension of this array as a yakl::FSArray object. More...
 
YAKL_INLINE FSArray< int, 1, SB< rank > > get_ubounds () const
 Returns the upper bound of each dimension of this array as a yakl::FSArray object. More...
 
YAKL_INLINE T & operator() (int const i0) const
 Returns a reference to the indexed element (1-D). More...
 
YAKL_INLINE T & operator() (int const i0, int const i1) const
 Returns a reference to the indexed element (2-D). More...
 
YAKL_INLINE T & operator() (int const i0, int const i1, int const i2) const
 Returns a reference to the indexed element (3-D). More...
 
YAKL_INLINE T & operator() (int const i0, int const i1, int const i2, int 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...
 

Static Public Attributes

static constexpr unsigned OFF3 = D0*D1*D2
 

Friends

std::ostream & operator<< (std::ostream &os, FSArray 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, class B0, class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
class yakl::FSArray< T, rank, B0, B1, B2, B3 >

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

This creates a Fortran-style "Stack Array" (FSArray) class. It should be thought of as similar in nature to a C-style multi-dimensional array, float arr[n1][n2][n3];, except that it uses column-majore index ordering (left-most index varies the fastest), and it has lower bounds that default to 1 but can also be arbitrary. An example of declaring a yakl:FSArray object is yakl::FSArray<float,3,SB<n1>,SB<0,n2+1>,SB<n3>> arr; The syntax is a bit ugly, but it's necessary to allow lower bounds other than 1. The array declared just now will have lower bounds of 1, 0, and 1, respectively, and upper bounds of n1, n2+1, n3, respectively. 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::FSArray object
rankNumber of dimensions
B[0-3]Bounds for each dimensions specified using a yakl::SB class. B1, B2, and B3 are optional template parameters. Each yakl::SB object can take one or two template parameters. Specifying only one template parameter assumes a lower bound of 1. Specifying two template parameters gives the lower and upper bound (inclusive).

Creating these arrays is very cheap, but copying them does a deep copy every time and can be expensive. Remember that yakl::FSArray objects use column-major index ordering, meaning the left-most index varies the fastest.

Member Typedef Documentation

◆ const_value_type

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
typedef std::add_const<type>::type yakl::FSArray< T, rank, B0, B1, B2, B3 >::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, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
typedef std::remove_const<type>::type yakl::FSArray< T, rank, B0, B1, B2, B3 >::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, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
typedef std::remove_cv<T>::type yakl::FSArray< T, rank, B0, B1, B2, B3 >::type

This is the type T without const and volatile modifiers.

◆ value_type

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
typedef T yakl::FSArray< T, rank, B0, B1, B2, B3 >::value_type

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

Constructor & Destructor Documentation

◆ FSArray() [1/2]

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
YAKL_INLINE yakl::FSArray< T, rank, B0, B1, B2, B3 >::FSArray ( init_fill)
inline

No constructor arguments allowed.

◆ FSArray() [2/2]

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
yakl::FSArray< T, rank, B0, B1, B2, B3 >::FSArray ( )
default

◆ ~FSArray()

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
yakl::FSArray< T, rank, B0, B1, B2, B3 >::~FSArray ( )
default

Member Function Documentation

◆ begin()

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
YAKL_INLINE T* yakl::FSArray< T, rank, B0, B1, B2, B3 >::begin ( ) const
inline

Returns pointer to beginning of the data.

◆ data()

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
YAKL_INLINE T* yakl::FSArray< T, rank, B0, B1, B2, B3 >::data ( ) const
inline

Get the underlying raw data pointer.

◆ end()

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
YAKL_INLINE T* yakl::FSArray< T, rank, B0, B1, B2, B3 >::end ( ) const
inline

Returns pointer to end of the data.

◆ get_data()

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
YAKL_INLINE T* yakl::FSArray< T, rank, B0, B1, B2, B3 >::get_data ( ) const
inline

Get the underlying raw data pointer.

◆ get_dimensions()

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
YAKL_INLINE FSArray<int,1,SB<rank> > yakl::FSArray< T, rank, B0, B1, B2, B3 >::get_dimensions ( ) const
inline

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

You should use one-based indexing on the returned yakl::FSArray object.

◆ get_elem_count()

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
static constexpr unsigned yakl::FSArray< T, rank, B0, B1, B2, B3 >::get_elem_count ( )
inlinestaticconstexpr

Get the total number of array elements.

◆ get_lbounds()

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
YAKL_INLINE FSArray<int,1,SB<rank> > yakl::FSArray< T, rank, B0, B1, B2, B3 >::get_lbounds ( ) const
inline

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

You should use one-based indexing on the returned yakl::FSArray object.

◆ get_rank()

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
static constexpr unsigned yakl::FSArray< T, rank, B0, B1, B2, B3 >::get_rank ( )
inlinestaticconstexpr

Get the number of dimensions.

◆ get_totElems()

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
static constexpr unsigned yakl::FSArray< T, rank, B0, B1, B2, B3 >::get_totElems ( )
inlinestaticconstexpr

Get the total number of array elements.

◆ get_ubounds()

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
YAKL_INLINE FSArray<int,1,SB<rank> > yakl::FSArray< T, rank, B0, B1, B2, B3 >::get_ubounds ( ) const
inline

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

You should use one-based indexing on the returned yakl::FSArray object.

◆ initialized()

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
static constexpr bool yakl::FSArray< T, rank, B0, B1, B2, B3 >::initialized ( )
inlinestaticconstexpr

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

◆ operator()() [1/4]

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
YAKL_INLINE T& yakl::FSArray< T, rank, B0, B1, B2, B3 >::operator() ( int 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 one-based indexing (unless the dimension has non-default bounds) with column-major ordering (left-most index varying the fastest).

◆ operator()() [2/4]

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
YAKL_INLINE T& yakl::FSArray< T, rank, B0, B1, B2, B3 >::operator() ( int const  i0,
int 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 one-based indexing (unless the dimension has non-default bounds) with column-major ordering (left-most index varying the fastest).

◆ operator()() [3/4]

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
YAKL_INLINE T& yakl::FSArray< T, rank, B0, B1, B2, B3 >::operator() ( int const  i0,
int const  i1,
int 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 one-based indexing (unless the dimension has non-default bounds) with column-major ordering (left-most index varying the fastest).

◆ operator()() [4/4]

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
YAKL_INLINE T& yakl::FSArray< T, rank, B0, B1, B2, B3 >::operator() ( int const  i0,
int const  i1,
int const  i2,
int 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 one-based indexing (unless the dimension has non-default bounds) with column-major ordering (left-most index varying the fastest).

◆ operator=()

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
template<class TLOC , typename std::enable_if< std::is_arithmetic< TLOC >::value, int >::type = 0>
YAKL_INLINE void yakl::FSArray< T, rank, B0, B1, B2, B3 >::operator= ( TLOC  val)
inline

Assign a single arithmetic value to the entire array.

◆ size()

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
static constexpr unsigned yakl::FSArray< T, rank, B0, B1, B2, B3 >::size ( )
inlinestaticconstexpr

Get the total number of array elements.

◆ span_is_contiguous()

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
static constexpr bool yakl::FSArray< T, rank, B0, B1, B2, B3 >::span_is_contiguous ( )
inlinestaticconstexpr

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

◆ totElems()

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
static constexpr unsigned yakl::FSArray< T, rank, B0, B1, B2, B3 >::totElems ( )
inlinestaticconstexpr

Get the total number of array elements.

Friends And Related Function Documentation

◆ operator<<

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
std::ostream& operator<< ( std::ostream &  os,
FSArray< T, rank, B0, B1, B2, B3 > const &  v 
)
friend

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

Member Data Documentation

◆ OFF3

template<class T , int rank, class B0 , class B1 = SB<1>, class B2 = SB<1>, class B3 = SB<1>>
constexpr unsigned yakl::FSArray< T, rank, B0, B1, B2, B3 >::OFF3 = D0*D1*D2
staticconstexpr

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