• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef TENSORFLOW_COMPILER_XLA_PJRT_TPU_CLIENT_H_
17 #define TENSORFLOW_COMPILER_XLA_PJRT_TPU_CLIENT_H_
18 
19 #include <array>
20 #include <memory>
21 #include <vector>
22 
23 #include "tensorflow/compiler/xla/pjrt/pjrt_stream_executor_client.h"
24 #include "tensorflow/compiler/xla/statusor.h"
25 #include "tensorflow/stream_executor/tpu/tpu_topology.h"
26 
27 namespace xla {
28 
29 class PjRtTpuDevice : public PjRtStreamExecutorDevice {
30  public:
PjRtTpuDevice(const tensorflow::tpu::TpuCoreLocationExternal core,std::unique_ptr<LocalDeviceState> local_device_state,int task_id,const std::array<int,3> & coords,std::string device_kind)31   PjRtTpuDevice(const tensorflow::tpu::TpuCoreLocationExternal core,
32                 std::unique_ptr<LocalDeviceState> local_device_state,
33                 int task_id, const std::array<int, 3>& coords,
34                 std::string device_kind)
35       : PjRtStreamExecutorDevice(core.Id(), std::move(local_device_state),
36                                  std::move(device_kind), task_id),
37         core_(core),
38         coords_(coords) {}
39 
coords()40   const std::array<int, 3>& coords() const { return coords_; }
core_on_chip()41   int core_on_chip() const { return core_.index(); }
core()42   const tensorflow::tpu::TpuCoreLocationExternal core() const { return core_; }
43 
DebugString()44   std::string DebugString() const override {
45     return absl::StrFormat("TPU_%i(host=%i,(%i,%i,%i,%i))", id(), task_id(),
46                            coords_[0], coords_[1], coords_[2], core_.index());
47   }
48 
49  private:
50   const tensorflow::tpu::TpuCoreLocationExternal core_;
51   const std::array<int, 3> coords_;
52 };
53 
54 StatusOr<std::shared_ptr<PjRtClient>> GetTpuClient(
55     bool asynchronous,
56     absl::Duration init_retry_timeout = absl::ZeroDuration());
57 
58 }  // namespace xla
59 
60 #endif  // TENSORFLOW_COMPILER_XLA_PJRT_TPU_CLIENT_H_
61