• 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 #ifndef TENSORFLOW_COMPILER_MLIR_TFR_INTEGRATION_NODE_EXPANSION_PASS_H_
16 #define TENSORFLOW_COMPILER_MLIR_TFR_INTEGRATION_NODE_EXPANSION_PASS_H_
17 
18 #include "tensorflow/compiler/mlir/tfr/integration/tfr_decompose_ctx.h"
19 #include "tensorflow/core/common_runtime/eager/eager_op_rewrite_registry.h"
20 #include "tensorflow/stream_executor/lib/statusor.h"
21 
22 namespace tensorflow {
23 namespace tfr {
24 
25 // An optimization pass that decompose the composite ops in a module according
26 // to the decomposition library. Currently the decomposition library is loaded
27 // each time the pass runs. A special environment variable is set to locate the
28 // decomposition library.
29 class CompositeOpExpansion : public EagerOpRewrite {
30  public:
CompositeOpExpansion(string name,string file,string line)31   CompositeOpExpansion(string name, string file, string line)
32       : EagerOpRewrite(name, file, line) {}
33 
34   Status Run(EagerOperation* orig_op,
35              std::unique_ptr<tensorflow::EagerOperation>* out_op) override;
36 
37  private:
38   // Whether to run this pass. If this is enabled, the NodeDef will be imported
39   // to MLIR even no tf composition file is found.
IsEnabled()40   bool IsEnabled() {
41     const char* tfr_lib_env_val = getenv(string(kTFRLibEnv).c_str());
42     return tfr_lib_env_val != nullptr;
43   }
44 };
45 
46 }  // namespace tfr
47 }  // namespace tensorflow
48 
49 #endif  // TENSORFLOW_COMPILER_MLIR_TFR_INTEGRATION_NODE_EXPANSION_PASS_H_
50