blob: 0694934c7336c10b3ed8304328a84ba612d26dbf [file] [log] [blame]
surmeh0149b9e102018-05-17 14:11:25 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beck93e48982018-09-05 13:05:09 +01003// SPDX-License-Identifier: MIT
surmeh0149b9e102018-05-17 14:11:25 +01004//
5#include "DriverTestHelpers.hpp"
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +01006
7#include "../1.0/HalPolicy.hpp"
8
surmeh0149b9e102018-05-17 14:11:25 +01009#include <boost/test/unit_test.hpp>
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010010
surmeh0149b9e102018-05-17 14:11:25 +010011#include <log/log.h>
12
13BOOST_AUTO_TEST_SUITE(ConcurrentDriverTests)
14
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010015using ArmnnDriver = armnn_driver::ArmnnDriver;
surmeh0149b9e102018-05-17 14:11:25 +010016using DriverOptions = armnn_driver::DriverOptions;
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010017using HalPolicy = armnn_driver::hal_1_0::HalPolicy;
18
surmeh0149b9e102018-05-17 14:11:25 +010019using namespace android::nn;
telsoa01ce3e84a2018-08-31 09:31:35 +010020using namespace android::hardware;
surmeh0149b9e102018-05-17 14:11:25 +010021using namespace driverTestHelpers;
telsoa01ce3e84a2018-08-31 09:31:35 +010022using namespace armnn_driver;
surmeh0149b9e102018-05-17 14:11:25 +010023
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.
28BOOST_AUTO_TEST_CASE(ConcurrentExecute)
29{
30 ALOGI("ConcurrentExecute: entry");
31
32 auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010033 HalPolicy::Model model = {};
surmeh0149b9e102018-05-17 14:11:25 +010034
35 // add operands
36 int32_t actValue = 0;
37 float weightValue[] = {2, 4, 1};
38 float biasValue[] = {4};
39
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010040 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});
surmeh0149b9e102018-05-17 14:11:25 +010045
46 // make the fully connected operation
47 model.operations.resize(1);
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010048 model.operations[0].type = HalPolicy::OperationType::FULLY_CONNECTED;
surmeh0149b9e102018-05-17 14:11:25 +010049 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 Armagand4636872020-04-27 10:15:41 +010054 size_t preparedModelsSize = 0;
Sadik Armagane6e54a82019-05-08 10:18:05 +010055 android::sp<V1_0::IPreparedModel> preparedModels[maxRequests];
surmeh0149b9e102018-05-17 14:11:25 +010056 for (size_t i = 0; i < maxRequests; ++i)
57 {
Sadik Armagand4636872020-04-27 10:15:41 +010058 auto preparedModel = PrepareModel(model, *driver);
59 if (preparedModel.get() != nullptr)
60 {
61 preparedModels[i] = PrepareModel(model, *driver);
62 preparedModelsSize++;
63 }
surmeh0149b9e102018-05-17 14:11:25 +010064 }
65
Sadik Armagand4636872020-04-27 10:15:41 +010066 BOOST_TEST(maxRequests == preparedModelsSize);
67
surmeh0149b9e102018-05-17 14:11:25 +010068 // 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 Mayec1e5b82020-02-26 17:00:39 +000086 V1_0::Request requests[maxRequests];
surmeh0149b9e102018-05-17 14:11:25 +010087 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-Thompson976ad3e2019-08-21 15:21:14 +010095 AddPoolAndSetData<float>(3, requests[i], indata);
surmeh0149b9e102018-05-17 14:11:25 +010096 // add memory for the output
Ellen Norris-Thompson976ad3e2019-08-21 15:21:14 +010097 outMemory[i] = AddPoolAndGetData<float>(1, requests[i]);
surmeh0149b9e102018-05-17 14:11:25 +010098 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
125BOOST_AUTO_TEST_SUITE_END()