Home | History | Annotate | Download | only in tensorflow_graph_matching
      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 #include "tensorflow/contrib/lite/toco/tensorflow_graph_matching/cluster.h"
     16 
     17 namespace toco {
     18 
     19 void Cluster::SetGraphDefInfo(const tensorflow::GraphDef* graph_def) {
     20   graph_def_ = graph_def;
     21   for (const tensorflow::NodeDef& node : graph_def_->node()) {
     22     if (StrContains(node.name(), name_)) {
     23       nodes_.push_back(&node);
     24     }
     25   }
     26 }
     27 
     28 bool Cluster::FindClusterInputsAndOutputs() {
     29   // For every node N in the graph:
     30   // If N belongs to this cluster C, then each of N's inputs that are not part
     31   // of C are then inputs of C.
     32   // If N does not belong to cluster C, then each of N's inputs that belong to C
     33   // are then outputs of C.
     34   for (const tensorflow::NodeDef& node : graph_def_->node()) {
     35     if (StrContains(node.name(), name_)) {
     36       for (int i = 0; i < node.input_size(); i++) {
     37         if (!StrContains(node.input(i), name_)) {
     38           inputs_.push_back(node.input(i));
     39         }
     40       }
     41     } else {
     42       for (int i = 0; i < node.input_size(); i++) {
     43         if (StrContains(node.input(i), name_)) {
     44           outputs_.push_back(node.input(i));
     45         }
     46       }
     47     }
     48   }
     49   return (!inputs_.empty()) && (!outputs_.empty());
     50 }
     51 
     52 }  // end namespace toco
     53