• 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 // This pass identifies patterns for certain Einsum Ops and replaces them
16 // with other equivalent TF Ops.
17 
18 #ifndef TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSFORMS_EINSUM_H_
19 #define TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSFORMS_EINSUM_H_
20 
21 #include <cstdint>
22 #include <initializer_list>
23 
24 #include "llvm/ADT/ArrayRef.h"
25 #include "llvm/Support/Casting.h"
26 #include "mlir/IR/Attributes.h"  // from @llvm-project
27 #include "mlir/IR/BuiltinTypes.h"  // from @llvm-project
28 #include "mlir/IR/Location.h"  // from @llvm-project
29 #include "mlir/IR/MLIRContext.h"  // from @llvm-project
30 #include "mlir/IR/Matchers.h"  // from @llvm-project
31 #include "mlir/IR/PatternMatch.h"  // from @llvm-project
32 #include "mlir/IR/TypeUtilities.h"  // from @llvm-project
33 #include "mlir/Pass/Pass.h"  // from @llvm-project
34 #include "tensorflow/compiler/mlir/tensorflow/ir/tf_ops.h"
35 #include "tensorflow/core/util/matmul_bcast.h"
36 
37 namespace mlir {
38 namespace TF {
39 
40 // TF.Einsum provides fully general tensor contractions. For a few select
41 // cases, we can convert this op to other TF Ops, which in later passes
42 // properly convert to TF Lite ops.
43 struct ConvertTFEinsumOp : public OpRewritePattern<TF::EinsumOp> {
44  public:
ConvertTFEinsumOpConvertTFEinsumOp45   explicit ConvertTFEinsumOp(MLIRContext* context)
46       : OpRewritePattern<TF::EinsumOp>(context) {}
47 
48   LogicalResult matchAndRewrite(TF::EinsumOp op,
49                                 PatternRewriter& rewriter) const override;
50 };
51 
52 }  // namespace TF
53 }  // namespace mlir
54 
55 #endif  // TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSFORMS_EINSUM_H_
56