From 49b9e100bfbb3b8da01472a0ff48b2bd92944e01 Mon Sep 17 00:00:00 2001 From: surmeh01 Date: Thu, 17 May 2018 14:11:25 +0100 Subject: Release 18.05 --- test/Concurrent.cpp | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 test/Concurrent.cpp (limited to 'test/Concurrent.cpp') diff --git a/test/Concurrent.cpp b/test/Concurrent.cpp new file mode 100644 index 00000000..16734dc3 --- /dev/null +++ b/test/Concurrent.cpp @@ -0,0 +1,109 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// See LICENSE file in the project root for full license information. +// +#include "DriverTestHelpers.hpp" +#include +#include + +BOOST_AUTO_TEST_SUITE(ConcurrentDriverTests) + +using ArmnnDriver = armnn_driver::ArmnnDriver; +using DriverOptions = armnn_driver::DriverOptions; +using namespace android::nn; +using namespace driverTestHelpers; + +// Add our own test for concurrent execution +// The main point of this test is to check that multiple requests can be +// executed without waiting for the callback from previous execution. +// The operations performed are not significant. +BOOST_AUTO_TEST_CASE(ConcurrentExecute) +{ + ALOGI("ConcurrentExecute: entry"); + + auto driver = std::make_unique(DriverOptions(armnn::Compute::CpuRef)); + 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); + AddTensorOperand(model, hidl_vec{1}, biasValue); + AddIntOperand(model, actValue); + AddOutputOperand(model, hidl_vec{1, 1}); + + // make the fully connected operation + model.operations.resize(1); + model.operations[0].type = OperationType::FULLY_CONNECTED; + model.operations[0].inputs = hidl_vec{0, 1, 2, 3}; + model.operations[0].outputs = hidl_vec{4}; + + // make the prepared models + const size_t maxRequests = 5; + android::sp preparedModels[maxRequests]; + for (size_t i = 0; i < maxRequests; ++i) + { + preparedModels[i] = PrepareModel(model, *driver); + } + + // 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 + 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 indata[] = {2, 32, 16}; + AddPoolAndSetData(3, requests[i], indata); + // 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("ConcurrentExecute: 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("ConcurrentExecute: waiting for callbacks"); + for (size_t i = 0; i < maxRequests; ++i) + { + cb[i]->wait(); + } + + // check the results + ALOGI("ConcurrentExecute: validating results"); + for (size_t i = 0; i < maxRequests; ++i) + { + BOOST_TEST(outdata[i][0] == 152); + } + ALOGI("ConcurrentExecute: exit"); +} + +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.1