IVGCVSW-3181 Add HAL 1.2 support to android-nn-driver

 * Updated Android.mk to build HAL 1.2 driver
 * Added 1.2 HalPolicy and ArmnnDriver
 * Added 1.2 ArmnnPreparedModel
 * Updated converters and utilities to accept new HAL 1.2 operands and operand types.

Signed-off-by: Sadik Armagan <sadik.armagan@arm.com>
Signed-off-by: Mike Kelly <mike.kelly@arm.com>
Change-Id: I62856deab24e106f72cccce09468db4971756fa6
diff --git a/ArmnnDriverImpl.cpp b/ArmnnDriverImpl.cpp
index cb77247..64188bb 100644
--- a/ArmnnDriverImpl.cpp
+++ b/ArmnnDriverImpl.cpp
@@ -7,15 +7,14 @@
 
 #include "ArmnnDriverImpl.hpp"
 #include "ArmnnPreparedModel.hpp"
-#include "ModelToINetworkConverter.hpp"
-#include "SystemPropertiesUtils.hpp"
 
-#if defined(ARMNN_ANDROID_P)
-// The headers of the ML framework have changed between Android O and Android P.
-// The validation functions have been moved into their own header, ValidateHal.h.
-#include <ValidateHal.h>
+#ifdef ARMNN_ANDROID_NN_V1_2 // Using ::android::hardware::neuralnetworks::V1_2
+#include "ArmnnPreparedModel_1_2.hpp"
 #endif
 
+#include "ModelToINetworkConverter.hpp"
+#include "SystemPropertiesUtils.hpp"
+#include <ValidateHal.h>
 #include <log/log.h>
 
 using namespace std;
@@ -35,7 +34,7 @@
     if (!returned.isOk())
     {
         ALOGE("ArmnnDriverImpl::prepareModel: hidl callback failed to return properly: %s ",
-            returned.description().c_str());
+              returned.description().c_str());
     }
 }
 
@@ -48,60 +47,13 @@
     return error;
 }
 
+
 } // namespace
 
 namespace armnn_driver
 {
 
 template<typename HalPolicy>
-Return<void> ArmnnDriverImpl<HalPolicy>::getSupportedOperations(const armnn::IRuntimePtr& runtime,
-                                                                const DriverOptions& options,
-                                                                const HalModel& model,
-                                                                HalGetSupportedOperations_cb cb)
-{
-    ALOGV("ArmnnDriverImpl::getSupportedOperations()");
-
-    vector<bool> result;
-
-    if (!runtime)
-    {
-        cb(ErrorStatus::DEVICE_UNAVAILABLE, result);
-        return Void();
-    }
-
-    // Run general model validation, if this doesn't pass we shouldn't analyse the model anyway.
-    if (!android::nn::validateModel(model))
-    {
-        cb(ErrorStatus::INVALID_ARGUMENT, result);
-        return Void();
-    }
-
-    // Attempt to convert the model to an ArmNN input network (INetwork).
-    ModelToINetworkConverter<HalPolicy> modelConverter(options.GetBackends(),
-                                                       model,
-                                                       options.GetForcedUnsupportedOperations());
-
-    if (modelConverter.GetConversionResult() != ConversionResult::Success
-            && modelConverter.GetConversionResult() != ConversionResult::UnsupportedFeature)
-    {
-        cb(ErrorStatus::GENERAL_FAILURE, result);
-        return Void();
-    }
-
-    // Check each operation if it was converted successfully and copy the flags
-    // into the result (vector<bool>) that we need to return to Android.
-    result.reserve(model.operations.size());
-    for (uint32_t operationIdx = 0; operationIdx < model.operations.size(); operationIdx++)
-    {
-        bool operationSupported = modelConverter.IsOperationSupported(operationIdx);
-        result.push_back(operationSupported);
-    }
-
-    cb(ErrorStatus::NONE, result);
-    return Void();
-}
-
-template<typename HalPolicy>
 Return<ErrorStatus> ArmnnDriverImpl<HalPolicy>::prepareModel(
         const armnn::IRuntimePtr& runtime,
         const armnn::IGpuAccTunedParametersPtr& clTunedParameters,
@@ -199,7 +151,7 @@
     }
 
     unique_ptr<ArmnnPreparedModel<HalPolicy>> preparedModel(
-                new ArmnnPreparedModel<HalPolicy>(
+            new ArmnnPreparedModel<HalPolicy>(
                     netId,
                     runtime.get(),
                     model,
@@ -234,6 +186,54 @@
 }
 
 template<typename HalPolicy>
+Return<void> ArmnnDriverImpl<HalPolicy>::getSupportedOperations(const armnn::IRuntimePtr& runtime,
+                                                                const DriverOptions& options,
+                                                                const HalModel& model,
+                                                                HalGetSupportedOperations_cb cb)
+{
+    ALOGV("ArmnnDriverImpl::getSupportedOperations()");
+
+    vector<bool> result;
+
+    if (!runtime)
+    {
+        cb(ErrorStatus::DEVICE_UNAVAILABLE, result);
+        return Void();
+    }
+
+    // Run general model validation, if this doesn't pass we shouldn't analyse the model anyway.
+    if (!android::nn::validateModel(model))
+    {
+        cb(ErrorStatus::INVALID_ARGUMENT, result);
+        return Void();
+    }
+
+    // Attempt to convert the model to an ArmNN input network (INetwork).
+    ModelToINetworkConverter<HalPolicy> modelConverter(options.GetBackends(),
+                                                       model,
+                                                       options.GetForcedUnsupportedOperations());
+
+    if (modelConverter.GetConversionResult() != ConversionResult::Success
+            && modelConverter.GetConversionResult() != ConversionResult::UnsupportedFeature)
+    {
+        cb(ErrorStatus::GENERAL_FAILURE, result);
+        return Void();
+    }
+
+    // Check each operation if it was converted successfully and copy the flags
+    // into the result (vector<bool>) that we need to return to Android.
+    result.reserve(model.operations.size());
+    for (uint32_t operationIdx = 0; operationIdx < model.operations.size(); operationIdx++)
+    {
+        bool operationSupported = modelConverter.IsOperationSupported(operationIdx);
+        result.push_back(operationSupported);
+    }
+
+    cb(ErrorStatus::NONE, result);
+    return Void();
+}
+
+template<typename HalPolicy>
 Return<DeviceStatus> ArmnnDriverImpl<HalPolicy>::getStatus()
 {
     ALOGV("ArmnnDriver::getStatus()");
@@ -251,4 +251,9 @@
 template class ArmnnDriverImpl<hal_1_1::HalPolicy>;
 #endif
 
+#ifdef ARMNN_ANDROID_NN_V1_2
+template class ArmnnDriverImpl<hal_1_1::HalPolicy>;
+template class ArmnnDriverImpl<hal_1_2::HalPolicy>;
+#endif
+
 } // namespace armnn_driver