From d1d4c51fcd2bf784b6267eb702cde16058bcc7e7 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Wed, 7 Oct 2020 15:11:13 -0700 Subject: [PATCH] Add HostCount() / ChipsPerHost() API to TPUTopologyExternal. PiperOrigin-RevId: 335962331 Change-Id: I4d9a3f8770039348dfc77616333d80c68f493bda --- tensorflow/stream_executor/tpu/BUILD | 5 ++++- tensorflow/stream_executor/tpu/tpu_executor_c_api.h | 6 ++++++ tensorflow/stream_executor/tpu/tpu_topology.cc | 8 ++++++++ tensorflow/stream_executor/tpu/tpu_topology.h | 2 ++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tensorflow/stream_executor/tpu/BUILD b/tensorflow/stream_executor/tpu/BUILD index 540a0a234ff..98d59726b60 100644 --- a/tensorflow/stream_executor/tpu/BUILD +++ b/tensorflow/stream_executor/tpu/BUILD @@ -3,7 +3,10 @@ load("//tensorflow/core/platform:rules_cc.bzl", "cc_library") package( - default_visibility = ["//tensorflow/core/tpu:__subpackages__"], + default_visibility = [ + "//learning/brain/experimental/dtensor:__subpackages__", + "//tensorflow/core/tpu:__subpackages__", + ], licenses = ["notice"], # Apache 2.0 ) diff --git a/tensorflow/stream_executor/tpu/tpu_executor_c_api.h b/tensorflow/stream_executor/tpu/tpu_executor_c_api.h index ed8c04af00d..193730567e7 100644 --- a/tensorflow/stream_executor/tpu/tpu_executor_c_api.h +++ b/tensorflow/stream_executor/tpu/tpu_executor_c_api.h @@ -246,6 +246,9 @@ int TpuTopology_LogicalDevicesPerHost(SE_TpuTopology* tpu_topology, TpuCoreTypeEnum tpu_core_type); int TpuTopology_LogicalDevicesPerChip(SE_TpuTopology* tpu_topology, TpuCoreTypeEnum tpu_core_type); +int TpuTopology_HostCount(SE_TpuTopology* tpu_topology); +int TpuTopology_ChipsPerHost(SE_TpuTopology* tpu_topology); + int TpuTopology_ChipBounds_X(SE_TpuTopology* tpu_topology); int TpuTopology_ChipBounds_Y(SE_TpuTopology* tpu_topology); int TpuTopology_ChipBounds_Z(SE_TpuTopology* tpu_topology); @@ -436,6 +439,9 @@ struct TfTpu_ExecutorApiFn { TFTPU_ADD_FN_IN_STRUCT(TpuTopology_LogicalDevicesPerHost); TFTPU_ADD_FN_IN_STRUCT(TpuTopology_LogicalDevicesPerChip); + TFTPU_ADD_FN_IN_STRUCT(TpuTopology_HostCount); + TFTPU_ADD_FN_IN_STRUCT(TpuTopology_ChipsPerHost); + TFTPU_ADD_FN_IN_STRUCT(TpuTopology_ChipBounds_X); TFTPU_ADD_FN_IN_STRUCT(TpuTopology_ChipBounds_Y); TFTPU_ADD_FN_IN_STRUCT(TpuTopology_ChipBounds_Z); diff --git a/tensorflow/stream_executor/tpu/tpu_topology.cc b/tensorflow/stream_executor/tpu/tpu_topology.cc index 2638cf2d93a..909f5bd9dac 100644 --- a/tensorflow/stream_executor/tpu/tpu_topology.cc +++ b/tensorflow/stream_executor/tpu/tpu_topology.cc @@ -73,6 +73,14 @@ int32 TpuTopologyExternal::LogicalDevicesPerChip( core_type); } +int32 TpuTopologyExternal::HostCount() const { + return tpu::ExecutorApiFn()->TpuTopology_HostCountFn(topology_); +} + +int32 TpuTopologyExternal::ChipsPerHost() const { + return tpu::ExecutorApiFn()->TpuTopology_ChipsPerHostFn(topology_); +} + TpuTopologyChipBoundsExternal TpuTopologyExternal::chip_bounds() const { return {tpu::ExecutorApiFn()->TpuTopology_ChipBounds_XFn(topology_), tpu::ExecutorApiFn()->TpuTopology_ChipBounds_YFn(topology_), diff --git a/tensorflow/stream_executor/tpu/tpu_topology.h b/tensorflow/stream_executor/tpu/tpu_topology.h index 7a92353993b..84e13a142b6 100644 --- a/tensorflow/stream_executor/tpu/tpu_topology.h +++ b/tensorflow/stream_executor/tpu/tpu_topology.h @@ -71,6 +71,8 @@ class TpuTopologyExternal { : topology_(topology) {} int32 LogicalDevicesPerHost(TpuCoreTypeEnum core_type) const; int32 LogicalDevicesPerChip(TpuCoreTypeEnum core_type) const; + int32 HostCount() const; + int32 ChipsPerHost() const; TpuTopologyChipBoundsExternal chip_bounds() const; bool HasChip(int x, int y, int z) const; TpuCoreLocationExternal Core(int x, int y, int z, TpuCoreTypeEnum core_type,