1 #include "caffe2/operators/onnx_while_op.h" 5 REGISTER_CPU_OPERATOR(ONNXWhile, ONNXWhileOp<CPUContext>);
7 OPERATOR_SCHEMA(ONNXWhile)
9 .NumOutputs(0, INT_MAX)
11 *** EXPERIMENTAL. This operator is a work-in-progress. No assumption should be 12 made about the stability or correctness of this op. *** 14 Generic Looping construct confirming to the ONNX Loop operator spec. This loop 15 has multiple termination conditions: 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. 26 This table summarizes the operating modes of this operator with equivalent 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. 34 for (int i=0; ; ++i) { 35 cond = ... // Note this value is ignored, but is required in the body 38 input ("", cond) // Note this is analogous to a while loop 40 for (int i=0; cond; ++i) { 44 input ("", 1) // Note this is analogous to a do-while loop 46 for (int i=0; cond; ++i) { 50 input (trip_count, "") // Note this is analogous to a for loop 52 for (int i=0; i < trip_count; ++i) { 53 cond = ...; // ignored 56 input (trip_count, cond) 59 for (int i=0; i < trip_count && cond; ++i) { 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 " 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 " 79 .NumOutputs(0, INT_MAX)
80 .AllowInplace([](
int in,
int out) ->
bool {
return true; });
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...