https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
Moose::Kokkos::ArrayBase< T, dimension, index_type > Class Template Reference

The base class for Kokkos arrays. More...

#include <KokkosArray.h>

Inheritance diagram for Moose::Kokkos::ArrayBase< T, dimension, index_type >:
[legend]

Classes

class  constructed_entry_iterator
 Iterator over tracked constructed entries. More...
 
class  constructed_entry_range
 Range over tracked constructed entries. More...
 
class  iterator
 Array iterator. More...
 

Public Types

using unsigned_index_type = index_type
 
using signed_index_type = typename std::make_signed< index_type >::type
 

Public Member Functions

 ArrayBase (const LayoutType layout)
 Constructor.
 
template<typename... size_type>
 ArrayBase (const LayoutType layout, size_type... n)
 Constructor Initialize and allocate array with given dimensions This allocates both host and device data.
 
 ArrayBase (const ArrayBase< T, dimension, index_type > &array)
 Copy constructor.
 
 ~ArrayBase ()
 Destructor.
 
void destroy ()
 Free all data and reset.
 
void shallowCopy (const ArrayBase< T, dimension, index_type > &array)
 Shallow copy another Kokkos array.
 
unsigned int useCount () const
 Get the reference count.
 
bool isSlotConstructed (index_type i) const
 Get whether slot i is tracked as constructed.
 
constructed_entry_range< false > constructedEntries ()
 Get host-side range over entries tracked as constructed.
 
constructed_entry_range< true > constructedEntries () const
 Get host-side range over entries tracked as constructed.
 
KOKKOS_FUNCTION bool isAlloc () const
 Get whether the array was allocated either on host or device.
 
KOKKOS_FUNCTION bool isHostAlloc () const
 Get whether the array was allocated on host.
 
KOKKOS_FUNCTION bool isDeviceAlloc () const
 Get whether the array was allocated on device.
 
KOKKOS_FUNCTION bool isHostAlias () const
 Get whether the host array was aliased.
 
KOKKOS_FUNCTION bool isDeviceAlias () const
 Get whether the device array was aliased.
 
KOKKOS_FUNCTION index_type size () const
 Get the total array size.
 
KOKKOS_FUNCTION index_type n (unsigned int dim) const
 Get the size of a dimension.
 
KOKKOS_FUNCTION T * data () const
 Get the data pointer.
 
KOKKOS_FUNCTION T & first () const
 Get the first element.
 
KOKKOS_FUNCTION T & last () const
 Get the last element.
 
KOKKOS_FUNCTION T & operator[] (index_type i) const
 Get an array entry.
 
T * hostData () const
 Get the host data pointer.
 
T * deviceData () const
 Get the device data pointer.
 
auto hostView () const
 Get the host unmanaged view.
 
auto deviceView () const
 Get the device unmanaged view.
 
template<typename... size_type>
void init (size_type... n)
 Initialize array with given dimensions but do not allocate.
 
template<bool initialize = true>
void create (const std::vector< index_type > &n)
 Allocate array on host and device.
 
template<bool initialize = true, typename... size_type>
void create (size_type... n)
 Allocate array on host and device.
 
template<bool initialize = true>
void createHost (const std::vector< index_type > &n)
 Allocate array on host only.
 
template<bool initialize = true, typename... size_type>
void createHost (size_type... n)
 Allocate array on host only.
 
void createDevice (const std::vector< index_type > &n)
 Allocate array on device only.
 
template<typename... size_type>
void createDevice (size_type... n)
 Allocate array on device only.
 
void aliasHost (T *ptr)
 Point the host data to an external data instead of allocating it.
 
void aliasDevice (T *ptr)
 Point the device data to an external data instead of allocating it.
 
void offset (const std::vector< signed_index_type > &d)
 Apply starting index offsets to each dimension.
 
template<typename... offset_type>
void offset (offset_type... d)
 Apply starting index offsets to each dimension.
 
void copyToDevice ()
 Copy data from host to device.
 
void copyToHost ()
 Copy data from device to host.
 
void copyIn (const T *ptr, MemcpyType dir, index_type n, index_type offset=0)
 Copy data from an external data to this array.
 
void copyOut (T *ptr, MemcpyType dir, index_type n, index_type offset=0)
 Copy data to an external data from this array.
 
void copyToDeviceNested ()
 Copy all the nested Kokkos arrays including self from host to device.
 
void moveToDevice (bool should_free_host=true)
 Copy data from host to device and deallocate host.
 
void moveToHost (bool should_free_device=true)
 Copy data from device to host and deallocate device.
 
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.
 
void swap (ArrayBase< T, dimension, index_type > &array)
 Swap with another Kokkos array.
 
auto & operator= (const T &scalar)
 Assign a scalar value uniformly.
 
KOKKOS_FUNCTION iterator begin () const
 Get the beginning iterator.
 
KOKKOS_FUNCTION iterator end () const
 Get the end iterator.
 

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.
 
template<bool host, bool device, bool initialize>
void createInternal (const std::vector< index_type > &n)
 The internal method to initialize and allocate this array.
 
template<bool initialize>
void createInternal (const std::vector< index_type > &n, bool host, bool device)
 The internal method to initialize and allocate this array.
 
template<typename TargetSpace , typename SourceSpace >
void copyInternal (T *target, const T *source, index_type n)
 The internal method to perform a memory copy.
 
template<typename... Args>
T & emplaceAt (index_type i, Args &&... args)
 Placement-new construct slot i from args, recording initialization.
 

Protected Attributes

index_type _n [dimension] = {0}
 Size of each dimension.
 
index_type _s [dimension] = {0}
 Stride of each dimension.
 
signed_index_type _d [dimension] = {0}
 Offset of each dimension.
 

Private Member Functions

template<bool initialize>
void allocHost ()
 Allocate host data for an initialized array that has not allocated host data.
 
void allocDevice ()
 Allocate device data for an initialized array that has not allocated device data.
 
void freeHost ()
 Free host data.
 
void freeDevice ()
 Free device data.
 

Private Attributes

std::shared_ptr< unsigned int_counter
 Reference counter.
 
std::shared_ptr< std::vector< bool > > _slots_constructed
 Non-null only for malloc-allocated arrays; tracks which slots have been emplace-constructed.
 
bool _is_init = false
 Flag whether array was initialized.
 
bool _is_host_alloc = false
 Flag whether host data was allocated.
 
bool _is_device_alloc = false
 Flag whether device data was allocated.
 
bool _is_host_alias = false
 Flag whether the host data points to an external data.
 
bool _is_device_alias = false
 Flag whether the device data points to an external data.
 
T * _host_data = nullptr
 Host data.
 
T * _device_data = nullptr
 Device data.
 
