From 2d0d126749d6d0cf82fb86691362c923a1bfbfe4 Mon Sep 17 00:00:00 2001 From: Vijay Vasudevan Date: Mon, 8 Aug 2016 14:06:20 -0800 Subject: Change DeviceFactory functions that create devices to propagate Statuses, so that failures to initialize devices don't crash the program. Changes swig for device_lib to be a lot simpler, thanks to mrry@ and keveman@'s help. Change allocation of eigen scratch memory to go through the allocator. Re-enable test for local devices now that python3 issue is fixed. Change: 129678132 --- tensorflow/core/common_runtime/device_factory.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'tensorflow/core/common_runtime/device_factory.cc') diff --git a/tensorflow/core/common_runtime/device_factory.cc b/tensorflow/core/common_runtime/device_factory.cc index 7d0a2380cb..8104f44636 100644 --- a/tensorflow/core/common_runtime/device_factory.cc +++ b/tensorflow/core/common_runtime/device_factory.cc @@ -20,6 +20,7 @@ limitations under the License. #include #include +#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/mutex.h" @@ -74,25 +75,26 @@ DeviceFactory* DeviceFactory::GetFactory(const string& device_type) { return it->second.factory.get(); } -void DeviceFactory::AddDevices(const SessionOptions& options, - const string& name_prefix, - std::vector* devices) { +Status DeviceFactory::AddDevices(const SessionOptions& options, + const string& name_prefix, + std::vector* devices) { // CPU first. auto cpu_factory = GetFactory("CPU"); if (!cpu_factory) { - LOG(FATAL) - << "CPU Factory not registered. Did you link in threadpool_device?"; + return errors::NotFound( + "CPU Factory not registered. Did you link in threadpool_device?"); } size_t init_size = devices->size(); cpu_factory->CreateDevices(options, name_prefix, devices); if (devices->size() == init_size) { - LOG(FATAL) << "No CPU devices are available in this process"; + return errors::NotFound("No CPU devices are available in this process"); } // Then GPU. auto gpu_factory = GetFactory("GPU"); if (gpu_factory) { - gpu_factory->CreateDevices(options, name_prefix, devices); + TF_RETURN_IF_ERROR( + gpu_factory->CreateDevices(options, name_prefix, devices)); } // Then the rest. @@ -100,9 +102,11 @@ void DeviceFactory::AddDevices(const SessionOptions& options, for (auto& p : device_factories()) { auto factory = p.second.factory.get(); if (factory != cpu_factory && factory != gpu_factory) { - factory->CreateDevices(options, name_prefix, devices); + TF_RETURN_IF_ERROR(factory->CreateDevices(options, name_prefix, devices)); } } + + return Status::OK(); } Device* DeviceFactory::NewDevice(const string& type, -- cgit v1.2.3