12#ifdef MOOSE_KOKKOS_SCOPE
21#define usingKokkosArrayBaseMembers(T, dimension, index_type) \
23 using ArrayBase<T, dimension, index_type>::_n; \
24 using ArrayBase<T, dimension, index_type>::_s; \
25 using ArrayBase<T, dimension, index_type>::_d; \
28 using typename ArrayBase<T, dimension, index_type>::signed_index_type; \
29 using ArrayBase<T, dimension, index_type>::operator=
62 unsigned int dimension = 1,
63 typename index_type = MOOSE_KOKKOS_INDEX_TYPE,
76template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
93 static constexpr bool value =
false;
96template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
106template <
typename T,
unsigned int dimension,
typename index_type>
109 static_assert(std::is_integral_v<index_type>,
"Kokkos array index type must be an integral type");
110 static_assert(std::is_unsigned_v<index_type>,
"Kokkos array index type must be unsigned");
111 static_assert(!std::is_same_v<bool, index_type>,
"Kokkos array index type must not be bool");
123#ifdef MOOSE_KOKKOS_SCOPE
131 template <
typename... size_type>
143#ifndef MOOSE_KOKKOS_SCOPE
145 "Kokkos array cannot be deep copied outside the Kokkos compilation scope");
189 template <
bool is_const>
190 class constructed_entry_range;
195 template <
bool is_const>
202 using pointer = std::conditional_t<is_const, const T *, T *>;
203 using reference = std::conditional_t<is_const, const T &, T &>;
204 using array_type = std::conditional_t<is_const, const ArrayBase, ArrayBase>;
210 bool operator==(
const constructed_entry_iterator & other)
const;
216 constructed_entry_iterator(
array_type & array, index_type i);
233 template <
bool is_const>
237 using array_type = std::conditional_t<is_const, const ArrayBase, ArrayBase>;
264#ifdef MOOSE_KOKKOS_SCOPE
294 KOKKOS_FUNCTION index_type
size()
const {
return _size; }
300 KOKKOS_FUNCTION index_type
n(
unsigned int dim)
const {
return _n[
dim]; }
306 KOKKOS_FUNCTION T *
data()
const
319 KOKKOS_ASSERT(
_size);
330 KOKKOS_FUNCTION T &
last()
const
332 KOKKOS_ASSERT(
_size);
346 KOKKOS_ASSERT(i <
_size);
369 return ::Kokkos::View<T *, ::Kokkos::HostSpace, ::Kokkos::MemoryTraits<::Kokkos::Unmanaged>>(
378 return ::Kokkos::View<T *, MemSpace, ::Kokkos::MemoryTraits<::Kokkos::Unmanaged>>(
_device_data,
385 template <
typename... size_type>
388 createInternal<false, false, false>(
n...);
395 template <
bool initialize = true>
396 void create(
const std::vector<index_type> &
n)
398 createInternal<true, true, initialize>(
n);
405 template <
bool initialize =
true,
typename... size_type>
408 createInternal<true, true, initialize>(
n...);
415 template <
bool initialize = true>
418 createInternal<true, false, initialize>(
n);
425 template <
bool initialize =
true,
typename... size_type>
428 createInternal<true, false, initialize>(
n...);
434 void createDevice(
const std::vector<index_type> &
n) { createInternal<false, true, false>(
n); }
439 template <
typename... size_type>
442 createInternal<false, true, false>(
n...);
458 void offset(
const std::vector<signed_index_type> & d);
463 template <
typename... offset_type>
594 index_type
_n[dimension] = {0};
598 index_type
_s[dimension] = {0};
604#ifdef MOOSE_KOKKOS_SCOPE
612 template <
bool host,
bool device,
bool initialize,
typename... size_type>
621 template <
bool host,
bool device,
bool initialize>
630 template <
bool initialize>
640 template <
typename TargetSpace,
typename SourceSpace>
648 template <
typename... Args>
653#ifdef MOOSE_KOKKOS_SCOPE
658 template <
bool initialize>
720template <
typename T,
unsigned int dimension,
typename index_type>
721template <
bool is_const>
725 is_const>::array_type & array,
727 : _array(array), _i(i)
732template <
typename T,
unsigned int dimension,
typename index_type>
733template <
bool is_const>
738 advanceToConstructed();
742template <
typename T,
unsigned int dimension,
typename index_type>
743template <
bool is_const>
752template <
typename T,
unsigned int dimension,
typename index_type>
753template <
bool is_const>
758 return &_array == &other.
_array && _i == other.
_i;
761template <
typename T,
unsigned int dimension,
typename index_type>
762template <
bool is_const>
767 return !(*
this == other);
770template <
typename T,
unsigned int dimension,
typename index_type>
771template <
bool is_const>
775 while (_i < _array._size && !_array.isSlotConstructed(_i))
779template <
typename T,
unsigned int dimension,
typename index_type>
780template <
bool is_const>
783 is_const>::array_type & array)
788template <
typename T,
unsigned int dimension,
typename index_type>
789template <
bool is_const>
796template <
typename T,
unsigned int dimension,
typename index_type>
797template <
bool is_const>
801 return iterator(_array, _array._size);
804template <
typename T,
unsigned int dimension,
typename index_type>
811template <
typename T,
unsigned int dimension,
typename index_type>
818template <
typename T,
unsigned int dimension,
typename index_type>
822 mooseAssert(i <
_size,
"isSlotConstructed index out of bounds");
830#ifdef MOOSE_KOKKOS_SCOPE
831template <
typename T,
unsigned int dimension,
typename index_type>
832template <
typename... Args>
837 "emplaceAt requires a malloc-allocated array (create<false>)");
838 mooseAssert(i <
_size,
"emplaceAt index out of bounds");
840 new (
_host_data + i) T(std::forward<Args>(args)...);
841 (*_slots_constructed)[i] =
true;
847template <
typename T,
unsigned int dimension,
typename index_type>
867 for (
const auto i : make_range(
_size))
880template <
typename T,
unsigned int dimension,
typename index_type>
898template <
typename T,
unsigned int dimension,
typename index_type>
918 for (
const auto i : make_range(dimension))
935template <
typename T,
unsigned int dimension,
typename index_type>
940 mooseError(
"Kokkos array error: cannot shallow copy arrays with different layouts.");
949 for (
const auto i : make_range(dimension))
966#ifdef MOOSE_KOKKOS_SCOPE
967template <
typename T,
unsigned int dimension,
typename index_type>
972 mooseError(
"Kokkos array error: attempted to alias host data before array initialization.");
975 mooseError(
"Kokkos array error: cannot alias host data because host data was not aliased.");
982template <
typename T,
unsigned int dimension,
typename index_type>
987 mooseError(
"Kokkos array error: attempted to alias device data before array initialization.");
990 mooseError(
"Kokkos array error: cannot alias device data because device data was not aliased.");
997template <
typename T,
unsigned int dimension,
typename index_type>
998template <
bool initialize>
1008 std::is_default_constructible<T>::value,
1009 "Data type is not default-constructible. Initialization argument should be set to false.");
1022template <
typename T,
unsigned int dimension,
typename index_type>
1030 static_cast<T *
>(::Kokkos::kokkos_malloc<ExecSpace::memory_space>(
_size *
sizeof(T)));
1035template <
typename T,
unsigned int dimension,
typename index_type>
1036template <
bool host,
bool device,
bool initialize>
1040 if (
n.size() != dimension)
1041 mooseError(
"Kokkos array error: the number of dimensions provided (",
1043 ") must match the array dimension (",
1050 _counter = std::make_shared<unsigned int>();
1052 uint64_t overflow_checker = 1;
1057 for (
const auto i : make_range(dimension))
1059 overflow_checker *=
n[i];
1065 if (overflow_checker > std::numeric_limits<index_type>::max())
1066 mooseError(
"Kokkos array error: the dimensions provided (",
1068 ") has the total size of ",
1070 " which exceeds the limit of ",
1071 MooseUtils::prettyCppType<index_type>(),
1078 for (
const auto i : make_range(1u, dimension))
1079 _s[i] =
_s[i - 1] *
_n[i - 1];
1083 _s[dimension - 1] = 1;
1085 for (
int i = dimension - 2; i >= 0; --i)
1086 _s[i] =
_s[i + 1] *
_n[i + 1];
1090 allocHost<initialize>();
1092 if constexpr (device)
1098template <
typename T,
unsigned int dimension,
typename index_type>
1099template <
bool initialize>
1106 createInternal<true, true, initialize>(
n);
1107 else if (host && !device)
1108 createInternal<true, false, initialize>(
n);
1109 else if (!host && device)
1110 createInternal<false, true, initialize>(
n);
1112 createInternal<false, false, initialize>(
n);
1115template <
typename T,
unsigned int dimension,
typename index_type>
1116template <
bool host,
bool device,
bool initialize,
typename... size_type>
1120 static_assert((std::is_convertible<size_type, index_type>::value && ...),
1121 "All arguments must be convertible to index_type");
1122 static_assert(
sizeof...(n) == dimension,
"Number of arguments should match array dimension");
1124 std::vector<index_type> dims;
1125 (dims.push_back(
n), ...);
1127 createInternal<host, device, initialize>(dims);
1130template <
typename T,
unsigned int dimension,
typename index_type>
1131template <
typename TargetSpace,
typename SourceSpace>
1135 ::Kokkos::Impl::DeepCopy<TargetSpace, SourceSpace>(target, source,
n *
sizeof(T));
1139template <
typename T,
unsigned int dimension,
typename index_type>
1143 if (d.size() > dimension)
1144 mooseError(
"Kokkos array error: the number of offsets provided (",
1146 ") cannot be larger than the array dimension (",
1150 for (
const auto i : index_range(d))
1154template <
typename T,
unsigned int dimension,
typename index_type>
1155template <
typename... offset_type>
1159 static_assert((std::is_convertible<offset_type, signed_index_type>::value && ...),
1160 "All arguments must be convertible to signed_index_type");
1161 static_assert(
sizeof...(d) == dimension,
"Number of arguments should match array dimension");
1163 std::vector<signed_index_type> offsets;
1164 (offsets.push_back(d), ...);
1169template <
typename T,
unsigned int dimension,
typename index_type>
1185 mooseError(
"Kokkos array error: cannot copy from host to device because device memory "
1186 "was not allocated. Cannot allocate device memory for copy because the array is "
1194template <
typename T,
unsigned int dimension,
typename index_type>
1210 mooseError(
"Kokkos array error: cannot copy from device to host because host memory "
1211 "was not allocated. Cannot allocate host memory for copy because the array is "
1219template <
typename T,
unsigned int dimension,
typename index_type>
1224 "moveToDevice() not allowed for a nested array whose data type is another array.");
1226 if (should_free_host &&
_counter.use_count() > 1)
1227 mooseError(
"Kokkos array error: cannot move array from host to device because there is at "
1228 "least one shallow copy of this array still alive.");
1236template <
typename T,
unsigned int dimension,
typename index_type>
1240 if (should_free_device &&
_counter.use_count() > 1)
1241 mooseError(
"Kokkos array error: cannot move array from device to host because there is at "
1242 "least one shallow copy of this array still alive.");
1250template <
typename T,
unsigned int dimension,
typename index_type>
1258 mooseError(
"Kokkos array error: cannot copy in data larger than the array size.");
1261 mooseError(
"Kokkos array error: offset cannot be larger than the array size.");
1268 "Kokkos array error: cannot copy in to the array because host memory was not allocated.");
1271 copyInternal<::Kokkos::HostSpace, ::Kokkos::HostSpace>(
_host_data +
offset, ptr,
n);
1277 mooseError(
"Kokkos array error: cannot copy in to the array because device memory was not "
1288 "Kokkos array error: cannot copy in to the array because host memory was not allocated.");
1297 mooseError(
"Kokkos array error: cannot copy in to the array because device memory was not "
1305template <
typename T,
unsigned int dimension,
typename index_type>
1313 mooseError(
"Kokkos array error: cannot copy out data larger than the array size.");
1316 mooseError(
"Kokkos array error: offset cannot be larger than the array size.");
1322 mooseError(
"Kokkos array error: cannot copy out from the array because host memory was not "
1326 copyInternal<::Kokkos::HostSpace, ::Kokkos::HostSpace>(ptr,
_host_data +
offset,
n);
1332 mooseError(
"Kokkos array error: cannot copy out from the array because host memory was not "
1342 mooseError(
"Kokkos array error: cannot copy out from the array because device memory was not "
1352 mooseError(
"Kokkos array error: cannot copy out from the array because device memory was not "
1360template <
typename T>
1366template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
1370 data.copyToDeviceNested();
1373template <
typename T,
unsigned int dimension,
typename index_type>
1377 for (
const auto i : make_range(
_size))
1383template <
typename T,
unsigned int dimension,
typename index_type>
1388 mooseError(
"Kokkos array error: cannot deep copy arrays with different layouts.");
1392 "Kokkos array error: cannot deep copy using constructor from array without host data.");
1394 std::vector<index_type>
n(std::begin(array.
_n), std::end(array.
_n));
1399 for (
const auto i : make_range(
_size))
1408 for (
const auto i : make_range(dimension))
1410 _d[i] = array.
_d[i];
1411 _s[i] = array.
_s[i];
1415template <
typename T,
unsigned int dimension,
typename index_type>
1426template <
typename T,
unsigned int dimension,
typename index_type>
1439template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
1445 bool is_alloc = array.
isAlloc();
1451 std::string type =
typeid(T).name();
1454 unsigned int dim = dimension;
1457 for (
const auto dim : make_range(dimension))
1459 auto n = array.
n(
dim);
1469 T *
data =
static_cast<T *
>(std::malloc(array.
size() *
sizeof(T)));
1473 for (
const auto i : make_range(array.
size()))
1479 for (
auto & value : array)
1483template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
1490 dataLoad(stream, is_alloc,
nullptr);
1495 std::string from_type_name;
1496 dataLoad(stream, from_type_name,
nullptr);
1498 if (from_type_name !=
typeid(T).name())
1499 mooseError(
"Kokkos array error: cannot load array because the stored array is of type '",
1501 "' but the loading array is of type '",
1505 unsigned int from_dimension;
1506 dataLoad(stream, from_dimension,
nullptr);
1508 if (from_dimension != dimension)
1509 mooseError(
"Kokkos array error: cannot load array because the stored array is ",
1511 "D but the loading array is ",
1515 std::vector<index_type> from_n(dimension);
1516 std::vector<index_type>
n(dimension);
1518 for (
const auto dim : make_range(dimension))
1525 mooseError(
"Kokkos array error: cannot load array because the stored array has dimensions (",
1527 ") but the loading array has dimensions (",
1533 for (
auto & value : array)
1543 for (
auto & value :
data)
1567template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
1570#ifdef MOOSE_KOKKOS_SCOPE
1583 :
ArrayBase<T, dimension, index_type>(array)
1586#ifdef MOOSE_KOKKOS_SCOPE
1593 template <
typename... size_type>
1605 this->shallowCopy(array);
1610#ifdef MOOSE_KOKKOS_SCOPE
1617 template <
typename... indices>
1620 return this->operator[](linearIndex(i...));
1630 return this->operator[](linearIndex(idx));
1638 template <
typename indices,
typename... Args>
1639 T &
emplace(
const indices (&idx)[dimension], Args &&... args);
1643#ifdef MOOSE_KOKKOS_SCOPE
1647 template <
typename... indices>
1653 template <
typename indices>
1654 KOKKOS_FUNCTION index_type
linearIndex(
const indices (&idx)[dimension])
const
1656 return linearIndexHelper(idx, std::make_integer_sequence<unsigned int, dimension>{});
1658 template <
typename indices,
unsigned int... i>
1660 std::integer_sequence<unsigned int, i...>)
const
1662 return linearIndex(idx[i]...);
1668#ifdef MOOSE_KOKKOS_SCOPE
1669template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
1670template <
typename indices,
typename... Args>
1674 return this->
emplaceAt(linearIndex(idx), std::forward<Args>(args)...);
1677template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
1678template <
typename... indices>
1679KOKKOS_FUNCTION index_type
1682 static_assert((std::is_convertible<indices, signed_index_type>::value && ...),
1683 "All arguments must be convertible to signed_index_type");
1684 static_assert(
sizeof...(i) == dimension,
"Number of arguments should match array dimension");
1690 for (
unsigned int d = 0; d <
sizeof...(i); ++d)
1691 KOKKOS_ASSERT(idx[d] -
_d[d] >= 0 &&
static_cast<index_type
>(idx[d] -
_d[d]) <
_n[d]);
1713template <
typename T,
typename index_type>
1716#ifdef MOOSE_KOKKOS_SCOPE
1732#ifdef MOOSE_KOKKOS_SCOPE
1758 this->shallowCopy(array);
1763#ifdef MOOSE_KOKKOS_SCOPE
1771 template <
bool host,
bool device>
1774 this->
template createInternal<host, device, false>({
static_cast<index_type
>(vector.size())});
1778 if constexpr (std::is_trivially_copyable<T>())
1779 std::memcpy(this->hostData(), vector.data(), this->size() *
sizeof(T));
1781 std::copy(vector.begin(), vector.end(), this->begin());
1785 this->
template copyInternal<MemSpace, ::Kokkos::HostSpace>(
1786 this->deviceData(), vector.data(), this->size());
1795 template <
bool host,
bool device>
1798 std::vector<T> vector(set.begin(), set.end());
1800 copyVector<host, device>(vector);
1810 copyVector<true, true>(vector);
1821 copySet<true, true>(set);
1833 return this->operator[](linearIndex(i));
1841 template <
typename indices,
typename... Args>
1842 T &
emplace(
const indices (&idx)[1], Args &&... args);
1856 const bool accumulate =
false);
1884#ifdef MOOSE_KOKKOS_SCOPE
1885template <
typename T,
typename index_type>
1886template <
typename indices,
typename... Args>
1890 return this->
emplaceAt(linearIndex(idx[0]), std::forward<Args>(args)...);
1893template <
typename T,
typename index_type>
1894KOKKOS_FUNCTION index_type
1898 KOKKOS_ASSERT(i -
_d[0] >= 0 &&
static_cast<index_type
>(i -
_d[0]) <
_n[0]);
1904template <
typename T,
typename index_type = MOOSE_KOKKOS_INDEX_TYPE>
1906template <
typename T,
1907 typename index_type = MOOSE_KOKKOS_INDEX_TYPE,
1910template <
typename T,
1911 typename index_type = MOOSE_KOKKOS_INDEX_TYPE,
1914template <
typename T,
1915 typename index_type = MOOSE_KOKKOS_INDEX_TYPE,
1918template <
typename T,
1919 typename index_type = MOOSE_KOKKOS_INDEX_TYPE,
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Iterator over tracked constructed entries.
std::conditional_t< is_const, const T *, T * > pointer
std::ptrdiff_t difference_type
bool operator!=(const constructed_entry_iterator &other) const
pointer operator->() const
reference operator*() const
std::conditional_t< is_const, const ArrayBase, ArrayBase > array_type
bool operator==(const constructed_entry_iterator &other) const
std::conditional_t< is_const, const T &, T & > reference
array_type & _array
Array whose constructed entries are being iterated.
index_type _i
Current slot index in _array.
std::forward_iterator_tag iterator_category
constructed_entry_iterator & operator++()
void advanceToConstructed()
Range over tracked constructed entries.
array_type & _array
Array that provides the constructed-entry iteration bounds.
std::conditional_t< is_const, const ArrayBase, ArrayBase > array_type
constructed_entry_iterator< is_const > iterator
KOKKOS_FUNCTION friend bool operator!=(const iterator &a, const iterator &b)
std::forward_iterator_tag iterator_category
KOKKOS_FUNCTION iterator(T *p)
KOKKOS_FUNCTION pointer operator->() const
KOKKOS_FUNCTION pointer operator&() const
KOKKOS_FUNCTION iterator()
std::ptrdiff_t difference_type
KOKKOS_FUNCTION reference operator*() const
KOKKOS_FUNCTION iterator & operator++()
KOKKOS_FUNCTION iterator operator++(int)
KOKKOS_FUNCTION friend bool operator==(const iterator &a, const iterator &b)
The base class for Kokkos arrays.
bool _is_host_alias
Flag whether the host data points to an external data.
bool _is_init
Flag whether array was initialized.
index_type _n[dimension]
Size of each dimension.
typename std::make_signed< index_type >::type signed_index_type
void aliasDevice(T *ptr)
Point the device data to an external data instead of allocating it.
T * deviceData() const
Get the device data pointer.
void createDevice(size_type... n)
Allocate array on device only.
void createInternal(const std::vector< index_type > &n)
The internal method to initialize and allocate this array.
index_type unsigned_index_type
void createInternal(const std::vector< index_type > &n, bool host, bool device)
The internal method to initialize and allocate this array.
std::shared_ptr< unsigned int > _counter
Reference counter.
void copyOut(T *ptr, MemcpyType dir, index_type n, index_type offset=0)
Copy data to an external data from this array.
KOKKOS_FUNCTION bool isHostAlias() const
Get whether the host array was aliased.
unsigned int useCount() const
Get the reference count.
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 copyToHost()
Copy data from device to host.
void swap(ArrayBase< T, dimension, index_type > &array)
Swap with another Kokkos array.
void offset(const std::vector< signed_index_type > &d)
Apply starting index offsets to each dimension.
void init(size_type... n)
Initialize array with given dimensions but do not allocate.
bool _is_host_alloc
Flag whether host data was allocated.
void copyToDevice()
Copy data from host to device.
KOKKOS_FUNCTION T * data() const
Get the data pointer.
auto & operator=(const T &scalar)
Assign a scalar value uniformly.
KOKKOS_FUNCTION iterator end() const
Get the end iterator.
void shallowCopy(const ArrayBase< T, dimension, index_type > &array)
Shallow copy another Kokkos array.
KOKKOS_FUNCTION bool isAlloc() const
Get whether the array was allocated either on host or device.
ArrayBase(const LayoutType layout, size_type... n)
Constructor Initialize and allocate array with given dimensions This allocates both host and device d...
void allocDevice()
Allocate device data for an initialized array that has not allocated device data.
T * _device_data
Device data.
auto deviceView() const
Get the device unmanaged view.
signed_index_type _d[dimension]
Offset of each dimension.
void offset(offset_type... d)
Apply starting index offsets to each dimension.
const LayoutType _layout
Memory layout type.
void moveToDevice(bool should_free_host=true)
Copy data from host to device and deallocate host.
KOKKOS_FUNCTION index_type size() const
Get the total array size.
auto hostView() const
Get the host unmanaged view.
void allocHost()
Allocate host data for an initialized array that has not allocated host data.
ArrayBase(const LayoutType layout)
Constructor.
void copyInternal(T *target, const T *source, index_type n)
The internal method to perform a memory copy.
KOKKOS_FUNCTION T & operator[](index_type i) const
Get an array entry.
T & emplaceAt(index_type i, Args &&... args)
Placement-new construct slot i from args, recording initialization.
KOKKOS_FUNCTION T & last() const
Get the last element.
KOKKOS_FUNCTION bool isDeviceAlias() const
Get whether the device array was aliased.
KOKKOS_FUNCTION index_type n(unsigned int dim) const
Get the size of a dimension.
void createDevice(const std::vector< index_type > &n)
Allocate array on device only.
void copyIn(const T *ptr, MemcpyType dir, index_type n, index_type offset=0)
Copy data from an external data to this array.
KOKKOS_FUNCTION bool isHostAlloc() const
Get whether the array was allocated on host.
T * hostData() const
Get the host data pointer.
void copyToDeviceNested()
Copy all the nested Kokkos arrays including self from host to device.
bool _is_device_alias
Flag whether the device data points to an external data.
bool _is_device_alloc
Flag whether device data was allocated.
KOKKOS_FUNCTION iterator begin() const
Get the beginning iterator.
index_type _size
Total size.
void createHost(size_type... n)
Allocate array on host only.
void freeHost()
Free host data.
bool isSlotConstructed(index_type i) const
Get whether slot i is tracked as constructed.
KOKKOS_FUNCTION T & first() const
Get the first element.
constructed_entry_range< false > constructedEntries()
Get host-side range over entries tracked as constructed.
std::shared_ptr< std::vector< bool > > _slots_constructed
Non-null only for malloc-allocated arrays; tracks which slots have been emplace-constructed.
void createInternal(size_type... n)
The internal method to initialize and allocate this array.
KOKKOS_FUNCTION bool isDeviceAlloc() const
Get whether the array was allocated on device.
void createHost(const std::vector< index_type > &n)
Allocate array on host only.
void aliasHost(T *ptr)
Point the host data to an external data instead of allocating it.
void moveToHost(bool should_free_device=true)
Copy data from device to host and deallocate device.
void freeDevice()
Free device data.
void destroy()
Free all data and reset.
index_type _s[dimension]
Stride of each dimension.
constructed_entry_range< true > constructedEntries() const
Get host-side range over entries tracked as constructed.
ArrayBase(const ArrayBase< T, dimension, index_type > &array)
Copy constructor.
void create(const std::vector< index_type > &n)
Allocate array on host and device.
void create(size_type... n)
Allocate array on host and device.
Array(const std::vector< T > &vector)
Constructor Initialize and allocate array by copying a standard vector variable This allocates and co...
T dot(const Array< T, 1, index_type, LayoutType::LEFT > &x)
Perform dot product between this array and x.
void scal(const T a)
Scale this array with a.
T & emplace(const indices(&idx)[1], Args &&... args)
Placement-new construct an entry from args, recording initialization.
Array(index_type n)
Constructor Initialize and allocate array with given size This allocates both host and device data.
void axby(const T a, const Array< T, 1, index_type, LayoutType::LEFT > &x, const char op, const T b, const Array< T, 1, index_type, LayoutType::LEFT > &y, const bool accumulate=false)
Device BLAS operations.
KOKKOS_FUNCTION index_type linearIndex(signed_index_type i) const
}@
void copyVector(const std::vector< T > &vector)
Copy a standard vector variable This re-initializes and re-allocates array with the size of the vecto...
Array()
Default constructor.
KOKKOS_FUNCTION T & operator()(signed_index_type i) const
Get an array entry.
usingKokkosArrayBaseMembers(T, 1, index_type)
Array(const Array< T, 1, index_type, LayoutType::LEFT > &array)
Copy constructor.
auto & operator=(const std::vector< T > &vector)
Copy a standard vector variable This allocates and copies to both host and device data.
void scal(const T a, const Array< T, 1, index_type, LayoutType::LEFT > &x)
Scale x with a and write the result to this array.
auto & operator=(const Array< T, 1, index_type, LayoutType::LEFT > &array)
Shallow copy another Kokkos array.
auto & operator=(const std::set< T > &set)
Copy a standard set variable This allocates and copies to both host and device data.
void copySet(const std::set< T > &set)
Copy a standard set variable This re-initializes and re-allocates array with the size of the set.
T nrm2()
Compute 2-norm of this array.
T & emplace(const indices(&idx)[dimension], Args &&... args)
Placement-new construct an entry from args, recording initialization.
KOKKOS_FUNCTION index_type linearIndex(indices... i) const
Get the dimensionless index for a multi-dimensional index.
KOKKOS_FUNCTION T & operator()(indices... i) const
Get an array entry.
KOKKOS_FUNCTION T & operator()(const signed_index_type(&idx)[dimension]) const
Get an array entry using indices stored in an array.
KOKKOS_FUNCTION index_type linearIndex(const indices(&idx)[dimension]) const
Get the dimensionless index for indices stored in an array.
auto & operator=(const Array< T, dimension, index_type, layout > &array)
Shallow copy another Kokkos array.
KOKKOS_FUNCTION index_type linearIndexHelper(const indices(&idx)[dimension], std::integer_sequence< unsigned int, i... >) const
Array(const Array< T, dimension, index_type, layout > &array)
Copy constructor.
usingKokkosArrayBaseMembers(T, dimension, index_type)
Array()
Default constructor.
Array(size_type... n)
Constructor Initialize and allocate array with given dimensions This allocates both host and device d...
void initialize(EquationSystems &es, const std::string &system_name)
std::string prettyCppType(const std::string &cpp_type)
void dataLoad(std::istream &stream, Array< T, dimension, index_type, layout > &array, void *context)
LayoutType
The enumerator that dictates the memory layout.
MemcpyType
The enumerator that dictates the memory copy direction.
void dataStore(std::ostream &stream, Array< T, dimension, index_type, layout > &array, void *context)
void copyToDeviceInner(T &)
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
std::string stringify(const T &t)
conversion to string
std::string demangle(const char *name)
The type trait that determines the default behavior of copy constructor and deepCopy() If this type t...
static constexpr bool value
The type trait that determines if a template type is Kokkos array.