40 #ifndef TPETRA_DETAILS_CHECKVIEW_HPP
41 #define TPETRA_DETAILS_CHECKVIEW_HPP
52 #include "Kokkos_DualView.hpp"
53 #include "Teuchos_TypeNameTraits.hpp"
54 #include "Teuchos_Comm.hpp"
55 #include "Teuchos_CommHelpers.hpp"
61 template<
class ExecutionSpace>
64 const ExecutionSpace& space);
95 template<
class DataType,
class ... Properties>
98 (std::ostream* lclErrStrm,
99 const int myMpiProcessRank,
100 const Kokkos::View<DataType, Properties...>& view)
102 using Teuchos::TypeNameTraits;
104 using view_type = Kokkos::View<DataType, Properties...>;
105 using ES =
typename view_type::execution_space;
107 if (view.size () == 0) {
113 auto ptr = view.data ();
115 if (ptr ==
nullptr) {
116 if (lclErrStrm !=
nullptr) {
117 const std::string viewName = TypeNameTraits<view_type>::name ();
118 *lclErrStrm <<
"Proc " << myMpiProcessRank <<
": Kokkos::View "
119 "of type " << viewName <<
" has nonzero size " << view.size ()
120 <<
" but a null pointer." << endl;
126 if (! canAcc && lclErrStrm !=
nullptr) {
127 const std::string viewName = TypeNameTraits<view_type>::name ();
128 const std::string esName = TypeNameTraits<ES>::name ();
129 *lclErrStrm <<
"Proc " << myMpiProcessRank <<
": Kokkos::View "
130 "of type " << viewName <<
" and nonzero size " << view.size ()
131 <<
" has a pointer " << ptr <<
" which is nonnull, but not "
132 "accessible from the View's claimed execution space "
133 << esName <<
". As far as I can tell, the View's pointer "
145 template<
class DataType ,
146 class Arg1Type = void ,
147 class Arg2Type = void ,
148 class Arg3Type =
void>
151 (std::ostream*
const lclErrStrm,
152 const int myMpiProcessRank,
153 const Kokkos::DualView<DataType, Arg1Type, Arg2Type, Arg3Type>& dv)
155 const bool dev_good =
158 const bool host_good =
161 const bool good = dev_good && host_good;
162 if (! good && lclErrStrm !=
nullptr) {
163 using Teuchos::TypeNameTraits;
166 Kokkos::DualView<DataType, Arg1Type, Arg2Type, Arg3Type>;
168 const std::string dvName = TypeNameTraits<dv_type>::name ();
169 *lclErrStrm <<
"Proc " << myMpiProcessRank <<
": Kokkos::DualView "
170 "of type " << dvName <<
" has one or more invalid Views. See "
171 "above error messages from this MPI process for details." << endl;
176 template<
class DataType ,
177 class Arg1Type = void ,
178 class Arg2Type = void ,
179 class Arg3Type =
void>
181 checkGlobalDualViewValidity
182 (std::ostream*
const gblErrStrm,
183 const Kokkos::DualView<DataType, Arg1Type, Arg2Type, Arg3Type>& dv,
185 const Teuchos::Comm<int>*
const comm)
188 const int myRank = comm ==
nullptr ? 0 : comm->getRank ();
189 std::ostringstream lclErrStrm;
193 const bool lclValid =
195 lclSuccess = lclValid ? 1 : 0;
197 catch (std::exception& e) {
198 lclErrStrm <<
"Proc " << myRank <<
": checkLocalDualViewValidity "
199 "threw an exception: " << e.what () << endl;
203 lclErrStrm <<
"Proc " << myRank <<
": checkLocalDualViewValidity "
204 "threw an exception not a subclass of std::exception." << endl;
209 if (comm ==
nullptr) {
210 gblSuccess = lclSuccess;
213 using Teuchos::outArg;
214 using Teuchos::REDUCE_MIN;
215 using Teuchos::reduceAll;
216 reduceAll (*comm, REDUCE_MIN, lclSuccess, outArg (gblSuccess));
219 if (gblSuccess != 1 && gblErrStrm !=
nullptr) {
220 *gblErrStrm <<
"On at least one (MPI) process, the "
221 "Kokkos::DualView has either device or host pointer that "
222 "is not accessible from the corresponding execution space. "
223 "This can happen if you, the user, created the DualView "
224 "with raw pointer(s) that is/are not in the correct memory "
225 "space. For example, you may have a Kokkos::DualView whose "
226 "device memory_space is Kokkos::CudaUVMSpace, but you gave "
227 "the device View's constructor a raw host pointer. It may "
228 "also happen if either the device or host pointer in the "
229 "DualView is null, but the DualView has a nonzero number of "
230 "rows. For more detailed information, please rerun with the "
231 "TPETRA_VERBOSE environment variable set to 1. (You do not "
232 "need to recompile.)";
234 *gblErrStrm <<
" Here are error messages from all "
235 "processes:" << endl;
236 if (comm ==
nullptr) {
237 *gblErrStrm << lclErrStrm.str ();
246 return gblSuccess == 1;
252 #endif // TPETRA_DETAILS_CHECKVIEW_HPP
bool checkLocalDualViewValidity(std::ostream *const lclErrStrm, const int myMpiProcessRank, const Kokkos::DualView< DataType, Arg1Type, Arg2Type, Arg3Type > &dv)
Is the given Kokkos::DualView valid?
std::string memorySpaceName(const void *ptr)
Return the Kokkos memory space name (without "Kokkos::") corresponding to the given nonnull pointer...
Declaration of functions for checking whether a given pointer is accessible from a given Kokkos execu...
Declaration of a function that prints strings from each process.
bool pointerAccessibleFromExecutionSpace(const void *ptr, const ExecutionSpace &space)
Is the given nonnull ptr accessible from the given execution space?
void gathervPrint(std::ostream &out, const std::string &s, const Teuchos::Comm< int > &comm)
On Process 0 in the given communicator, print strings from each process in that communicator, in rank order.
bool checkLocalViewValidity(std::ostream *lclErrStrm, const int myMpiProcessRank, const Kokkos::View< DataType, Properties...> &view)
Is the given View valid?