Caffe2 - C++ API
A deep learning, cross platform ML framework
runcnt_observer.h
1 #pragma once
2 
3 #include "caffe2/core/net.h"
4 #include "caffe2/core/observer.h"
5 #include "caffe2/core/operator.h"
6 #include "caffe2/observers/operator_attaching_net_observer.h"
7 
8 namespace caffe2 {
9 
10 class RunCountNetObserver;
11 
12 class CAFFE2_API RunCountOperatorObserver final : public ObserverBase<OperatorBase> {
13  public:
14  explicit RunCountOperatorObserver(OperatorBase* op) = delete;
17  std::unique_ptr<ObserverBase<OperatorBase>> rnnCopy(
18  OperatorBase* subject,
19  int rnn_order) const override;
20 
21  private:
22  void Start() override;
23  void Stop() override;
24 
25  private:
26  RunCountNetObserver* netObserver_;
27 };
28 
29 class CAFFE2_API RunCountNetObserver final : public OperatorAttachingNetObserver<
30  RunCountOperatorObserver,
31  RunCountNetObserver> {
32  public:
33  explicit RunCountNetObserver(NetBase* subject_)
36  RunCountNetObserver>(subject_, this),
37  cnt_(0) {}
39 
40  std::string debugInfo() override;
41 
42  friend class RunCountOperatorObserver;
43 
44  private:
45  void Start() override;
46  void Stop() override;
47 
48  protected:
49  std::atomic<int> cnt_;
50 };
51 
52 } // namespace caffe2
Use this to implement a Observer using the Observer Pattern template.
Definition: observer.h:15
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13