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 class RunCountOperatorObserver final : public ObserverBase<OperatorBase> {
12  public:
13  explicit RunCountOperatorObserver(OperatorBase* op) = delete;
16 
17  std::unique_ptr<ObserverBase<OperatorBase>> copy(
18  OperatorBase* subject) override;
19 
20  private:
21  void Start() override;
22  void Stop() override;
23 
24  private:
25  RunCountNetObserver* netObserver_;
26 };
27 
29  RunCountOperatorObserver,
30  RunCountNetObserver> {
31  public:
32  explicit RunCountNetObserver(NetBase* subject_)
35  RunCountNetObserver>(subject_, this),
36  cnt_(0) {}
38 
39  std::string debugInfo() override;
40 
41  friend class RunCountOperatorObserver;
42 
43  private:
44  void Start() override;
45  void Stop() override;
46 
47  protected:
48  std::atomic<int> cnt_;
49 };
50 
51 } // namespace caffe2
Use this to implement a Observer using the Observer Pattern template.
Definition: observer.h:30
Copyright (c) 2016-present, Facebook, Inc.