xref: /aosp_15_r20/external/tensorflow/tensorflow/core/tpu/kernels/tpu_reshard_variables_op_util.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
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 
16 #ifndef TENSORFLOW_CORE_TPU_KERNELS_TPU_RESHARD_VARIABLES_OP_UTIL_H_
17 #define TENSORFLOW_CORE_TPU_KERNELS_TPU_RESHARD_VARIABLES_OP_UTIL_H_
18 
19 #include <memory>
20 
21 #include "tensorflow/compiler/jit/xla_launch_util.h"
22 #include "tensorflow/core/framework/op.h"
23 #include "tensorflow/core/framework/op_kernel.h"
24 #include "tensorflow/core/platform/mutex.h"
25 #include "tensorflow/core/tpu/kernels/tpu_compilation_cache_common.pb.h"
26 #include "tensorflow/core/tpu/kernels/tpu_compilation_cache_interface.h"
27 
28 namespace tensorflow {
29 namespace tpu {
30 namespace reshard_variables {
31 
32 Status FlushProgramMemory(se::Platform* platform, int device_ordinal);
33 
34 Status CheckIsValidKey(const Tensor& key);
35 
36 bool IsDefaultKey(const Tensor& key);
37 
38 Status GetComputationCacheEntry(
39     const Tensor& key, string* rendezvous_key_base,
40     std::unique_ptr<tpu::CompilationCacheEntryRef>* entry,
41     tpu::CompilationCacheFetchTarget fetch_target);
42 
43 xla::StatusOr<xla::ShapeTree<xla::MaybeOwningDeviceMemory>> BuildInputBuffers(
44     OpKernelContext* context, const std::vector<VariableInfo>& variables,
45     const xla::Shape& input_host_shape, xla::Backend* backend,
46     int device_ordinal, se::Stream* stream);
47 
48 Status PerformCompaction(stream_executor::Stream* stream);
49 
50 Status UpdateOutputVariables(
51     OpKernelContext* context, xla::ScopedShapedBuffer result_buffers,
52     absl::Span<const TensorShapeProto* const> output_tensor_shape_protos,
53     xla::Backend* backend, se::Stream* stream, int device_ordinal,
54     const std::vector<VariableInfo>& variables,
55     const std::shared_ptr<se::Event>& definition_event);
56 
57 }  // namespace reshard_variables
58 }  // namespace tpu
59 }  // namespace tensorflow
60 
61 #endif  // TENSORFLOW_CORE_TPU_KERNELS_TPU_RESHARD_VARIABLES_OP_UTIL_H_
62