aboutsummaryrefslogtreecommitdiff
path: root/1.1
diff options
context:
space:
mode:
authorMatteo Martincigh <matteo.martincigh@arm.com>2018-09-03 13:50:50 +0100
committerMatthew Bentham <matthew.bentham@arm.com>2018-09-18 12:40:38 +0100
commite48bdff741568236d3c0747ad3d18a8eba5b36dd (patch)
tree77aabce6f75d86d3f2f3924f342292ae5a7267e7 /1.1
parenta15dc11fd7bf3ad49e752ec75157b731287fe46d (diff)
downloadandroid-nn-driver-e48bdff741568236d3c0747ad3d18a8eba5b36dd.tar.gz
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
Diffstat (limited to '1.1')
-rw-r--r--1.1/ArmnnDriver.hpp63
-rw-r--r--1.1/ArmnnDriverImpl.cpp151
-rw-r--r--1.1/ArmnnDriverImpl.hpp39
3 files changed, 39 insertions, 214 deletions
diff --git a/1.1/ArmnnDriver.hpp b/1.1/ArmnnDriver.hpp
index 6bd8e03c..f55aad4b 100644
--- a/1.1/ArmnnDriver.hpp
+++ b/1.1/ArmnnDriver.hpp
@@ -8,13 +8,14 @@
#include <HalInterfaces.h>
#include "ArmnnDevice.hpp"
-#include "1.0/ArmnnDriverImpl.hpp"
-#include "1.1/ArmnnDriverImpl.hpp"
+#include "../ArmnnDriverImpl.hpp"
#include <log/log.h>
-namespace armnn_driver {
-namespace V1_1 {
+namespace armnn_driver
+{
+namespace V1_1
+{
class ArmnnDriver : public ArmnnDevice, public ::android::hardware::neuralnetworks::V1_1::IDevice
{
@@ -28,74 +29,88 @@ public:
public:
Return<void> getCapabilities(
- ::android::hardware::neuralnetworks::V1_0::IDevice::getCapabilities_cb cb)
+ ::android::hardware::neuralnetworks::V1_0::IDevice::getCapabilities_cb cb) override
{
ALOGV("V1_1::ArmnnDriver::getCapabilities()");
- return V1_0::ArmnnDriverImpl::getCapabilities(m_Runtime, cb);
+ return armnn_driver::ArmnnDriverImpl<HalVersion_1_0>::getCapabilities(m_Runtime,
+ cb);
}
Return<void> getSupportedOperations(
const ::android::hardware::neuralnetworks::V1_0::Model& model,
- ::android::hardware::neuralnetworks::V1_0::IDevice::getSupportedOperations_cb cb)
+ ::android::hardware::neuralnetworks::V1_0::IDevice::getSupportedOperations_cb cb) override
{
ALOGV("V1_1::ArmnnDriver::getSupportedOperations()");
- return V1_0::ArmnnDriverImpl::getSupportedOperations(m_Runtime, m_Options, model, cb);
+ return armnn_driver::ArmnnDriverImpl<HalVersion_1_0>::getSupportedOperations(m_Runtime,
+ m_Options,
+ model,
+ cb);
}
Return<ErrorStatus> prepareModel(
const ::android::hardware::neuralnetworks::V1_0::Model& model,
- const android::sp<IPreparedModelCallback>& cb)
+ const android::sp<IPreparedModelCallback>& cb) override
{
ALOGV("V1_1::ArmnnDriver::prepareModel()");
- return V1_0::ArmnnDriverImpl::prepareModel(m_Runtime, m_ClTunedParameters, m_Options, model, cb);
+ return armnn_driver::ArmnnDriverImpl<HalVersion_1_0>::prepareModel(m_Runtime,
+ m_ClTunedParameters,
+ m_Options,
+ model,
+ cb);
}
Return<void> getCapabilities_1_1(
- ::android::hardware::neuralnetworks::V1_1::IDevice::getCapabilities_1_1_cb cb)
+ ::android::hardware::neuralnetworks::V1_1::IDevice::getCapabilities_1_1_cb cb) override
{
ALOGV("V1_1::ArmnnDriver::getCapabilities_1_1()");
- return V1_1::ArmnnDriverImpl::getCapabilities_1_1(m_Runtime, cb);
+ return armnn_driver::ArmnnDriverImpl<HalVersion_1_1>::getCapabilities(m_Runtime,
+ cb);
}
Return<void> getSupportedOperations_1_1(
const ::android::hardware::neuralnetworks::V1_1::Model& model,
- ::android::hardware::neuralnetworks::V1_1::IDevice::getSupportedOperations_1_1_cb cb)
+ ::android::hardware::neuralnetworks::V1_1::IDevice::getSupportedOperations_1_1_cb cb) override
{
ALOGV("V1_1::ArmnnDriver::getSupportedOperations_1_1()");
- return V1_1::ArmnnDriverImpl::getSupportedOperations_1_1(m_Runtime, m_Options, model, cb);
+ return armnn_driver::ArmnnDriverImpl<HalVersion_1_1>::getSupportedOperations(m_Runtime,
+ m_Options,
+ model,
+ cb);
}
Return<ErrorStatus> prepareModel_1_1(
const ::android::hardware::neuralnetworks::V1_1::Model& model,
::android::hardware::neuralnetworks::V1_1::ExecutionPreference preference,
- const android::sp<IPreparedModelCallback>& cb)
+ const android::sp<IPreparedModelCallback>& cb) override
{
- using namespace ::android::hardware::neuralnetworks::V1_0;
-
ALOGV("V1_1::ArmnnDriver::prepareModel_1_1()");
- if(!(preference == ExecutionPreference::LOW_POWER ||
- preference == ExecutionPreference::FAST_SINGLE_ANSWER ||
- preference == ExecutionPreference::SUSTAINED_SPEED))
+ if (!(preference == ExecutionPreference::LOW_POWER ||
+ preference == ExecutionPreference::FAST_SINGLE_ANSWER ||
+ preference == ExecutionPreference::SUSTAINED_SPEED))
{
- ALOGV("V1_1::ArmnnDriver::prepareModel_1_1(): Invalid execution preference");
+ ALOGV("V1_1::ArmnnDriver::prepareModel_1_1: Invalid execution preference");
cb->notify(ErrorStatus::INVALID_ARGUMENT, nullptr);
return ErrorStatus::INVALID_ARGUMENT;
}
- return V1_1::ArmnnDriverImpl::prepareModel_1_1(m_Runtime, m_ClTunedParameters, m_Options, model, cb);
+ return armnn_driver::ArmnnDriverImpl<HalVersion_1_1>::prepareModel(m_Runtime,
+ m_ClTunedParameters,
+ m_Options,
+ model,
+ cb);
}
- Return<DeviceStatus> getStatus()
+ Return<DeviceStatus> getStatus() override
{
ALOGV("V1_1::ArmnnDriver::getStatus()");
- return V1_0::ArmnnDriverImpl::getStatus();
+ return armnn_driver::ArmnnDriverImpl<HalVersion_1_1>::getStatus();
}
};
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 <OperationsUtils.h>
-
-#include <log/log.h>
-#include <boost/assert.hpp>
-
-#include <ValidateHal.h>
-
-using namespace std;
-using namespace android;
-using namespace android::nn;
-using namespace android::hardware;
-
-namespace
-{
-
-void NotifyCallbackAndCheck(const sp<IPreparedModelCallback>& callback,
- ErrorStatus errorStatus,
- const sp<IPreparedModel>& preparedModelPtr)
-{
- Return<void> 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<ErrorStatus> FailPrepareModel(ErrorStatus error,
- const string& message,
- const sp<IPreparedModelCallback>& 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<void> 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<void> 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<bool> 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<ErrorStatus> ArmnnDriverImpl::prepareModel_1_1(
- const armnn::IRuntimePtr& runtime,
- const armnn::IGpuAccTunedParametersPtr& clTunedParameters,
- const DriverOptions& options,
- const neuralnetworks::V1_1::Model& model,
- const sp<IPreparedModelCallback>& 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
diff --git a/1.1/ArmnnDriverImpl.hpp b/1.1/ArmnnDriverImpl.hpp
deleted file mode 100644
index 307d96bf..00000000
--- a/1.1/ArmnnDriverImpl.hpp
+++ /dev/null
@@ -1,39 +0,0 @@
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// See LICENSE file in the project root for full license information.
-//
-
-#pragma once
-
-#include <HalInterfaces.h>
-
-#include "DriverOptions.hpp"
-
-#include <armnn/ArmNN.hpp>
-
-namespace armnn_driver
-{
-namespace V1_1
-{
-
-class ArmnnDriverImpl
-{
-public:
- static Return<void> getCapabilities_1_1(
- const armnn::IRuntimePtr& runtime,
- ::android::hardware::neuralnetworks::V1_1::IDevice::getCapabilities_1_1_cb cb);
- static Return<void> getSupportedOperations_1_1(
- const armnn::IRuntimePtr& runtime,
- const DriverOptions& options,
- const ::android::hardware::neuralnetworks::V1_1::Model& model,
- ::android::hardware::neuralnetworks::V1_1::IDevice::getSupportedOperations_1_1_cb cb);
- static Return<ErrorStatus> prepareModel_1_1(
- const armnn::IRuntimePtr& runtime,
- const armnn::IGpuAccTunedParametersPtr& clTunedParameters,
- const DriverOptions& options,
- const ::android::hardware::neuralnetworks::V1_1::Model& model,
- const android::sp<IPreparedModelCallback>& cb);
-};
-
-} // namespace armnn_driver::V1_1
-} // namespace armnn_driver