42#include "TpetraCore_config.h"
44#include "Kokkos_Core.hpp"
45#include "Teuchos_TimeMonitor.hpp"
46#include "Teuchos_Time.hpp"
47#include "Teuchos_RCP.hpp"
48#ifdef HAVE_TEUCHOS_ADD_TIME_MONITOR_TO_STACKED_TIMER
49#include "Teuchos_StackedTimer.hpp"
57 namespace DeepCopyTimerInjection {
58 Teuchos::RCP<Teuchos::Time> timer_;
59 bool initialized_ =
false;
61 void kokkosp_begin_deep_copy(Kokkos::Tools::SpaceHandle dst_handle,
const char* dst_name,
const void* dst_ptr,
62 Kokkos::Tools::SpaceHandle src_handle,
const char* src_name,
const void* src_ptr,
64 if(timer_ != Teuchos::null)
65 std::cout <<
"WARNING: Kokkos::deep_copy() started within another Kokkos::deep_copy(). Timers will be in error"<<std::endl;
67 timer_ = Teuchos::TimeMonitor::getNewTimer(std::string(
"Kokkos::deep_copy [")+src_handle.name+
"=>"+dst_handle.name+
"]");
69 timer_->incrementNumCalls();
70#ifdef HAVE_TEUCHOS_ADD_TIME_MONITOR_TO_STACKED_TIMER
71 const auto stackedTimer = Teuchos::TimeMonitor::getStackedTimer();
72 if (nonnull(stackedTimer))
73 stackedTimer->start(timer_->name());
77 void kokkosp_end_deep_copy() {
78 if (timer_ != Teuchos::null) {
80#ifdef HAVE_TEUCHOS_ADD_TIME_MONITOR_TO_STACKED_TIMER
82 const auto stackedTimer = Teuchos::TimeMonitor::getStackedTimer();
83 if (nonnull(stackedTimer))
84 stackedTimer->stop(timer_->name());
86 catch (std::runtime_error&) {
87 std::ostringstream warning;
89 "\n*********************************************************************\n"
90 "WARNING: Overlapping timers detected!\n"
91 "A TimeMonitor timer was stopped before a nested subtimer was\n"
92 "stopped. This is not allowed by the StackedTimer. This corner case\n"
93 "typically occurs if the TimeMonitor is stored in an RCP and the RCP is\n"
94 "assigned to a new timer. To disable this warning, either fix the\n"
95 "ordering of timer creation and destuction or disable the StackedTimer\n";
96 std::cout << warning.str() << std::endl;
97 Teuchos::TimeMonitor::setStackedTimer(Teuchos::null);
102 timer_ = Teuchos::null;
108 void AddKokkosDeepCopyToTimeMonitor(
bool force) {
109 if (!DeepCopyTimerInjection::initialized_) {
111 Kokkos::Tools::Experimental::set_begin_deep_copy_callback(DeepCopyTimerInjection::kokkosp_begin_deep_copy);
112 Kokkos::Tools::Experimental::set_end_deep_copy_callback(DeepCopyTimerInjection::kokkosp_end_deep_copy);
113 DeepCopyTimerInjection::initialized_=
true;
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.
Declaration of Tpetra::Details::DeepCopyTeuchosTimerInjection, a class that uses Kokkos' profiling li...
static bool timeKokkosDeepCopy()
Add Teuchos timers for all host calls to Kokkos::deep_copy(). This is especially useful for identifyi...
Nonmember function that computes a residual Computes R = B - A * X.
Namespace Tpetra contains the class and methods constituting the Tpetra library.