Caffe2 - C++ API
A deep learning, cross platform ML framework
onnx_while_op.cc
1 #include "caffe2/operators/onnx_while_op.h"
2 
3 namespace caffe2 {
4 
5 REGISTER_CPU_OPERATOR(ONNXWhile, ONNXWhileOp<CPUContext>);
6 
7 OPERATOR_SCHEMA(ONNXWhile)
8  .NumInputs(2, INT_MAX)
9  .NumOutputs(0, INT_MAX)
10  .SetDoc(R"DOC(
11 *** EXPERIMENTAL. This operator is a work-in-progress. No assumption should be
12 made about the stability or correctness of this op. ***
13 
14 Generic Looping construct confirming to the ONNX Loop operator spec. This loop
15 has multiple termination conditions:
16 
17 1. Trip count. Iteration count specified at runtime. Set by specifying the
18  input M. Optional. Set to empty string to omit. Note that a static trip
19  count (specified at graph construction time) can be specified by passing
20  in a constant node for input M.
21 2. Loop termination condition. This is an input to the op that determines
22  whether to run the first interation and also a loop-carried dependency for
23  the body graph. The body graph must yield a value for the condition
24  variable, whether this input is provided or not.
25 
26 This table summarizes the operating modes of this operator with equivalent
27 C-style code:
28 
29 Operator inputs defined as (max_trip_count, condition_var). Omitted optional
30 inputs are represented as empty string. Concretely, in this caffe2 op an input
31 is marked as omitted by setting its 'has_{name}' argument to False.
32 
33  input ("", ""):
34  for (int i=0; ; ++i) {
35  cond = ... // Note this value is ignored, but is required in the body
36  }
37 
38  input ("", cond) // Note this is analogous to a while loop
39  bool cond = ...;
40  for (int i=0; cond; ++i) {
41  cond = ...;
42  }
43 
44  input ("", 1) // Note this is analogous to a do-while loop
45  bool cond = true
46  for (int i=0; cond; ++i) {
47  cond = ...;
48  }
49 
50  input (trip_count, "") // Note this is analogous to a for loop
51  int trip_count = ...
52  for (int i=0; i < trip_count; ++i) {
53  cond = ...; // ignored
54  }
55 
56  input (trip_count, cond)
57  int trip_count = ...;
58  bool cond = ...;
59  for (int i=0; i < trip_count && cond; ++i) {
60  cond = ...;
61  }
62  )DOC")
63  .Arg("body", "Net executed on each iteration")
64  .Arg("has_trip_count", "Whether to use the trip count input")
65  .Arg("has_cond", "Whether to use the condition input")
66  .Arg("save_scopes", "Whether to save the scopes across iterations, as in "
67  "for backprop")
68  .Arg("disable_scopes", "Do not create new scopes. Use this only if you're "
69  "certain there will be no name collision, for "
70  "example if you're converting from a fully-SSA IR")
71  .NumInputs(2, INT_MAX)
72  .Input(0, "max_trip_count", "Number of iterations to go out to. Used if "
73  "the flag has_trip_count is True.")
74  .Input(1, "first_iter_condition", "Dynamic condition value for the first "
75  "iteration. For all subsequent iterations,"
76  " the condition from the body graph is "
77  "used. This input is used if the flag "
78  "has_cond is true.")
79  .NumOutputs(0, INT_MAX)
80  .AllowInplace([](int in, int out) -> bool { return true; });
81 
82 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13