• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2022 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 XLA_MLIR_UTILS_RUNTIME_CONSTRAINTS_H_
17 #define XLA_MLIR_UTILS_RUNTIME_CONSTRAINTS_H_
18 
19 #include "mlir/Dialect/Func/IR/FuncOps.h"  // from @llvm-project
20 #include "mlir/IR/BuiltinTypes.h"  // from @llvm-project
21 #include "mlir/IR/Types.h"  // from @llvm-project
22 #include "tensorflow/compiler/xla/runtime/constraints.h"
23 
24 namespace xla {
25 namespace runtime {
26 
27 // Returns arguments constraints inferred from the function signature.
28 llvm::Expected<llvm::SmallVector<ArgumentConstraint>> GetArgumentsConstraints(
29     mlir::func::FuncOp func);
30 
31 // Resolves argument constraint based on the argument type, if constraint is
32 // fully satisfied by the type, returns `kResolved`.
33 llvm::Expected<ArgumentConstraint> ResolveArgumentConstraint(
34     ArgumentConstraint constraint, mlir::Type type);
35 
36 // Returns true iff the value of given type can be sunk into the function body
37 // at run time via value specialization.
SupportsValueSpecialization(mlir::Type type)38 inline bool SupportsValueSpecialization(mlir::Type type) {
39   // TODO(ezhulenev): Add support for sinking `memref` values once the value
40   // specialization will support it.
41   mlir::TensorType tensor = type.dyn_cast<mlir::TensorType>();
42   return tensor && (tensor.getRank() == 0 || tensor.getRank() == 1) &&
43          (tensor.getElementType().isInteger(32) ||
44           tensor.getElementType().isInteger(64));
45 }
46 
47 }  // namespace runtime
48 }  // namespace xla
49 
50 #endif  // XLA_MLIR_UTILS_RUNTIME_CONSTRAINTS_H_
51