blob: 99e0c622bd24026b5b54577e8d02a1297fef8873 [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
Sadik Armagan9150bff2021-05-26 15:40:53 +01009#include <doctest/doctest.h>
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010010
surmeh0149b9e102018-05-17 14:11:25 +010011#include <log/log.h>
12
Sadik Armagan9150bff2021-05-26 15:40:53 +010013TEST_SUITE("GenericLayerTests")
14{
surmeh0149b9e102018-05-17 14:11:25 +010015
telsoa01ce3e84a2018-08-31 09:31:35 +010016using namespace android::hardware;
surmeh0149b9e102018-05-17 14:11:25 +010017using namespace driverTestHelpers;
telsoa01ce3e84a2018-08-31 09:31:35 +010018using namespace armnn_driver;
surmeh0149b9e102018-05-17 14:11:25 +010019
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010020using HalPolicy = hal_1_0::HalPolicy;
21
Sadik Armagan9150bff2021-05-26 15:40:53 +010022TEST_CASE("GetSupportedOperations")
surmeh0149b9e102018-05-17 14:11:25 +010023{
24 auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
25
Kevin Mayec1e5b82020-02-26 17:00:39 +000026 V1_0::ErrorStatus errorStatus;
telsoa01ce3e84a2018-08-31 09:31:35 +010027 std::vector<bool> supported;
surmeh0149b9e102018-05-17 14:11:25 +010028
Kevin Mayec1e5b82020-02-26 17:00:39 +000029 auto cb = [&](V1_0::ErrorStatus _errorStatus, const std::vector<bool>& _supported)
surmeh0149b9e102018-05-17 14:11:25 +010030 {
telsoa01ce3e84a2018-08-31 09:31:35 +010031 errorStatus = _errorStatus;
32 supported = _supported;
surmeh0149b9e102018-05-17 14:11:25 +010033 };
34
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010035 HalPolicy::Model model0 = {};
surmeh0149b9e102018-05-17 14:11:25 +010036
telsoa01ce3e84a2018-08-31 09:31:35 +010037 // Add operands
surmeh0149b9e102018-05-17 14:11:25 +010038 int32_t actValue = 0;
39 float weightValue[] = {2, 4, 1};
40 float biasValue[] = {4};
41
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010042 AddInputOperand<HalPolicy>(model0, hidl_vec<uint32_t>{1, 3});
43 AddTensorOperand<HalPolicy>(model0, hidl_vec<uint32_t>{1, 3}, weightValue);
44 AddTensorOperand<HalPolicy>(model0, hidl_vec<uint32_t>{1}, biasValue);
45 AddIntOperand<HalPolicy>(model0, actValue);
46 AddOutputOperand<HalPolicy>(model0, hidl_vec<uint32_t>{1, 1});
telsoa01ce3e84a2018-08-31 09:31:35 +010047
48 model0.operations.resize(1);
49
50 // Make a correct fully connected operation
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010051 model0.operations[0].type = HalPolicy::OperationType::FULLY_CONNECTED;
telsoa01ce3e84a2018-08-31 09:31:35 +010052 model0.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2, 3};
53 model0.operations[0].outputs = hidl_vec<uint32_t>{4};
54
55 driver->getSupportedOperations(model0, cb);
Sadik Armagan9150bff2021-05-26 15:40:53 +010056 CHECK((int)errorStatus == (int)V1_0::ErrorStatus::NONE);
57 CHECK(supported.size() == (size_t)1);
58 CHECK(supported[0] == true);
telsoa01ce3e84a2018-08-31 09:31:35 +010059
Matteo Martincigh8b287c22018-09-07 09:25:10 +010060 V1_0::Model model1 = {};
telsoa01ce3e84a2018-08-31 09:31:35 +010061
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010062 AddInputOperand<HalPolicy>(model1, hidl_vec<uint32_t>{1, 3});
63 AddTensorOperand<HalPolicy>(model1, hidl_vec<uint32_t>{1, 3}, weightValue);
64 AddTensorOperand<HalPolicy>(model1, hidl_vec<uint32_t>{1}, biasValue);
65 AddIntOperand<HalPolicy>(model1, actValue);
66 AddOutputOperand<HalPolicy>(model1, hidl_vec<uint32_t>{1, 1});
surmeh0149b9e102018-05-17 14:11:25 +010067
surmeh0149b9e102018-05-17 14:11:25 +010068 model1.operations.resize(2);
telsoa01ce3e84a2018-08-31 09:31:35 +010069
70 // Make a correct fully connected operation
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010071 model1.operations[0].type = HalPolicy::OperationType::FULLY_CONNECTED;
surmeh0149b9e102018-05-17 14:11:25 +010072 model1.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2, 3};
73 model1.operations[0].outputs = hidl_vec<uint32_t>{4};
74
telsoa01ce3e84a2018-08-31 09:31:35 +010075 // Add an incorrect fully connected operation
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010076 AddIntOperand<HalPolicy>(model1, actValue);
77 AddOutputOperand<HalPolicy>(model1, hidl_vec<uint32_t>{1, 1});
78
79 model1.operations[1].type = HalPolicy::OperationType::FULLY_CONNECTED;
telsoa01ce3e84a2018-08-31 09:31:35 +010080 model1.operations[1].inputs = hidl_vec<uint32_t>{4}; // Only 1 input operand, expected 4
surmeh0149b9e102018-05-17 14:11:25 +010081 model1.operations[1].outputs = hidl_vec<uint32_t>{5};
82
83 driver->getSupportedOperations(model1, cb);
surmeh0149b9e102018-05-17 14:11:25 +010084
Sadik Armagan9150bff2021-05-26 15:40:53 +010085 CHECK((int)errorStatus == (int)V1_0::ErrorStatus::INVALID_ARGUMENT);
86 CHECK(supported.empty());
surmeh0149b9e102018-05-17 14:11:25 +010087
telsoa01ce3e84a2018-08-31 09:31:35 +010088 // Test Broadcast on add/mul operators
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010089 HalPolicy::Model model2 = {};
telsoa01ce3e84a2018-08-31 09:31:35 +010090
David Monahanc60d0fd2020-05-19 14:58:34 +010091 AddInputOperand<HalPolicy>(model2,
92 hidl_vec<uint32_t>{1, 1, 3, 4},
93 HalPolicy::OperandType::TENSOR_FLOAT32,
94 0.0f,
95 0,
96 2);
97 AddInputOperand<HalPolicy>(model2,
98 hidl_vec<uint32_t>{4},
99 HalPolicy::OperandType::TENSOR_FLOAT32,
100 0.0f,
101 0,
102 2);
103 AddIntOperand<HalPolicy>(model2, actValue, 2);
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100104 AddOutputOperand<HalPolicy>(model2, hidl_vec<uint32_t>{1, 1, 3, 4});
105 AddOutputOperand<HalPolicy>(model2, hidl_vec<uint32_t>{1, 1, 3, 4});
surmeh0149b9e102018-05-17 14:11:25 +0100106
107 model2.operations.resize(2);
108
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100109 model2.operations[0].type = HalPolicy::OperationType::ADD;
telsoa01ce3e84a2018-08-31 09:31:35 +0100110 model2.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2};
111 model2.operations[0].outputs = hidl_vec<uint32_t>{3};
surmeh0149b9e102018-05-17 14:11:25 +0100112
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100113 model2.operations[1].type = HalPolicy::OperationType::MUL;
telsoa01ce3e84a2018-08-31 09:31:35 +0100114 model2.operations[1].inputs = hidl_vec<uint32_t>{0, 1, 2};
115 model2.operations[1].outputs = hidl_vec<uint32_t>{4};
surmeh0149b9e102018-05-17 14:11:25 +0100116
117 driver->getSupportedOperations(model2, cb);
Sadik Armagan9150bff2021-05-26 15:40:53 +0100118 CHECK((int)errorStatus == (int)V1_0::ErrorStatus::NONE);
119 CHECK(supported.size() == (size_t)2);
120 CHECK(supported[0] == true);
121 CHECK(supported[1] == true);
surmeh0149b9e102018-05-17 14:11:25 +0100122
Matteo Martincigh8b287c22018-09-07 09:25:10 +0100123 V1_0::Model model3 = {};
telsoa01ce3e84a2018-08-31 09:31:35 +0100124
Aron Virginas-Tar8edb16d2019-10-01 13:34:59 +0100125 AddInputOperand<HalPolicy>(model3,
126 hidl_vec<uint32_t>{1, 1, 3, 4},
127 HalPolicy::OperandType::TENSOR_INT32);
128 AddInputOperand<HalPolicy>(model3,
129 hidl_vec<uint32_t>{4},
130 HalPolicy::OperandType::TENSOR_INT32);
131 AddInputOperand<HalPolicy>(model3, hidl_vec<uint32_t>{1, 1, 3, 4});
132
133 AddOutputOperand<HalPolicy>(model3, hidl_vec<uint32_t>{1, 1, 3, 4});
134 AddOutputOperand<HalPolicy>(model3,
135 hidl_vec<uint32_t>{1, 1, 3, 4},
136 HalPolicy::OperandType::TENSOR_QUANT8_ASYMM,
137 1.f / 225.f);
telsoa01ce3e84a2018-08-31 09:31:35 +0100138
139 model3.operations.resize(1);
surmeh0149b9e102018-05-17 14:11:25 +0100140
141 // Add unsupported operation, should return no error but we don't support it
Aron Virginas-Tar8edb16d2019-10-01 13:34:59 +0100142 model3.operations[0].type = HalPolicy::OperationType::HASHTABLE_LOOKUP;
143 model3.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2};
144 model3.operations[0].outputs = hidl_vec<uint32_t>{3, 4};
surmeh0149b9e102018-05-17 14:11:25 +0100145
146 driver->getSupportedOperations(model3, cb);
Sadik Armagan9150bff2021-05-26 15:40:53 +0100147 CHECK((int)errorStatus == (int)V1_0::ErrorStatus::NONE);
148 CHECK(supported.size() == (size_t)1);
149 CHECK(supported[0] == false);
telsoa01ce3e84a2018-08-31 09:31:35 +0100150
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100151 HalPolicy::Model model4 = {};
telsoa01ce3e84a2018-08-31 09:31:35 +0100152
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100153 AddIntOperand<HalPolicy>(model4, 0);
telsoa01ce3e84a2018-08-31 09:31:35 +0100154
155 model4.operations.resize(1);
surmeh0149b9e102018-05-17 14:11:25 +0100156
157 // Add invalid operation
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100158 model4.operations[0].type = static_cast<HalPolicy::OperationType>(100);
surmeh0149b9e102018-05-17 14:11:25 +0100159 model4.operations[0].outputs = hidl_vec<uint32_t>{0};
160
161 driver->getSupportedOperations(model4, cb);
Sadik Armagan9150bff2021-05-26 15:40:53 +0100162 CHECK((int)errorStatus == (int)V1_0::ErrorStatus::INVALID_ARGUMENT);
163 CHECK(supported.empty());
surmeh0149b9e102018-05-17 14:11:25 +0100164}
165
166// The purpose of this test is to ensure that when encountering an unsupported operation
telsoa01ce3e84a2018-08-31 09:31:35 +0100167// it is skipped and getSupportedOperations() continues (rather than failing and stopping).
168// As per IVGCVSW-710.
Sadik Armagan9150bff2021-05-26 15:40:53 +0100169TEST_CASE("UnsupportedLayerContinueOnFailure")
surmeh0149b9e102018-05-17 14:11:25 +0100170{
171 auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
172
Kevin Mayec1e5b82020-02-26 17:00:39 +0000173 V1_0::ErrorStatus errorStatus;
telsoa01ce3e84a2018-08-31 09:31:35 +0100174 std::vector<bool> supported;
surmeh0149b9e102018-05-17 14:11:25 +0100175
Kevin Mayec1e5b82020-02-26 17:00:39 +0000176 auto cb = [&](V1_0::ErrorStatus _errorStatus, const std::vector<bool>& _supported)
surmeh0149b9e102018-05-17 14:11:25 +0100177 {
telsoa01ce3e84a2018-08-31 09:31:35 +0100178 errorStatus = _errorStatus;
179 supported = _supported;
surmeh0149b9e102018-05-17 14:11:25 +0100180 };
181
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100182 HalPolicy::Model model = {};
surmeh0149b9e102018-05-17 14:11:25 +0100183
telsoa01ce3e84a2018-08-31 09:31:35 +0100184 // Operands
surmeh0149b9e102018-05-17 14:11:25 +0100185 int32_t actValue = 0;
186 float weightValue[] = {2, 4, 1};
187 float biasValue[] = {4};
188
telsoa01ce3e84a2018-08-31 09:31:35 +0100189 // HASHTABLE_LOOKUP is unsupported at the time of writing this test, but any unsupported layer will do
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100190 AddInputOperand<HalPolicy>(model,
191 hidl_vec<uint32_t>{1, 1, 3, 4},
192 HalPolicy::OperandType::TENSOR_INT32);
193 AddInputOperand<HalPolicy>(model,
194 hidl_vec<uint32_t>{4},
David Monahanc60d0fd2020-05-19 14:58:34 +0100195 HalPolicy::OperandType::TENSOR_INT32,
196 0.0f,
197 0,
198 2);
199 AddInputOperand<HalPolicy>(model,
200 hidl_vec<uint32_t>{1, 1, 3, 4},
201 HalPolicy::OperandType::TENSOR_FLOAT32,
202 0.0f,
203 0,
204 2);
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100205
206 AddOutputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 1, 3, 4});
207 AddOutputOperand<HalPolicy>(model,
208 hidl_vec<uint32_t>{1, 1, 3, 4},
Ellen Norris-Thompson976ad3e2019-08-21 15:21:14 +0100209 HalPolicy::OperandType::TENSOR_QUANT8_ASYMM,
210 1.f / 225.f);
surmeh0149b9e102018-05-17 14:11:25 +0100211
telsoa01ce3e84a2018-08-31 09:31:35 +0100212 // Fully connected is supported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100213 AddInputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 3});
214
215 AddTensorOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 3}, weightValue);
216 AddTensorOperand<HalPolicy>(model, hidl_vec<uint32_t>{1}, biasValue);
217
218 AddIntOperand<HalPolicy>(model, actValue);
219
220 AddOutputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 1});
surmeh0149b9e102018-05-17 14:11:25 +0100221
telsoa01ce3e84a2018-08-31 09:31:35 +0100222 // EMBEDDING_LOOKUP is unsupported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100223 AddOutputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 1, 3, 4});
surmeh0149b9e102018-05-17 14:11:25 +0100224
225 model.operations.resize(3);
226
telsoa01ce3e84a2018-08-31 09:31:35 +0100227 // Unsupported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100228 model.operations[0].type = HalPolicy::OperationType::HASHTABLE_LOOKUP;
telsoa01ce3e84a2018-08-31 09:31:35 +0100229 model.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2};
230 model.operations[0].outputs = hidl_vec<uint32_t>{3, 4};
surmeh0149b9e102018-05-17 14:11:25 +0100231
telsoa01ce3e84a2018-08-31 09:31:35 +0100232 // Supported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100233 model.operations[1].type = HalPolicy::OperationType::FULLY_CONNECTED;
telsoa01ce3e84a2018-08-31 09:31:35 +0100234 model.operations[1].inputs = hidl_vec<uint32_t>{5, 6, 7, 8};
235 model.operations[1].outputs = hidl_vec<uint32_t>{9};
surmeh0149b9e102018-05-17 14:11:25 +0100236
telsoa01ce3e84a2018-08-31 09:31:35 +0100237 // Unsupported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100238 model.operations[2].type = HalPolicy::OperationType::EMBEDDING_LOOKUP;
telsoa01ce3e84a2018-08-31 09:31:35 +0100239 model.operations[2].inputs = hidl_vec<uint32_t>{1, 2};
240 model.operations[2].outputs = hidl_vec<uint32_t>{10};
surmeh0149b9e102018-05-17 14:11:25 +0100241
telsoa01ce3e84a2018-08-31 09:31:35 +0100242 // We are testing that the unsupported layers return false and the test continues rather than failing and stopping
surmeh0149b9e102018-05-17 14:11:25 +0100243 driver->getSupportedOperations(model, cb);
Sadik Armagan9150bff2021-05-26 15:40:53 +0100244 CHECK((int)errorStatus == (int)V1_0::ErrorStatus::NONE);
245 CHECK(supported.size() == (size_t)3);
246 CHECK(supported[0] == false);
247 CHECK(supported[1] == true);
248 CHECK(supported[2] == false);
surmeh0149b9e102018-05-17 14:11:25 +0100249}
250
251// The purpose of this test is to ensure that when encountering an failure
telsoa01ce3e84a2018-08-31 09:31:35 +0100252// during mem pool mapping we properly report an error to the framework via a callback
Sadik Armagan9150bff2021-05-26 15:40:53 +0100253TEST_CASE("ModelToINetworkConverterMemPoolFail")
surmeh0149b9e102018-05-17 14:11:25 +0100254{
Nikhil Raj77605822018-09-03 11:25:56 +0100255 auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
surmeh0149b9e102018-05-17 14:11:25 +0100256
Kevin Mayec1e5b82020-02-26 17:00:39 +0000257 V1_0::ErrorStatus errorStatus;
telsoa01ce3e84a2018-08-31 09:31:35 +0100258 std::vector<bool> supported;
surmeh0149b9e102018-05-17 14:11:25 +0100259
Kevin Mayec1e5b82020-02-26 17:00:39 +0000260 auto cb = [&](V1_0::ErrorStatus _errorStatus, const std::vector<bool>& _supported)
surmeh0149b9e102018-05-17 14:11:25 +0100261 {
telsoa01ce3e84a2018-08-31 09:31:35 +0100262 errorStatus = _errorStatus;
263 supported = _supported;
surmeh0149b9e102018-05-17 14:11:25 +0100264 };
265
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100266 HalPolicy::Model model = {};
surmeh0149b9e102018-05-17 14:11:25 +0100267
268 model.pools = hidl_vec<hidl_memory>{hidl_memory("Unsuported hidl memory type", nullptr, 0)};
269
telsoa01ce3e84a2018-08-31 09:31:35 +0100270 // Memory pool mapping should fail, we should report an error
surmeh0149b9e102018-05-17 14:11:25 +0100271 driver->getSupportedOperations(model, cb);
Sadik Armagan9150bff2021-05-26 15:40:53 +0100272 CHECK((int)errorStatus != (int)V1_0::ErrorStatus::NONE);
273 CHECK(supported.empty());
surmeh0149b9e102018-05-17 14:11:25 +0100274}
275
Sadik Armagan9150bff2021-05-26 15:40:53 +0100276}