blob: 16734dc3cf5f046351445f4ef9a44b636cf08275 [file] [log] [blame]
surmeh0149b9e102018-05-17 14:11:25 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// See LICENSE file in the project root for full license information.
4//
5#include "DriverTestHelpers.hpp"
6#include <boost/test/unit_test.hpp>
7#include <log/log.h>
8
9BOOST_AUTO_TEST_SUITE(ConcurrentDriverTests)
10
11using ArmnnDriver = armnn_driver::ArmnnDriver;
12using DriverOptions = armnn_driver::DriverOptions;
13using namespace android::nn;
14using namespace driverTestHelpers;
15
16// Add our own test for concurrent execution
17// The main point of this test is to check that multiple requests can be
18// executed without waiting for the callback from previous execution.
19// The operations performed are not significant.
20BOOST_AUTO_TEST_CASE(ConcurrentExecute)
21{
22 ALOGI("ConcurrentExecute: entry");
23
24 auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
25 Model model = {};
26
27 // add operands
28 int32_t actValue = 0;
29 float weightValue[] = {2, 4, 1};
30 float biasValue[] = {4};
31
32 AddInputOperand(model, hidl_vec<uint32_t>{1, 3});
33 AddTensorOperand(model, hidl_vec<uint32_t>{1, 3}, weightValue);
34 AddTensorOperand(model, hidl_vec<uint32_t>{1}, biasValue);
35 AddIntOperand(model, actValue);
36 AddOutputOperand(model, hidl_vec<uint32_t>{1, 1});
37
38 // make the fully connected operation
39 model.operations.resize(1);
40 model.operations[0].type = OperationType::FULLY_CONNECTED;
41 model.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2, 3};
42 model.operations[0].outputs = hidl_vec<uint32_t>{4};
43
44 // make the prepared models
45 const size_t maxRequests = 5;
46 android::sp<IPreparedModel> preparedModels[maxRequests];
47 for (size_t i = 0; i < maxRequests; ++i)
48 {
49 preparedModels[i] = PrepareModel(model, *driver);
50 }
51
52 // construct the request data
53 DataLocation inloc = {};
54 inloc.poolIndex = 0;
55 inloc.offset = 0;
56 inloc.length = 3 * sizeof(float);
57 RequestArgument input = {};
58 input.location = inloc;
59 input.dimensions = hidl_vec<uint32_t>{};
60
61 DataLocation outloc = {};
62 outloc.poolIndex = 1;
63 outloc.offset = 0;
64 outloc.length = 1 * sizeof(float);
65 RequestArgument output = {};
66 output.location = outloc;
67 output.dimensions = hidl_vec<uint32_t>{};
68
69 // build the requests
70 Request requests[maxRequests];
71 android::sp<IMemory> outMemory[maxRequests];
72 float* outdata[maxRequests];
73 for (size_t i = 0; i < maxRequests; ++i)
74 {
75 requests[i].inputs = hidl_vec<RequestArgument>{input};
76 requests[i].outputs = hidl_vec<RequestArgument>{output};
77 // set the input data (matching source test)
78 float indata[] = {2, 32, 16};
79 AddPoolAndSetData(3, requests[i], indata);
80 // add memory for the output
81 outMemory[i] = AddPoolAndGetData(1, requests[i]);
82 outdata[i] = static_cast<float*>(static_cast<void*>(outMemory[i]->getPointer()));
83 }
84
85 // invoke the execution of the requests
86 ALOGI("ConcurrentExecute: executing requests");
87 android::sp<ExecutionCallback> cb[maxRequests];
88 for (size_t i = 0; i < maxRequests; ++i)
89 {
90 cb[i] = ExecuteNoWait(preparedModels[i], requests[i]);
91 }
92
93 // wait for the requests to complete
94 ALOGI("ConcurrentExecute: waiting for callbacks");
95 for (size_t i = 0; i < maxRequests; ++i)
96 {
97 cb[i]->wait();
98 }
99
100 // check the results
101 ALOGI("ConcurrentExecute: validating results");
102 for (size_t i = 0; i < maxRequests; ++i)
103 {
104 BOOST_TEST(outdata[i][0] == 152);
105 }
106 ALOGI("ConcurrentExecute: exit");
107}
108
109BOOST_AUTO_TEST_SUITE_END()