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
328 KOKKOS_FUNCTION T &
last()
const
342 KOKKOS_ASSERT(i <
_size);
365 return ::Kokkos::View<T *, ::Kokkos::HostSpace, ::Kokkos::MemoryTraits<::Kokkos::Unmanaged>>(
374 return ::Kokkos::View<T *, MemSpace, ::Kokkos::MemoryTraits<::Kokkos::Unmanaged>>(
_device_data,
381 template <
typename... size_type>
384 createInternal<false, false, false>(
n...);
391 template <
bool initialize = true>
392 void create(
const std::vector<index_type> &
n)
394 createInternal<true, true, initialize>(
n);
401 template <
bool initialize =
true,
typename... size_type>
404 createInternal<true, true, initialize>(
n...);
411 template <
bool initialize = true>
414 createInternal<true, false, initialize>(
n);
421 template <
bool initialize =
true,
typename... size_type>
424 createInternal<true, false, initialize>(
n...);
430 void createDevice(
const std::vector<index_type> &
n) { createInternal<false, true, false>(
n); }
435 template <
typename... size_type>
438 createInternal<false, true, false>(
n...);
454 void offset(
const std::vector<signed_index_type> & d);
459 template <
typename... offset_type>
590 index_type
_n[dimension] = {0};
594 index_type
_s[dimension] = {0};
600#ifdef MOOSE_KOKKOS_SCOPE
608 template <
bool host,
bool device,
bool initialize,
typename... size_type>
617 template <
bool host,
bool device,
bool initialize>
626 template <
bool initialize>
636 template <
typename TargetSpace,
typename SourceSpace>
644 template <
typename... Args>
649#ifdef MOOSE_KOKKOS_SCOPE
654 template <
bool initialize>
716template <
typename T,
unsigned int dimension,
typename index_type>
717template <
bool is_const>
721 is_const>::array_type & array,
723 : _array(array), _i(i)
728template <
typename T,
unsigned int dimension,
typename index_type>
729template <
bool is_const>
734 advanceToConstructed();
738template <
typename T,
unsigned int dimension,
typename index_type>
739template <
bool is_const>
748template <
typename T,
unsigned int dimension,
typename index_type>
749template <
bool is_const>
754 return &_array == &other.
_array && _i == other.
_i;
757template <
typename T,
unsigned int dimension,
typename index_type>
758template <
bool is_const>
763 return !(*
this == other);
766template <
typename T,
unsigned int dimension,
typename index_type>
767template <
bool is_const>
771 while (_i < _array._size && !_array.isSlotConstructed(_i))
775template <
typename T,
unsigned int dimension,
typename index_type>
776template <
bool is_const>
779 is_const>::array_type & array)
784template <
typename T,
unsigned int dimension,
typename index_type>
785template <
bool is_const>
792template <
typename T,
unsigned int dimension,
typename index_type>
793template <
bool is_const>
797 return iterator(_array, _array._size);
800template <
typename T,
unsigned int dimension,
typename index_type>
807template <
typename T,
unsigned int dimension,
typename index_type>
814template <
typename T,
unsigned int dimension,
typename index_type>
818 mooseAssert(i <
_size,
"isSlotConstructed index out of bounds");
826#ifdef MOOSE_KOKKOS_SCOPE
827template <
typename T,
unsigned int dimension,
typename index_type>
828template <
typename... Args>
833 "emplaceAt requires a malloc-allocated array (create<false>)");
834 mooseAssert(i <
_size,
"emplaceAt index out of bounds");
836 new (
_host_data + i) T(std::forward<Args>(args)...);
837 (*_slots_constructed)[i] =
true;
843template <
typename T,
unsigned int dimension,
typename index_type>
863 for (
const auto i : make_range(
_size))
876template <
typename T,
unsigned int dimension,
typename index_type>
894template <
typename T,
unsigned int dimension,
typename index_type>
914 for (
const auto i : make_range(dimension))
931template <
typename T,
unsigned int dimension,
typename index_type>
936 mooseError(
"Kokkos array error: cannot shallow copy arrays with different layouts.");
945 for (
const auto i : make_range(dimension))
962#ifdef MOOSE_KOKKOS_SCOPE
963template <
typename T,
unsigned int dimension,
typename index_type>
968 mooseError(
"Kokkos array error: attempted to alias host data before array initialization.");
971 mooseError(
"Kokkos array error: cannot alias host data because host data was not aliased.");
978template <
typename T,
unsigned int dimension,
typename index_type>
983 mooseError(
"Kokkos array error: attempted to alias device data before array initialization.");
986 mooseError(
"Kokkos array error: cannot alias device data because device data was not aliased.");
993template <
typename T,
unsigned int dimension,
typename index_type>
994template <
bool initialize>
1004 std::is_default_constructible<T>::value,
1005 "Data type is not default-constructible. Initialization argument should be set to false.");
1018template <
typename T,
unsigned int dimension,
typename index_type>
1026 static_cast<T *
>(::Kokkos::kokkos_malloc<ExecSpace::memory_space>(
_size *
sizeof(T)));
1031template <
typename T,
unsigned int dimension,
typename index_type>
1032template <
bool host,
bool device,
bool initialize>
1036 if (
n.size() != dimension)
1037 mooseError(
"Kokkos array error: the number of dimensions provided (",
1039 ") must match the array dimension (",
1046 _counter = std::make_shared<unsigned int>();
1048 uint64_t overflow_checker = 1;
1053 for (
const auto i : make_range(dimension))
1055 overflow_checker *=
n[i];
1061 if (overflow_checker > std::numeric_limits<index_type>::max())
1062 mooseError(
"Kokkos array error: the dimensions provided (",
1064 ") has the total size of ",
1066 " which exceeds the limit of ",
1067 MooseUtils::prettyCppType<index_type>(),
1074 for (
const auto i : make_range(1u, dimension))
1075 _s[i] =
_s[i - 1] *
_n[i - 1];
1079 _s[dimension - 1] = 1;
1081 for (
int i = dimension - 2; i >= 0; --i)
1082 _s[i] =
_s[i + 1] *
_n[i + 1];
1086 allocHost<initialize>();
1088 if constexpr (device)
1094template <
typename T,
unsigned int dimension,
typename index_type>
1095template <
bool initialize>
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);
1108 createInternal<false, false, initialize>(
n);
1111template <
typename T,
unsigned int dimension,
typename index_type>
1112template <
bool host,
bool device,
bool initialize,
typename... size_type>
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");
1120 std::vector<index_type> dims;
1121 (dims.push_back(
n), ...);
1123 createInternal<host, device, initialize>(dims);
1126template <
typename T,
unsigned int dimension,
typename index_type>
1127template <
typename TargetSpace,
typename SourceSpace>
1131 ::Kokkos::Impl::DeepCopy<TargetSpace, SourceSpace>(target, source,
n *
sizeof(T));
1135template <
typename T,
unsigned int dimension,
typename index_type>
1139 if (d.size() > dimension)
1140 mooseError(
"Kokkos array error: the number of offsets provided (",
1142 ") cannot be larger than the array dimension (",
1146 for (
const auto i : index_range(d))
1150template <
typename T,
unsigned int dimension,
typename index_type>
1151template <
typename... offset_type>
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");
1159 std::vector<signed_index_type> offsets;
1160 (offsets.push_back(d), ...);
1165template <
typename T,
unsigned int dimension,
typename index_type>
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 "
1190template <
typename T,
unsigned int dimension,
typename index_type>
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 "
1215template <
typename T,
unsigned int dimension,
typename index_type>
1220 "moveToDevice() not allowed for a nested array whose data type is another array.");
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.");
1232template <
typename T,
unsigned int dimension,
typename index_type>
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.");
1246template <
typename T,
unsigned int dimension,
typename index_type>
1254 mooseError(
"Kokkos array error: cannot copy in data larger than the array size.");
1257 mooseError(
"Kokkos array error: offset cannot be larger than the array size.");
1264 "Kokkos array error: cannot copy in to the array because host memory was not allocated.");
1267 copyInternal<::Kokkos::HostSpace, ::Kokkos::HostSpace>(
_host_data +
offset, ptr,
n);
1273 mooseError(
"Kokkos array error: cannot copy in to the array because device memory was not "
1284 "Kokkos array error: cannot copy in to the array because host memory was not allocated.");
1293 mooseError(
"Kokkos array error: cannot copy in to the array because device memory was not "
1301template <
typename T,
unsigned int dimension,
typename index_type>
1309 mooseError(
"Kokkos array error: cannot copy out data larger than the array size.");
1312 mooseError(
"Kokkos array error: offset cannot be larger than the array size.");
1318 mooseError(
"Kokkos array error: cannot copy out from the array because host memory was not "
1322 copyInternal<::Kokkos::HostSpace, ::Kokkos::HostSpace>(ptr,
_host_data +
offset,
n);
1328 mooseError(
"Kokkos array error: cannot copy out from the array because host memory was not "
1338 mooseError(
"Kokkos array error: cannot copy out from the array because device memory was not "
1348 mooseError(
"Kokkos array error: cannot copy out from the array because device memory was not "
1356template <
typename T>
1362template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
1366 data.copyToDeviceNested();
1369template <
typename T,
unsigned int dimension,
typename index_type>
1373 for (
const auto i : make_range(
_size))
1379template <
typename T,
unsigned int dimension,
typename index_type>
1384 mooseError(
"Kokkos array error: cannot deep copy arrays with different layouts.");
1388 "Kokkos array error: cannot deep copy using constructor from array without host data.");
1390 std::vector<index_type>
n(std::begin(array.
_n), std::end(array.
_n));
1395 for (
const auto i : make_range(
_size))
1404 for (
const auto i : make_range(dimension))
1406 _d[i] = array.
_d[i];
1407 _s[i] = array.
_s[i];
1411template <
typename T,
unsigned int dimension,
typename index_type>
1422template <
typename T,
unsigned int dimension,
typename index_type>
1430 ::Kokkos::Experimental::fill_n(ExecSpace(),
deviceView(),
_size, scalar);
1435template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
1441 bool is_alloc = array.
isAlloc();
1447 std::string type =
typeid(T).name();
1450 unsigned int dim = dimension;
1453 for (
const auto dim : make_range(dimension))
1455 auto n = array.
n(
dim);
1465 T *
data =
static_cast<T *
>(std::malloc(array.
size() *
sizeof(T)));
1469 for (
const auto i : make_range(array.
size()))
1475 for (
auto & value : array)
1479template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
1486 dataLoad(stream, is_alloc,
nullptr);
1491 std::string from_type_name;
1492 dataLoad(stream, from_type_name,
nullptr);
1494 if (from_type_name !=
typeid(T).name())
1495 mooseError(
"Kokkos array error: cannot load array because the stored array is of type '",
1497 "' but the loading array is of type '",
1501 unsigned int from_dimension;
1502 dataLoad(stream, from_dimension,
nullptr);
1504 if (from_dimension != dimension)
1505 mooseError(
"Kokkos array error: cannot load array because the stored array is ",
1507 "D but the loading array is ",
1511 std::vector<index_type> from_n(dimension);
1512 std::vector<index_type>
n(dimension);
1514 for (
const auto dim : make_range(dimension))
1521 mooseError(
"Kokkos array error: cannot load array because the stored array has dimensions (",
1523 ") but the loading array has dimensions (",
1529 for (
auto & value : array)
1539 for (
auto & value :
data)
1563template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
1566#ifdef MOOSE_KOKKOS_SCOPE
1579 :
ArrayBase<T, dimension, index_type>(array)
1582#ifdef MOOSE_KOKKOS_SCOPE
1589 template <
typename... size_type>
1601 this->shallowCopy(array);
1606#ifdef MOOSE_KOKKOS_SCOPE
1613 template <
typename... indices>
1616 return this->operator[](linearIndex(i...));
1626 return this->operator[](linearIndex(idx));
1634 template <
typename indices,
typename... Args>
1635 T &
emplace(
const indices (&idx)[dimension], Args &&... args);
1639#ifdef MOOSE_KOKKOS_SCOPE
1643 template <
typename... indices>
1649 template <
typename indices>
1650 KOKKOS_FUNCTION index_type
linearIndex(
const indices (&idx)[dimension])
const
1652 return linearIndexHelper(idx, std::make_integer_sequence<unsigned int, dimension>{});
1654 template <
typename indices,
unsigned int... i>
1656 std::integer_sequence<unsigned int, i...>)
const
1658 return linearIndex(idx[i]...);
1664#ifdef MOOSE_KOKKOS_SCOPE
1665template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
1666template <
typename indices,
typename... Args>
1670 return this->
emplaceAt(linearIndex(idx), std::forward<Args>(args)...);
1673template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
1674template <
typename... indices>
1675KOKKOS_FUNCTION index_type
1678 static_assert((std::is_convertible<indices, signed_index_type>::value && ...),
1679 "All arguments must be convertible to signed_index_type");
1680 static_assert(
sizeof...(i) == dimension,
"Number of arguments should match array dimension");
1686 for (
unsigned int d = 0; d <
sizeof...(i); ++d)
1687 KOKKOS_ASSERT(idx[d] -
_d[d] >= 0 &&
static_cast<index_type
>(idx[d] -
_d[d]) <
_n[d]);
1709template <
typename T,
typename index_type>
1712#ifdef MOOSE_KOKKOS_SCOPE
1728#ifdef MOOSE_KOKKOS_SCOPE
1754 this->shallowCopy(array);
1759#ifdef MOOSE_KOKKOS_SCOPE
1767 template <
bool host,
bool device>
1770 this->
template createInternal<host, device, false>({
static_cast<index_type
>(vector.size())});
1774 if constexpr (std::is_trivially_copyable<T>())
1775 std::memcpy(this->hostData(), vector.data(), this->size() *
sizeof(T));
1777 std::copy(vector.begin(), vector.end(), this->begin());
1781 this->
template copyInternal<MemSpace, ::Kokkos::HostSpace>(
1782 this->deviceData(), vector.data(), this->size());
1791 template <
bool host,
bool device>
1794 std::vector<T> vector(set.begin(), set.end());
1796 copyVector<host, device>(vector);
1806 copyVector<true, true>(vector);
1817 copySet<true, true>(set);
1829 return this->operator[](linearIndex(i));
1837 template <
typename indices,
typename... Args>
1838 T &
emplace(
const indices (&idx)[1], Args &&... args);
1852 const bool accumulate =
false);
1880#ifdef MOOSE_KOKKOS_SCOPE
1881template <
typename T,
typename index_type>
1882template <
typename indices,
typename... Args>
1886 return this->
emplaceAt(linearIndex(idx[0]), std::forward<Args>(args)...);
1889template <
typename T,
typename index_type>
1890KOKKOS_FUNCTION index_type
1894 KOKKOS_ASSERT(i -
_d[0] >= 0 &&
static_cast<index_type
>(i -
_d[0]) <
_n[0]);
1900template <
typename T,
typename index_type = MOOSE_KOKKOS_INDEX_TYPE>
1902template <
typename T,
1903 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,
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.