index_type _size = 0
 Total size.
 
const LayoutType _layout
 Memory layout type.
 

Detailed Description

template<typename T, unsigned int dimension, typename index_type>
class Moose::Kokkos::ArrayBase< T, dimension, index_type >

The base class for Kokkos arrays.

Definition at line 107 of file KokkosArray.h.

Member Typedef Documentation

◆ signed_index_type

template<typename T , unsigned int dimension, typename index_type >
using Moose::Kokkos::ArrayBase< T, dimension, index_type >::signed_index_type = typename std::make_signed<index_type>::type

Definition at line 115 of file KokkosArray.h.

◆ unsigned_index_type

template<typename T , unsigned int dimension, typename index_type >
using Moose::Kokkos::ArrayBase< T, dimension, index_type >::unsigned_index_type = index_type

Definition at line 114 of file KokkosArray.h.

Constructor & Destructor Documentation

◆ ArrayBase() [1/3]

template<typename T , unsigned int dimension, typename index_type >
Moose::Kokkos::ArrayBase< T, dimension, index_type >::ArrayBase ( const LayoutType  layout)
inline

Constructor.

Parameters
layoutThe memory layout type

Definition at line 121 of file KokkosArray.h.

121: _layout(layout) {}
const LayoutType _layout
Memory layout type.

◆ ArrayBase() [2/3]

template<typename T , unsigned int dimension, typename index_type >
template<typename... size_type>
Moose::Kokkos::ArrayBase< T, dimension, index_type >::ArrayBase ( const LayoutType  layout,
size_type...  n 
)
inline

Constructor Initialize and allocate array with given dimensions This allocates both host and device data.

Parameters
layoutThe memory layout type
nThe size of each dimension

Definition at line 132 of file KokkosArray.h.

132 : _layout(layout)
133 {
134 create(n...);
135 }
KOKKOS_FUNCTION index_type n(unsigned int dim) const
Get the size of a dimension.
void create(const std::vector< index_type > &n)
Allocate array on host and device.

◆ ArrayBase() [3/3]

template<typename T , unsigned int dimension, typename index_type >
Moose::Kokkos::ArrayBase< T, dimension, index_type >::ArrayBase ( const ArrayBase< T, dimension, index_type > &  array)
inline

Copy constructor.

Definition at line 141 of file KokkosArray.h.

141 : _layout(array._layout)
142 {
143#ifndef MOOSE_KOKKOS_SCOPE
144 static_assert(!ArrayDeepCopy<T>::value,
145 "Kokkos array cannot be deep copied outside the Kokkos compilation scope");
146#endif
147
148 if constexpr (ArrayDeepCopy<T>::value)
149 deepCopy(array);
150 else
151 shallowCopy(array);
152 }
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 ...
void shallowCopy(const ArrayBase< T, dimension, index_type > &array)
Shallow copy another Kokkos array.
static constexpr bool value
Definition KokkosArray.h:93

◆ ~ArrayBase()

template<typename T , unsigned int dimension, typename index_type >
Moose::Kokkos::ArrayBase< T, dimension, index_type >::~ArrayBase ( )
inline

Destructor.

Definition at line 157 of file KokkosArray.h.

157{ destroy(); }
void destroy()
Free all data and reset.

Member Function Documentation

◆ aliasDevice()

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::aliasDevice ( T *  ptr)

Point the device data to an external data instead of allocating it.

Parameters
ptrThe pointer to the external device data

Definition at line 980 of file KokkosArray.h.

981{
982 if (!_is_init)
983 mooseError("Kokkos array error: attempted to alias device data before array initialization.");
984
986 mooseError("Kokkos array error: cannot alias device data because device data was not aliased.");
987
988 _device_data = ptr;
989 _is_device_alloc = true;
990 _is_device_alias = true;
991}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
bool _is_init
Flag whether array was initialized.
T * _device_data
Device data.
bool _is_device_alias
Flag whether the device data points to an external data.
bool _is_device_alloc
Flag whether device data was allocated.

◆ aliasHost()

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::aliasHost ( T *  ptr)

Point the host data to an external data instead of allocating it.

Parameters
ptrThe pointer to the external host data

Definition at line 965 of file KokkosArray.h.

966{
967 if (!_is_init)
968 mooseError("Kokkos array error: attempted to alias host data before array initialization.");
969
971 mooseError("Kokkos array error: cannot alias host data because host data was not aliased.");
972
973 _host_data = ptr;
974 _is_host_alloc = true;
975 _is_host_alias = true;
976}
bool _is_host_alias
Flag whether the host data points to an external data.
bool _is_host_alloc
Flag whether host data was allocated.

◆ allocDevice()

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::allocDevice ( )
private

Allocate device data for an initialized array that has not allocated device data.

Definition at line 1020 of file KokkosArray.h.

1021{
1022 if (_is_device_alloc)
1023 return;
1024
1025 _device_data =
1026 static_cast<T *>(::Kokkos::kokkos_malloc<ExecSpace::memory_space>(_size * sizeof(T)));
1027
1028 _is_device_alloc = true;
1029}
index_type _size
Total size.

Referenced by Moose::Kokkos::ArrayBase< T, dimension, index_type >::copyToDevice(), and Moose::Kokkos::ArrayBase< T, dimension, index_type >::createInternal().

◆ allocHost()

template<typename T , unsigned int dimension, typename index_type >
template<bool initialize>
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::allocHost ( )
private

Allocate host data for an initialized array that has not allocated host data.

Template Parameters
initializeWhether to initialize host data (calls default constructor)

Definition at line 996 of file KokkosArray.h.

997{
998 if (_is_host_alloc)
999 return;
1000
1001 if constexpr (initialize)
1002 {
1003 static_assert(
1004 std::is_default_constructible<T>::value,
1005 "Data type is not default-constructible. Initialization argument should be set to false.");
1006
1007 _host_data = new T[_size];
1008 }
1009 else
1010 {
1011 _host_data = static_cast<T *>(std::malloc(_size * sizeof(T)));
1012 _slots_constructed = std::make_shared<std::vector<bool>>(_size, false);
1013 }
1014
1015 _is_host_alloc = true;
1016}
std::shared_ptr< std::vector< bool > > _slots_constructed
Non-null only for malloc-allocated arrays; tracks which slots have been emplace-constructed.
void initialize(EquationSystems &es, const std::string &system_name)

◆ begin()

template<typename T , unsigned int dimension, typename index_type >
KOKKOS_FUNCTION iterator Moose::Kokkos::ArrayBase< T, dimension, index_type >::begin ( ) const
inline

Get the beginning iterator.

Returns
The beginning iterator

Definition at line 568 of file KokkosArray.h.

