Caffe2 - C++ API
A deep learning, cross platform ML framework
recurrent_network_executor_incl.h
1 
2 #ifndef CAFFE2_OPERATORS_RECURRENT_NETWORK_EXECUTOR_INCL_H_
3 #define CAFFE2_OPERATORS_RECURRENT_NETWORK_EXECUTOR_INCL_H_
4 
5 #include <vector>
6 #include "caffe2/core/operator.h"
7 
8 namespace caffe2 {
9 
14  int order; // Position in the step net (i.e nth operator)
15  std::shared_ptr<OperatorBase> op = nullptr;
16  bool link_op; // Special flag for link op, see RNNApplyLinkOp.
17 
18  // Bookkeeping, used by ThreadedRecurrentNetworkExecutor
19  int num_dynamic_inputs = 0;
20  int num_recurrent_inputs = 0;
21  std::atomic<int> proc_inputs;
22 
23  // Dependencies to other ops. If dependency index < order, it is
24  // a recurrent dependency (i.e to the next timestep)
25  std::vector<int> dependencies;
26  std::vector<int> parents;
27  bool frontier = true; // For ops that are launched first
28  bool has_timestep_blob = false;
29 
30  explicit RNNNetOperator(const OperatorDef& def, int order) : order(order) {
31  proc_inputs = 0;
32  link_op = def.type() == "rnn_internal_apply_link";
33  }
34 
35  RNNNetOperator(const RNNNetOperator& x) {
36  order = x.order;
37  op = x.op;
38  link_op = x.link_op;
39  num_dynamic_inputs = x.num_dynamic_inputs;
40  num_recurrent_inputs = x.num_recurrent_inputs;
41  proc_inputs = 0;
42  dependencies = x.dependencies;
43  parents = x.parents;
44  frontier = x.frontier;
45  }
46 };
47 
51 struct OpTask {
52  int timestep;
53  int op_idx; // matches RNNNetOperator.order
54  int T; // number of timesteps in this execution
55  int direction; // +1 for forward, -1 for backward pass
56  int stream_id = -1; // only used by gpu version
57  OpTask() {}
58  OpTask(int _timestep, int _op_idx, int _T, int _direction)
59  : timestep(_timestep), op_idx(_op_idx), T(_T), direction(_direction) {
60  CAFFE_ENFORCE(direction == 1 || direction == -1);
61  CAFFE_ENFORCE(timestep >= 0 && timestep < _T);
62  }
63 
64  inline bool backward() {
65  return direction == -1;
66  }
67  inline bool forward() {
68  return direction == 1;
69  }
70 };
71 
72 } // namespace caffe2
73 
74 #endif // CAFFE2_OPERATORS_RECURRENT_NETWORK_EXECUTOR_H_
Struct for operator in a timestep and its dependenceis.
Data structure for a scheduled task in the task queue.
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13