17 #include "profile_observer.h" 18 #include "caffe2/core/logging.h" 22 void ProfileOperatorObserver::Dump()
const {
23 static std::mutex loggingMutex;
24 std::lock_guard<std::mutex> lock(loggingMutex);
26 LOG(INFO) <<
"--------- Starting operator " << subject_->debug_def().type()
27 <<
" op#" << getId() <<
" ---------";
28 for (
int i = 0; i < subject_->InputSize(); ++i) {
29 if (subject_->InputIsTensorType(i, CPU)) {
30 const auto& tensor = subject_->Input<
Tensor>(i, CPU);
31 const auto& name = subject_->debug_def().input(i);
32 TensorPrinter printer(name);
33 LOG(INFO) <<
"Input " << i <<
": " << printer.MetaStr(tensor);
34 }
else if (subject_->InputIsTensorType(i, CUDA)) {
35 const auto& tensor = subject_->Input<
Tensor>(i, CUDA);
36 const auto& name = subject_->debug_def().input(i);
37 TensorPrinter printer(name);
38 LOG(INFO) <<
"Input " << i <<
": " << printer.MetaStr(tensor);
43 for (
const auto& arg : subject_->debug_def().arg()) {
44 LOG(INFO) <<
"Argument " << a <<
": " << arg.ShortDebugString();
48 for (
int o = 0; o < subject_->OutputSize(); ++o) {
49 if (subject_->OutputIsTensorType(o, CPU)) {
50 auto* tensor = subject_->Output<
Tensor>(o, CPU);
51 const auto& name = subject_->debug_def().output(o);
52 TensorPrinter printer(name);
53 LOG(INFO) <<
"Output " << o <<
": " << printer.MetaStr(*tensor);
54 }
else if (subject_->OutputIsTensorType(o, CUDA)) {
55 auto* tensor = subject_->Output<
Tensor>(o, CUDA);
56 const auto& name = subject_->debug_def().output(o);
57 TensorPrinter printer(name);
58 LOG(INFO) <<
"Output " << o <<
": " << printer.MetaStr(*tensor);
62 LOG(INFO) <<
"--------- Finished operator " << subject_->debug_def().type()
63 <<
" in " << run_time_ <<
" ms ---------";
66 void ProfileOperatorObserver::Start() {
70 void ProfileOperatorObserver::Stop() {
75 std::unique_ptr<ObserverBase<OperatorBase>> ProfileOperatorObserver::rnnCopy(
76 OperatorBase* subject,
77 int rnn_order)
const {
78 return std::unique_ptr<ObserverBase<OperatorBase>>(
79 new ProfileOperatorObserver(
80 subject, netObserver_, net_position_, rnn_order));
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
float MilliSeconds()
Returns the elapsed time in milliseconds.