Remove preprocessor guards.
PiperOrigin-RevId: 358313521 Change-Id: I9100dbf8d82dc695a896a7b61c433ef38865ec9d
This commit is contained in:
parent
4a7d4b3887
commit
61f4be7e5b
@ -65,11 +65,13 @@ Status InitializeTpuLibrary(void* library_handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool FindAndLoadTpuLibrary() {
|
bool FindAndLoadTpuLibrary() {
|
||||||
if (!TryAcquireTpuLock()) return false;
|
|
||||||
|
|
||||||
void* library = dlopen("libtpu.so", RTLD_NOW);
|
void* library = dlopen("libtpu.so", RTLD_NOW);
|
||||||
if (library) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -62,11 +62,13 @@ Status InitializeTpuLibrary(void* library_handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool FindAndLoadTpuLibrary() {
|
bool FindAndLoadTpuLibrary() {
|
||||||
if (!TryAcquireTpuLock()) return false;
|
|
||||||
|
|
||||||
void* library = dlopen("libtpu.so", RTLD_NOW);
|
void* library = dlopen("libtpu.so", RTLD_NOW);
|
||||||
if (library) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,9 @@ limitations under the License.
|
|||||||
|
|
||||||
#include "tensorflow/core/tpu/tpu_initializer_helper.h"
|
#include "tensorflow/core/tpu/tpu_initializer_helper.h"
|
||||||
|
|
||||||
#if defined(LIBTPU_ON_GCE)
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif // LIBTPU_ON_GCE
|
|
||||||
|
|
||||||
#include "absl/strings/str_cat.h"
|
#include "absl/strings/str_cat.h"
|
||||||
#include "absl/strings/str_split.h"
|
#include "absl/strings/str_split.h"
|
||||||
@ -30,7 +28,6 @@ namespace tensorflow {
|
|||||||
namespace tpu {
|
namespace tpu {
|
||||||
|
|
||||||
bool TryAcquireTpuLock() {
|
bool TryAcquireTpuLock() {
|
||||||
#if defined(LIBTPU_ON_GCE)
|
|
||||||
static absl::Mutex* mu = new absl::Mutex();
|
static absl::Mutex* mu = new absl::Mutex();
|
||||||
absl::MutexLock l(mu);
|
absl::MutexLock l(mu);
|
||||||
|
|
||||||
@ -56,8 +53,8 @@ bool TryAcquireTpuLock() {
|
|||||||
// This lock is held until the process exits intentionally. The underlying
|
// This lock is held until the process exits intentionally. The underlying
|
||||||
// TPU device will be held on until it quits.
|
// TPU device will be held on until it quits.
|
||||||
if (lockf(fd, F_TLOCK, 0) != 0) {
|
if (lockf(fd, F_TLOCK, 0) != 0) {
|
||||||
LOG(WARNING) << "libtpu.so already in used by another process. Not "
|
LOG(ERROR) << "libtpu.so already in used by another process. Not "
|
||||||
"attempting to load libtpu.so in this process.";
|
"attempting to load libtpu.so in this process.";
|
||||||
should_load_library = false;
|
should_load_library = false;
|
||||||
} else {
|
} else {
|
||||||
should_load_library = true;
|
should_load_library = true;
|
||||||
@ -69,9 +66,6 @@ bool TryAcquireTpuLock() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return should_load_library;
|
return should_load_library;
|
||||||
#else // LIBTPU_ON_GCE
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<std::vector<std::string>, std::vector<const char*>>
|
std::pair<std::vector<std::string>, std::vector<const char*>>
|
||||||
|
Loading…
Reference in New Issue
Block a user