YAKL
Classes | Public Types | Public Member Functions | Public Attributes | Friends | List of all members
yakl::ArrayBase< T, rank, myMem, myStyle > Class Template Reference

This class implements functionality common to both yakl::styleC and yakl::styleFortran Array objects. More...

#include <YAKL_ArrayBase.h>

Collaboration diagram for yakl::ArrayBase< T, rank, myMem, myStyle >:
Collaboration graph
[legend]

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

void add_stream_dependencies (std::vector< Stream > streams)
 Declare a dependencies on the multiple streams at one time. More...
 
void add_stream_dependency (Stream stream)
 Declare a dependency on the passed stream. More...
 
YAKL_INLINE T * begin () const
 Returns pointer to beginning of the data. More...
 
YAKL_INLINE T * data () const
 Returns the raw data pointer of this array object. More...
 
template<class TLOC = T, typename std::enable_if< std::is_const< TLOC >::value, int >::type = 0>
void deallocate ()
 If owned, decrement the reference counter; if ref counter reaches zero, deallocate memory; If non-owned, does nothing. More...
 
template<class TLOC = T, typename std::enable_if< ! std::is_const< TLOC >::value, int >::type = 0>
void deallocate ()
 If owned, decrement the reference counter; if ref counter reaches zero, deallocate memory; If non-owned, does nothing. More...
 
template<int theirRank, int theirStyle>
void deep_copy_to (Array< typename std::remove_cv< T >::type, theirRank, memDevice, theirStyle > const &lhs, Stream stream=Stream()) const
 [ASYNCHRONOUS] [DEEP_COPY] Copy this array's contents to a yakl::memDevice array. More...
 
template<int theirRank, int theirStyle>
void deep_copy_to (Array< typename std::remove_cv< T >::type, theirRank, memHost, theirStyle > const &lhs, Stream stream=Stream()) const
 [ASYNCHRONOUS] [DEEP_COPY] Copy this array's contents to a yakl::memHost array. More...
 
YAKL_INLINE T * end () const
 Returns pointer to end of the data. More...
 
YAKL_INLINE T * get_data () const
 Returns the raw data pointer of this array object. More...
 
YAKL_INLINE index_t get_elem_count () const
 Returns the total number of elements in this array object. More...
 
YAKL_INLINE int get_memory_space () const
 Returns this array object's string label if the YAKL_DEBUG CPP macro is defined. Otherwise, returns an empty string. More...
 
YAKL_INLINE int get_rank () const
 Returns the number of dimensions in this array object. More...
 
YAKL_INLINE index_t get_totElems () const
 Returns the total number of elements in this array object. More...
 
YAKL_INLINE bool initialized () const
 Returns whether this array object has is in an initialized / allocated state. More...
 
const char * label () const
 
YAKL_INLINE index_t size () const
 Returns the total number of elements in this array object. More...
 
YAKL_INLINE bool span_is_contiguous () const
 Always true. yakl::Array objects are always contiguous in memory with no padding. More...
 
YAKL_INLINE index_t totElems () const
 Returns the total number of elements in this array object. More...
 
int use_count () const
 Returns how many array objects share this pointer if owned; or 0 if unowned. More...
 

Public Attributes

StreamListDummy stream_dependencies
 

Friends

std::ostream & operator<< (std::ostream &os, Array< T, rank, myMem, myStyle > const &v)
 Allows the user to std::cout << this_array_object;. This works even for yakl::memDevice array objects. More...
 

Detailed Description

template<class T, int rank, int myMem, int myStyle>
class yakl::ArrayBase< T, rank, myMem, myStyle >

This class implements functionality common to both yakl::styleC and yakl::styleFortran Array objects.

Parameters
TType of the array. For yakl::memHost array objects, this can generally be any type. For yakl::memDevice array objects, this needs to be a type without a constructor, preferrably an arithmetic type.
rankThe number of dimensions for this array object.
myMemThe memory space for this array object: Either yakl::memHost or yakl::memDevice
myStyleThe behavior of this array object: Either yakl::styleC or yakl::styleFortran

Member Typedef Documentation

◆ const_value_type

