Caffe2 - C++ API
A deep learning, cross platform ML framework
net_simple_refcount.h
1 #ifndef CAFFE2_CORE_NET_SIMPLE_REFCOUNT_H_
2 #define CAFFE2_CORE_NET_SIMPLE_REFCOUNT_H_
3 
4 #include <vector>
5 
6 #include "c10/util/Registry.h"
7 #include "caffe2/core/common.h"
8 #include "caffe2/core/logging.h"
9 #include "caffe2/core/net.h"
10 #include "caffe2/core/net_simple.h"
11 #include "caffe2/core/tensor.h"
12 #include "caffe2/core/workspace.h"
13 #include "caffe2/proto/caffe2_pb.h"
14 
15 namespace caffe2 {
16 
17 // SimpleRefcountNet is an implementation that adds an additional abstraction
18 // on top of SimpleRefCountNet: it tracks all the tensors and for those that are
19 // considered internal/temporary, delete them once their refcount go to zero.
20 // In the context of a simple static run, this can be carried out during
21 // construction time: we will do a pass through the network and track what
22 // blobs we need to do reset on, after the execution of every op.
23 //
24 // To identify which blob is considered temporary, we employ the following
25 // strategy: any blob that is
26 // (1) consumed but not produced by ops in the net, or
27 // (2) produced but not consumed by ops in the net, or
28 // (3) is marked as external_output in the protobuf
29 // will NOT be considered temporary.
30 //
31 // In the long run, we should design proper functional interfaces so that
32 // nets are less imperative and more functional.
33 //
34 // Also, for now, SimpleRefCountNet should only be used for benchmarking
35 // purposes and not product use, since it is not going to provide better
36 // performance gain, and is implicitly incompatible with the contract that
37 // earlier Nets expose - that all intermediate blobs are visible to the users.
38 class SimpleRefCountNet final : public SimpleNet {
39  public:
41  const std::shared_ptr<const NetDef>& net_def,
42  Workspace* ws);
43 
44  protected:
45  bool Run() override;
46 
47  using SimpleNet::operators_;
48 
49  private:
50  // The list of blobs to delete when each operator finishes its run.
51  // This will be populated during construction time.
52  vector<vector<Blob*>> delete_list_;
53 
54  C10_DISABLE_COPY_AND_ASSIGN(SimpleRefCountNet);
55 };
56 
57 } // namespace caffe2
58 
59 #endif // CAFFE2_CORE_NET_SIMPLE_REFCOUNT_H_
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
Definition: workspace.h:47
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13