Caffe2 - C++ API
A deep learning, cross platform ML framework
runcnt_observer.cc
1 #include "runcnt_observer.h"
2 
3 namespace caffe2 {
4 
5 RunCountOperatorObserver::RunCountOperatorObserver(
6  OperatorBase* op,
7  RunCountNetObserver* netObserver)
8  : ObserverBase<OperatorBase>(op), netObserver_(netObserver) {
9  CAFFE_ENFORCE(netObserver_, "Observers can't operate outside of the net");
10 }
11 
12 std::string RunCountNetObserver::debugInfo() {
13 #if C10_ANDROID
14  // workaround
15  int foo = cnt_;
16  return "This operator runs " + c10::to_string(foo) + " times.";
17 #else
18  return "This operator runs " + c10::to_string(cnt_) + " times.";
19 #endif
20 }
21 
22 void RunCountNetObserver::Start() {}
23 
24 void RunCountNetObserver::Stop() {}
25 
26 void RunCountOperatorObserver::Start() {
27  ++netObserver_->cnt_;
28 }
29 void RunCountOperatorObserver::Stop() {}
30 
31 std::unique_ptr<ObserverBase<OperatorBase>> RunCountOperatorObserver::rnnCopy(
32  OperatorBase* subject,
33  int rnn_order) const {
34  return std::unique_ptr<ObserverBase<OperatorBase>>(
35  new RunCountOperatorObserver(subject, netObserver_));
36 }
37 
38 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13