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 const Node* frame = nullptr; // frame of a node 29 const Node* parent_frame = nullptr; // parent frame of a node 30 string frame_name; // frame name of a node 31 }; 32 33 // Clear and populate `info` with each node's frame and the level it belongs to. 34 // We check the well-formedness of the graph: 35 // 1) All inputs to a node must come from the same frame and have the same 36 // "static" iteration level. 37 // 2) Each frame has at most one LoopCond node. 38 // 3) Each frame has a single parent frame. 39 // If `unreachable_nodes` is set, return names of nodes unreachable from the 40 // source node. We cannot build ControlFlowInfo for such nodes. They might be 41 // pruned later. 42 // 43 // NOTE(yuanbyu): For now, we require all sends/recvs have iteration level 0. 44 // This essentially means there can't be multiple serial Nexts in an iteration, 45 // which all sane front-ends should satisfy. 46 Status BuildControlFlowInfo(const Graph* g, std::vector<ControlFlowInfo>* info, 47 std::vector<string>* unreachable_nodes = nullptr); 48 49 } // namespace tensorflow 50 51 #endif // TENSORFLOW_CORE_GRAPH_CONTROL_FLOW_H_ 52