1 /* Copyright 2017 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_GRAPPLER_UTILS_SCC_H_ 17 #define TENSORFLOW_CORE_GRAPPLER_UTILS_SCC_H_ 18 19 #include <unordered_map> 20 #include "tensorflow/core/framework/graph.pb.h" 21 #include "tensorflow/core/grappler/inputs/utils.h" 22 #include "tensorflow/core/lib/io/path.h" 23 24 namespace tensorflow { 25 namespace grappler { 26 27 // Computes modified strongly connected components: 28 // All nodes that are not part of a loop are assigned the special -1 id 29 // All nodes that are part of at least one loop are assigned a positive 30 // component id: if 2 nodes v and w are reachable from one another (i.e. if they 31 // belong to the same scc), they'll be assigned the same id, otherwise they'll 32 // be assigned distinct ids. *num_components is set to the number of distinct 33 // ids. 34 void StronglyConnectedComponents( 35 const GraphDef& graph, std::unordered_map<const NodeDef*, int>* components, 36 int* num_components); 37 38 // Returns the number of individual loops present in the graph, and populate the 39 // 'loops' argument with the collection of loops (denoted by their loop ids) a 40 // node is part of. Loops ids are arbitrary. 41 int IdentifyLoops(const GraphDef& graph, 42 std::unordered_map<const NodeDef*, std::vector<int>>* loops); 43 44 } // namespace grappler 45 } // namespace tensorflow 46 47 #endif // TENSORFLOW_CORE_GRAPPLER_UTILS_SCC_H_ 48