Home | History | Annotate | Download | only in utils
      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 // Compute 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. Returns the number of distinct ids.
     33 void StronglyConnectedComponents(
     34     const GraphDef& graph, std::unordered_map<const NodeDef*, int>* components,
     35     int* num_ids);
     36 
     37 // Returns the number of individual loops present in the graph, and populate the
     38 // 'loops' argument with the collection of loops (denoted by their loop ids) a
     39 // node is part of. Loops ids are arbitrary.
     40 int IdentifyLoops(const GraphDef& graph,
     41                   std::unordered_map<const NodeDef*, std::vector<int>>* loops);
     42 
     43 }  // namespace grappler
     44 }  // namespace tensorflow
     45 
     46 #endif  // TENSORFLOW_CORE_GRAPPLER_UTILS_SCC_H_
     47