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 TENSORFLOW_DTENSOR_MLIR_SHAPE_UTILS_H_ 17 #define TENSORFLOW_DTENSOR_MLIR_SHAPE_UTILS_H_ 18 19 #include "llvm/ADT/ArrayRef.h" 20 #include "mlir/IR/Operation.h" // from @llvm-project 21 #include "mlir/IR/Value.h" // from @llvm-project 22 #include "tensorflow/dtensor/cc/dstatus.h" 23 24 namespace tensorflow { 25 namespace dtensor { 26 27 StatusOr<llvm::ArrayRef<int64_t>> ExtractGlobalInputShape( 28 mlir::OpOperand& input_value); 29 30 StatusOr<llvm::ArrayRef<int64_t>> ExtractGlobalOutputShape( 31 mlir::OpResult result_value); 32 33 // Returns op with recalculated local shape of `op` given all it's operands. 34 mlir::Operation* InferSPMDExpandedLocalShape(mlir::Operation* op); 35 36 // Gets the shape of a Value if the type is a RankedTensorType, otherwise 37 // returns an error. 38 StatusOr<llvm::ArrayRef<int64_t>> GetShapeOfValue(const mlir::Value& value, 39 bool fail_on_dynamic = false); 40 41 // If the producer or consumer of this value is a DTensorLayout, retrieves 42 // the global shape from that layout, otherwise returns an error. 43 StatusOr<llvm::ArrayRef<int64_t>> GetGlobalShapeOfValueFromDTensorLayout( 44 const mlir::Value& value); 45 46 } // namespace dtensor 47 } // namespace tensorflow 48 49 #endif // TENSORFLOW_DTENSOR_MLIR_SHAPE_UTILS_H_ 50