surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | 93e4898 | 2018-09-05 13:05:09 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 4 | // |
| 5 | #include "DriverTestHelpers.hpp" |
Aron Virginas-Tar | 44cfd84 | 2019-06-14 15:45:03 +0100 | [diff] [blame] | 6 | |
| 7 | #include "../1.0/HalPolicy.hpp" |
| 8 | |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 9 | #include <boost/test/unit_test.hpp> |
Aron Virginas-Tar | 44cfd84 | 2019-06-14 15:45:03 +0100 | [diff] [blame] | 10 | |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 11 | #include <log/log.h> |
| 12 | |
| 13 | BOOST_AUTO_TEST_SUITE(ConcurrentDriverTests) |
| 14 | |
Aron Virginas-Tar | 44cfd84 | 2019-06-14 15:45:03 +0100 | [diff] [blame] | 15 | using ArmnnDriver = armnn_driver::ArmnnDriver; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 16 | using DriverOptions = armnn_driver::DriverOptions; |
Aron Virginas-Tar | 44cfd84 | 2019-06-14 15:45:03 +0100 | [diff] [blame] | 17 | using HalPolicy = armnn_driver::hal_1_0::HalPolicy; |
| 18 | |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 19 | using namespace android::nn; |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 20 | using namespace android::hardware; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 21 | using namespace driverTestHelpers; |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 22 | using namespace armnn_driver; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 23 | |
| 24 | // Add our own test for concurrent execution |
| 25 | // The main point of this test is to check that multiple requests can be |
| 26 | // executed without waiting for the callback from previous execution. |
| 27 | // The operations performed are not significant. |
| 28 | BOOST_AUTO_TEST_CASE(ConcurrentExecute) |
| 29 | { |
| 30 | ALOGI("ConcurrentExecute: entry"); |
| 31 | |
| 32 | auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef)); |
Aron Virginas-Tar | 44cfd84 | 2019-06-14 15:45:03 +0100 | [diff] [blame] | 33 | HalPolicy::Model model = {}; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 34 | |
| 35 | // add operands |
| 36 | int32_t actValue = 0; |
| 37 | float weightValue[] = {2, 4, 1}; |
| 38 | float biasValue[] = {4}; |
| 39 | |
Aron Virginas-Tar | 44cfd84 | 2019-06-14 15:45:03 +0100 | [diff] [blame] | 40 | AddInputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 3}); |
| 41 | AddTensorOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 3}, weightValue); |
| 42 | AddTensorOperand<HalPolicy>(model, hidl_vec<uint32_t>{1}, biasValue); |
| 43 | AddIntOperand<HalPolicy>(model, actValue); |
| 44 | AddOutputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 1}); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 45 | |
| 46 | // make the fully connected operation |
| 47 | model.operations.resize(1); |
Aron Virginas-Tar | 44cfd84 | 2019-06-14 15:45:03 +0100 | [diff] [blame] | 48 | model.operations[0].type = HalPolicy::OperationType::FULLY_CONNECTED; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 49 | model.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2, 3}; |
| 50 | model.operations[0].outputs = hidl_vec<uint32_t>{4}; |
| 51 | |
| 52 | // make the prepared models |
| 53 | const size_t maxRequests = 5; |
Sadik Armagan | d463687 | 2020-04-27 10:15:41 +0100 | [diff] [blame^] | 54 | size_t preparedModelsSize = 0; |
Sadik Armagan | e6e54a8 | 2019-05-08 10:18:05 +0100 | [diff] [blame] | 55 | android::sp<V1_0::IPreparedModel> preparedModels[maxRequests]; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 56 | for (size_t i = 0; i < maxRequests; ++i) |
| 57 | { |
Sadik Armagan | d463687 | 2020-04-27 10:15:41 +0100 | [diff] [blame^] | 58 | auto preparedModel = PrepareModel(model, *driver); |
| 59 | if (preparedModel.get() != nullptr) |
| 60 | { |
| 61 | preparedModels[i] = PrepareModel(model, *driver); |
| 62 | preparedModelsSize++; |
| 63 | } |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Sadik Armagan | d463687 | 2020-04-27 10:15:41 +0100 | [diff] [blame^] | 66 | BOOST_TEST(maxRequests == preparedModelsSize); |
| 67 | |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 68 | // construct the request data |
| 69 | DataLocation inloc = {}; |
| 70 | inloc.poolIndex = 0; |
| 71 | inloc.offset = 0; |
| 72 | inloc.length = 3 * sizeof(float); |
| 73 | RequestArgument input = {}; |
| 74 | input.location = inloc; |
| 75 | input.dimensions = hidl_vec<uint32_t>{}; |
| 76 | |
| 77 | DataLocation outloc = {}; |
| 78 | outloc.poolIndex = 1; |
| 79 | outloc.offset = 0; |
| 80 | outloc.length = 1 * sizeof(float); |
| 81 | RequestArgument output = {}; |
| 82 | output.location = outloc; |
| 83 | output.dimensions = hidl_vec<uint32_t>{}; |
| 84 | |
| 85 | // build the requests |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 86 | V1_0::Request requests[maxRequests]; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 87 | android::sp<IMemory> outMemory[maxRequests]; |
| 88 | float* outdata[maxRequests]; |
| 89 | for (size_t i = 0; i < maxRequests; ++i) |
| 90 | { |
| 91 | requests[i].inputs = hidl_vec<RequestArgument>{input}; |
| 92 | requests[i].outputs = hidl_vec<RequestArgument>{output}; |
| 93 | // set the input data (matching source test) |
| 94 | float indata[] = {2, 32, 16}; |
Ellen Norris-Thompson | 976ad3e | 2019-08-21 15:21:14 +0100 | [diff] [blame] | 95 | AddPoolAndSetData<float>(3, requests[i], indata); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 96 | // add memory for the output |
Ellen Norris-Thompson | 976ad3e | 2019-08-21 15:21:14 +0100 | [diff] [blame] | 97 | outMemory[i] = AddPoolAndGetData<float>(1, requests[i]); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 98 | outdata[i] = static_cast<float*>(static_cast<void*>(outMemory[i]->getPointer())); |
| 99 | } |
| 100 | |
| 101 | // invoke the execution of the requests |
| 102 | ALOGI("ConcurrentExecute: executing requests"); |
| 103 | android::sp<ExecutionCallback> cb[maxRequests]; |
| 104 | for (size_t i = 0; i < maxRequests; ++i) |
| 105 | { |
| 106 | cb[i] = ExecuteNoWait(preparedModels[i], requests[i]); |
| 107 | } |
| 108 | |
| 109 | // wait for the requests to complete |
| 110 | ALOGI("ConcurrentExecute: waiting for callbacks"); |
| 111 | for (size_t i = 0; i < maxRequests; ++i) |
| 112 | { |
| 113 | cb[i]->wait(); |
| 114 | } |
| 115 | |
| 116 | // check the results |
| 117 | ALOGI("ConcurrentExecute: validating results"); |
| 118 | for (size_t i = 0; i < maxRequests; ++i) |
| 119 | { |
| 120 | BOOST_TEST(outdata[i][0] == 152); |
| 121 | } |
| 122 | ALOGI("ConcurrentExecute: exit"); |
| 123 | } |
| 124 | |
| 125 | BOOST_AUTO_TEST_SUITE_END() |