From ba4804031357abecd1f412eeb5a04810a248391a Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Tue, 19 May 2020 17:28:21 -0700 Subject: [PATCH] Add a global resource manager for TPU specific operations. PiperOrigin-RevId: 312388244 Change-Id: I30dd6ce3a2f0eed3d257750626e11b3bb6eded97 --- tensorflow/core/tpu/BUILD | 7 ++++ tensorflow/core/tpu/tpu_configuration.cc | 44 ++++++++++++++++++++++++ tensorflow/core/tpu/tpu_configuration.h | 30 ++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 tensorflow/core/tpu/tpu_configuration.cc create mode 100644 tensorflow/core/tpu/tpu_configuration.h diff --git a/tensorflow/core/tpu/BUILD b/tensorflow/core/tpu/BUILD index 46a8759a257..48a9a229d2a 100644 --- a/tensorflow/core/tpu/BUILD +++ b/tensorflow/core/tpu/BUILD @@ -68,6 +68,13 @@ cc_library( deps = ["//tensorflow/core:protos_all_cc"], ) +cc_library( + name = "tpu_configuration", + srcs = ["tpu_configuration.cc"], + hdrs = ["tpu_configuration.h"], + deps = ["//tensorflow/core:framework"], +) + cc_library( name = "tpu_init_mode", srcs = ["tpu_init_mode.cc"], diff --git a/tensorflow/core/tpu/tpu_configuration.cc b/tensorflow/core/tpu/tpu_configuration.cc new file mode 100644 index 00000000000..3788d5cc6c2 --- /dev/null +++ b/tensorflow/core/tpu/tpu_configuration.cc @@ -0,0 +1,44 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/core/tpu/tpu_configuration.h" + +namespace tensorflow { + +namespace { + +ResourceMgr* GetGlobalResourceMgr() { + static ResourceMgr* const rmgr = new ResourceMgr(); + return rmgr; +} + +} // namespace + +#if !defined(PLATFORM_GOOGLE) +// Used only by Google-internal tests, so deliberately left empty. +void MaybeInitializeTPUSystemForTests() {} +#endif + +ResourceMgr* GetTPUConfigResourceMgr() { + MaybeInitializeTPUSystemForTests(); + + // Put all TPU-related state in the global ResourceMgr. This includes the + // TpuPodState, compilation cache, etc. We don't use the TPU_SYSTEM + // ResourceMgr because there may be more than one TPU_SYSTEM ResourceMgr when + // DirectSession or isolate_session_state are used. + return GetGlobalResourceMgr(); +} + +} // namespace tensorflow diff --git a/tensorflow/core/tpu/tpu_configuration.h b/tensorflow/core/tpu/tpu_configuration.h new file mode 100644 index 00000000000..6c337bd0fe7 --- /dev/null +++ b/tensorflow/core/tpu/tpu_configuration.h @@ -0,0 +1,30 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_CORE_TPU_TPU_CONFIGURATION_H_ +#define TENSORFLOW_CORE_TPU_TPU_CONFIGURATION_H_ + +#include "tensorflow/core/framework/resource_mgr.h" + +namespace tensorflow { + +void MaybeInitializeTPUSystemForTests(); + +// Returns a process-wide global ResourceMgr. +ResourceMgr* GetTPUConfigResourceMgr(); + +} // namespace tensorflow + +#endif // TENSORFLOW_CORE_TPU_TPU_CONFIGURATION_H_