xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/xla/stream_executor/tpu/tpu_executable.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_COMPILER_XLA_STREAM_EXECUTOR_TPU_TPU_EXECUTABLE_H_
17 #define TENSORFLOW_COMPILER_XLA_STREAM_EXECUTOR_TPU_TPU_EXECUTABLE_H_
18 
19 #include "tensorflow/compiler/xla/stream_executor/tpu/tpu_executable_interface.h"
20 #include "tensorflow/compiler/xla/stream_executor/tpu/tpu_executor_c_api.h"
21 
22 namespace xla {
23 
24 class TpuExecutable : public xla::TpuExecutableInterface {
25  public:
TpuExecutable(SE_Executable * se_executable,std::shared_ptr<HloModule> hlo_module)26   TpuExecutable(SE_Executable* se_executable,
27                 std::shared_ptr<HloModule> hlo_module)
28       : TpuExecutableInterface(std::move(hlo_module)),
29         se_executable_(se_executable) {}
30 
31   ~TpuExecutable() override;
32 
33   StatusOr<ExecutionOutput> ExecuteAsyncOnStream(
34       const ServiceExecutableRunOptions* run_options,
35       std::vector<ExecutionInput> arguments,
36       HloExecutionProfile* hlo_execution_profile) override;
37 
38   absl::string_view fingerprint() const override;
39 
40   // The serialization is not guaranteed to be stable over time and has no
41   // compatibility guarantees (i.e. this is not a suitable long-term storage
42   // format).
43   StatusOr<std::string> Serialize() const;
44   static StatusOr<std::unique_ptr<TpuExecutable>> Deserialize(
45       absl::string_view serialized);
46 
47  private:
LoadProgramAndEnqueueToStream(const ServiceExecutableRunOptions & run_options,absl::Span<const stream_executor::DeviceMemoryBase> arguments,stream_executor::DeviceMemoryBase result,std::optional<stream_executor::DeviceMemoryBase> cross_program_prefetch_addr)48   Status LoadProgramAndEnqueueToStream(
49       const ServiceExecutableRunOptions& run_options,
50       absl::Span<const stream_executor::DeviceMemoryBase> arguments,
51       stream_executor::DeviceMemoryBase result,
52       std::optional<stream_executor::DeviceMemoryBase>
53           cross_program_prefetch_addr) override {
54     LOG(FATAL) << "LoadProgramAndEnqueueToStream unimplemented";
55   }
56 
HostShapeToDeviceShape(const Shape & host_shape)57   Shape HostShapeToDeviceShape(const Shape& host_shape) override {
58     LOG(FATAL) << "HostShapeToDeviceShape unimplemented";
59   }
60 
ShapeSize(const Shape & shape)61   int64_t ShapeSize(const Shape& shape) override {
62     LOG(FATAL) << "ShapeSize unimplemented";
63   }
64 
65   SE_Executable* se_executable_;
66 };
67 
68 }  // namespace xla
69 
70 #endif  // TENSORFLOW_COMPILER_XLA_STREAM_EXECUTOR_TPU_TPU_EXECUTABLE_H_
71