From 61f4be7e5b5a0a7b87c60107a6785c40d21cbab1 Mon Sep 17 00:00:00 2001 From: Yi Situ Date: Thu, 18 Feb 2021 18:52:38 -0800 Subject: [PATCH] Remove preprocessor guards. PiperOrigin-RevId: 358313521 Change-Id: I9100dbf8d82dc695a896a7b61c433ef38865ec9d --- tensorflow/core/tpu/tpu_api_dlsym_initializer.cc | 8 +++++--- tensorflow/core/tpu/tpu_executor_dlsym_initializer.cc | 8 +++++--- tensorflow/core/tpu/tpu_initializer_helper.cc | 10 ++-------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/tensorflow/core/tpu/tpu_api_dlsym_initializer.cc b/tensorflow/core/tpu/tpu_api_dlsym_initializer.cc index eb32962be0d..3b21543728a 100644 --- a/tensorflow/core/tpu/tpu_api_dlsym_initializer.cc +++ b/tensorflow/core/tpu/tpu_api_dlsym_initializer.cc @@ -65,11 +65,13 @@ Status InitializeTpuLibrary(void* library_handle) { } bool FindAndLoadTpuLibrary() { - if (!TryAcquireTpuLock()) return false; - void* library = dlopen("libtpu.so", RTLD_NOW); if (library) { - InitializeTpuLibrary(library); + // We can open the shared library which means we are in a TPU environment. + // Try to acquire exclusive access. + if (TryAcquireTpuLock()) { + InitializeTpuLibrary(library); + } } return true; } diff --git a/tensorflow/core/tpu/tpu_executor_dlsym_initializer.cc b/tensorflow/core/tpu/tpu_executor_dlsym_initializer.cc index d3a70da6dbf..fd51ecfadbf 100644 --- a/tensorflow/core/tpu/tpu_executor_dlsym_initializer.cc +++ b/tensorflow/core/tpu/tpu_executor_dlsym_initializer.cc @@ -62,11 +62,13 @@ Status InitializeTpuLibrary(void* library_handle) { } bool FindAndLoadTpuLibrary() { - if (!TryAcquireTpuLock()) return false; - void* library = dlopen("libtpu.so", RTLD_NOW); if (library) { - InitializeTpuLibrary(library); + // We can open the shared library which means we are in a TPU environment. + // Try to acquire exclusive access. + if (TryAcquireTpuLock()) { + InitializeTpuLibrary(library); + } } return true; } diff --git a/tensorflow/core/tpu/tpu_initializer_helper.cc b/tensorflow/core/tpu/tpu_initializer_helper.cc index 61501332658..5fb5a6b1940 100644 --- a/tensorflow/core/tpu/tpu_initializer_helper.cc +++ b/tensorflow/core/tpu/tpu_initializer_helper.cc @@ -15,11 +15,9 @@ limitations under the License. #include "tensorflow/core/tpu/tpu_initializer_helper.h" -#if defined(LIBTPU_ON_GCE) #include #include #include -#endif // LIBTPU_ON_GCE #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" @@ -30,7 +28,6 @@ namespace tensorflow { namespace tpu { bool TryAcquireTpuLock() { -#if defined(LIBTPU_ON_GCE) static absl::Mutex* mu = new absl::Mutex(); absl::MutexLock l(mu); @@ -56,8 +53,8 @@ bool TryAcquireTpuLock() { // This lock is held until the process exits intentionally. The underlying // TPU device will be held on until it quits. if (lockf(fd, F_TLOCK, 0) != 0) { - LOG(WARNING) << "libtpu.so already in used by another process. Not " - "attempting to load libtpu.so in this process."; + LOG(ERROR) << "libtpu.so already in used by another process. Not " + "attempting to load libtpu.so in this process."; should_load_library = false; } else { should_load_library = true; @@ -69,9 +66,6 @@ bool TryAcquireTpuLock() { } return should_load_library; -#else // LIBTPU_ON_GCE - return false; -#endif } std::pair, std::vector>