1 /* Copyright 2020 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 #ifndef TENSORFLOW_COMPILER_MLIR_TFR_INTEGRATION_GRAPH_DECOMPOSE_PASS_H_ 16 #define TENSORFLOW_COMPILER_MLIR_TFR_INTEGRATION_GRAPH_DECOMPOSE_PASS_H_ 17 18 #include "mlir/IR/MLIRContext.h" // from @llvm-project 19 #include "tensorflow/compiler/mlir/mlir_graph_optimization_pass.h" 20 #include "tensorflow/compiler/mlir/tfr/integration/tfr_decompose_ctx.h" 21 #include "tensorflow/stream_executor/lib/statusor.h" 22 23 namespace tensorflow { 24 namespace tfr { 25 26 // An optimization pass that decompose the composite ops in a module according 27 // to the decomposition library. Currently the decomposition library is loaded 28 // each time the pass runs. A special environment variable is set to locate the 29 // decomposition library. 30 class GraphDecomposePass : public MlirOptimizationPass { 31 public: name()32 llvm::StringRef name() const override { return "tfr"; } 33 34 // Whether to run this pass. If this is enabled, the GraphDef will be imported 35 // to MLIR even no tf composition file is found. 36 ::tensorflow::MlirOptimizationPassState GetPassState( 37 const DeviceSet* device_set, const ConfigProto& config_proto, 38 const Graph& graph, 39 const FunctionLibraryDefinition& function_library) const override; 40 41 // This should be used as a thin mapper around mlir::ModulePass::runOnModule 42 // API integrated with the Tensorflow runtime. 43 Status Run(const ConfigProto& config_proto, mlir::ModuleOp module, 44 const Graph& graph, 45 const FunctionLibraryDefinition& function_library) override; 46 }; 47 48 } // namespace tfr 49 } // namespace tensorflow 50 51 #endif // TENSORFLOW_COMPILER_MLIR_TFR_INTEGRATION_GRAPH_DECOMPOSE_PASS_H_ 52