1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_CORE_GRAPH_CONTROL_FLOW_H_ 17 #define TENSORFLOW_CORE_GRAPH_CONTROL_FLOW_H_ 18 19 #include <vector> 20 21 #include "tensorflow/core/graph/graph.h" 22 #include "tensorflow/core/lib/core/status.h" 23 24 namespace tensorflow { 25 26 // Control flow info for a graph node. 27 struct ControlFlowInfo { 28 // 'frame' and 'parent_frame' are pointers to: 29 // 30 // a) One of the Enter nodes corresponding to the loop body, if the node 31 // executes inside a loop. If multiple tensors enter the while loop, it's 32 // undefined which Enter node will be used. 33 // 34 // b) SOURCE node (node.id() == Graph::kSourceId), if the node is not inside 35 // any of the while loops. 36 37 const Node* frame = nullptr; // frame of a node 38 const Node* parent_frame = nullptr; // parent frame of a node 39 string frame_name; // frame name of a node 40 }; 41 42 // Clear and populate `info` with each node's frame and the level it belongs to. 43 // We check the well-formedness of the graph: 44 // 1) All inputs to a node must come from the same frame and have the same 45 // "static" iteration level. 46 // 2) Each frame has at most one LoopCond node. 47 // 3) Each frame has a single parent frame. 48 // If `unreachable_nodes` is set, return names of nodes unreachable from the 49 // source node. We cannot build ControlFlowInfo for such nodes. They might be 50 // pruned later. 51 // 52 // NOTE(yuanbyu): For now, we require all sends/recvs have iteration level 0. 53 // This essentially means there can't be multiple serial Nexts in an iteration, 54 // which all sane front-ends should satisfy. 55 Status BuildControlFlowInfo(const Graph* g, std::vector<ControlFlowInfo>* info, 56 std::vector<string>* unreachable_nodes = nullptr); 57 58 } // namespace tensorflow 59 60 #endif // TENSORFLOW_CORE_GRAPH_CONTROL_FLOW_H_ 61