Caffe2 - C++ API
A deep learning, cross platform ML framework
recurrent_network_executor_incl.h
1 
18 #ifndef CAFFE2_OPERATORS_RECURRENT_NETWORK_EXECUTOR_INCL_H_
19 #define CAFFE2_OPERATORS_RECURRENT_NETWORK_EXECUTOR_INCL_H_
20 
21 #include <vector>
22 #include "caffe2/core/operator.h"
23 
24 namespace caffe2 {
25 
30  int order; // Position in the step net (i.e nth operator)
31  std::shared_ptr<OperatorBase> op = nullptr;
32  bool link_op; // Special flag for link op, see RNNApplyLinkOp.
33 
34  // Bookkeeping, used by ThreadedRecurrentNetworkExecutor
35  int num_dynamic_inputs = 0;
36  int num_recurrent_inputs = 0;
37  std::atomic<int> proc_inputs;
38 
39  // Dependencies to other ops. If dependency index < order, it is
40  // a recurrent dependency (i.e to the next timestep)
41  std::vector<int> dependencies;
42  std::vector<int> parents;
43  bool frontier = true; // For ops that are launched first
44  bool has_timestep_blob = false;
45 
46  explicit RNNNetOperator(const OperatorDef& def, int order) : order(order) {
47  proc_inputs = 0;
48  link_op = def.type() == "rnn_internal_apply_link";
49  }
50 
51  RNNNetOperator(const RNNNetOperator& x) {
52  order = x.order;
53  op = x.op;
54  link_op = x.link_op;
55  num_dynamic_inputs = x.num_dynamic_inputs;
56  num_recurrent_inputs = x.num_recurrent_inputs;
57  proc_inputs = 0;
58  dependencies = x.dependencies;
59  parents = x.parents;
60  frontier = x.frontier;
61  }
62 };
63 
67 struct OpTask {
68  int timestep;
69  int op_idx; // matches RNNNetOperator.order
70  int T; // number of timesteps in this execution
71  int direction; // +1 for forward, -1 for backward pass
72  int stream_id = -1; // only used by gpu version
73  OpTask() {}
74  OpTask(int _timestep, int _op_idx, int _T, int _direction)
75  : timestep(_timestep), op_idx(_op_idx), T(_T), direction(_direction) {
76  CHECK(direction == 1 || direction == -1);
77  CHECK(timestep >= 0 && timestep < _T);
78  }
79 
80  inline bool backward() {
81  return direction == -1;
82  }
83  inline bool forward() {
84  return direction == 1;
85  }
86 };
87 
88 } // namespace caffe2
89 
90 #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.
Copyright (c) 2016-present, Facebook, Inc.