The Kokkos array class. More...
#include <KokkosArray.h>
Public Types | |
| using | unsigned_index_type = index_type |
| using | signed_index_type = typename std::make_signed< index_type >::type |
Public Member Functions | |
| Array () | |
| Default constructor. More... | |
| Array (const Array< T, dimension, index_type, layout > &array) | |
| Copy constructor. More... | |
| template<typename... size_type> | |
| Array (size_type... n) | |
| Constructor Initialize and allocate array with given dimensions This allocates both host and device data. More... | |
| auto & | operator= (const Array< T, dimension, index_type, layout > &array) |
| Shallow copy another Kokkos array. More... | |
| KOKKOS_FUNCTION T & | operator() (const signed_index_type(&idx)[dimension]) const |
| Get an array entry using indices stored in an array. More... | |
| void | destroy () |
| Free all data and reset. More... | |
| void | shallowCopy (const ArrayBase< T, dimension, index_type > &array) |
| Shallow copy another Kokkos array. More... | |
| unsigned int | useCount () const |
| Get the reference count. More... | |
| KOKKOS_FUNCTION bool | isAlloc () const |
| Get whether the array was allocated either on host or device. More... | |
| KOKKOS_FUNCTION bool | isHostAlloc () const |
| Get whether the array was allocated on host. More... | |
| KOKKOS_FUNCTION bool | isDeviceAlloc () const |
| Get whether the array was allocated on device. More... | |
| KOKKOS_FUNCTION bool | isHostAlias () const |
| Get whether the host array was aliased. More... | |
| KOKKOS_FUNCTION bool | isDeviceAlias () const |
| Get whether the device array was aliased. More... | |
| KOKKOS_FUNCTION index_type | size () const |
| Get the total array size. More... | |
| KOKKOS_FUNCTION index_type | n (unsigned int dim) const |
| Get the size of a dimension. More... | |
| KOKKOS_FUNCTION T * | data () const |
| Get the data pointer. More... | |
| KOKKOS_FUNCTION T & | first () const |
| Get the first element. More... | |
| KOKKOS_FUNCTION T & | last () const |
| Get the last element. More... | |
| KOKKOS_FUNCTION T & | operator[] (index_type i) const |
| Get an array entry. More... | |
| T * | hostData () const |
| Get the host data pointer. More... | |
| T * | deviceData () const |
| Get the device data pointer. More... | |
| auto | hostView () const |
| Get the host unmanaged view. More... | |
| auto | deviceView () const |
| Get the device unmanaged view. More... | |
| template<typename... size_type> | |
| void | init (size_type... n) |
| Initialize array with given dimensions but do not allocate. More... | |
| template<bool initialize = true> | |
| void | create (const std::vector< index_type > &n) |
| Allocate array on host and device. More... | |
| template<bool initialize = true, typename... size_type> | |
| void | create (size_type... n) |
| Allocate array on host and device. More... | |
| template<bool initialize = true> | |
| void | createHost (const std::vector< index_type > &n) |
| Allocate array on host only. More... | |
| template<bool initialize = true, typename... size_type> | |
| void | createHost (size_type... n) |
| Allocate array on host only. More... | |
| void | createDevice (const std::vector< index_type > &n) |
| Allocate array on device only. More... | |
| template<typename... size_type> | |
| void | createDevice (size_type... n) |
| Allocate array on device only. More... | |
| void | aliasHost (T *ptr) |
| Point the host data to an external data instead of allocating it. More... | |
| void | aliasDevice (T *ptr) |
| Point the device data to an external data instead of allocating it. More... | |
| void | offset (const std::vector< signed_index_type > &d) |
| Apply starting index offsets to each dimension. More... | |
| template<typename... offset_type> | |
| void | offset (offset_type... d) |
| Apply starting index offsets to each dimension. More... | |
| void | copyToDevice () |
| Copy data from host to device. More... | |
| void | copyToHost () |
| Copy data from device to host. More... | |
| void | copyIn (const T *ptr, MemcpyType dir, index_type n, index_type offset=0) |
| Copy data from an external data to this array. More... | |
| void | copyOut (T *ptr, MemcpyType dir, index_type n, index_type offset=0) |
| Copy data to an external data from this array. More... | |
| void | copyToDeviceNested () |
| Copy all the nested Kokkos arrays including self from host to device. More... | |
| void | moveToDevice (bool should_free_host=true) |
| Copy data from host to device and deallocate host. More... | |
| void | moveToHost (bool should_free_device=true) |
| Copy data from device to host and deallocate device. More... | |
| void | deepCopy (const ArrayBase< T, dimension, index_type > &array) |
| Deep copy another Kokkos array If ArrayDeepCopy<T>::value is true, it will copy-construct each entry If ArrayDeepCopy<T>::value is false, it will do a memory copy. More... | |
| void | swap (ArrayBase< T, dimension, index_type > &array) |
| Swap with another Kokkos array. More... | |
| KOKKOS_FUNCTION iterator | begin () const |
| Get the beginning iterator. More... | |
| KOKKOS_FUNCTION iterator | end () const |
| Get the end iterator. More... | |
| template<typename... indices> | |
| KOKKOS_FUNCTION T & | operator() (indices... i) const |
| Get an array entry. More... | |
Protected Member Functions | |
| template<bool host, bool device, bool initialize, typename... size_type> | |
| void | createInternal (size_type... n) |
| The internal method to initialize and allocate this array. More... | |
| template<bool host, bool device, bool initialize> | |
| void | createInternal (const std::vector< index_type > &n) |
| The internal method to initialize and allocate this array. More... | |
| template<bool initialize> | |
| void | createInternal (const std::vector< index_type > &n, bool host, bool device) |
| The internal method to initialize and allocate this array. More... | |
| template<typename TargetSpace , typename SourceSpace > | |
| void | copyInternal (T *target, const T *source, index_type n) |
| The internal method to perform a memory copy. More... | |
Protected Attributes | |
| index_type | _n [dimension] = {0} |
| Size of each dimension. More... | |
| index_type | _s [dimension] = {0} |
| Stride of each dimension. More... | |
| signed_index_type | _d [dimension] = {0} |
| Offset of each dimension. More... | |
| bool | _is_offset = false |
| Flag whether the array indices are offset. More... | |
| bool | _is_malloc = false |
| Flag whether host data was allocated using malloc. More... | |
Private Member Functions | |
| usingKokkosArrayBaseMembers (T, dimension, index_type) | |
| template<unsigned int... i> | |
| KOKKOS_FUNCTION T & | operatorInternal (const signed_index_type(&idx)[dimension], std::integer_sequence< unsigned int, i... >) const |
| Internal method for calling operator() with array indices. More... | |
The Kokkos array class.
The specialization of the Kokkos array class for each dimension.
All array data that needs to be accessed on device in Kokkos objects should use this class. If the array is populated on host and is to be accessed on device, make sure to call copyToDevice() after populating data. For a nested Kokkos array, either copyToDeviceNested() should be called for the outermost array or copyToDevice() should be called for each instance of Kokkos array from the innermost to the outermost. Do not store this object as reference in your Kokkos object if it is used on device, because the reference refers to a host object and therefore is not accessible on device. If storing it as a reference is required, see ReferenceWrapper.
| T | The data type |
| dimension | The array dimension size |
| index_type | The array index type |
| layout | The memory layout type |
Definition at line 64 of file KokkosArray.h.
|
inherited |
Definition at line 114 of file KokkosArray.h.
|
inherited |
Definition at line 113 of file KokkosArray.h.
|
inline |
Default constructor.
Definition at line 1362 of file KokkosArray.h.
|
inline |
Copy constructor.
Definition at line 1366 of file KokkosArray.h.
|
inline |
Constructor Initialize and allocate array with given dimensions This allocates both host and device data.
| n | The size of each dimension |
Definition at line 1378 of file KokkosArray.h.
|
inherited |
Point the device data to an external data instead of allocating it.
| ptr | The pointer to the external device data |
Definition at line 760 of file KokkosArray.h.
|
inherited |
Point the host data to an external data instead of allocating it.
| ptr | The pointer to the external host data |
Definition at line 745 of file KokkosArray.h.
|
inlineinherited |
Get the beginning iterator.
Definition at line 479 of file KokkosArray.h.
Referenced by Moose::Kokkos::Array< T, 1, index_type, LayoutType::LEFT >::copySet().
|
inherited |
Copy data from an external data to this array.
| ptr | The pointer to the external data |
| dir | The copy direction |
| n | The number of entries to copy |
| offset | The starting offset of this array |
Definition at line 1028 of file KokkosArray.h.
Referenced by Moose::Kokkos::dataLoad().
|
protectedinherited |
The internal method to perform a memory copy.
| TargetSpace | The Kokkos memory space of target data |
| Sourcespace | The Kokkos memory space of source data |
| target | The pointer to the target data |
| source | The pointer to the source data |
| n | The number of entries to copy |
Definition at line 907 of file KokkosArray.h.
|
inherited |
Copy data to an external data from this array.
| ptr | The pointer to the external data |
| dir | The copy direction |
| n | The number of entries to copy |
| offset | The starting offset of this array |
Definition at line 1083 of file KokkosArray.h.
Referenced by Moose::Kokkos::dataStore().
|
inherited |
Copy data from host to device.
Definition at line 947 of file KokkosArray.h.
Referenced by Moose::Kokkos::VariableGradientTempl< is_ad >::VariableGradientTempl(), and Moose::Kokkos::VariableValueTempl< is_ad >::VariableValueTempl().
|
inherited |
Copy all the nested Kokkos arrays including self from host to device.
Definition at line 1151 of file KokkosArray.h.
Referenced by Moose::Kokkos::copyToDeviceInner().
|
inherited |
Copy data from device to host.
Definition at line 972 of file KokkosArray.h.
|
inlineinherited |
Allocate array on host and device.
| initialize | Whether to initialize host data (calls default constructor) |
| n | The vector containing the size of each dimension |
Definition at line 303 of file KokkosArray.h.
Referenced by Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::ArrayBase(), Moose::Kokkos::VariableGradientTempl< is_ad >::VariableGradientTempl(), and Moose::Kokkos::VariableValueTempl< is_ad >::VariableValueTempl().
|
inlineinherited |
Allocate array on host and device.
| initialize | Whether to initialize host data (calls default constructor) |
| n | The size of each dimension |
Definition at line 313 of file KokkosArray.h.
|
inlineinherited |
Allocate array on device only.
| n | The vector containing the size of each dimension |
Definition at line 341 of file KokkosArray.h.
|
inlineinherited |
Allocate array on device only.
| n | The size of each dimension |
Definition at line 347 of file KokkosArray.h.
|
inlineinherited |
Allocate array on host only.
| initialize | Whether to initialize host data (calls default constructor) |
| n | The vector containing the size of each dimension |
Definition at line 323 of file KokkosArray.h.
|
inlineinherited |
Allocate array on host only.
| initialize | Whether to initialize host data (calls default constructor) |
| n | The size of each dimension |
Definition at line 333 of file KokkosArray.h.
|
protectedinherited |
The internal method to initialize and allocate this array.
| host | Whether host data will be allocated |
| device | Whether device data will be allocated |
| initialize | Whether to initialize host data (calls default constructor) |
| n | The size of each dimension |
Definition at line 892 of file KokkosArray.h.
|
protectedinherited |
The internal method to initialize and allocate this array.
| host | Whether host data will be allocated |
| device | Whether device data will be allocated |
| initialize | Whether to initialize host data (calls default constructor) |
| n | The vector containing the size of each dimension |
Definition at line 812 of file KokkosArray.h.
|
protectedinherited |
The internal method to initialize and allocate this array.
| initialize | Whether to initialize host data (calls default constructor) |
| n | The vector containing the size of each dimension |
| host | The flag whether host data will be allocated |
| device | The flag whether device data will be allocated |
Definition at line 875 of file KokkosArray.h.
|
inlineinherited |
Get the data pointer.
Definition at line 217 of file KokkosArray.h.
Referenced by Moose::Kokkos::Matrix::find().
|
inherited |
Deep copy another Kokkos array If ArrayDeepCopy<T>::value is true, it will copy-construct each entry If ArrayDeepCopy<T>::value is false, it will do a memory copy.
| array | The Kokkos array to be deep copied |
Definition at line 1161 of file KokkosArray.h.
Referenced by Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::ArrayBase().
|
inherited |
Free all data and reset.
Definition at line 674 of file KokkosArray.h.
Referenced by Moose::Kokkos::System::clearActiveMatrixTags(), Moose::Kokkos::System::clearActiveResidualTags(), Moose::Kokkos::System::clearActiveSolutionTags(), Moose::Kokkos::System::clearActiveVariables(), and Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::~ArrayBase().
|
inlineinherited |
Get the device data pointer.
Definition at line 269 of file KokkosArray.h.
Referenced by Moose::Kokkos::Array< T, 1, index_type, LayoutType::LEFT >::copyVector().
|
inlineinherited |
Get the device unmanaged view.
Definition at line 283 of file KokkosArray.h.
|
inlineinherited |
Get the end iterator.
Definition at line 489 of file KokkosArray.h.
Referenced by Moose::Kokkos::Array< T, 1, index_type, LayoutType::LEFT >::copySet().
|
inlineinherited |
Get the first element.
Definition at line 228 of file KokkosArray.h.
Referenced by Moose::Kokkos::RPNEvaluator::eval().
|
inlineinherited |
Get the host data pointer.
Definition at line 264 of file KokkosArray.h.
Referenced by Moose::Kokkos::Array< T, 1, index_type, LayoutType::LEFT >::copyVector().
|
inlineinherited |
Get the host unmanaged view.
Definition at line 274 of file KokkosArray.h.
|
inlineinherited |
Initialize array with given dimensions but do not allocate.
| n | The size of each dimension |
Definition at line 293 of file KokkosArray.h.
|
inlineinherited |
Get whether the array was allocated either on host or device.
Definition at line 180 of file KokkosArray.h.
Referenced by Moose::Kokkos::dataStore(), Moose::Kokkos::VariableGradientTempl< is_ad >::VariableGradientTempl(), and Moose::Kokkos::VariableValueTempl< is_ad >::VariableValueTempl().
|
inlineinherited |
Get whether the device array was aliased.
Definition at line 200 of file KokkosArray.h.
|
inlineinherited |
Get whether the array was allocated on device.
Definition at line 190 of file KokkosArray.h.
Referenced by Moose::Kokkos::dataStore().
|
inlineinherited |
Get whether the host array was aliased.
Definition at line 195 of file KokkosArray.h.
|
inlineinherited |
Get whether the array was allocated on host.
Definition at line 185 of file KokkosArray.h.
Referenced by Moose::Kokkos::dataLoad().
|
inlineinherited |
Get the last element.
Definition at line 239 of file KokkosArray.h.
|
inherited |
Copy data from host to device and deallocate host.
| should_free_host | Whether the host memory should be freed. Host memory cannot be freed when there are shallow copies of this array that are still alive. If should_free_host is true, and we cannot free for above reason, it will error. |
Definition at line 997 of file KokkosArray.h.
Referenced by Moose::Kokkos::JaggedArray< T, inner, outer, index_type, layout >::moveToDevice().
|
inherited |
Copy data from device to host and deallocate device.
| should_free_device | Whether the device memory should be freed. Device memory cannot be freed when there are shallow copies of this array that are still alive. If should_free_device is true, and we cannot free for above reason, it will error. |
Definition at line 1014 of file KokkosArray.h.
Referenced by Moose::Kokkos::JaggedArray< T, inner, outer, index_type, layout >::moveToHost().
|
inlineinherited |
Get the size of a dimension.
| dim | The dimension index |
Definition at line 211 of file KokkosArray.h.
Referenced by Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::ArrayBase(), Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::create(), Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::createDevice(), Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::createHost(), Moose::Kokkos::dataLoad(), Moose::Kokkos::dataStore(), Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::init(), Moose::Kokkos::MaterialPropertyValueBase< T, 0 >::n(), and Moose::Kokkos::JaggedArray< T, inner, outer, index_type, layout >::n().
|
inherited |
Apply starting index offsets to each dimension.
| d | The vector containing the offset of each dimension |
Definition at line 915 of file KokkosArray.h.
|
inherited |
Apply starting index offsets to each dimension.
| d | The offset of each dimension |
Definition at line 933 of file KokkosArray.h.
| KOKKOS_FUNCTION T & Moose::Kokkos::Array< T, dimension, index_type, layout >::operator() | ( | indices... | i | ) | const |
Get an array entry.
| i | The index of each dimension |
Definition at line 1433 of file KokkosArray.h.
Referenced by Moose::Kokkos::Array< ContiguousElementID >::operatorInternal().
|
inline |
Get an array entry using indices stored in an array.
| idx | The array storing the indices |
Definition at line 1409 of file KokkosArray.h.
|
inline |
Shallow copy another Kokkos array.
| array | The Kokkos array to be shallow copied |
Definition at line 1387 of file KokkosArray.h.
|
inlineinherited |
Get an array entry.
| i | The dimensionless index |
Definition at line 251 of file KokkosArray.h.
Referenced by Moose::Kokkos::Array< T, 1, index_type, LayoutType::LEFT >::operator()().
|
inlineprivate |
Internal method for calling operator() with array indices.
Definition at line 1421 of file KokkosArray.h.
Referenced by Moose::Kokkos::Array< ContiguousElementID >::operator()().
|
inherited |
Shallow copy another Kokkos array.
| array | The Kokkos array to be shallow copied |
Definition at line 712 of file KokkosArray.h.
Referenced by Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::ArrayBase(), Moose::Kokkos::Array< ContiguousElementID >::operator=(), Moose::Kokkos::Array< T, 1, index_type, LayoutType::LEFT >::operator=(), and Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::swap().
|
inlineinherited |
Get the total array size.
Definition at line 205 of file KokkosArray.h.
Referenced by Moose::Kokkos::ResidualObject::accumulateTaggedElementalMatrix(), Moose::Kokkos::ResidualObject::accumulateTaggedElementalResidual(), Moose::Kokkos::ResidualObject::accumulateTaggedNodalMatrix(), Moose::Kokkos::ResidualObject::accumulateTaggedNodalResidual(), Moose::Kokkos::Array< T, 1, index_type, LayoutType::LEFT >::copyVector(), Moose::Kokkos::dataLoad(), Moose::Kokkos::dataStore(), KokkosPiecewiseBase::functionSize(), Moose::Kokkos::Variable::mooseVar(), Moose::Kokkos::JaggedArray< T, inner, outer, index_type, layout >::n(), BlockRestrictable::numKokkosBlockElements(), BlockRestrictable::numKokkosBlockNodes(), BlockRestrictable::numKokkosBlockSides(), BoundaryRestrictable::numKokkosBoundaryNodes(), BoundaryRestrictable::numKokkosBoundarySides(), Moose::Kokkos::MaterialBase::numKokkosElements(), Moose::Kokkos::Vector::operator()(), Moose::Kokkos::Vector::operator[](), Moose::Kokkos::MapBase< unsigned int, unsigned int >::size(), and KokkosBoundNodalKernel::skipOnBoundary().
|
inherited |
Swap with another Kokkos array.
| array | The Kokkos array to be swapped |
Definition at line 1201 of file KokkosArray.h.
|
inlineinherited |
Get the reference count.
Definition at line 173 of file KokkosArray.h.
|
private |
|
protectedinherited |
Offset of each dimension.
Definition at line 509 of file KokkosArray.h.
Referenced by Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::deepCopy(), Moose::Kokkos::Array< T, 1, index_type, LayoutType::LEFT >::operator()(), and Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::shallowCopy().
|
protectedinherited |
Flag whether host data was allocated using malloc.
Definition at line 517 of file KokkosArray.h.
Referenced by Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::shallowCopy().
|
protectedinherited |
Flag whether the array indices are offset.
Definition at line 513 of file KokkosArray.h.
Referenced by Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::deepCopy(), Moose::Kokkos::Array< T, 1, index_type, LayoutType::LEFT >::operator()(), and Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::shallowCopy().
|
protectedinherited |
Size of each dimension.
Definition at line 501 of file KokkosArray.h.
Referenced by Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::deepCopy(), Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::n(), Moose::Kokkos::Array< T, 1, index_type, LayoutType::LEFT >::operator()(), and Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::shallowCopy().
|
protectedinherited |
Stride of each dimension.
Definition at line 505 of file KokkosArray.h.
Referenced by Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::deepCopy(), and Moose::Kokkos::ArrayBase< Moose::Kokkos::RPNEvaluator::Instruction, dimension, index_type >::shallowCopy().
1.8.14