10 #ifndef TPETRA_DETAILS_REALLOCDUALVIEWIFNEEDED_HPP
11 #define TPETRA_DETAILS_REALLOCDUALVIEWIFNEEDED_HPP
21 #include "Kokkos_DualView.hpp"
49 template<
class ValueType,
class DeviceType>
53 const char newLabel[],
54 const size_t tooBigFactor = 2,
55 const bool needFenceBeforeRealloc =
true)
57 typedef typename DeviceType::execution_space execution_space;
58 typedef Kokkos::DualView<ValueType*, DeviceType> dual_view_type;
59 typedef Kokkos::pair<size_t, size_t> range_type;
65 const size_t curSize =
static_cast<size_t> (dv.extent (0));
66 if (curSize == newSize) {
69 else if (curSize < newSize) {
70 if (needFenceBeforeRealloc) {
71 execution_space().fence ();
73 dv = dual_view_type ();
75 dv = dual_view_type (curSize == 0 ? newLabel : dv.d_view.label (), newSize);
80 if (needFenceBeforeRealloc) {
81 execution_space().fence ();
84 dv = dual_view_type (curSize == 0 ? newLabel : dv.d_view.label (), 0);
90 else if (curSize / newSize >= tooBigFactor) {
93 if (needFenceBeforeRealloc) {
94 execution_space().fence ();
96 dv = dual_view_type ();
98 dv = dual_view_type (curSize == 0 ? newLabel : dv.d_view.label (), newSize);
102 dv.d_view = Kokkos::subview (dv.d_view, range_type (0, newSize));
103 dv.h_view = Kokkos::subview (dv.h_view, range_type (0, newSize));
110 template<
class ValueType,
class DeviceType>
113 const size_t newSize,
114 const std::string& newLabel,
115 const size_t tooBigFactor = 2,
116 const bool needFenceBeforeRealloc =
true)
118 return reallocDualViewIfNeeded<ValueType, DeviceType> (exports, newSize,
121 needFenceBeforeRealloc);
127 #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.