diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2017-10-16 17:50:50 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-10-16 17:50:50 +0000 |
commit | f315e6afa7cff2b271a4c4c8f0643d43508f92db (patch) | |
tree | 5238f417f6603850a59d82c4275bc5d6cccb3be4 | |
parent | 874b092491c3885195e23b74a58f7de3c4479bfd (diff) | |
parent | f4ececdcf4879279e0559b5111e0e0b32f25e0de (diff) | |
download | ml-oreo-mr1-dev.tar.gz |
Merge "Handle errors on getCapabilities" into oc-mr1-devoreo-mr1-dev
-rw-r--r-- | nn/runtime/Manager.cpp | 29 | ||||
-rw-r--r-- | nn/runtime/Manager.h | 9 |
2 files changed, 25 insertions, 13 deletions
diff --git a/nn/runtime/Manager.cpp b/nn/runtime/Manager.cpp index 25ccb21d9..bdf0b1257 100644 --- a/nn/runtime/Manager.cpp +++ b/nn/runtime/Manager.cpp @@ -31,7 +31,7 @@ namespace android { namespace nn { // TODO: handle errors from initialize correctly -void Device::initialize() { +bool Device::initialize() { #ifdef NN_DEBUGGABLE static const char samplePrefix[] = "sample"; @@ -39,16 +39,24 @@ void Device::initialize() { (mName.substr(0, sizeof(samplePrefix) - 1) == samplePrefix) ? getProp("debug.nn.sample.supported") : 0; #endif // NN_DEBUGGABLE - - mInterface->getCapabilities([&](ErrorStatus status, const Capabilities& capabilities) { + bool success = false; + auto ret = mInterface->getCapabilities([&](ErrorStatus status, + const Capabilities& capabilities) { if (status != ErrorStatus::NONE) { LOG(ERROR) << "IDevice::getCapabilities returned the error " << toString(status); + } else { + VLOG(MANAGER) << "Capab " << capabilities.float32Performance.execTime; + VLOG(MANAGER) << "Capab " << capabilities.quantized8Performance.execTime; + mFloat32Performance = capabilities.float32Performance; + mQuantized8Performance = capabilities.quantized8Performance; + success = true; } - VLOG(MANAGER) << "Capab " << capabilities.float32Performance.execTime; - VLOG(MANAGER) << "Capab " << capabilities.quantized8Performance.execTime; - mFloat32Performance = capabilities.float32Performance; - mQuantized8Performance = capabilities.quantized8Performance; }); + if (!ret.isOk()) { + LOG(ERROR) << "IDevice::getCapabilities failed for " << getName() + << ": " << ret.description(); + } + return success; } void Device::getSupportedOperations(const Model& hidlModel, @@ -139,6 +147,13 @@ void DeviceManager::findAvailableDevices() { }); } +void DeviceManager::registerDevice(const char* name, const sp<IDevice>& device) { + auto d = std::make_shared<Device>(name, device); + if (d->initialize()) { + mDevices.push_back(d); + } +} + DeviceManager::DeviceManager() { VLOG(MANAGER) << "DeviceManager::DeviceManager"; findAvailableDevices(); diff --git a/nn/runtime/Manager.h b/nn/runtime/Manager.h index 721e72fe4..12295528a 100644 --- a/nn/runtime/Manager.h +++ b/nn/runtime/Manager.h @@ -34,7 +34,8 @@ public: Device(const std::string& name, const sp<IDevice>& device) : mName(name), mInterface(device) {} sp<IDevice> getInterface() { return mInterface; } const std::string& getName() const { return mName; } - void initialize(); + // Returns true if succesfully initialized. + bool initialize(); void getSupportedOperations(const Model& hidlModel, hidl_vec<bool>* supportedOperations) const; @@ -92,11 +93,7 @@ private: DeviceManager(); // Adds a device for the manager to use. - void registerDevice(const char* name, const sp<IDevice>& device) { - auto d = std::make_shared<Device>(name, device); - mDevices.push_back(d); - d->initialize(); - } + void registerDevice(const char* name, const sp<IDevice>& device); void findAvailableDevices(); |