1 /* Copyright 2020 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_KERNELS_TPU_COMPILE_OP_IMPL_H_ 16 #define TENSORFLOW_CORE_TPU_KERNELS_TPU_COMPILE_OP_IMPL_H_ 17 18 #include <string> 19 #include <vector> 20 21 #include "absl/types/variant.h" 22 #include "tensorflow/compiler/jit/shape_inference.h" 23 #include "tensorflow/core/framework/function.h" 24 #include "tensorflow/core/tpu/kernels/tpu_compilation_cache_key.h" 25 #include "tensorflow/core/tpu/kernels/tpu_compile_op_common.h" 26 #include "tensorflow/core/tpu/kernels/tpu_program_group_interface.h" 27 #include "tensorflow/core/tpu/tpu_ops_c_api.h" 28 29 namespace tensorflow { 30 namespace tpu { 31 32 // Base class for TpuCompileOp and TpuCompileMlirOp. 33 // Depends on whether it is given a computation in the form of serialized MLIR 34 // module or a Tensorflow function, TpuCompileOpKernelImpl converts computation 35 // into XLA HLO and then into a TPU execuable binary. 36 class TpuCompileOpKernelImpl : public TpuCompileOpKernelCommon { 37 public: TpuCompileOpKernelImpl(const std::string & mlir_module,const tpu::TPUCompileMetadataProto & metadata,int num_computations,bool return_hlo_protos,bool unload_cache_on_session_close)38 TpuCompileOpKernelImpl(const std::string& mlir_module, 39 const tpu::TPUCompileMetadataProto& metadata, 40 int num_computations, bool return_hlo_protos, 41 bool unload_cache_on_session_close) 42 : TpuCompileOpKernelCommon(mlir_module, metadata, num_computations, 43 return_hlo_protos, 44 unload_cache_on_session_close) {} 45 TpuCompileOpKernelImpl(const NameAttrList & function,const tpu::TPUCompileMetadataProto & metadata,int num_computations,bool return_hlo_protos,bool unload_cache_on_session_close)46 TpuCompileOpKernelImpl(const NameAttrList& function, 47 const tpu::TPUCompileMetadataProto& metadata, 48 int num_computations, bool return_hlo_protos, 49 bool unload_cache_on_session_close) 50 : TpuCompileOpKernelCommon( 51 function, metadata, num_computations, return_hlo_protos, 52 unload_cache_on_session_close, /*persistent_cache=*/nullptr) {} 53 54 Status Compile( 55 const absl::variant<MlirToHloArgs, FunctionToHloArgs>& computation, 56 const XLA_TpuMeshState* mesh_state, 57 const std::vector<TensorShape>& arg_shapes, 58 TpuProgramGroupInterface* tpu_program_group) override; 59 }; 60 } // namespace tpu 61 } // namespace tensorflow 62 63 #endif // TENSORFLOW_CORE_TPU_KERNELS_TPU_COMPILE_OP_IMPL_H_ 64