569 {
570 KOKKOS_IF_ON_HOST(return iterator(_host_data);)
571
572 return iterator(_device_data);
573 }

◆ constructedEntries() [1/2]

template<typename T , unsigned int dimension, typename index_type >
ArrayBase< T, dimension, index_type >::template constructed_entry_range< false > Moose::Kokkos::ArrayBase< T, dimension, index_type >::constructedEntries ( )

Get host-side range over entries tracked as constructed.

Returns
Range that skips slots for which isSlotConstructed() is false

Definition at line 802 of file KokkosArray.h.

803{
804 return constructed_entry_range<false>(*this);
805}

◆ constructedEntries() [2/2]

template<typename T , unsigned int dimension, typename index_type >
ArrayBase< T, dimension, index_type >::template constructed_entry_range< true > Moose::Kokkos::ArrayBase< T, dimension, index_type >::constructedEntries ( ) const

Get host-side range over entries tracked as constructed.

Returns
Range that skips slots for which isSlotConstructed() is false

Definition at line 809 of file KokkosArray.h.

810{
811 return constructed_entry_range<true>(*this);
812}

◆ copyIn()

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::copyIn ( const T *  ptr,
MemcpyType  dir,
index_type  n,
index_type  offset = 0 
)

Copy data from an external data to this array.

Parameters
ptrThe pointer to the external data
dirThe copy direction
nThe number of entries to copy
offsetThe starting offset of this array

Definition at line 1248 of file KokkosArray.h.

1252{
1253 if (n > _size)
1254 mooseError("Kokkos array error: cannot copy in data larger than the array size.");
1255
1256 if (offset > _size)
1257 mooseError("Kokkos array error: offset cannot be larger than the array size.");
1258
1259 if (dir == MemcpyType::HOST_TO_HOST)
1260 {
1261 // If host side memory is not allocated, print error
1262 if (!_is_host_alloc)
1263 mooseError(
1264 "Kokkos array error: cannot copy in to the array because host memory was not allocated.");
1265
1266 // Copy from host to host
1267 copyInternal<::Kokkos::HostSpace, ::Kokkos::HostSpace>(_host_data + offset, ptr, n);
1268 }
1269 else if (dir == MemcpyType::HOST_TO_DEVICE)
1270 {
1271 // If device side memory is not allocated, print error
1272 if (!_is_device_alloc)
1273 mooseError("Kokkos array error: cannot copy in to the array because device memory was not "
1274 "allocated.");
1275
1276 // Copy from host to device
1277 copyInternal<MemSpace, ::Kokkos::HostSpace>(_device_data + offset, ptr, n);
1278 }
1279 else if (dir == MemcpyType::DEVICE_TO_HOST)
1280 {
1281 // If host side memory is not allocated, print error
1282 if (!_is_host_alloc)
1283 mooseError(
1284 "Kokkos array error: cannot copy in to the array because host memory was not allocated.");
1285
1286 // Copy from device to host
1287 copyInternal<::Kokkos::HostSpace, MemSpace>(_host_data + offset, ptr, n);
1288 }
1289 else if (dir == MemcpyType::DEVICE_TO_DEVICE)
1290 {
1291 // If device side memory is not allocated, print error
1292 if (!_is_device_alloc)
1293 mooseError("Kokkos array error: cannot copy in to the array because device memory was not "
1294 "allocated.");
1295
1296 // Copy from device to device
1297 copyInternal<MemSpace, MemSpace>(_device_data + offset, ptr, n);
1298 }
1299}
void offset(const std::vector< signed_index_type > &d)
Apply starting index offsets to each dimension.

Referenced by Moose::Kokkos::dataLoad().

◆ copyInternal()

template<typename T , unsigned int dimension, typename index_type >
template<typename TargetSpace , typename SourceSpace >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::copyInternal ( T *  target,
const T *  source,
index_type  n 
)
protected

The internal method to perform a memory copy.

Template Parameters
TargetSpaceThe Kokkos memory space of target data
SourcespaceThe Kokkos memory space of source data
Parameters
targetThe pointer to the target data
sourceThe pointer to the source data
nThe number of entries to copy

Definition at line 1129 of file KokkosArray.h.

1130{
1131 ::Kokkos::Impl::DeepCopy<TargetSpace, SourceSpace>(target, source, n * sizeof(T));
1132 ::Kokkos::fence();
1133}

◆ copyOut()

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::copyOut ( T *  ptr,
MemcpyType  dir,
index_type  n,
index_type  offset = 0 
)

Copy data to an external data from this array.

Parameters
ptrThe pointer to the external data
dirThe copy direction
nThe number of entries to copy
offsetThe starting offset of this array

Definition at line 1303 of file KokkosArray.h.

1307{
1308 if (n > _size)
1309 mooseError("Kokkos array error: cannot copy out data larger than the array size.");
1310
1311 if (offset > _size)
1312 mooseError("Kokkos array error: offset cannot be larger than the array size.");
1313
1314 if (dir == MemcpyType::HOST_TO_HOST)
1315 {
1316 // If host side memory is not allocated, print error
1317 if (!_is_host_alloc)
1318 mooseError("Kokkos array error: cannot copy out from the array because host memory was not "
1319 "allocated.");
1320
1321 // Copy from host to host
1322 copyInternal<::Kokkos::HostSpace, ::Kokkos::HostSpace>(ptr, _host_data + offset, n);
1323 }
1324 else if (dir == MemcpyType::HOST_TO_DEVICE)
1325 {
1326 // If host side memory is not allocated, print error
1327 if (!_is_host_alloc)
1328 mooseError("Kokkos array error: cannot copy out from the array because host memory was not "
1329 "allocated.");
1330
1331 // Copy from host to device
1332 copyInternal<MemSpace, ::Kokkos::HostSpace>(ptr, _host_data + offset, n);
1333 }
1334 else if (dir == MemcpyType::DEVICE_TO_HOST)
1335 {
1336 // If device side memory is not allocated, print error
1337 if (!_is_device_alloc)
1338 mooseError("Kokkos array error: cannot copy out from the array because device memory was not "
1339 "allocated.");
1340
1341 // Copy from device to host
1342 copyInternal<::Kokkos::HostSpace, MemSpace>(ptr, _device_data + offset, n);
1343 }
1344 else if (dir == MemcpyType::DEVICE_TO_DEVICE)
1345 {
1346 // If device side memory is not allocated, print error
1347 if (!_is_device_alloc)
1348 mooseError("Kokkos array error: cannot copy out from the array because device memory was not "
1349 "allocated.");
1350
1351 // Copy from device to device
1352 copyInternal<MemSpace, MemSpace>(ptr, _device_data + offset, n);
1353 }
1354}

Referenced by Moose::Kokkos::dataStore().

