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::unique_ptr<ObserverBase<OperatorBase>> RunCountOperatorObserver::copy(
13  OperatorBase* subject) {
14  return std::unique_ptr<ObserverBase<OperatorBase>>(
15  new RunCountOperatorObserver(subject, netObserver_));
16 }
17 
18 std::string RunCountNetObserver::debugInfo() {
19  return "This operator runs " + caffe2::to_string(cnt_) + " times.";
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 } // namespace caffe2
Copyright (c) 2016-present, Facebook, Inc.