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= 36 void free(
void * ptr);
62 unsigned int dimension = 1,
63 typename index_type = MOOSE_KOKKOS_INDEX_TYPE,
76 template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
93 static constexpr
bool value =
false;
96 template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
106 template <
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>
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>;
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>
460 void offset(offset_type... d);
502 void moveToHost(
bool should_free_device =
true);
568 KOKKOS_FUNCTION iterator
begin()
const 570 KOKKOS_IF_ON_HOST(
return iterator(
_host_data);)
578 KOKKOS_FUNCTION iterator
end()
const 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>
627 void createInternal(
const std::vector<index_type> &
n,
bool host,
bool device);
636 template <
typename TargetSpace,
typename SourceSpace>
637 void copyInternal(T * target,
const T * source, index_type
n);
644 template <
typename... Args>
645 T &
emplaceAt(index_type i, Args &&... args);
649 #ifdef MOOSE_KOKKOS_SCOPE 654 template <
bool initialize>
716 template <
typename T,
unsigned int dimension,
typename index_type>
717 template <
bool is_const>
723 : _array(array), _i(i)
728 template <
typename T,
unsigned int dimension,
typename index_type>
729 template <
bool is_const>
734 advanceToConstructed();
738 template <
typename T,
unsigned int dimension,
typename index_type>
739 template <
bool is_const>
748 template <
typename T,
unsigned int dimension,
typename index_type>
749 template <
bool is_const>
754 return &_array == &other.
_array && _i == other.
_i;
757 template <
typename T,
unsigned int dimension,
typename index_type>
758 template <
bool is_const>
763 return !(*
this == other);
766 template <
typename T,
unsigned int dimension,
typename index_type>
767 template <
bool is_const>
771 while (_i < _array._size && !_array.isSlotConstructed(_i))
775 template <
typename T,
unsigned int dimension,
typename index_type>
776 template <
bool is_const>
784 template <
typename T,
unsigned int dimension,
typename index_type>
785 template <
bool is_const>
792 template <
typename T,
unsigned int dimension,
typename index_type>
793 template <
bool is_const>
797 return iterator(_array, _array._size);
800 template <
typename T,
unsigned int dimension,
typename index_type>
804 return constructed_entry_range<false>(*this);
807 template <
typename T,
unsigned int dimension,
typename index_type>
811 return constructed_entry_range<true>(*this);
814 template <
typename T,
unsigned int dimension,
typename index_type>
818 mooseAssert(i <
_size,
"isSlotConstructed index out of bounds");
826 #ifdef MOOSE_KOKKOS_SCOPE 827 template <
typename T,
unsigned int dimension,
typename index_type>
828 template <
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;
841 #endif // MOOSE_KOKKOS_SCOPE 843 template <
typename T,
unsigned int dimension,
typename index_type>
876 template <
typename T,
unsigned int dimension,
typename index_type>
894 template <
typename T,
unsigned int dimension,
typename index_type>
931 template <
typename T,
unsigned int dimension,
typename index_type>
936 mooseError(
"Kokkos array error: cannot shallow copy arrays with different layouts.");
962 #ifdef MOOSE_KOKKOS_SCOPE 963 template <
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.");
978 template <
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.");
993 template <
typename T,
unsigned int dimension,
typename index_type>
994 template <
bool initialize>
1004 std::is_default_constructible<T>::value,
1005 "Data type is not default-constructible. Initialization argument should be set to false.");
1018 template <
typename T,
unsigned int dimension,
typename index_type>
1026 static_cast<T *
>(::Kokkos::kokkos_malloc<ExecSpace::memory_space>(
_size *
sizeof(T)));
1031 template <
typename T,
unsigned int dimension,
typename index_type>
1032 template <
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;
1055 overflow_checker *=
n[i];
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)
1094 template <
typename T,
unsigned int dimension,
typename index_type>
1095 template <
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);
1111 template <
typename T,
unsigned int dimension,
typename index_type>
1112 template <
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);
1126 template <
typename T,
unsigned int dimension,
typename index_type>
1127 template <
typename TargetSpace,
typename SourceSpace>
1131 ::Kokkos::Impl::DeepCopy<TargetSpace, SourceSpace>(target, source,
n *
sizeof(T));
1135 template <
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 (",
1150 template <
typename T,
unsigned int dimension,
typename index_type>
1151 template <
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), ...);
1165 template <
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 " 1190 template <
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 " 1215 template <
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.");
1232 template <
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.");
1246 template <
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 " 1301 template <
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 " 1356 template <
typename T>
1362 template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
1366 data.copyToDeviceNested();
1369 template <
typename T,
unsigned int dimension,
typename index_type>
1379 template <
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));
1406 _d[i] = array.
_d[i];
1407 _s[i] = array.
_s[i];
1411 template <
typename T,
unsigned int dimension,
typename index_type>
1422 template <
typename T,
unsigned int dimension,
typename index_type>
1430 ::Kokkos::Experimental::fill_n(ExecSpace(),
deviceView(),
_size, scalar);
1435 template <
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;
1455 auto n = array.
n(
dim);
1465 T *
data =
static_cast<T *
>(std::malloc(array.
size() *
sizeof(T)));
1475 for (
auto &
value : array)
1479 template <
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);
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)
1532 if (array.isDeviceAlloc())
1533 array.copyToDevice();
1562 template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
1564 class Array :
public ArrayBase<T, dimension, index_type>
1566 #ifdef MOOSE_KOKKOS_SCOPE 1567 usingKokkosArrayBaseMembers(T, dimension, index_type);
1579 :
ArrayBase<T, dimension, index_type>(array)
1582 #ifdef MOOSE_KOKKOS_SCOPE 1589 template <
typename... size_type>
1606 #ifdef MOOSE_KOKKOS_SCOPE 1613 template <
typename... indices>
1634 template <
typename indices,
typename... Args>
1635 T & emplace(
const indices (&idx)[dimension], Args &&... args);
1639 #ifdef MOOSE_KOKKOS_SCOPE 1643 template <
typename... indices>
1644 KOKKOS_FUNCTION index_type linearIndex(indices... i)
const;
1648 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 1665 template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
1666 template <
typename indices,
typename... Args>
1670 return this->
emplaceAt(linearIndex(
idx), std::forward<Args>(args)...);
1673 template <
typename T,
unsigned int dimension,
typename index_type, LayoutType layout>
1674 template <
typename... indices>
1675 KOKKOS_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]);
1696 : (static_cast<signed_index_type>(i) -
_d[d]) *
_s[d])),
1700 (((
idx += (d == dimension - 1 ? static_cast<signed_index_type>(i) -
_d[d]
1709 template <
typename T,
typename index_type>
1712 #ifdef MOOSE_KOKKOS_SCOPE 1713 usingKokkosArrayBaseMembers(T, 1, index_type);
1728 #ifdef MOOSE_KOKKOS_SCOPE 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>(
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);
1837 template <
typename indices,
typename... Args>
1838 T & emplace(
const indices (&idx)[1], Args &&... args);
1847 void axby(
const T a,
1852 const bool accumulate =
false);
1860 void scal(
const T a);
1880 #ifdef MOOSE_KOKKOS_SCOPE 1881 template <
typename T,
typename index_type>
1882 template <
typename indices,
typename... Args>
1886 return this->
emplaceAt(linearIndex(
idx[0]), std::forward<Args>(args)...);
1889 template <
typename T,
typename index_type>
1890 KOKKOS_FUNCTION index_type
1894 KOKKOS_ASSERT(i -
_d[0] >= 0 && static_cast<index_type>(i -
_d[0]) <
_n[0]);
1900 template <
typename T,
typename index_type = MOOSE_KOKKOS_INDEX_TYPE>
1902 template <
typename T,
1903 typename index_type = MOOSE_KOKKOS_INDEX_TYPE,
1906 template <
typename T,
1907 typename index_type = MOOSE_KOKKOS_INDEX_TYPE,
1910 template <
typename T,
1911 typename index_type = MOOSE_KOKKOS_INDEX_TYPE,
1914 template <
typename T,
1915 typename index_type = MOOSE_KOKKOS_INDEX_TYPE,
KOKKOS_FUNCTION index_type linearIndex(indices... i) const
Get the dimensionless index for a multi-dimensional index.
std::string name(const ElemQuality q)
typename std::make_signed< index_type >::type signed_index_type
T * deviceData() const
Get the device data pointer.
MemcpyType
The enumerator that dictates the memory copy direction.
KOKKOS_FUNCTION index_type n(unsigned int dim) const
Get the size of a dimension.
KOKKOS_FUNCTION iterator(T *p)
auto & operator=(const Array< T, dimension, index_type, layout > &array)
Shallow copy another Kokkos array.
void moveToHost(bool should_free_device=true)
Copy data from device to host and deallocate device.
KOKKOS_FUNCTION pointer operator &() const
KOKKOS_FUNCTION T & last() const
Get the last element.
Array(const Array< T, dimension, index_type, layout > &array)
Copy constructor.
signed_index_type _d[dimension]
Offset of each dimension.
LayoutType
The enumerator that dictates the memory layout.
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...
KOKKOS_FUNCTION iterator operator++(int)
array_type & _array
Array that provides the constructed-entry iteration bounds.
KOKKOS_FUNCTION T & operator()(indices... i) const
Get an array entry.
Array()
Default constructor.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
KOKKOS_FUNCTION bool isDeviceAlloc() const
Get whether the array was allocated on device.
void dataLoad(std::istream &stream, Array< T, dimension, index_type, layout > &array, void *context)
Array()
Default constructor.
std::conditional_t< is_const, const T *, T * > pointer
index_type _i
Current slot index in _array.
void createHost(size_type... n)
Allocate array on host only.
std::conditional_t< is_const, const ArrayBase, ArrayBase > array_type
KOKKOS_FUNCTION T & operator[](index_type i) const
Get an array entry.
KOKKOS_FUNCTION T & operator()(signed_index_type i) const
Get an array entry.
KOKKOS_FUNCTION iterator end() const
Get the end iterator.
void moveToDevice(bool should_free_host=true)
Copy data from host to device and deallocate host.
bool operator!=(const ReporterProducerEnum &producer_mode, const ReporterMode &mode)
bool isSlotConstructed(index_type i) const
Get whether slot i is tracked as constructed.
KOKKOS_FUNCTION T & first() const
Get the first element.
void shallowCopy(const ArrayBase< T, dimension, index_type > &array)
Shallow copy another Kokkos array.
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
The type trait that determines if a template type is Kokkos array.
void allocDevice()
Allocate device data for an initialized array that has not allocated device data. ...
bool _is_device_alloc
Flag whether device data was allocated.
std::conditional_t< is_const, const ArrayBase, ArrayBase > array_type
Array(size_type... n)
Constructor Initialize and allocate array with given dimensions This allocates both host and device d...
void copyOut(T *ptr, MemcpyType dir, index_type n, index_type offset=0)
Copy data to an external data from this array.
index_type _s[dimension]
Stride of each dimension.
void swap(ArrayBase< T, dimension, index_type > &array)
Swap with another Kokkos array.
void allocHost()
Allocate host data for an initialized array that has not allocated host data.
void createInternal(size_type... n)
The internal method to initialize and allocate this array.
void initialize(EquationSystems &es, const std::string &system_name)
Range over tracked constructed entries.
bool _is_host_alloc
Flag whether host data was allocated.
auto max(const L &left, const R &right)
void aliasDevice(T *ptr)
Point the device data to an external data instead of allocating it.
KOKKOS_FUNCTION index_type linearIndexHelper(const indices(&idx)[dimension], std::integer_sequence< unsigned int, i... >) const
constructed_entry_iterator & operator++()
void advanceToConstructed()
Array(const Array< T, 1, index_type, LayoutType::LEFT > &array)
Copy constructor.
auto hostView() const
Get the host unmanaged view.
KOKKOS_FUNCTION bool isHostAlloc() const
Get whether the array was allocated on host.
auto deviceView() const
Get the device unmanaged view.
void freeDevice()
Free device data.
KOKKOS_FUNCTION bool isDeviceAlias() const
Get whether the device array was aliased.
bool operator!=(const constructed_entry_iterator &other) const
KOKKOS_FUNCTION bool isAlloc() const
Get whether the array was allocated either on host or device.
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...
index_type _size
Total size.
const LayoutType _layout
Memory layout type.
KOKKOS_FUNCTION pointer operator->() const
bool operator==(const std::unique_ptr< Attribute > &lhs, const std::unique_ptr< Attribute > &rhs)
TheWarehouse uses this operator function for indexing and caching queries.
std::ptrdiff_t difference_type
bool _is_device_alias
Flag whether the device data points to an external data.
KOKKOS_FUNCTION friend bool operator==(const iterator &a, const iterator &b)
Iterator over tracked constructed entries.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
void copyToDeviceInner(T &)
unsigned int useCount() const
Get the reference count.
std::forward_iterator_tag iterator_category
Array(const std::vector< T > &vector)
Constructor Initialize and allocate array by copying a standard vector variable This allocates and co...
void create(const std::vector< index_type > &n)
Allocate array on host and device.
constructed_entry_range< false > constructedEntries()
Get host-side range over entries tracked as constructed.
KOKKOS_FUNCTION T * data() const
Get the data pointer.
void aliasHost(T *ptr)
Point the host data to an external data instead of allocating it.
The base class for Kokkos arrays.
T & emplaceAt(index_type i, Args &&... args)
Placement-new construct slot i from args, recording initialization.
void copyToDevice()
Copy data from host to device.
KOKKOS_FUNCTION index_type size() const
Get the total array size.
void dataStore(std::ostream &stream, Array< T, dimension, index_type, layout > &array, void *context)
void create(size_type... n)
Allocate array on host and device.
void copyIn(const T *ptr, MemcpyType dir, index_type n, index_type offset=0)
Copy data from an external data to this array.
void destroy()
Free all data and reset.
std::string stringify(const T &t)
conversion to string
ArrayBase(const ArrayBase< T, dimension, index_type > &array)
Copy constructor.
std::string demangle(const char *name)
std::shared_ptr< unsigned int > _counter
Reference counter.
KOKKOS_FUNCTION iterator & operator++()
KOKKOS_FUNCTION friend bool operator!=(const iterator &a, const iterator &b)
ArrayBase(const LayoutType layout)
Constructor.
The type trait that determines the default behavior of copy constructor and deepCopy() If this type t...
bool _is_host_alias
Flag whether the host data points to an external data.
KOKKOS_FUNCTION T & operator()(const signed_index_type(&idx)[dimension]) const
Get an array entry using indices stored in an array.
auto & operator=(const T &scalar)
Assign a scalar value uniformly.
std::conditional_t< is_const, const T &, T & > reference
void createDevice(const std::vector< index_type > &n)
Allocate array on device only.
KOKKOS_FUNCTION reference operator*() const
KOKKOS_FUNCTION iterator begin() const
Get the beginning iterator.
void copyInternal(T *target, const T *source, index_type n)
The internal method to perform a memory copy.
T & emplace(const indices(&idx)[dimension], Args &&... args)
Placement-new construct an entry from args, recording initialization.
std::shared_ptr< std::vector< bool > > _slots_constructed
Non-null only for malloc-allocated arrays; tracks which slots have been emplace-constructed.
pointer operator->() const
std::forward_iterator_tag iterator_category
IntRange< T > make_range(T beg, T end)
infix_ostream_iterator< T, charT, traits > & operator++()
array_type & _array
Array whose constructed entries are being iterated.
auto & operator=(const Array< T, 1, index_type, LayoutType::LEFT > &array)
Shallow copy another Kokkos array.
void init(size_type... n)
Initialize array with given dimensions but do not allocate.
constructed_entry_iterator(array_type &array, index_type i)
index_type unsigned_index_type
reference operator*() const
T * hostData() const
Get the host data pointer.
T * _device_data
Device data.
auto & operator=(const std::set< T > &set)
Copy a standard set variable This allocates and copies to both host and device data.
bool operator==(const constructed_entry_iterator &other) const
Array(index_type n)
Constructor Initialize and allocate array with given size This allocates both host and device data...
void copyToDeviceNested()
Copy all the nested Kokkos arrays including self from host to device.
auto & operator=(const std::vector< T > &vector)
Copy a standard vector variable This allocates and copies to both host and device data...
void createDevice(size_type... n)
Allocate array on device only.
constructed_entry_range(array_type &array)
bool _is_init
Flag whether array was initialized.
void copyToHost()
Copy data from device to host.
void createHost(const std::vector< index_type > &n)
Allocate array on host only.
ArrayBase(const LayoutType layout, size_type... n)
Constructor Initialize and allocate array with given dimensions This allocates both host and device d...
std::ptrdiff_t difference_type
void freeHost()
Free host data.
KOKKOS_FUNCTION bool isHostAlias() const
Get whether the host array was aliased.
auto index_range(const T &sizable)
KOKKOS_FUNCTION index_type linearIndex(const indices(&idx)[dimension]) const
Get the dimensionless index for indices stored in an array.
static constexpr bool value
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 ...
std::string prettyCppType(const std::string &cpp_type)
index_type _n[dimension]
Size of each dimension.
void offset(const std::vector< signed_index_type > &d)
Apply starting index offsets to each dimension.
KOKKOS_FUNCTION iterator()