• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSFORMS_TF_SAVED_MODEL_PASSES_H_
17 #define TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSFORMS_TF_SAVED_MODEL_PASSES_H_
18 
19 #include <memory>
20 
21 #include "mlir/Pass/Pass.h"  // from @llvm-project
22 #include "tensorflow/core/public/session.h"
23 
24 namespace mlir {
25 namespace tf_saved_model {
26 
27 // Creates a pass that optimizes tf_saved_model.global_tensor ops.
28 std::unique_ptr<OperationPass<ModuleOp>> CreateOptimizeGlobalTensorsPass();
29 
30 // Creates a pass that freezes tf_saved_model.global_tensor ops.
31 std::unique_ptr<OperationPass<ModuleOp>> CreateFreezeGlobalTensorsPass(
32     bool allow_mutable_tensors = false);
33 
34 // Creates a pass that freezes tf_saved_model.asset ops.
35 std::unique_ptr<OperationPass<ModuleOp>> CreateFreezeAssetsPass(
36     std::string saved_model_dir);
37 
38 // Creates as pass that removes variables in the session initializer.
39 // This job is required with lifting variable passes. Originally, the session
40 // initializer function does assigning variables. However, the read-only
41 // variable assignments will be done via lifting variables pass by converting
42 // the read-only variables to constant ops, instead. This pass removes the
43 // redundant operations. This pass should be located in front of the pass for
44 // lifting read-only variables.
45 std::unique_ptr<OperationPass<ModuleOp>>
46 CreateRemoveVariablesInSessionInitializerPass();
47 
48 // Creates as pass that creates GlobalTensorOp for each variable from function
49 // arguments and converts the function arguments to the corresponding saved
50 // model arguments.
51 std::unique_ptr<OperationPass<ModuleOp>> CreateLiftVariablesPass(
52     ::tensorflow::Session* session);
53 
54 // Creates a pass that removes duplicate 'tf_saved_model.bound_input' bindings.
55 std::unique_ptr<OperationPass<FuncOp>> CreateDedupBoundInputBindingPass();
56 
57 // Creates a pass that marks variables whether they are initialized or not.
58 std::unique_ptr<OperationPass<FuncOp>> CreateMarkInitializedVariablesPass(
59     ::tensorflow::Session* session);
60 
61 // Creates a pass that initializes all variables in Session Init function
62 // for all variables in 'session'.
63 std::unique_ptr<OperationPass<ModuleOp>>
64 CreateInitializeVariablesInSessionInitializerPass(tensorflow::Session* session);
65 
66 // Creates a pass that freezes readonly variables in the graph.
67 std::unique_ptr<OperationPass<ModuleOp>> CreateFreezeVariablesPass(
68     tensorflow::Session* session);
69 
70 #define GEN_PASS_REGISTRATION
71 #include "tensorflow/compiler/mlir/tensorflow/transforms/tf_savedmodel_passes.h.inc"
72 
73 }  // namespace tf_saved_model
74 
75 }  // namespace mlir
76 
77 #endif  // TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSFORMS_TF_SAVED_MODEL_PASSES_H_
78