• 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_STREAM_EXECUTOR_TPU_TPU_TOPOLOGY_H_
17 #define TENSORFLOW_STREAM_EXECUTOR_TPU_TPU_TOPOLOGY_H_
18 
19 #include <vector>
20 
21 #include "tensorflow/core/platform/types.h"
22 #include "tensorflow/stream_executor/tpu/c_api_decl.h"
23 
24 namespace tensorflow {
25 namespace tpu {
26 
27 struct TpuDimensionsExternal {
28   int x;
29   int y;
30   int z;
31 };
32 
33 class TpuCoreLocationExternal {
34  public:
TpuCoreLocationExternal()35   TpuCoreLocationExternal() : core_location_(nullptr) {}
TpuCoreLocationExternal(SE_TpuTopology_Core * core_location)36   explicit TpuCoreLocationExternal(SE_TpuTopology_Core* core_location)
37       : core_location_(core_location) {}
38   TpuDimensionsExternal chip_coordinates() const;
39   TpuDimensionsExternal host_coordinates() const;
40   int32 index() const;
41   int32 Id() const;
42 
impl()43   SE_TpuTopology_Core* impl() const { return core_location_; }
44 
45  private:
46   SE_TpuTopology_Core* core_location_;
47 };
48 
49 class TpuHostLocationExternal {
50  public:
TpuHostLocationExternal(SE_TpuTopology_Host * host_location)51   explicit TpuHostLocationExternal(SE_TpuTopology_Host* host_location)
52       : host_location_(host_location) {}
53   int32 Id() const;
54   std::vector<TpuCoreLocationExternal> Cores(TpuCoreTypeEnum core_type) const;
55 
impl()56   SE_TpuTopology_Host* impl() const { return host_location_; }
57 
58  private:
59   SE_TpuTopology_Host* host_location_;
60 };
61 
62 struct TpuTopologyChipBoundsExternal {
63   int x;
64   int y;
65   int z;
66 };
67 
68 class TpuTopologyExternal {
69  public:
TpuTopologyExternal(SE_TpuTopology * topology)70   explicit TpuTopologyExternal(SE_TpuTopology* topology)
71       : topology_(topology) {}
72   int32 LogicalDevicesPerHost(TpuCoreTypeEnum core_type) const;
73   int32 LogicalDevicesPerChip(TpuCoreTypeEnum core_type) const;
74   int32 HostCount() const;
75   int32 ChipsPerHost() const;
76   TpuTopologyChipBoundsExternal chip_bounds() const;
77   bool HasChip(int x, int y, int z) const;
78   TpuCoreLocationExternal CoreForId(TpuCoreTypeEnum core_type, int id) const;
79   TpuCoreLocationExternal Core(TpuCoreTypeEnum core_type, int x, int y, int z,
80                                int index) const;
81   std::vector<TpuCoreLocationExternal> cores(TpuCoreTypeEnum core_type) const;
82   int IdForHost(TpuDimensionsExternal host) const;
83   TpuVersionEnum version() const;
84 
85  private:
86   SE_TpuTopology* topology_;
87 };
88 
89 std::string TpuVersionEnumToString(TpuVersionEnum version);
90 
91 }  // namespace tpu
92 }  // namespace tensorflow
93 
94 #endif  // TENSORFLOW_STREAM_EXECUTOR_TPU_TPU_TOPOLOGY_H_
95