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_PROGRAM_GROUP_INTERFACE_H_ 16 #define TENSORFLOW_CORE_TPU_KERNELS_TPU_PROGRAM_GROUP_INTERFACE_H_ 17 18 #include <stdint.h> 19 20 #include <memory> 21 #include <vector> 22 23 #include "absl/time/time.h" 24 #include "absl/types/span.h" 25 #include "tensorflow/compiler/tf2xla/host_compute_metadata.pb.h" 26 #include "tensorflow/compiler/xla/service/hlo.pb.h" 27 #include "tensorflow/core/lib/core/status.h" 28 #include "tensorflow/core/tpu/kernels/tpu_compilation_cache_key.h" 29 30 namespace tensorflow { 31 namespace tpu { 32 33 // An interface to holds all the programs and metadatas generated by the 34 // compiler, including those for the sharding/unsharding programs. 35 class TpuProgramGroupInterface { 36 public: 37 virtual ~TpuProgramGroupInterface() = default; 38 39 // Check if whether sharding/unsharding program exists. 40 virtual bool has_sharding_program() const = 0; 41 42 // Computes program count. 43 virtual size_t program_count() const = 0; 44 45 // Computes total program size. 46 virtual int64_t program_size() const = 0; 47 48 // Unloads and destroys safely TPU programs. 49 virtual void UnloadAndDestroyPrograms() = 0; 50 51 // Logs program memory summary. 52 virtual bool LogProgramMemorySummary() = 0; 53 54 // Logs TPU Compilation statistics. 55 virtual Status LogCompilationStats(const TpuCompilationCacheKey& key, 56 absl::Duration duration) = 0; 57 58 // Hlo metadatas. The pointers can only be used as long as the cache entry is 59 // referenced. 60 virtual absl::Span<const xla::HloProto* const> hlo_metadatas() const = 0; 61 62 // Boolean array to indicate if the modification of variables are 63 // allowed. 64 virtual const std::vector<bool>& may_modify_variables_list() const = 0; 65 66 // Gets may modify variables value of the TPU program for the given core 67 // `index`. 68 virtual bool may_modify_variables(int index) const = 0; 69 }; 70 71 } // namespace tpu 72 } // namespace tensorflow 73 74 #endif // TENSORFLOW_CORE_TPU_KERNELS_TPU_PROGRAM_GROUP_INTERFACE_H_ 75