◆ copyToDevice()

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::copyToDevice ( )

Copy data from host to device.

Definition at line 1167 of file KokkosArray.h.

1168{
1169 // If host side memory is not allocated, do nothing
1170 if (!_is_host_alloc)
1171 return;
1172
1173 // If device side memory is not allocated,
1174 if (!_is_device_alloc)
1175 {
1176 if (_counter.use_count() == 1)
1177 // allocate memory if this array is not shared with other arrays
1178 allocDevice();
1179 else
1180 // print error if this array is shared with other arrays
1181 mooseError("Kokkos array error: cannot copy from host to device because device memory "
1182 "was not allocated. Cannot allocate device memory for copy because the array is "
1183 "being shared.");
1184 }
1185
1186 // Copy from host to device
1187 copyInternal<MemSpace, ::Kokkos::HostSpace>(_device_data, _host_data, _size);
1188}
std::shared_ptr< unsigned int > _counter
Reference counter.
void allocDevice()
Allocate device data for an initialized array that has not allocated device data.

Referenced by Moose::Kokkos::ArrayBase< T, dimension, index_type >::copyToDeviceNested(), Moose::Kokkos::dataLoad(), Moose::Kokkos::ArrayBase< T, dimension, index_type >::deepCopy(), Moose::Kokkos::ArrayBase< T, dimension, index_type >::moveToDevice(), Moose::Kokkos::VariableGradientTempl< is_ad >::VariableGradientTempl(), and Moose::Kokkos::VariableValueTempl< is_ad >::VariableValueTempl().

◆ copyToDeviceNested()

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::copyToDeviceNested ( )

Copy all the nested Kokkos arrays including self from host to device.

Definition at line 1371 of file KokkosArray.h.

1372{
1373 for (const auto i : make_range(_size))
1375
1376 copyToDevice();
1377}
void copyToDevice()
Copy data from host to device.
void copyToDeviceInner(T &)
IntRange< T > make_range(T beg, T end)

◆ copyToHost()

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::copyToHost ( )

Copy data from device to host.

Definition at line 1192 of file KokkosArray.h.

1193{
1194 // If device side memory is not allocated, do nothing
1195 if (!_is_device_alloc)
1196 return;
1197
1198 // If host side memory is not allocated,
1199 if (!_is_host_alloc)
1200 {
1201 if (_counter.use_count() == 1)
1202 // allocate memory if this array is not shared with other arrays
1203 allocHost<false>();
1204 else
1205 // print error if this array is shared with other arrays
1206 mooseError("Kokkos array error: cannot copy from device to host because host memory "
1207 "was not allocated. Cannot allocate host memory for copy because the array is "
1208 "being shared.");
1209 }
1210
1211 // Copy from device to host
1212 copyInternal<::Kokkos::HostSpace, MemSpace>(_host_data, _device_data, _size);
1213}

Referenced by Moose::Kokkos::ArrayBase< T, dimension, index_type >::moveToHost().

◆ create() [1/2]

template<typename T , unsigned int dimension, typename index_type >
template<bool initialize = true>
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::create ( const std::vector< index_type > &  n)
inline

Allocate array on host and device.

Template Parameters
initializeWhether to initialize host data (calls default constructor)
Parameters
nThe vector containing the size of each dimension

Definition at line 392 of file KokkosArray.h.

393 {
394 createInternal<true, true, initialize>(n);
395 }

Referenced by Moose::Kokkos::ArrayBase< T, dimension, index_type >::ArrayBase(), Moose::Kokkos::VariableGradientTempl< is_ad >::VariableGradientTempl(), and Moose::Kokkos::VariableValueTempl< is_ad >::VariableValueTempl().

◆ create() [2/2]

template<typename T , unsigned int dimension, typename index_type >
template<bool initialize = true, typename... size_type>
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::create ( size_type...  n)
inline

Allocate array on host and device.

Template Parameters
initializeWhether to initialize host data (calls default constructor)
Parameters
nThe size of each dimension

Definition at line 402 of file KokkosArray.h.

403 {
404 createInternal<true, true, initialize>(n...);
405 }

◆ createDevice() [1/2]

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::createDevice ( const std::vector< index_type > &  n)
inline

Allocate array on device only.

Parameters
nThe vector containing the size of each dimension

Definition at line 430 of file KokkosArray.h.

430{ createInternal<false, true, false>(n); }

◆ createDevice() [2/2]

template<typename T , unsigned int dimension, typename index_type >
template<typename... size_type>
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::createDevice ( size_type...  n)
inline

Allocate array on device only.

Parameters
nThe size of each dimension

Definition at line 436 of file KokkosArray.h.

437 {
438 createInternal<false, true, false>(n...);
439 }

◆ createHost() [1/2]

template<typename T , unsigned int dimension, typename index_type >
template<bool initialize = true>
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::createHost ( const std::vector< index_type > &  n)
inline

Allocate array on host only.

Template Parameters
initializeWhether to initialize host data (calls default constructor)
Parameters
nThe vector containing the size of each dimension

Definition at line 412 of file KokkosArray.h.

413 {
414 createInternal<true, false, initialize>(n);
415 }

◆ createHost() [2/2]

template<typename T , unsigned int dimension, typename index_type >
template<bool initialize = true, typename... size_type>
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::createHost ( size_type...  n)
inline

Allocate array on host only.

Template Parameters
initializeWhether to initialize host data (calls default constructor)
Parameters
nThe size of each dimension

Definition at line 422 of file KokkosArray.h.

423 {
424 createInternal<true, false, initialize>(n...);
425 }

◆ createInternal() [1/3]

template<typename T , unsigned int dimension, typename index_type >
template<bool host, bool device, bool initialize>
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::createInternal ( const std::vector< index_type > &  n)
protected

The internal method to initialize and allocate this array.

Template Parameters
hostWhether host data will be allocated
deviceWhether device data will be allocated
initializeWhether to initialize host data (calls default constructor)
Parameters
nThe vector containing the size of each dimension

Definition at line 1034 of file KokkosArray.h.

