xref: /aosp_15_r20/external/tensorflow/tensorflow/core/tpu/kernels/tpu_program_group_interface.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
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 #include "tensorflow/core/tpu/kernels/tpu_executable_info.pb.h"
30 #include "tensorflow/core/tpu/tpu_ops_c_api.h"
31 
32 namespace tensorflow {
33 namespace tpu {
34 
35 // An interface to holds all the programs and metadatas generated by the
36 // compiler, including those for the sharding/unsharding programs.
37 class TpuProgramGroupInterface {
38  public:
39   virtual ~TpuProgramGroupInterface() = default;
40 
41   // Check if whether sharding/unsharding program exists.
42   virtual bool has_sharding_program() const = 0;
43 
44   // Computes program count.
45   virtual size_t program_count() const = 0;
46 
47   // Computes total program size.
48   virtual int64_t program_size() const = 0;
49 
50   // Unloads and destroys safely TPU programs.
51   virtual void UnloadAndDestroyPrograms() = 0;
52 
53   // Logs program memory summary.
54   virtual bool LogProgramMemorySummary() = 0;
55 
56   // Program fingerprints.
57   virtual const std::string& fingerprint(int index) const = 0;
58 
59   // Hlo metadatas. The pointers can only be used as long as the cache entry is
60   // referenced.
61   virtual absl::Span<const xla::HloProto* const> hlo_metadatas() const = 0;
62 
63   // Boolean array to indicate if the modification of variables are
64   // allowed.
65   virtual const std::vector<bool>& may_modify_variables_list() const = 0;
66 
67   // Gets may modify variables value of the TPU program for the given core
68   // `index`.
69   virtual bool may_modify_variables(int index) const = 0;
70 
71   // Get Executable Info Proto
72   virtual const TPUExecutableInfoProto& executable_info(int index) const = 0;
73 
74   // Get HostTransferInfo Proto
75   virtual const TPUHostTransferInfoProto& host_transfer_info(
76       int index) const = 0;
77 
78   // Get XLA_TpuProgram Proto
79   virtual const XLA_TpuProgram* tpu_program(int index) const = 0;
80 };
81 
82 }  // namespace tpu
83 }  // namespace tensorflow
84 
85 #endif  // TENSORFLOW_CORE_TPU_KERNELS_TPU_PROGRAM_GROUP_INTERFACE_H_
86