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 | e6e54a8 | 2019-05-08 10:18:05 +0100 | [diff] [blame] | 54 | android::sp<V1_0::IPreparedModel> preparedModels[maxRequests]; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 55 | for (size_t i = 0; i < maxRequests; ++i) |
| 56 | { |
| 57 | preparedModels[i] = PrepareModel(model, *driver); |
| 58 | } |
| 59 | |
| 60 | // construct the request data |
| 61 | DataLocation inloc = {}; |
| 62 | inloc.poolIndex = 0; |
| 63 | inloc.offset = 0; |
| 64 | inloc.length = 3 * sizeof(float); |
| 65 | RequestArgument input = {}; |
| 66 | input.location = inloc; |
| 67 | input.dimensions = hidl_vec<uint32_t>{}; |
| 68 | |
| 69 | DataLocation outloc = {}; |
| 70 | outloc.poolIndex = 1; |
| 71 | outloc.offset = 0; |
| 72 | outloc.length = 1 * sizeof(float); |
| 73 | RequestArgument output = {}; |
| 74 | output.location = outloc; |
| 75 | output.dimensions = hidl_vec<uint32_t>{}; |
| 76 | |
| 77 | // build the requests |
| 78 | Request requests[maxRequests]; |
| 79 | android::sp<IMemory> outMemory[maxRequests]; |
| 80 | float* outdata[maxRequests]; |
| 81 | for (size_t i = 0; i < maxRequests; ++i) |
| 82 | { |
| 83 | requests[i].inputs = hidl_vec<RequestArgument>{input}; |
| 84 | requests[i].outputs = hidl_vec<RequestArgument>{output}; |
| 85 | // set the input data (matching source test) |
| 86 | float indata[] = {2, 32, 16}; |
Ellen Norris-Thompson | 976ad3e | 2019-08-21 15:21:14 +0100 | [diff] [blame^] | 87 | AddPoolAndSetData<float>(3, requests[i], indata); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 88 | // add memory for the output |
Ellen Norris-Thompson | 976ad3e | 2019-08-21 15:21:14 +0100 | [diff] [blame^] | 89 | outMemory[i] = AddPoolAndGetData<float>(1, requests[i]); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 90 | outdata[i] = static_cast<float*>(static_cast<void*>(outMemory[i]->getPointer())); |
| 91 | } |
| 92 | |
| 93 | // invoke the execution of the requests |
| 94 | ALOGI("ConcurrentExecute: executing requests"); |
| 95 | android::sp<ExecutionCallback> cb[maxRequests]; |
| 96 | for (size_t i = 0; i < maxRequests; ++i) |
| 97 | { |
| 98 | cb[i] = ExecuteNoWait(preparedModels[i], requests[i]); |
| 99 | } |
| 100 | |
| 101 | // wait for the requests to complete |
| 102 | ALOGI("ConcurrentExecute: waiting for callbacks"); |
| 103 | for (size_t i = 0; i < maxRequests; ++i) |
| 104 | { |
| 105 | cb[i]->wait(); |
| 106 | } |
| 107 | |
| 108 | // check the results |
| 109 | ALOGI("ConcurrentExecute: validating results"); |
| 110 | for (size_t i = 0; i < maxRequests; ++i) |
| 111 | { |
| 112 | BOOST_TEST(outdata[i][0] == 152); |
| 113 | } |
| 114 | ALOGI("ConcurrentExecute: exit"); |
| 115 | } |
| 116 | |
| 117 | BOOST_AUTO_TEST_SUITE_END() |