template<class T , int rank, int myMem, int myStyle>
typedef std::add_const<type>::type yakl::ArrayBase< T, rank, myMem, myStyle >::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, int myMem, int myStyle>
typedef std::remove_const<type>::type yakl::ArrayBase< T, rank, myMem, myStyle >::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, int myMem, int myStyle>
typedef std::remove_cv<T>::type yakl::ArrayBase< T, rank, myMem, myStyle >::type

This is the type T without const and volatile modifiers.

◆ value_type

template<class T , int rank, int myMem, int myStyle>
typedef T yakl::ArrayBase< T, rank, myMem, myStyle >::value_type

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

Member Function Documentation

◆ add_stream_dependencies()

template<class T , int rank, int myMem, int myStyle>
void yakl::ArrayBase< T, rank, myMem, myStyle >::add_stream_dependencies ( std::vector< Stream streams)
inline

Declare a dependencies on the multiple streams at one time.

Upon deallocation, an event is placed in each stream this array depends on. The data pointer is not released from the pool until all dependent events complete. This avoids potential pointer aliasing of Arrays potentially being used simultaneous in different parallel streams. The pool allocator is non-blocking, so erroneous aliasing can occur if the user uses multiple streams, deallocates and allocates during runtime, and does not use this function.

◆ add_stream_dependency()

template<class T , int rank, int myMem, int myStyle>
void yakl::ArrayBase< T, rank, myMem, myStyle >::add_stream_dependency ( Stream  stream)
inline

Declare a dependency on the passed stream.

Upon deallocation, an event is placed in each stream this array depends on. The data pointer is not released from the pool until all dependent events complete. This avoids potential pointer aliasing of Arrays potentially being used simultaneous in different parallel streams. The pool allocator is non-blocking, so erroneous aliasing can occur if the user uses multiple streams, deallocates and allocates during runtime, and does not use this function.

◆ begin()

template<class T , int rank, int myMem, int myStyle>
YAKL_INLINE T* yakl::ArrayBase< T, rank, myMem, myStyle >::begin ( ) const
inline

Returns pointer to beginning of the data.

◆ data()

template<class T , int rank, int myMem, int myStyle>
YAKL_INLINE T* yakl::ArrayBase< T, rank, myMem, myStyle >::data ( ) const
inline

Returns the raw data pointer of this array object.

◆ deallocate() [1/2]

template<class T , int rank, int myMem, int myStyle>
template<class TLOC = T, typename std::enable_if< std::is_const< TLOC >::value, int >::type = 0>
void yakl::ArrayBase< T, rank, myMem, myStyle >::deallocate ( )
inline

If owned, decrement the reference counter; if ref counter reaches zero, deallocate memory; If non-owned, does nothing.

If the reference counter reaches zero, meaning no other array objects are sharing this data pointer, the deallocate the data. This routine has the same effect as assigning this array object to an empty array object. This is safe to call even if this array object is not yet allocated.

◆ deallocate() [2/2]

template<class T , int rank, int myMem, int myStyle>
template<class TLOC = T, typename std::enable_if< ! std::is_const< TLOC >::value, int >::type = 0>
void yakl::ArrayBase< T, rank, myMem, myStyle >::deallocate ( )
inline

If owned, decrement the reference counter; if ref counter reaches zero, deallocate memory; If non-owned, does nothing.

If the reference counter reaches zero, meaning no other array objects are sharing this data pointer, the deallocate the data. This routine has the same effect as assigning this array object to an empty array object. This is safe to call even if this array object is not yet allocated.

◆ deep_copy_to() [1/2]

template<class T , int rank, int myMem, int myStyle>
template<int theirRank, int theirStyle>
void yakl::ArrayBase< T, rank, myMem, myStyle >::deep_copy_to ( Array< typename std::remove_cv< T >::type, theirRank, memDevice, theirStyle > const &  lhs,
Stream  stream = Stream() 
) const
inline

[ASYNCHRONOUS] [DEEP_COPY] Copy this array's contents to a yakl::memDevice array.

Arrays must have the same type and total number of elements. No checking of rank, style, or dimensionality is performed. Both arrays must be allocated. this array may be in yakl::memHost or yakl::memDevice space.

◆ deep_copy_to() [2/2]

