From e48bdff741568236d3c0747ad3d18a8eba5b36dd Mon Sep 17 00:00:00 2001 From: Matteo Martincigh Date: Mon, 3 Sep 2018 13:50:50 +0100 Subject: IVGCVSW-1806 Refactored Android-NN-Driver, added common "getCapabilities", "getSupportedOperations" and "prepareModel" implementations * Added common base ArmnnDriverImpl class * Added common template implementation of the driver's "getCapabilities", "getSupportedOperations" and "prepareModel" methods * Refactored ArmnnPreparedModel and RequestThread to support HAL v1.1 models * Moved "getStatus" to the common base class, as it is shared by both HAL implementations * Refactored the code where necessary Change-Id: I747334730026d63b4002662523fb93608f67c899 --- 1.1/ArmnnDriverImpl.cpp | 151 ------------------------------------------------ 1 file changed, 151 deletions(-) delete mode 100644 1.1/ArmnnDriverImpl.cpp (limited to '1.1/ArmnnDriverImpl.cpp') diff --git a/1.1/ArmnnDriverImpl.cpp b/1.1/ArmnnDriverImpl.cpp deleted file mode 100644 index a5e32766..00000000 --- a/1.1/ArmnnDriverImpl.cpp +++ /dev/null @@ -1,151 +0,0 @@ -// -// Copyright © 2017 Arm Ltd. All rights reserved. -// See LICENSE file in the project root for full license information. -// - -#include "ArmnnDriverImpl.hpp" -#include "../1.0/ArmnnDriverImpl.hpp" - -#include - -#include -#include - -#include - -using namespace std; -using namespace android; -using namespace android::nn; -using namespace android::hardware; - -namespace -{ - -void NotifyCallbackAndCheck(const sp& callback, - ErrorStatus errorStatus, - const sp& preparedModelPtr) -{ - Return returned = callback->notify(errorStatus, preparedModelPtr); - // This check is required, if the callback fails and it isn't checked it will bring down the service - if (!returned.isOk()) - { - ALOGE("V1_1::ArmnnDriverImpl::prepareModel_1_1: hidl callback failed to return properly: %s ", - returned.description().c_str()); - } -} - -Return FailPrepareModel(ErrorStatus error, - const string& message, - const sp& callback) -{ - ALOGW("V1_1::ArmnnDriverImpl::prepareModel_1_1: %s", message.c_str()); - NotifyCallbackAndCheck(callback, error, nullptr); - return error; -} - -} // namespace - -namespace armnn_driver -{ -namespace V1_1 -{ - -Return ArmnnDriverImpl::getCapabilities_1_1( - const armnn::IRuntimePtr& runtime, - neuralnetworks::V1_1::IDevice::getCapabilities_1_1_cb cb) -{ - ALOGV("V1_1::ArmnnDriverImpl::getCapabilities_1_1()"); - - neuralnetworks::V1_0::IDevice::getCapabilities_cb cb_1_0 = - [&](ErrorStatus status, const neuralnetworks::V1_0::Capabilities& capabilities) - { - BOOST_ASSERT_MSG(compliantWithV1_1(capabilities), - "V1_1::ArmnnDriverImpl: V1_0::Capabilities not compliant with V1_1::Capabilities"); - - cb(status, convertToV1_1(capabilities)); - }; - - V1_0::ArmnnDriverImpl::getCapabilities(runtime, cb_1_0); - - return Void(); -} - -Return ArmnnDriverImpl::getSupportedOperations_1_1( - const armnn::IRuntimePtr& runtime, - const DriverOptions& options, - const neuralnetworks::V1_1::Model& model, - neuralnetworks::V1_1::IDevice::getSupportedOperations_1_1_cb cb) -{ - ALOGV("V1_1::ArmnnDriverImpl::getSupportedOperations_1_1()"); - - if(compliantWithV1_0(model)) - { - V1_0::ArmnnDriverImpl::getSupportedOperations(runtime, options, convertToV1_0(model), cb); - } - else - { - std::vector result; - - if (!runtime) - { - ALOGW("V1_1::ArmnnDriverImpl::getSupportedOperations_1_1: Device unavailable"); - cb(ErrorStatus::DEVICE_UNAVAILABLE, result); - return Void(); - } - - if (!android::nn::validateModel(model)) - { - ALOGW("V1_1::ArmnnDriverImpl::getSupportedOperations_1_1: Invalid model passed as input"); - cb(ErrorStatus::INVALID_ARGUMENT, result); - return Void(); - } - - result.assign(model.operations.size(), false); - cb(ErrorStatus::NONE, result); - } - - return Void(); -} - -Return ArmnnDriverImpl::prepareModel_1_1( - const armnn::IRuntimePtr& runtime, - const armnn::IGpuAccTunedParametersPtr& clTunedParameters, - const DriverOptions& options, - const neuralnetworks::V1_1::Model& model, - const sp& cb) -{ - ALOGV("V1_1::ArmnnDriverImpl::prepareModel_1_1()"); - - if(compliantWithV1_0(model)) - { - return V1_0::ArmnnDriverImpl::prepareModel(runtime, clTunedParameters, options, convertToV1_0(model), cb, - model.relaxComputationFloat32toFloat16 && options.GetFp16Enabled()); - } - else - { - if (cb.get() == nullptr) - { - ALOGW("V1_1::ArmnnDriverImpl::prepareModel_1_1: Invalid callback passed to prepareModel"); - return ErrorStatus::INVALID_ARGUMENT; - } - - if (!runtime) - { - return FailPrepareModel(ErrorStatus::DEVICE_UNAVAILABLE, - "V1_1::ArmnnDriverImpl::prepareModel_1_1: Device unavailable", cb); - } - - if (!android::nn::validateModel(model)) - { - return FailPrepareModel(ErrorStatus::INVALID_ARGUMENT, - "V1_1::ArmnnDriverImpl::prepareModel_1_1: Invalid model passed as input", cb); - } - - FailPrepareModel(ErrorStatus::GENERAL_FAILURE, - "V1_1::ArmnnDriverImpl::prepareModel_1_1: Unsupported model", cb); - return ErrorStatus::NONE; - } -} - -} // armnn_driver::namespace V1_1 -} // namespace armnn_driver -- cgit v1.2.1