| 118 | } |
| 119 | |
| 120 | void CheckLoopConstruction(const GraphDef& graph_def) { |
| 121 | std::unordered_map<string, GraphDef> partitions; |
| 122 | Partition(graph_def, &partitions); |
| 123 | for (const auto& kv : partitions) { |
| 124 | const GraphDef& gdef = kv.second; |
| 125 | bool has_control_enter = false; |
| 126 | bool has_control_merge = false; |
| 127 | bool has_control_switch = false; |
| 128 | bool has_control_next = false; |
| 129 | for (const NodeDef& ndef : gdef.node()) { |
| 130 | // _recvs must have a control input |
| 131 | if (ndef.op() == "_Recv") { |
| 132 | bool has_control = false; |
| 133 | for (const string& input_name : ndef.input()) { |
| 134 | if (absl::StartsWith(input_name, "^")) { |
| 135 | has_control = true; |
| 136 | break; |
| 137 | } |
| 138 | } |
| 139 | EXPECT_TRUE(has_control); |
| 140 | } |
| 141 | // Must have a control loop |
| 142 | if (absl::StartsWith(ndef.name(), "_cloop")) { |
| 143 | if (ndef.op() == "Enter") { |
| 144 | has_control_enter = true; |
| 145 | } |
| 146 | if (ndef.op() == "Merge") { |
| 147 | has_control_merge = true; |
| 148 | } |
| 149 | if (ndef.op() == "Switch") { |
| 150 | has_control_switch = true; |
| 151 | } |
| 152 | if (ndef.op() == "NextIteration") { |
| 153 | has_control_next = true; |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | EXPECT_TRUE(has_control_enter); |
| 158 | EXPECT_TRUE(has_control_merge); |
| 159 | EXPECT_TRUE(has_control_switch); |
| 160 | EXPECT_TRUE(has_control_next); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | REGISTER_OP("FloatInput") |
| 165 | .Output("o: float") |