template<class T , int rank, int myMem, int myStyle>
template<int theirRank, int theirStyle>
void yakl::ArrayBase< T, rank, myMem, myStyle >::deep_copy_to ( Array< typename std::remove_cv< T >::type, theirRank, memHost, theirStyle > const &  lhs,
Stream  stream = Stream() 
) const
inline

[ASYNCHRONOUS] [DEEP_COPY] Copy this array's contents to a yakl::memHost array.

Arrays must have the same type and total number of elements. No checking of rank, style, or dimensionality is performed. Both arrays must be allocated. this array may be in yakl::memHost or yakl::memDevice space.

◆ end()

template<class T , int rank, int myMem, int myStyle>
YAKL_INLINE T* yakl::ArrayBase< T, rank, myMem, myStyle >::end ( ) const
inline

Returns pointer to end of the data.

◆ get_data()

template<class T , int rank, int myMem, int myStyle>
YAKL_INLINE T* yakl::ArrayBase< T, rank, myMem, myStyle >::get_data ( ) const
inline

Returns the raw data pointer of this array object.

◆ get_elem_count()

template<class T , int rank, int myMem, int myStyle>
YAKL_INLINE index_t yakl::ArrayBase< T, rank, myMem, myStyle >::get_elem_count ( ) const
inline

Returns the total number of elements in this array object.

◆ get_memory_space()

template<class T , int rank, int myMem, int myStyle>
YAKL_INLINE int yakl::ArrayBase< T, rank, myMem, myStyle >::get_memory_space ( ) const
inline

Returns this array object's string label if the YAKL_DEBUG CPP macro is defined. Otherwise, returns an empty string.

◆ get_rank()

template<class T , int rank, int myMem, int myStyle>
YAKL_INLINE int yakl::ArrayBase< T, rank, myMem, myStyle >::get_rank ( ) const
inline

Returns the number of dimensions in this array object.

◆ get_totElems()

template<class T , int rank, int myMem, int myStyle>
YAKL_INLINE index_t yakl::ArrayBase< T, rank, myMem, myStyle >::get_totElems ( ) const
inline

Returns the total number of elements in this array object.

◆ initialized()

template<class T , int rank, int myMem, int myStyle>
YAKL_INLINE bool yakl::ArrayBase< T, rank, myMem, myStyle >::initialized ( ) const
inline

Returns whether this array object has is in an initialized / allocated state.

◆ label()

template<class T , int rank, int myMem, int myStyle>
const char* yakl::ArrayBase< T, rank, myMem, myStyle >::label ( ) const
inline

◆ size()

template<class T , int rank, int myMem, int myStyle>
YAKL_INLINE index_t yakl::ArrayBase< T, rank, myMem, myStyle >::size ( ) const
inline

Returns the total number of elements in this array object.

◆ span_is_contiguous()

template<class T , int rank, int myMem, int myStyle>
YAKL_INLINE bool yakl::ArrayBase< T, rank, myMem, myStyle >::span_is_contiguous ( ) const
inline

Always true. yakl::Array objects are always contiguous in memory with no padding.

◆ totElems()

template<class T , int rank, int myMem, int myStyle>
YAKL_INLINE index_t yakl::ArrayBase< T, rank, myMem, myStyle >::totElems ( ) const
inline

Returns the total number of elements in this array object.

◆ use_count()

template<class T , int rank, int myMem, int myStyle>
int yakl::ArrayBase< T, rank, myMem, myStyle >::use_count ( ) const
inline

Returns how many array objects share this pointer if owned; or 0 if unowned.

Returns the use count for this array object's data pointer. I.e., this is how many yakl::Array objects currently share this data pointer. If this returns a value of 0, that means that this array object is not being reference counted, meaning it performed no allocation upon creation, will perform no deallocation upon destruction, and has no control over whether the memory pointed to by the data pointer stays allocated or not.

Friends And Related Function Documentation

◆ operator<<

template<class T , int rank, int myMem, int myStyle>
std::ostream& operator<< ( std::ostream &  os,
Array< T, rank, myMem, myStyle > const &  v 
)
friend

Allows the user to std::cout << this_array_object;. This works even for yakl::memDevice array objects.

Member Data Documentation

◆ stream_dependencies

template<class T , int rank, int myMem, int myStyle>
StreamListDummy yakl::ArrayBase< T, rank, myMem, myStyle >::stream_dependencies

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