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"
61 namespace DeepCopyTimerInjection {
62 Teuchos::RCP<Teuchos::Time> timer_;
63 bool initialized_ =
false;
65 void kokkosp_begin_deep_copy(Kokkos::Tools::SpaceHandle dst_handle,
const char* dst_name,
const void* dst_ptr,
66 Kokkos::Tools::SpaceHandle src_handle,
const char* src_name,
const void* src_ptr,
69 std::string extra_label;
71 extra_label = std::string(
" {") + src_name +
"=>" + dst_name +
"," + std::to_string(size)+
"}";
74 if(timer_ != Teuchos::null)
75 std::cout <<
"WARNING: Kokkos::deep_copy() started within another Kokkos::deep_copy(). Timers will be in error"<<std::endl;
78 if(!strcmp(src_name,
"Scalar"))
79 timer_ = Teuchos::TimeMonitor::getNewTimer(std::string(
"Kokkos::deep_copy_scalar [")+src_handle.name+
"=>"+dst_handle.name+
"]" + extra_label);
82 timer_ = Teuchos::TimeMonitor::getNewTimer(std::string(
"Kokkos::deep_copy_small [")+src_handle.name+
"=>"+dst_handle.name+
"]" + extra_label);
84 timer_ = Teuchos::TimeMonitor::getNewTimer(std::string(
"Kokkos::deep_copy [")+src_handle.name+
"=>"+dst_handle.name+
"]" + extra_label);
86 timer_->incrementNumCalls();
87 #ifdef HAVE_TEUCHOS_ADD_TIME_MONITOR_TO_STACKED_TIMER
88 const auto stackedTimer = Teuchos::TimeMonitor::getStackedTimer();
89 if (nonnull(stackedTimer))
90 stackedTimer->start(timer_->name());
94 void kokkosp_end_deep_copy() {
95 if (timer_ != Teuchos::null) {
97 #ifdef HAVE_TEUCHOS_ADD_TIME_MONITOR_TO_STACKED_TIMER
99 const auto stackedTimer = Teuchos::TimeMonitor::getStackedTimer();
100 if (nonnull(stackedTimer))
101 stackedTimer->stop(timer_->name());
103 catch (std::runtime_error&) {
104 std::ostringstream warning;
106 "\n*********************************************************************\n"
107 "WARNING: Overlapping timers detected!\n"
108 "A TimeMonitor timer was stopped before a nested subtimer was\n"
109 "stopped. This is not allowed by the StackedTimer. This corner case\n"
110 "typically occurs if the TimeMonitor is stored in an RCP and the RCP is\n"
111 "assigned to a new timer. To disable this warning, either fix the\n"
112 "ordering of timer creation and destuction or disable the StackedTimer\n";
113 std::cout << warning.str() << std::endl;
114 Teuchos::TimeMonitor::setStackedTimer(Teuchos::null);
119 timer_ = Teuchos::null;
125 void AddKokkosDeepCopyToTimeMonitor(
bool force) {
126 if (!DeepCopyTimerInjection::initialized_) {
128 Kokkos::Tools::Experimental::set_begin_deep_copy_callback(DeepCopyTimerInjection::kokkosp_begin_deep_copy);
129 Kokkos::Tools::Experimental::set_end_deep_copy_callback(DeepCopyTimerInjection::kokkosp_end_deep_copy);
130 DeepCopyTimerInjection::initialized_=
true;
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...
static bool timeKokkosDeepCopyVerbose()
Adds verbose output to Kokkos deep_copy timers This is especially useful for identifying host/device ...
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.