42 #ifndef TPETRA_DETAILS_REALLOCDUALVIEWIFNEEDED_HPP
43 #define TPETRA_DETAILS_REALLOCDUALVIEWIFNEEDED_HPP
53 #include "Kokkos_DualView.hpp"
81 template<
class ValueType,
class DeviceType>
85 const char newLabel[],
86 const size_t tooBigFactor = 2,
87 const bool needFenceBeforeRealloc =
true)
89 typedef typename DeviceType::execution_space execution_space;
90 typedef Kokkos::DualView<ValueType*, DeviceType> dual_view_type;
91 typedef Kokkos::pair<size_t, size_t> range_type;
97 const size_t curSize =
static_cast<size_t> (dv.extent (0));
98 if (curSize == newSize) {
101 else if (curSize < newSize) {
102 if (needFenceBeforeRealloc) {
103 execution_space::fence ();
105 dv = dual_view_type ();
107 dv = dual_view_type (curSize == 0 ? newLabel : dv.d_view.label (), newSize);
108 execution_space::fence ();
113 if (needFenceBeforeRealloc) {
114 execution_space::fence ();
117 dv = dual_view_type (curSize == 0 ? newLabel : dv.d_view.label (), 0);
118 execution_space::fence ();
124 else if (curSize / newSize >= tooBigFactor) {
127 if (needFenceBeforeRealloc) {
128 execution_space::fence ();
130 dv = dual_view_type ();
132 dv = dual_view_type (curSize == 0 ? newLabel : dv.d_view.label (), newSize);
133 execution_space::fence ();
137 dv.d_view = Kokkos::subview (dv.d_view, range_type (0, newSize));
138 dv.h_view = Kokkos::subview (dv.h_view, range_type (0, newSize));
145 template<
class ValueType,
class DeviceType>
148 const size_t newSize,
149 const std::string& newLabel,
150 const size_t tooBigFactor = 2,
151 const bool needFenceBeforeRealloc =
true)
153 return reallocDualViewIfNeeded<ValueType, DeviceType> (exports, newSize,
156 needFenceBeforeRealloc);
162 #endif // TPETRA_DETAILS_REALLOCDUALVIEWIFNEEDED_HPP
Declaration of Tpetra::Details::Profiling, a scope guard for Kokkos Profiling.
bool reallocDualViewIfNeeded(Kokkos::DualView< ValueType *, DeviceType > &dv, const size_t newSize, const char newLabel[], const size_t tooBigFactor=2, const bool needFenceBeforeRealloc=true)
Reallocate the DualView in/out argument, if needed.