Home | History | Annotate | Download | only in common_runtime
      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 #include "tensorflow/core/common_runtime/optimization_registry.h"
     17 
     18 namespace tensorflow {
     19 
     20 // static
     21 OptimizationPassRegistry* OptimizationPassRegistry::Global() {
     22   static OptimizationPassRegistry* global_optimization_registry =
     23       new OptimizationPassRegistry;
     24   return global_optimization_registry;
     25 }
     26 
     27 void OptimizationPassRegistry::Register(
     28     Grouping grouping, int phase, std::unique_ptr<GraphOptimizationPass> pass) {
     29   groups_[grouping][phase].push_back(std::move(pass));
     30 }
     31 
     32 Status OptimizationPassRegistry::RunGrouping(
     33     Grouping grouping, const GraphOptimizationPassOptions& options) {
     34   auto group = groups_.find(grouping);
     35   if (group != groups_.end()) {
     36     for (auto& phase : group->second) {
     37       VLOG(1) << "Running optimization phase " << phase.first;
     38       for (auto& pass : phase.second) {
     39         Status s = pass->Run(options);
     40         if (!s.ok()) return s;
     41       }
     42     }
     43   }
     44   return Status::OK();
     45 }
     46 
     47 }  // namespace tensorflow
     48