1035{
1036 if (n.size() != dimension)
1037 mooseError("Kokkos array error: the number of dimensions provided (",
1038 n.size(),
1039 ") must match the array dimension (",
1040 dimension,
1041 ").");
1042
1043 if (_counter)
1044 destroy();
1045
1046 _counter = std::make_shared<unsigned int>();
1047
1048 uint64_t overflow_checker = 1;
1049
1050 _size = 1;
1051 _s[0] = 1;
1052
1053 for (const auto i : make_range(dimension))
1054 {
1055 overflow_checker *= n[i];
1056
1057 _n[i] = n[i];
1058 _size *= n[i];
1059 }
1060
1061 if (overflow_checker > std::numeric_limits<index_type>::max())
1062 mooseError("Kokkos array error: the dimensions provided (",
1064 ") has the total size of ",
1065 overflow_checker,
1066 " which exceeds the limit of ",
1067 MooseUtils::prettyCppType<index_type>(),
1068 ".");
1069
1071 {
1072 _s[0] = 1;
1073
1074 for (const auto i : make_range(1u, dimension))
1075 _s[i] = _s[i - 1] * _n[i - 1];
1076 }
1077 else
1078 {
1079 _s[dimension - 1] = 1;
1080
1081 for (int i = dimension - 2; i >= 0; --i)
1082 _s[i] = _s[i + 1] * _n[i + 1];
1083 }
1084
1085 if constexpr (host)
1086 allocHost<initialize>();
1087
1088 if constexpr (device)
1089 allocDevice();
1090
1091 _is_init = true;
1092}
index_type _n[dimension]
Size of each dimension.
index_type _s[dimension]
Stride of each dimension.
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:64

◆ createInternal() [2/3]

template<typename T , unsigned int dimension, typename index_type >
template<bool initialize>
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::createInternal ( const std::vector< index_type > &  n,
bool  host,
bool  device 
)
protected

The internal method to initialize and allocate this array.

Template Parameters
initializeWhether to initialize host data (calls default constructor)
Parameters
nThe vector containing the size of each dimension
hostThe flag whether host data will be allocated
deviceThe flag whether device data will be allocated

Definition at line 1097 of file KokkosArray.h.

1100{
1101 if (host && device)
1102 createInternal<true, true, initialize>(n);
1103 else if (host && !device)
1104 createInternal<true, false, initialize>(n);
1105 else if (!host && device)
1106 createInternal<false, true, initialize>(n);
1107 else
1108 createInternal<false, false, initialize>(n);
1109}

◆ createInternal() [3/3]

template<typename T , unsigned int dimension, typename index_type >
template<bool host, bool device, bool initialize, typename... size_type>
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::createInternal ( size_type...  n)
protected

The internal method to initialize and allocate this array.

Template Parameters
hostWhether host data will be allocated
deviceWhether device data will be allocated
initializeWhether to initialize host data (calls default constructor)
Parameters
nThe size of each dimension

Definition at line 1114 of file KokkosArray.h.

1115{
1116 static_assert((std::is_convertible<size_type, index_type>::value && ...),
1117 "All arguments must be convertible to index_type");
1118 static_assert(sizeof...(n) == dimension, "Number of arguments should match array dimension");
1119
1120 std::vector<index_type> dims;
1121 (dims.push_back(n), ...);
1122
1123 createInternal<host, device, initialize>(dims);
1124}

◆ data()

template<typename T , unsigned int dimension, typename index_type >
KOKKOS_FUNCTION T * Moose::Kokkos::ArrayBase< T, dimension, index_type >::data ( ) const
inline

Get the data pointer.

Returns
The pointer to the underlying data depending on the architecture this function is being called on

Definition at line 306 of file KokkosArray.h.

307 {
308 KOKKOS_IF_ON_HOST(return _host_data;)
309
310 return _device_data;
311 }

Referenced by Moose::Kokkos::copyToDeviceInner(), Moose::Kokkos::dataLoad(), Moose::Kokkos::dataStore(), and Moose::Kokkos::Matrix::find().

◆ deepCopy()

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::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.

Parameters
arrayThe Kokkos array to be deep copied

Definition at line 1381 of file KokkosArray.h.

1382{
1383 if (_layout != array._layout)
1384 mooseError("Kokkos array error: cannot deep copy arrays with different layouts.");
1385
1386 if (ArrayDeepCopy<T>::value && !array._is_host_alloc)
1387 mooseError(
1388 "Kokkos array error: cannot deep copy using constructor from array without host data.");
1389
1390 std::vector<index_type> n(std::begin(array._n), std::end(array._n));
1391
1392 createInternal<false>(n, array._is_host_alloc, array._is_device_alloc);
1393
1394 if (_is_host_alloc)
1395 for (const auto i : make_range(_size))
1396 if (array.isSlotConstructed(i))
1397 emplaceAt(i, array._host_data[i]);
1398
1400 copyToDevice();
1401 else if (_is_device_alloc)
1402 copyInternal<MemSpace, MemSpace>(_device_data, array._device_data, _size);
1403
1404 for (const auto i : make_range(dimension))
1405 {
1406 _d[i] = array._d[i];
1407 _s[i] = array._s[i];
1408 }
1409}
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
signed_index_type _d[dimension]
Offset of each dimension.
T & emplaceAt(index_type i, Args &&... args)
Placement-new construct slot i from args, recording initialization.
bool isSlotConstructed(index_type i) const
Get whether slot i is tracked as constructed.

Referenced by Moose::Kokkos::ArrayBase< T, dimension, index_type >::ArrayBase().

◆ destroy()

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::destroy ( )

Free all data and reset.

Definition at line 896 of file KokkosArray.h.

897{
898 if (!_counter)
899 return;
900
901 if (_counter.use_count() > 1)
902 {
903 _host_data = nullptr;
904 _device_data = nullptr;
905 }
906 else if (_counter.use_count() == 1)
907 {
908 freeHost();
909 freeDevice();
910 }
911
912 _size = 0;
913
914 for (const auto i : make_range(dimension))
915 {
916 _n[i] = 0;
917 _s[i] = 0;
918 _d[i] = 0;
919 }
920
921 _is_init = false;
922 _is_host_alloc = false;
923 _is_device_alloc = false;
924 _is_host_alias = false;
925 _is_device_alias = false;
926
927 _counter.reset();
928 _slots_constructed.reset();
929}
void freeHost()
Free host data.
void freeDevice()
Free device data.

Referenced by Moose::Kokkos::System::clearActiveMatrixTags(), Moose::Kokkos::System::clearActiveResidualTags(), Moose::Kokkos::System::clearActiveSolutionTags(), Moose::Kokkos::System::clearActiveVariables(), Moose::Kokkos::ArrayBase< T, dimension, index_type >::createInternal(), Moose::Kokkos::ArrayBase< T, dimension, index_type >::shallowCopy(), and Moose::Kokkos::ArrayBase< T, dimension, index_type >::~ArrayBase().

◆ deviceData()

template<typename T , unsigned int dimension, typename index_type >
T * Moose::Kokkos::ArrayBase< T, dimension, index_type >::deviceData ( ) const
inline

Get the device data pointer.

Returns
The pointer to the underlying device data

Definition at line 358 of file KokkosArray.h.

358{ return _device_data; }

◆ deviceView()

