1 /* Copyright 2021 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 #ifndef TENSORFLOW_CORE_TPU_TPU_COMPILE_H_ 16 #define TENSORFLOW_CORE_TPU_TPU_COMPILE_H_ 17 18 #include "tensorflow/compiler/jit/shape_inference.h" 19 #include "tensorflow/compiler/tf2xla/xla_compiler.h" 20 #include "tensorflow/compiler/xla/client/compile_only_client.h" 21 #include "tensorflow/core/framework/function.h" 22 #include "tensorflow/core/protobuf/tpu/compile_metadata.pb.h" 23 #include "tensorflow/core/tpu/kernels/tpu_compile_op_support.h" 24 25 namespace tensorflow { 26 namespace tpu { 27 namespace internal { 28 29 // Performs shape inference on the body of `graph`. Shapes for arguments 30 // are taken from `metadata` and `arg_shapes`. 31 Status RunShapeInferenceOnComputation( 32 const tpu::TPUCompileMetadataProto& metadata, 33 const std::vector<PartialTensorShape>& arg_shapes, Graph* graph, 34 FunctionLibraryRuntime* flr, GraphShapeInfo* shape_info); 35 } // namespace internal 36 37 // Converts a TF Function into XLA HLO, stores generated HLO module and 38 // accompanying metadata in CompilationResult. 39 Status CompileTFFunctionToHlo( 40 const FunctionLibraryDefinition& flib_def, int graph_def_version, 41 const XlaCompiler::ShapeRepresentationFn shape_representation_fn, 42 const std::vector<TensorShape>& arg_shapes, 43 const GuaranteedConsts& guaranteed_constants, const NameAttrList& function, 44 const tpu::TPUCompileMetadataProto& metadata, 45 std::function<Status(ResourceMgr*)> populate_resource_manager_fn, 46 xla::CompileOnlyClient* client, 47 std::vector<tpu::ShardingAndIndex>* arg_core_mapping, 48 std::vector<std::vector<xla::Shape>>* per_core_arg_shapes, 49 XlaCompiler::CompilationResult* compilation_result); 50 51 // Gets information regarding how input arguments are sharded across multiple 52 // cores. 53 Status GetShardingInfo( 54 const tpu::TPUCompileMetadataProto& metadata, 55 absl::Span<const TensorShape> arg_shapes, 56 const XlaCompiler::ShapeRepresentationFn shape_representation_fn, 57 std::vector<tpu::ShardingAndIndex>* arg_core_mapping, 58 std::vector<std::vector<xla::Shape>>* per_core_arg_shapes); 59 60 } // namespace tpu 61 } // namespace tensorflow 62 63 #endif // TENSORFLOW_CORE_TPU_TPU_COMPILE_H_ 64