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_TENSORFLOW_TRANSFORMS_SHAPE_INFERENCE_H_ 17 #define TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSFORMS_SHAPE_INFERENCE_H_ 18 19 #include <cstdint> 20 21 #include "mlir/Dialect/Func/IR/FuncOps.h" // from @llvm-project 22 #include "mlir/IR/BuiltinOps.h" // from @llvm-project 23 #include "mlir/IR/Operation.h" // from @llvm-project 24 #include "mlir/IR/Region.h" // from @llvm-project 25 #include "mlir/Support/LogicalResult.h" // from @llvm-project 26 27 namespace mlir { 28 namespace TF { 29 30 // Returns whether type can be further refined. 31 bool CanBeRefined(Type type); 32 33 // Refines all the shapes in a module. 34 // Returns a failure() on error, otherwise returns true to indicate that it 35 // reached convergence, false otherwise. 36 FailureOr<bool> InferModuleShape(ModuleOp module, int64_t max_iterations = 10); 37 38 // Given a list of refined shapes matching the function arguments of func, runs 39 // shape inference over the function to propagate this updated information. 40 // If arg_shapes are empty, then argument shapes will be left unchanged. 41 // Note: This affects the entire module, and changes are not just scoped to the 42 // function being inferred. 43 // Returns a failure() on error, otherwise returns true to indicate that it 44 // reached convergence, false otherwise. 45 FailureOr<bool> InferShapeForFunction(func::FuncOp func, 46 ArrayRef<ArrayRef<int64_t>> arg_shapes, 47 int64_t graph_version, 48 int64_t max_iterations = 10); 49 50 } // namespace TF 51 52 } // namespace mlir 53 54 #endif // TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSFORMS_SHAPE_INFERENCE_H_ 55