template<typename T , unsigned int dimension, typename index_type >
auto Moose::Kokkos::ArrayBase< T, dimension, index_type >::deviceView ( ) const
inline

Get the device unmanaged view.

Returns
The device unmanaged view

Definition at line 372 of file KokkosArray.h.

373 {
374 return ::Kokkos::View<T *, MemSpace, ::Kokkos::MemoryTraits<::Kokkos::Unmanaged>>(_device_data,
375 _size);
376 }

Referenced by Moose::Kokkos::ArrayBase< T, dimension, index_type >::operator=().

◆ emplaceAt()

template<typename T , unsigned int dimension, typename index_type >
template<typename... Args>
T & Moose::Kokkos::ArrayBase< T, dimension, index_type >::emplaceAt ( index_type  i,
Args &&...  args 
)
protected

Placement-new construct slot i from args, recording initialization.

Parameters
iThe dimensionless slot index
argsArguments forwarded to T's constructor
Returns
Reference to the constructed element

Definition at line 830 of file KokkosArray.h.

831{
832 mooseAssert(_is_host_alloc && _slots_constructed,
833 "emplaceAt requires a malloc-allocated array (create<false>)");
834 mooseAssert(i < _size, "emplaceAt index out of bounds");
835
836 new (_host_data + i) T(std::forward<Args>(args)...);
837 (*_slots_constructed)[i] = true;
838
839 return _host_data[i];
840}

Referenced by Moose::Kokkos::ArrayBase< T, dimension, index_type >::deepCopy(), Moose::Kokkos::Array< T, 1, index_type, LayoutType::LEFT >::emplace(), and Moose::Kokkos::Array< T, dimension, index_type, layout >::emplace().

◆ end()

template<typename T , unsigned int dimension, typename index_type >
KOKKOS_FUNCTION iterator Moose::Kokkos::ArrayBase< T, dimension, index_type >::end ( ) const
inline

Get the end iterator.

Returns
The end iterator

Definition at line 578 of file KokkosArray.h.

579 {
580 KOKKOS_IF_ON_HOST(return iterator(_host_data + _size);)
581
582 return iterator(_device_data + _size);
583 }

◆ first()

template<typename T , unsigned int dimension, typename index_type >
KOKKOS_FUNCTION T & Moose::Kokkos::ArrayBase< T, dimension, index_type >::first ( ) const
inline

Get the first element.

Returns
The reference of the first element depending on the architecture this function is being called on

Definition at line 317 of file KokkosArray.h.

318 {
319 KOKKOS_IF_ON_HOST(return _host_data[0];)
320
321 return _device_data[0];
322 }

Referenced by Moose::Kokkos::RPNEvaluator::eval().

◆ freeDevice()

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::freeDevice ( )
private

Free device data.

Definition at line 878 of file KokkosArray.h.

879{
880 if (!_is_device_alloc)
881 return;
882
884 {
885 _device_data = nullptr;
886 _is_device_alias = false;
887 }
888 else
890
891 _is_device_alloc = false;
892}
void free(void *ptr)

Referenced by Moose::Kokkos::ArrayBase< T, dimension, index_type >::destroy(), and Moose::Kokkos::ArrayBase< T, dimension, index_type >::moveToHost().

◆ freeHost()

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::freeHost ( )
private

Free host data.

Definition at line 845 of file KokkosArray.h.

846{
847 if (!_is_host_alloc)
848 return;
849
850 if (_is_host_alias)
851 {
852 _host_data = nullptr;
853 _is_host_alias = false;
854 }
855 else
856 {
858 // Allocated by new
859 delete[] _host_data;
860 else
861 {
862 // Allocated by malloc
863 for (const auto i : make_range(_size))
865 _host_data[i].~T();
866
867 std::free(_host_data);
868
869 _slots_constructed.reset();
870 }
871 }
872
873 _is_host_alloc = false;
874}

Referenced by Moose::Kokkos::ArrayBase< T, dimension, index_type >::destroy(), and Moose::Kokkos::ArrayBase< T, dimension, index_type >::moveToDevice().

◆ hostData()

template<typename T , unsigned int dimension, typename index_type >
T * Moose::Kokkos::ArrayBase< T, dimension, index_type >::hostData ( ) const
inline

Get the host data pointer.

Returns
The pointer to the underlying host data

Definition at line 353 of file KokkosArray.h.

353{ return _host_data; }

◆ hostView()

template<typename T , unsigned int dimension, typename index_type >
auto Moose::Kokkos::ArrayBase< T, dimension, index_type >::hostView ( ) const
inline

Get the host unmanaged view.

Returns
The host unmanaged view

Definition at line 363 of file KokkosArray.h.

