• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 XlaShapeLayoutHelpers::ShapeDeterminationFns shape_determination_fns,
42     const std::vector<TensorShape>& arg_shapes,
43     const GuaranteedConsts& guaranteed_constants, const NameAttrList& function,
44     const tpu::TPUCompileMetadataProto& metadata,
45     xla::CompileOnlyClient* client,
46     std::vector<tpu::ShardingAndIndex>* arg_core_mapping,
47     std::vector<std::vector<xla::Shape>>* per_core_arg_shapes,
48     bool use_tuple_args, XlaCompiler::CompilationResult* compilation_result);
49 
50 // Gets information regarding how input arguments are sharded across multiple
51 // cores.
52 Status GetShardingInfo(
53     const tpu::TPUCompileMetadataProto& metadata,
54     absl::Span<const TensorShape> arg_shapes,
55     const XlaShapeLayoutHelpers::ShapeDeterminationFns shape_determination_fns,
56     std::vector<tpu::ShardingAndIndex>* arg_core_mapping,
57     std::vector<std::vector<xla::Shape>>* per_core_arg_shapes);
58 
59 }  // namespace tpu
60 }  // namespace tensorflow
61 
62 #endif  // TENSORFLOW_CORE_TPU_TPU_COMPILE_H_
63