blob: 9fe6f46e0ad64198061af500f57a9d210be056db [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 Armagane6e54a82019-05-08 10:18:05 +010054 android::sp<V1_0::IPreparedModel> preparedModels[maxRequests];
surmeh0149b9e102018-05-17 14:11:25 +010055 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-Thompson976ad3e2019-08-21 15:21:14 +010087 AddPoolAndSetData<float>(3, requests[i], indata);
surmeh0149b9e102018-05-17 14:11:25 +010088 // add memory for the output
Ellen Norris-Thompson976ad3e2019-08-21 15:21:14 +010089 outMemory[i] = AddPoolAndGetData<float>(1, requests[i]);
surmeh0149b9e102018-05-17 14:11:25 +010090 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
117BOOST_AUTO_TEST_SUITE_END()