364 {
365 return ::Kokkos::View<T *, ::Kokkos::HostSpace, ::Kokkos::MemoryTraits<::Kokkos::Unmanaged>>(
367 }

◆ init()

template<typename T , unsigned int dimension, typename index_type >
template<typename... size_type>
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::init ( size_type...  n)
inline

Initialize array with given dimensions but do not allocate.

Parameters
nThe size of each dimension

Definition at line 382 of file KokkosArray.h.

383 {
384 createInternal<false, false, false>(n...);
385 }

◆ isAlloc()

template<typename T , unsigned int dimension, typename index_type >
KOKKOS_FUNCTION bool Moose::Kokkos::ArrayBase< T, dimension, index_type >::isAlloc ( ) const
inline

Get whether the array was allocated either on host or device.

Returns
Whether the array was allocated either on host or device

Definition at line 269 of file KokkosArray.h.

269{ return _is_host_alloc || _is_device_alloc; }

Referenced by Moose::Kokkos::dataStore(), Moose::Kokkos::VariableGradientTempl< is_ad >::VariableGradientTempl(), and Moose::Kokkos::VariableValueTempl< is_ad >::VariableValueTempl().

◆ isDeviceAlias()

template<typename T , unsigned int dimension, typename index_type >
KOKKOS_FUNCTION bool Moose::Kokkos::ArrayBase< T, dimension, index_type >::isDeviceAlias ( ) const
inline

Get whether the device array was aliased.

Returns
Whether the device array was aliased

Definition at line 289 of file KokkosArray.h.

289{ return _is_device_alias; }

◆ isDeviceAlloc()

template<typename T , unsigned int dimension, typename index_type >
KOKKOS_FUNCTION bool Moose::Kokkos::ArrayBase< T, dimension, index_type >::isDeviceAlloc ( ) const
inline

Get whether the array was allocated on device.

Returns
Whether the array was allocated on device

Definition at line 279 of file KokkosArray.h.

279{ return _is_device_alloc; }

Referenced by Moose::Kokkos::dataLoad(), and Moose::Kokkos::dataStore().

◆ isHostAlias()

template<typename T , unsigned int dimension, typename index_type >
KOKKOS_FUNCTION bool Moose::Kokkos::ArrayBase< T, dimension, index_type >::isHostAlias ( ) const
inline

Get whether the host array was aliased.

Returns
Whether the host array was aliased

Definition at line 284 of file KokkosArray.h.

284{ return _is_host_alias; }

◆ isHostAlloc()

template<typename T , unsigned int dimension, typename index_type >
KOKKOS_FUNCTION bool Moose::Kokkos::ArrayBase< T, dimension, index_type >::isHostAlloc ( ) const
inline

Get whether the array was allocated on host.

Returns
Whether the array was allocated on host

Definition at line 274 of file KokkosArray.h.

274{ return _is_host_alloc; }

Referenced by Moose::Kokkos::dataLoad().

◆ isSlotConstructed()

template<typename T , unsigned int dimension, typename index_type >
bool Moose::Kokkos::ArrayBase< T, dimension, index_type >::isSlotConstructed ( index_type  i) const

Get whether slot i is tracked as constructed.

For an array created with initialization (initialize = true) every slot is default-constructed at allocation, so all slots are reported as constructed. For an array created without initialization (initialize = false) only slots constructed through emplace() are tracked; placement-new directly into the storage is not recorded here, so such a slot is reported as not constructed and its destructor is skipped on free (a leak for types that own resources).

Parameters
iThe slot index
Returns
true if the slot is tracked as constructed

Definition at line 816 of file KokkosArray.h.

817{
818 mooseAssert(i < _size, "isSlotConstructed index out of bounds");
819
821 return _is_host_alloc;
822
823 return (*_slots_constructed)[i];
824}

Referenced by Moose::Kokkos::ArrayBase< T, dimension, index_type >::deepCopy(), and Moose::Kokkos::ArrayBase< T, dimension, index_type >::freeHost().

◆ last()

template<typename T , unsigned int dimension, typename index_type >
KOKKOS_FUNCTION T & Moose::Kokkos::ArrayBase< T, dimension, index_type >::last ( ) const
inline

Get the last element.

Returns
The reference of the last element depending on the architecture this function is being called on

Definition at line 328 of file KokkosArray.h.

329 {
330 KOKKOS_IF_ON_HOST(return _host_data[_size - 1];)
331
332 return _device_data[_size - 1];
333 }

◆ moveToDevice()

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::moveToDevice ( bool  should_free_host = true)

Copy data from host to device and deallocate host.

Parameters
should_free_hostWhether 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 1217 of file KokkosArray.h.

1218{
1219 static_assert(!is_kokkos_array<T>::value,
1220 "moveToDevice() not allowed for a nested array whose data type is another array.");
1221
1222 if (should_free_host && _counter.use_count() > 1)
1223 mooseError("Kokkos array error: cannot move array from host to device because there is at "
1224 "least one shallow copy of this array still alive.");
1225
1226 copyToDevice();
1227
1228 if (_counter.use_count() == 1)
1229 freeHost();
1230}

◆ moveToHost()

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::moveToHost ( bool  should_free_device = true)

Copy data from device to host and deallocate device.

Parameters
should_free_deviceWhether 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 1234 of file KokkosArray.h.

1235{
1236 if (should_free_device && _counter.use_count() > 1)
1237 mooseError("Kokkos array error: cannot move array from device to host because there is at "
1238 "least one shallow copy of this array still alive.");
1239
1240 copyToHost();
1241
1242 if (_counter.use_count() == 1)
1243 freeDevice();
1244}
void copyToHost()
Copy data from device to host.

◆ n()

template<typename T , unsigned int dimension, typename index_type >
KOKKOS_FUNCTION index_type Moose::Kokkos::ArrayBase< T, dimension, index_type >::n ( unsigned int  dim) const
inline

◆ offset() [1/2]

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::offset ( const std::vector< signed_index_type > &  d)

Apply starting index offsets to each dimension.

Parameters
dThe vector containing the offset of each dimension

Definition at line 1137 of file KokkosArray.h.

1138{
1139 if (d.size() > dimension)
1140 mooseError("Kokkos array error: the number of offsets provided (",
1141 d.size(),
1142 ") cannot be larger than the array dimension (",
1143 dimension,
1144 ").");
1145
1146 for (const auto i : index_range(d))
1147 _d[i] = d[i];
1148}
auto index_range(const T &sizable)

Referenced by Moose::Kokkos::ArrayBase< T, dimension, index_type >::copyIn(), Moose::Kokkos::ArrayBase< T, dimension, index_type >::copyOut(), and Moose::Kokkos::ArrayBase< T, dimension, index_type >::offset().

◆ offset() [2/2]

template<typename T , unsigned int dimension, typename index_type >
template<typename... offset_type>
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::offset ( offset_type...  d)

Apply starting index offsets to each dimension.

Parameters
dThe offset of each dimension

Definition at line 1153 of file KokkosArray.h.

1154{
1155 static_assert((std::is_convertible<offset_type, signed_index_type>::value && ...),
1156 "All arguments must be convertible to signed_index_type");
1157 static_assert(sizeof...(d) == dimension, "Number of arguments should match array dimension");
1158
1159 std::vector<signed_index_type> offsets;
1160 (offsets.push_back(d), ...);
1161
1162 offset(offsets);
1163}

◆ operator=()

template<typename T , unsigned int dimension, typename index_type >
auto & Moose::Kokkos::ArrayBase< T, dimension, index_type >::operator= ( const T &  scalar)

Assign a scalar value uniformly.

Parameters
scalarThe scalar value to be assigned

Definition at line 1424 of file KokkosArray.h.

1425{
1426 if (_is_host_alloc)
1427 std::fill_n(_host_data, _size, scalar);
1428
1429 if (_is_device_alloc)
1430 ::Kokkos::Experimental::fill_n(ExecSpace(), deviceView(), _size, scalar);
1431
1432 return *this;
1433}
auto deviceView() const
Get the device unmanaged view.

◆ operator[]()

template<typename T , unsigned int dimension, typename index_type >
KOKKOS_FUNCTION T & Moose::Kokkos::ArrayBase< T, dimension, index_type >::operator[] ( index_type  i) const
inline

Get an array entry.

Parameters
iThe dimensionless index
Returns
The reference of the entry depending on the architecture this function is being called on

Definition at line 340 of file KokkosArray.h.

341 {
342 KOKKOS_ASSERT(i < _size);
343
344 KOKKOS_IF_ON_HOST(return _host_data[i];)
345
346 return _device_data[i];
347 }

◆ shallowCopy()

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::shallowCopy ( const ArrayBase< T, dimension, index_type > &  array)

Shallow copy another Kokkos array.

Parameters
arrayThe Kokkos array to be shallow copied

Definition at line 933 of file KokkosArray.h.

934{
935 if (_layout != array._layout)
936 mooseError("Kokkos array error: cannot shallow copy arrays with different layouts.");
937
938 destroy();
939
940 _counter = array._counter;
941 _slots_constructed = array._slots_constructed;
942
943 _size = array._size;
944
945 for (const auto i : make_range(dimension))
946 {
947 _n[i] = array._n[i];
948 _s[i] = array._s[i];
949 _d[i] = array._d[i];
950 }
951
952 _is_init = array._is_init;
953 _is_host_alloc = array._is_host_alloc;
954 _is_device_alloc = array._is_device_alloc;
955 _is_host_alias = array._is_host_alias;
956 _is_device_alias = array._is_device_alias;
957
958 _host_data = array._host_data;
959 _device_data = array._device_data;
960}

Referenced by Moose::Kokkos::ArrayBase< T, dimension, index_type >::ArrayBase(), and Moose::Kokkos::ArrayBase< T, dimension, index_type >::swap().

◆ size()

template<typename T , unsigned int dimension, typename index_type >
KOKKOS_FUNCTION index_type Moose::Kokkos::ArrayBase< T, dimension, index_type >::size ( ) const
inline

Get the total array size.

Returns
The total array size

Definition at line 294 of file KokkosArray.h.

294{ return _size; }

Referenced by Moose::Kokkos::ResidualObject::accumulateTaggedElementalMatrix(), Moose::Kokkos::ResidualObject::accumulateTaggedElementalMatrix(), Moose::Kokkos::ResidualObject::accumulateTaggedElementalResidual(), Moose::Kokkos::LinearSystemContributionObject::accumulateTaggedMatrix(), Moose::Kokkos::ResidualObject::accumulateTaggedNodalMatrix(), Moose::Kokkos::ResidualObject::accumulateTaggedNodalMatrix(), Moose::Kokkos::ResidualObject::accumulateTaggedNodalResidual(), Moose::Kokkos::LinearSystemContributionObject::accumulateTaggedVector(), Moose::Kokkos::ResidualObject::accumulateTaggedVectorNodalMatrix(), Moose::Kokkos::ResidualObject::accumulateTaggedVectorNodalResidual(), Moose::Kokkos::MemoryPool::allocate(), Moose::Kokkos::dataLoad(), Moose::Kokkos::dataStore(), KokkosPiecewiseBase::functionSize(), Moose::Kokkos::Mesh::getElementVolume(), Moose::Kokkos::Variable::mooseVar(), BlockRestrictable::numKokkosBlockElements(), BlockRestrictable::numKokkosBlockNodes(), BlockRestrictable::numKokkosBlockSides(), BoundaryRestrictable::numKokkosBoundaryNodes(), BoundaryRestrictable::numKokkosBoundarySides(), Moose::Kokkos::MaterialBase::numKokkosElements(), Moose::Kokkos::MaterialBase::numKokkosElementSides(), Moose::Kokkos::Vector::operator()(), Moose::Kokkos::Vector::operator[](), Moose::Kokkos::MapBase< T1, T2, MapType >::size(), and KokkosBoundNodalKernel::skipOnBoundary().

◆ swap()

template<typename T , unsigned int dimension, typename index_type >
void Moose::Kokkos::ArrayBase< T, dimension, index_type >::swap ( ArrayBase< T, dimension, index_type > &  array)

Swap with another Kokkos array.

Parameters
arrayThe Kokkos array to be swapped

Definition at line 1413 of file KokkosArray.h.

1414{
1415 ArrayBase<T, dimension, index_type> clone(_layout);
1416
1417 clone.shallowCopy(*this);
1418 this->shallowCopy(array);
1419 array.shallowCopy(clone);
1420}

◆ useCount()

template<typename T , unsigned int dimension, typename index_type >
unsigned int Moose::Kokkos::ArrayBase< T, dimension, index_type >::useCount ( ) const
inline

Get the reference count.

Returns
The reference count

Definition at line 174 of file KokkosArray.h.

174{ return _counter.use_count(); }

Member Data Documentation

◆ _counter

template<typename T , unsigned int dimension, typename index_type >
std::shared_ptr<unsigned int> Moose::Kokkos::ArrayBase< T, dimension, index_type >::_counter
private

◆ _d

template<typename T , unsigned int dimension, typename index_type >
signed_index_type Moose::Kokkos::ArrayBase< T, dimension, index_type >::_d[dimension] = {0}
protected

◆ _device_data

template<typename T , unsigned int dimension, typename index_type >
T* Moose::Kokkos::ArrayBase< T, dimension, index_type >::_device_data = nullptr
private

◆ _host_data

template<typename T , unsigned int dimension, typename index_type >
T* Moose::Kokkos::ArrayBase< T, dimension, index_type >::_host_data = nullptr
private

◆ _is_device_alias

template<typename T , unsigned int dimension, typename index_type >
bool Moose::Kokkos::ArrayBase< T, dimension, index_type >::_is_device_alias = false
private

◆ _is_device_alloc

template<typename T , unsigned int dimension, typename index_type >
bool Moose::Kokkos::ArrayBase< T, dimension, index_type >::_is_device_alloc = false
private

◆ _is_host_alias

template<typename T , unsigned int dimension, typename index_type >
bool Moose::Kokkos::ArrayBase< T, dimension, index_type >::_is_host_alias = false
private

◆ _is_host_alloc

template<typename T , unsigned int dimension, typename index_type >
bool Moose::Kokkos::ArrayBase< T, dimension, index_type >::_is_host_alloc = false
private

◆ _is_init

template<typename T , unsigned int dimension, typename index_type >
bool Moose::Kokkos::ArrayBase< T, dimension, index_type >::_is_init = false
private

◆ _layout

template<typename T , unsigned int dimension, typename index_type >
const LayoutType Moose::Kokkos::ArrayBase< T, dimension, index_type >::_layout
private

◆ _n

template<typename T , unsigned int dimension, typename index_type >
index_type Moose::Kokkos::ArrayBase< T, dimension, index_type >::_n[dimension] = {0}
protected

◆ _s

template<typename T , unsigned int dimension, typename index_type >
index_type Moose::Kokkos::ArrayBase< T, dimension, index_type >::_s[dimension] = {0}
protected

◆ _size

template<typename T , unsigned int dimension, typename index_type >
index_type Moose::Kokkos::ArrayBase< T, dimension, index_type >::_size = 0
private

◆ _slots_constructed

template<typename T , unsigned int dimension, typename index_type >
std::shared_ptr<std::vector<bool> > Moose::Kokkos::ArrayBase< T, dimension, index_type >::_slots_constructed
private

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