From b5fdf38f0c6596958fab2b84882f2792a31e585a Mon Sep 17 00:00:00 2001 From: Mike Kelly Date: Tue, 11 Jun 2019 16:35:25 +0100 Subject: 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 Signed-off-by: Mike Kelly Change-Id: I62856deab24e106f72cccce09468db4971756fa6 --- ArmnnDriverImpl.cpp | 117 +++++++++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 56 deletions(-) (limited to 'ArmnnDriverImpl.cpp') diff --git a/ArmnnDriverImpl.cpp b/ArmnnDriverImpl.cpp index cb772478..64188bbf 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 +#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 #include using namespace std; @@ -35,7 +34,7 @@ void NotifyCallbackAndCheck(const sp& callback, if (!returned.isOk()) { ALOGE("ArmnnDriverImpl::prepareModel: hidl callback failed to return properly: %s ", - returned.description().c_str()); + returned.description().c_str()); } } @@ -48,59 +47,12 @@ Return FailPrepareModel(ErrorStatus error, return error; } + } // namespace namespace armnn_driver { -template -Return ArmnnDriverImpl::getSupportedOperations(const armnn::IRuntimePtr& runtime, - const DriverOptions& options, - const HalModel& model, - HalGetSupportedOperations_cb cb) -{ - ALOGV("ArmnnDriverImpl::getSupportedOperations()"); - - vector 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 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) 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 Return ArmnnDriverImpl::prepareModel( const armnn::IRuntimePtr& runtime, @@ -199,7 +151,7 @@ Return ArmnnDriverImpl::prepareModel( } unique_ptr> preparedModel( - new ArmnnPreparedModel( + new ArmnnPreparedModel( netId, runtime.get(), model, @@ -233,6 +185,54 @@ Return ArmnnDriverImpl::prepareModel( return ErrorStatus::NONE; } +template +Return ArmnnDriverImpl::getSupportedOperations(const armnn::IRuntimePtr& runtime, + const DriverOptions& options, + const HalModel& model, + HalGetSupportedOperations_cb cb) +{ + ALOGV("ArmnnDriverImpl::getSupportedOperations()"); + + vector 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 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) 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 Return ArmnnDriverImpl::getStatus() { @@ -251,4 +251,9 @@ template class ArmnnDriverImpl; template class ArmnnDriverImpl; #endif +#ifdef ARMNN_ANDROID_NN_V1_2 +template class ArmnnDriverImpl; +template class ArmnnDriverImpl; +#endif + } // namespace armnn_driver -- cgit v1.2.1