Snap for 4399693 from f315e6afa7cff2b271a4c4c8f0643d43508f92db to oc-mr1-release

Change-Id: I20fa06c560213d572c7a5f7d5940d43aea4822a6
diff --git a/nn/runtime/Manager.cpp b/nn/runtime/Manager.cpp
index 25ccb21..bdf0b12 100644
--- a/nn/runtime/Manager.cpp
+++ b/nn/runtime/Manager.cpp
@@ -31,7 +31,7 @@
 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 @@
             (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::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 721e72f..1229552 100644
--- a/nn/runtime/Manager.h
+++ b/nn/runtime/Manager.h
@@ -34,7 +34,8 @@
     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 @@
     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();
 
diff --git a/nn/runtime/test/generated/models/conv_3_h3_w2_SAME.model.cpp b/nn/runtime/test/generated/models/conv_3_h3_w2_SAME.model.cpp
index dec8578..5424ef0 100644
--- a/nn/runtime/test/generated/models/conv_3_h3_w2_SAME.model.cpp
+++ b/nn/runtime/test/generated/models/conv_3_h3_w2_SAME.model.cpp
@@ -24,7 +24,7 @@
   model->setOperandValue(b6, b6_init, sizeof(int32_t) * 1);
   int32_t b7_init[] = {0};
   model->setOperandValue(b7, b7_init, sizeof(int32_t) * 1);
-  float op0_init[] = {-0.966213, -0.579455, -0.684259, 0.738216, 0.184325, 0.0973683, -0.176863, -0.23936, -0.000233404, 0.055546, -0.232658, -0.316404, -0.012904, 0.320705, -0.326657, -0.919674, 0.868081, -0.824608, -0.467474, 0.0278809, 0.563238, 0.386045, -0.270568, -0.941308, -0.779227, -0.261492, -0.774804, -0.79665, 0.22473, -0.414312, 0.685897, -0.327792, 0.77395, -0.714578, -0.972365, 0.0696099, -0.82203, -0.79946, 0.37289, -0.917775, 0.82236, -0.144706, -0.167188, 0.268062, 0.702641, -0.412223, 0.755759, 0.721547, -0.43637, -0.274905, -0.269165, 0.16102, 0.819857, -0.312008};
+  static float op0_init[] = {-0.966213, -0.579455, -0.684259, 0.738216, 0.184325, 0.0973683, -0.176863, -0.23936, -0.000233404, 0.055546, -0.232658, -0.316404, -0.012904, 0.320705, -0.326657, -0.919674, 0.868081, -0.824608, -0.467474, 0.0278809, 0.563238, 0.386045, -0.270568, -0.941308, -0.779227, -0.261492, -0.774804, -0.79665, 0.22473, -0.414312, 0.685897, -0.327792, 0.77395, -0.714578, -0.972365, 0.0696099, -0.82203, -0.79946, 0.37289, -0.917775, 0.82236, -0.144706, -0.167188, 0.268062, 0.702641, -0.412223, 0.755759, 0.721547, -0.43637, -0.274905, -0.269165, 0.16102, 0.819857, -0.312008};
   model->setOperandValue(op0, op0_init, sizeof(float) * 54);
   float op1_init[] = {0, 0, 0};
   model->setOperandValue(op1, op1_init, sizeof(float) * 3);
diff --git a/nn/runtime/test/generated/models/conv_3_h3_w2_VALID.model.cpp b/nn/runtime/test/generated/models/conv_3_h3_w2_VALID.model.cpp
index c6cbb0a..3ee8752 100644
--- a/nn/runtime/test/generated/models/conv_3_h3_w2_VALID.model.cpp
+++ b/nn/runtime/test/generated/models/conv_3_h3_w2_VALID.model.cpp
@@ -22,7 +22,7 @@
   model->setOperandValue(b6, b6_init, sizeof(int32_t) * 1);
   int32_t b7_init[] = {0};
   model->setOperandValue(b7, b7_init, sizeof(int32_t) * 1);
-  float op0_init[] = {-0.966213, -0.579455, -0.684259, 0.738216, 0.184325, 0.0973683, -0.176863, -0.23936, -0.000233404, 0.055546, -0.232658, -0.316404, -0.012904, 0.320705, -0.326657, -0.919674, 0.868081, -0.824608, -0.467474, 0.0278809, 0.563238, 0.386045, -0.270568, -0.941308, -0.779227, -0.261492, -0.774804, -0.79665, 0.22473, -0.414312, 0.685897, -0.327792, 0.77395, -0.714578, -0.972365, 0.0696099, -0.82203, -0.79946, 0.37289, -0.917775, 0.82236, -0.144706, -0.167188, 0.268062, 0.702641, -0.412223, 0.755759, 0.721547, -0.43637, -0.274905, -0.269165, 0.16102, 0.819857, -0.312008};
+  static float op0_init[] = {-0.966213, -0.579455, -0.684259, 0.738216, 0.184325, 0.0973683, -0.176863, -0.23936, -0.000233404, 0.055546, -0.232658, -0.316404, -0.012904, 0.320705, -0.326657, -0.919674, 0.868081, -0.824608, -0.467474, 0.0278809, 0.563238, 0.386045, -0.270568, -0.941308, -0.779227, -0.261492, -0.774804, -0.79665, 0.22473, -0.414312, 0.685897, -0.327792, 0.77395, -0.714578, -0.972365, 0.0696099, -0.82203, -0.79946, 0.37289, -0.917775, 0.82236, -0.144706, -0.167188, 0.268062, 0.702641, -0.412223, 0.755759, 0.721547, -0.43637, -0.274905, -0.269165, 0.16102, 0.819857, -0.312008};
   model->setOperandValue(op0, op0_init, sizeof(float) * 54);
   float op1_init[] = {0, 0, 0};
   model->setOperandValue(op1, op1_init, sizeof(float) * 3);