xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/mlir/xla/attribute_importer.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2019 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_XLA_ATTRIBUTE_IMPORTER_H_
17 #define TENSORFLOW_COMPILER_MLIR_XLA_ATTRIBUTE_IMPORTER_H_
18 
19 #include "mlir/IR/Attributes.h"  // from @llvm-project
20 #include "mlir/IR/Builders.h"  // from @llvm-project
21 #include "tensorflow/compiler/xla/mlir_hlo/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.h"
22 #include "tensorflow/compiler/xla/service/hlo.pb.h"
23 #include "tensorflow/compiler/xla/shape.h"
24 #include "tensorflow/compiler/xla/statusor.h"
25 #include "tensorflow/compiler/xla/xla_data.pb.h"
26 #include "tensorflow/core/platform/types.h"
27 
28 namespace xla {
29 
30 // Converts an XLA PrecisionConfig to the corresponding MLIR attribute.
31 mlir::ArrayAttr ConvertPrecisionConfig(const PrecisionConfig* config,
32                                        mlir::Builder* builder);
33 
34 // Converts the gather dimensions to attributes.
35 mlir::mhlo::GatherDimensionNumbersAttr ConvertGatherDimensionNumbers(
36     const xla::GatherDimensionNumbers& dnums, mlir::Builder* builder);
37 
38 // Converts the scatter dimensions to attributes.
39 mlir::mhlo::ScatterDimensionNumbersAttr ConvertScatterDimensionNumbers(
40     const xla::ScatterDimensionNumbers& dnums, mlir::Builder* builder);
41 
42 // Converts the dot dimensions to attributes.
43 mlir::mhlo::DotDimensionNumbersAttr ConvertDotDimensionNumbers(
44     const DotDimensionNumbers& dnums, mlir::Builder* builder);
45 
46 // Converts the conv dimensions to attributes.
47 mlir::mhlo::ConvDimensionNumbersAttr ConvertConvDimensionNumbers(
48     const xla::ConvolutionDimensionNumbers& dnums, mlir::Builder* builder);
49 
50 StatusOr<mlir::mhlo::FftType> ConvertFftType(FftType type);
51 StatusOr<mlir::mhlo::Transpose> ConvertTranspose(
52     TriangularSolveOptions_Transpose transpose);
53 
54 StatusOr<mlir::mhlo::CustomCallApiVersion> ConvertCustomCallApiVersion(
55     xla::CustomCallApiVersion api_version);
56 
57 // Extracts layouts from shapes and converts it into layout attributes (array of
58 // rank-1 index tensors). Returns an error if any of the shapes is a tuple.
59 StatusOr<mlir::ArrayAttr> ExtractLayoutsFromShapes(
60     const absl::Span<const Shape> shapes_with_layouts, mlir::Builder* builder);
61 
62 // Extracts the layouts of each element from a tuple shape and returns them as
63 // an array of rank-1 index tensors. Returns an error in presence of nested
64 // tuple shapes.
65 StatusOr<mlir::ArrayAttr> ExtractLayoutsFromTuple(const xla::Shape shape,
66                                                   mlir::Builder* builder);
67 
68 }  // namespace xla
69 
70 #endif  // TENSORFLOW_COMPILER_MLIR_XLA_ATTRIBUTE_IMPORTER_H_
71