From 82609564981ca40d0fc86d2bb4b8ee62648a41c6 Mon Sep 17 00:00:00 2001 From: David Monahan Date: Mon, 31 Aug 2020 15:50:32 +0100 Subject: IVGCVSW-4917 Adding Unit test to Android-nn-driver for Hal1.3 Qos Signed-off-by: David Monahan Change-Id: Ie45464f2b04c8f2bb30ca06ff91b96492f2466b0 --- test/1.3/QosTests.cpp | 192 +++++++++++++++++++++++++++++++++++++++++++++ test/Android.mk | 1 + test/DriverTestHelpers.cpp | 5 +- test/DriverTestHelpers.hpp | 3 +- 4 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 test/1.3/QosTests.cpp diff --git a/test/1.3/QosTests.cpp b/test/1.3/QosTests.cpp new file mode 100644 index 00000000..d51152b5 --- /dev/null +++ b/test/1.3/QosTests.cpp @@ -0,0 +1,192 @@ +// +// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "../DriverTestHelpers.hpp" +#include "../TestTensor.hpp" + +#include "../1.3/HalPolicy.hpp" + +#include + +#include +#include + + +BOOST_AUTO_TEST_SUITE(QosTests) + +using ArmnnDriver = armnn_driver::ArmnnDriver; +using DriverOptions = armnn_driver::DriverOptions; + +using namespace android::nn; +using namespace android::hardware; +using namespace driverTestHelpers; +using namespace armnn_driver; + +using HalPolicy = hal_1_3::HalPolicy; + +namespace +{ + +void ExecuteModel(const armnn_driver::hal_1_3::HalPolicy::Model& model, + armnn_driver::ArmnnDriver& driver, + const V1_0::Request& request) +{ + android::sp preparedModel = PrepareModel_1_3(model, driver); + if (preparedModel.get() != nullptr) + { + Execute(preparedModel, request); + } +} + +#ifndef ARMCOMPUTECL_ENABLED +static const std::array COMPUTE_DEVICES = {{ armnn::Compute::CpuRef }}; +#else +static const std::array COMPUTE_DEVICES = {{ armnn::Compute::CpuRef, armnn::Compute::CpuAcc }}; +#endif + +BOOST_AUTO_TEST_CASE(ConcurrentExecuteWithQosPriority) +{ + ALOGI("ConcurrentExecuteWithQOSPriority: entry"); + + auto driver = std::make_unique(DriverOptions(armnn::Compute::CpuRef)); + HalPolicy::Model model = {}; + + // add operands + int32_t actValue = 0; + float weightValue[] = {2, 4, 1}; + float biasValue[] = {4}; + + AddInputOperand(model, hidl_vec{1, 3}); + AddTensorOperand(model, + hidl_vec{1, 3}, + weightValue, + HalPolicy::OperandType::TENSOR_FLOAT32, + V1_3::OperandLifeTime::CONSTANT_COPY); + AddTensorOperand(model, + hidl_vec{1}, + biasValue, + HalPolicy::OperandType::TENSOR_FLOAT32, + V1_3::OperandLifeTime::CONSTANT_COPY); + AddIntOperand(model, actValue); + AddOutputOperand(model, hidl_vec{1, 1}); + + // make the fully connected operation + model.main.operations.resize(1); + model.main.operations[0].type = HalPolicy::OperationType::FULLY_CONNECTED; + model.main.operations[0].inputs = hidl_vec{0, 1, 2, 3}; + model.main.operations[0].outputs = hidl_vec{4}; + + // make the prepared models + const size_t maxRequests = 45; + size_t preparedModelsSize = 0; + android::sp preparedModels[maxRequests]; + V1_3::ErrorStatus status(V1_3::ErrorStatus::NONE); + size_t start = preparedModelsSize; + for (size_t i = start; i < start+15; ++i) + { + preparedModels[i] = PrepareModelWithStatus_1_3(model, *driver, status, V1_3::Priority::LOW); + preparedModelsSize++; + } + start = preparedModelsSize; + for (size_t i = start; i < start+15; ++i) + { + preparedModels[i] = PrepareModelWithStatus_1_3(model, *driver, status, V1_3::Priority::MEDIUM); + preparedModelsSize++; + } + start = preparedModelsSize; + for (size_t i = start; i < start+15; ++i) + { + preparedModels[i] = PrepareModelWithStatus_1_3(model, *driver, status, V1_3::Priority::HIGH); + preparedModelsSize++; + } + + BOOST_TEST(maxRequests == preparedModelsSize); + + // construct the request data + DataLocation inloc = {}; + inloc.poolIndex = 0; + inloc.offset = 0; + inloc.length = 3 * sizeof(float); + RequestArgument input = {}; + input.location = inloc; + input.dimensions = hidl_vec{}; + + DataLocation outloc = {}; + outloc.poolIndex = 1; + outloc.offset = 0; + outloc.length = 1 * sizeof(float); + RequestArgument output = {}; + output.location = outloc; + output.dimensions = hidl_vec{}; + + // build the requests + V1_0::Request requests[maxRequests]; + android::sp outMemory[maxRequests]; + float* outdata[maxRequests]; + for (size_t i = 0; i < maxRequests; ++i) + { + requests[i].inputs = hidl_vec{input}; + requests[i].outputs = hidl_vec{output}; + // set the input data (matching source test) + float inDataLow[] = {2, 32, 16}; + float inDataMedium[] = {1, 31, 11}; + float inDataHigh[] = {3, 33, 17}; + if (i < 15) + { + AddPoolAndSetData(3, requests[i], inDataLow); + } + else if (i < 30) + { + AddPoolAndSetData(3, requests[i], inDataMedium); + } + else + { + AddPoolAndSetData(3, requests[i], inDataHigh); + } + // add memory for the output + outMemory[i] = AddPoolAndGetData(1, requests[i]); + outdata[i] = static_cast(static_cast(outMemory[i]->getPointer())); + } + + // invoke the execution of the requests + ALOGI("ConcurrentExecuteWithQOSPriority: executing requests"); + android::sp cb[maxRequests]; + for (size_t i = 0; i < maxRequests; ++i) + { + cb[i] = ExecuteNoWait(preparedModels[i], requests[i]); + } + + // wait for the requests to complete + ALOGI("ConcurrentExecuteWithQOSPriority: waiting for callbacks"); + for (size_t i = 0; i < maxRequests; ++i) + { + ARMNN_ASSERT(cb[i]); + cb[i]->wait(); + } + + // check the results + ALOGI("ConcurrentExecuteWithQOSPriority: validating results"); + for (size_t i = 0; i < maxRequests; ++i) + { + if (i < 15) + { + BOOST_TEST(outdata[i][0] == 152); + } + else if (i < 30) + { + BOOST_TEST(outdata[i][0] == 141); + } + else + { + BOOST_TEST(outdata[i][0] == 159); + } + + } + ALOGI("ConcurrentExecuteWithQOSPriority: exit"); +} + +} // anonymous namespace + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test/Android.mk b/test/Android.mk index 9349a368..ca940f5b 100644 --- a/test/Android.mk +++ b/test/Android.mk @@ -379,6 +379,7 @@ LOCAL_SRC_FILES := \ 1.1/Lstm.cpp \ 1.2/Lstm.cpp \ 1.3/QLstm.cpp \ + 1.3/QosTests.cpp \ Tests.cpp \ UtilsTests.cpp \ Concurrent.cpp \ diff --git a/test/DriverTestHelpers.cpp b/test/DriverTestHelpers.cpp index c6d44065..8e8d7bef 100644 --- a/test/DriverTestHelpers.cpp +++ b/test/DriverTestHelpers.cpp @@ -198,7 +198,8 @@ android::sp PrepareModelWithStatus_1_2(const armnn_driver: android::sp PrepareModelWithStatus_1_3(const armnn_driver::hal_1_3::HalPolicy::Model& model, armnn_driver::ArmnnDriver& driver, - V1_3::ErrorStatus& prepareStatus) + V1_3::ErrorStatus& prepareStatus, + V1_3::Priority priority) { android::sp cb(new PreparedModelCallback_1_3()); @@ -208,7 +209,7 @@ android::sp PrepareModelWithStatus_1_3(const armnn_driver: driver.prepareModel_1_3(model, V1_1::ExecutionPreference::LOW_POWER, - V1_3::Priority::LOW, + priority, {}, emptyHandle1, emptyHandle2, diff --git a/test/DriverTestHelpers.hpp b/test/DriverTestHelpers.hpp index f8f38545..05b78925 100644 --- a/test/DriverTestHelpers.hpp +++ b/test/DriverTestHelpers.hpp @@ -385,7 +385,8 @@ void AddOutputOperand(armnn_driver::hal_1_3::HalPolicy::Model& model, android::sp PrepareModelWithStatus_1_3(const armnn_driver::hal_1_3::HalPolicy::Model& model, armnn_driver::ArmnnDriver& driver, - V1_3::ErrorStatus& prepareStatus); + V1_3::ErrorStatus& prepareStatus, + V1_3::Priority priority = V1_3::Priority::LOW); template android::sp PrepareModel_1_3(const HalModel& model, -- cgit v1.2.1