blob: bd86a88592b79df6f37d584d4902e6673360e0b1 [file] [log] [blame]
surmeh0149b9e102018-05-17 14:11:25 +01001//
Mike Kellye2d611e2021-10-14 12:35:58 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
David Beck93e48982018-09-05 13:05:09 +01003// SPDX-License-Identifier: MIT
surmeh0149b9e102018-05-17 14:11:25 +01004//
Mike Kellye2d611e2021-10-14 12:35:58 +01005
surmeh0149b9e102018-05-17 14:11:25 +01006#include "DriverTestHelpers.hpp"
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +01007
surmeh0149b9e102018-05-17 14:11:25 +01008#include <log/log.h>
9
Mike Kellye2d611e2021-10-14 12:35:58 +010010DOCTEST_TEST_SUITE("GenericLayerTests")
Sadik Armagan9150bff2021-05-26 15:40:53 +010011{
surmeh0149b9e102018-05-17 14:11:25 +010012
telsoa01ce3e84a2018-08-31 09:31:35 +010013using namespace android::hardware;
surmeh0149b9e102018-05-17 14:11:25 +010014using namespace driverTestHelpers;
telsoa01ce3e84a2018-08-31 09:31:35 +010015using namespace armnn_driver;
surmeh0149b9e102018-05-17 14:11:25 +010016
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010017using HalPolicy = hal_1_0::HalPolicy;
18
Mike Kellye2d611e2021-10-14 12:35:58 +010019DOCTEST_TEST_CASE("GetSupportedOperations")
surmeh0149b9e102018-05-17 14:11:25 +010020{
21 auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
22
Kevin Mayec1e5b82020-02-26 17:00:39 +000023 V1_0::ErrorStatus errorStatus;
telsoa01ce3e84a2018-08-31 09:31:35 +010024 std::vector<bool> supported;
surmeh0149b9e102018-05-17 14:11:25 +010025
Kevin Mayec1e5b82020-02-26 17:00:39 +000026 auto cb = [&](V1_0::ErrorStatus _errorStatus, const std::vector<bool>& _supported)
surmeh0149b9e102018-05-17 14:11:25 +010027 {
telsoa01ce3e84a2018-08-31 09:31:35 +010028 errorStatus = _errorStatus;
29 supported = _supported;
surmeh0149b9e102018-05-17 14:11:25 +010030 };
31
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010032 HalPolicy::Model model0 = {};
surmeh0149b9e102018-05-17 14:11:25 +010033
telsoa01ce3e84a2018-08-31 09:31:35 +010034 // Add operands
surmeh0149b9e102018-05-17 14:11:25 +010035 int32_t actValue = 0;
36 float weightValue[] = {2, 4, 1};
37 float biasValue[] = {4};
38
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010039 AddInputOperand<HalPolicy>(model0, hidl_vec<uint32_t>{1, 3});
40 AddTensorOperand<HalPolicy>(model0, hidl_vec<uint32_t>{1, 3}, weightValue);
41 AddTensorOperand<HalPolicy>(model0, hidl_vec<uint32_t>{1}, biasValue);
42 AddIntOperand<HalPolicy>(model0, actValue);
43 AddOutputOperand<HalPolicy>(model0, hidl_vec<uint32_t>{1, 1});
telsoa01ce3e84a2018-08-31 09:31:35 +010044
45 model0.operations.resize(1);
46
47 // Make a correct fully connected operation
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010048 model0.operations[0].type = HalPolicy::OperationType::FULLY_CONNECTED;
telsoa01ce3e84a2018-08-31 09:31:35 +010049 model0.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2, 3};
50 model0.operations[0].outputs = hidl_vec<uint32_t>{4};
51
52 driver->getSupportedOperations(model0, cb);
Mike Kellye2d611e2021-10-14 12:35:58 +010053 DOCTEST_CHECK((int)errorStatus == (int)V1_0::ErrorStatus::NONE);
54 DOCTEST_CHECK(supported.size() == (size_t)1);
55 DOCTEST_CHECK(supported[0] == true);
telsoa01ce3e84a2018-08-31 09:31:35 +010056
Matteo Martincigh8b287c22018-09-07 09:25:10 +010057 V1_0::Model model1 = {};
telsoa01ce3e84a2018-08-31 09:31:35 +010058
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010059 AddInputOperand<HalPolicy>(model1, hidl_vec<uint32_t>{1, 3});
60 AddTensorOperand<HalPolicy>(model1, hidl_vec<uint32_t>{1, 3}, weightValue);
61 AddTensorOperand<HalPolicy>(model1, hidl_vec<uint32_t>{1}, biasValue);
62 AddIntOperand<HalPolicy>(model1, actValue);
63 AddOutputOperand<HalPolicy>(model1, hidl_vec<uint32_t>{1, 1});
surmeh0149b9e102018-05-17 14:11:25 +010064
surmeh0149b9e102018-05-17 14:11:25 +010065 model1.operations.resize(2);
telsoa01ce3e84a2018-08-31 09:31:35 +010066
67 // Make a correct fully connected operation
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010068 model1.operations[0].type = HalPolicy::OperationType::FULLY_CONNECTED;
surmeh0149b9e102018-05-17 14:11:25 +010069 model1.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2, 3};
70 model1.operations[0].outputs = hidl_vec<uint32_t>{4};
71
telsoa01ce3e84a2018-08-31 09:31:35 +010072 // Add an incorrect fully connected operation
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010073 AddIntOperand<HalPolicy>(model1, actValue);
74 AddOutputOperand<HalPolicy>(model1, hidl_vec<uint32_t>{1, 1});
75
76 model1.operations[1].type = HalPolicy::OperationType::FULLY_CONNECTED;
telsoa01ce3e84a2018-08-31 09:31:35 +010077 model1.operations[1].inputs = hidl_vec<uint32_t>{4}; // Only 1 input operand, expected 4
surmeh0149b9e102018-05-17 14:11:25 +010078 model1.operations[1].outputs = hidl_vec<uint32_t>{5};
79
80 driver->getSupportedOperations(model1, cb);
surmeh0149b9e102018-05-17 14:11:25 +010081
Mike Kellye2d611e2021-10-14 12:35:58 +010082 DOCTEST_CHECK((int)errorStatus == (int)V1_0::ErrorStatus::INVALID_ARGUMENT);
83 DOCTEST_CHECK(supported.empty());
surmeh0149b9e102018-05-17 14:11:25 +010084
telsoa01ce3e84a2018-08-31 09:31:35 +010085 // Test Broadcast on add/mul operators
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010086 HalPolicy::Model model2 = {};
telsoa01ce3e84a2018-08-31 09:31:35 +010087
David Monahanc60d0fd2020-05-19 14:58:34 +010088 AddInputOperand<HalPolicy>(model2,
89 hidl_vec<uint32_t>{1, 1, 3, 4},
90 HalPolicy::OperandType::TENSOR_FLOAT32,
91 0.0f,
92 0,
93 2);
94 AddInputOperand<HalPolicy>(model2,
95 hidl_vec<uint32_t>{4},
96 HalPolicy::OperandType::TENSOR_FLOAT32,
97 0.0f,
98 0,
99 2);
100 AddIntOperand<HalPolicy>(model2, actValue, 2);
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100101 AddOutputOperand<HalPolicy>(model2, hidl_vec<uint32_t>{1, 1, 3, 4});
102 AddOutputOperand<HalPolicy>(model2, hidl_vec<uint32_t>{1, 1, 3, 4});
surmeh0149b9e102018-05-17 14:11:25 +0100103
104 model2.operations.resize(2);
105
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100106 model2.operations[0].type = HalPolicy::OperationType::ADD;
telsoa01ce3e84a2018-08-31 09:31:35 +0100107 model2.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2};
108 model2.operations[0].outputs = hidl_vec<uint32_t>{3};
surmeh0149b9e102018-05-17 14:11:25 +0100109
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100110 model2.operations[1].type = HalPolicy::OperationType::MUL;
telsoa01ce3e84a2018-08-31 09:31:35 +0100111 model2.operations[1].inputs = hidl_vec<uint32_t>{0, 1, 2};
112 model2.operations[1].outputs = hidl_vec<uint32_t>{4};
surmeh0149b9e102018-05-17 14:11:25 +0100113
114 driver->getSupportedOperations(model2, cb);
Mike Kellye2d611e2021-10-14 12:35:58 +0100115 DOCTEST_CHECK((int)errorStatus == (int)V1_0::ErrorStatus::NONE);
116 DOCTEST_CHECK(supported.size() == (size_t)2);
117 DOCTEST_CHECK(supported[0] == true);
118 DOCTEST_CHECK(supported[1] == true);
surmeh0149b9e102018-05-17 14:11:25 +0100119
Matteo Martincigh8b287c22018-09-07 09:25:10 +0100120 V1_0::Model model3 = {};
telsoa01ce3e84a2018-08-31 09:31:35 +0100121
Aron Virginas-Tar8edb16d2019-10-01 13:34:59 +0100122 AddInputOperand<HalPolicy>(model3,
123 hidl_vec<uint32_t>{1, 1, 3, 4},
124 HalPolicy::OperandType::TENSOR_INT32);
125 AddInputOperand<HalPolicy>(model3,
126 hidl_vec<uint32_t>{4},
127 HalPolicy::OperandType::TENSOR_INT32);
128 AddInputOperand<HalPolicy>(model3, hidl_vec<uint32_t>{1, 1, 3, 4});
129
130 AddOutputOperand<HalPolicy>(model3, hidl_vec<uint32_t>{1, 1, 3, 4});
131 AddOutputOperand<HalPolicy>(model3,
132 hidl_vec<uint32_t>{1, 1, 3, 4},
133 HalPolicy::OperandType::TENSOR_QUANT8_ASYMM,
134 1.f / 225.f);
telsoa01ce3e84a2018-08-31 09:31:35 +0100135
136 model3.operations.resize(1);
surmeh0149b9e102018-05-17 14:11:25 +0100137
138 // Add unsupported operation, should return no error but we don't support it
Aron Virginas-Tar8edb16d2019-10-01 13:34:59 +0100139 model3.operations[0].type = HalPolicy::OperationType::HASHTABLE_LOOKUP;
140 model3.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2};
141 model3.operations[0].outputs = hidl_vec<uint32_t>{3, 4};
surmeh0149b9e102018-05-17 14:11:25 +0100142
143 driver->getSupportedOperations(model3, cb);
Mike Kellye2d611e2021-10-14 12:35:58 +0100144 DOCTEST_CHECK((int)errorStatus == (int)V1_0::ErrorStatus::NONE);
145 DOCTEST_CHECK(supported.size() == (size_t)1);
146 DOCTEST_CHECK(supported[0] == false);
telsoa01ce3e84a2018-08-31 09:31:35 +0100147
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100148 HalPolicy::Model model4 = {};
telsoa01ce3e84a2018-08-31 09:31:35 +0100149
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100150 AddIntOperand<HalPolicy>(model4, 0);
telsoa01ce3e84a2018-08-31 09:31:35 +0100151
152 model4.operations.resize(1);
surmeh0149b9e102018-05-17 14:11:25 +0100153
154 // Add invalid operation
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100155 model4.operations[0].type = static_cast<HalPolicy::OperationType>(100);
surmeh0149b9e102018-05-17 14:11:25 +0100156 model4.operations[0].outputs = hidl_vec<uint32_t>{0};
157
158 driver->getSupportedOperations(model4, cb);
Mike Kellye2d611e2021-10-14 12:35:58 +0100159 DOCTEST_CHECK((int)errorStatus == (int)V1_0::ErrorStatus::INVALID_ARGUMENT);
160 DOCTEST_CHECK(supported.empty());
surmeh0149b9e102018-05-17 14:11:25 +0100161}
162
163// The purpose of this test is to ensure that when encountering an unsupported operation
telsoa01ce3e84a2018-08-31 09:31:35 +0100164// it is skipped and getSupportedOperations() continues (rather than failing and stopping).
165// As per IVGCVSW-710.
Mike Kellye2d611e2021-10-14 12:35:58 +0100166DOCTEST_TEST_CASE("UnsupportedLayerContinueOnFailure")
surmeh0149b9e102018-05-17 14:11:25 +0100167{
168 auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
169
Kevin Mayec1e5b82020-02-26 17:00:39 +0000170 V1_0::ErrorStatus errorStatus;
telsoa01ce3e84a2018-08-31 09:31:35 +0100171 std::vector<bool> supported;
surmeh0149b9e102018-05-17 14:11:25 +0100172
Kevin Mayec1e5b82020-02-26 17:00:39 +0000173 auto cb = [&](V1_0::ErrorStatus _errorStatus, const std::vector<bool>& _supported)
surmeh0149b9e102018-05-17 14:11:25 +0100174 {
telsoa01ce3e84a2018-08-31 09:31:35 +0100175 errorStatus = _errorStatus;
176 supported = _supported;
surmeh0149b9e102018-05-17 14:11:25 +0100177 };
178
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100179 HalPolicy::Model model = {};
surmeh0149b9e102018-05-17 14:11:25 +0100180
telsoa01ce3e84a2018-08-31 09:31:35 +0100181 // Operands
surmeh0149b9e102018-05-17 14:11:25 +0100182 int32_t actValue = 0;
183 float weightValue[] = {2, 4, 1};
184 float biasValue[] = {4};
185
telsoa01ce3e84a2018-08-31 09:31:35 +0100186 // 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 +0100187 AddInputOperand<HalPolicy>(model,
188 hidl_vec<uint32_t>{1, 1, 3, 4},
189 HalPolicy::OperandType::TENSOR_INT32);
190 AddInputOperand<HalPolicy>(model,
191 hidl_vec<uint32_t>{4},
David Monahanc60d0fd2020-05-19 14:58:34 +0100192 HalPolicy::OperandType::TENSOR_INT32,
193 0.0f,
194 0,
195 2);
196 AddInputOperand<HalPolicy>(model,
197 hidl_vec<uint32_t>{1, 1, 3, 4},
198 HalPolicy::OperandType::TENSOR_FLOAT32,
199 0.0f,
200 0,
201 2);
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100202
203 AddOutputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 1, 3, 4});
204 AddOutputOperand<HalPolicy>(model,
205 hidl_vec<uint32_t>{1, 1, 3, 4},
Ellen Norris-Thompson976ad3e2019-08-21 15:21:14 +0100206 HalPolicy::OperandType::TENSOR_QUANT8_ASYMM,
207 1.f / 225.f);
surmeh0149b9e102018-05-17 14:11:25 +0100208
telsoa01ce3e84a2018-08-31 09:31:35 +0100209 // Fully connected is supported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100210 AddInputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 3});
211
212 AddTensorOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 3}, weightValue);
213 AddTensorOperand<HalPolicy>(model, hidl_vec<uint32_t>{1}, biasValue);
214
215 AddIntOperand<HalPolicy>(model, actValue);
216
217 AddOutputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 1});
surmeh0149b9e102018-05-17 14:11:25 +0100218
telsoa01ce3e84a2018-08-31 09:31:35 +0100219 // EMBEDDING_LOOKUP is unsupported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100220 AddOutputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 1, 3, 4});
surmeh0149b9e102018-05-17 14:11:25 +0100221
222 model.operations.resize(3);
223
telsoa01ce3e84a2018-08-31 09:31:35 +0100224 // Unsupported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100225 model.operations[0].type = HalPolicy::OperationType::HASHTABLE_LOOKUP;
telsoa01ce3e84a2018-08-31 09:31:35 +0100226 model.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2};
227 model.operations[0].outputs = hidl_vec<uint32_t>{3, 4};
surmeh0149b9e102018-05-17 14:11:25 +0100228
telsoa01ce3e84a2018-08-31 09:31:35 +0100229 // Supported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100230 model.operations[1].type = HalPolicy::OperationType::FULLY_CONNECTED;
telsoa01ce3e84a2018-08-31 09:31:35 +0100231 model.operations[1].inputs = hidl_vec<uint32_t>{5, 6, 7, 8};
232 model.operations[1].outputs = hidl_vec<uint32_t>{9};
surmeh0149b9e102018-05-17 14:11:25 +0100233
telsoa01ce3e84a2018-08-31 09:31:35 +0100234 // Unsupported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100235 model.operations[2].type = HalPolicy::OperationType::EMBEDDING_LOOKUP;
telsoa01ce3e84a2018-08-31 09:31:35 +0100236 model.operations[2].inputs = hidl_vec<uint32_t>{1, 2};
237 model.operations[2].outputs = hidl_vec<uint32_t>{10};
surmeh0149b9e102018-05-17 14:11:25 +0100238
telsoa01ce3e84a2018-08-31 09:31:35 +0100239 // We are testing that the unsupported layers return false and the test continues rather than failing and stopping
surmeh0149b9e102018-05-17 14:11:25 +0100240 driver->getSupportedOperations(model, cb);
Mike Kellye2d611e2021-10-14 12:35:58 +0100241 DOCTEST_CHECK((int)errorStatus == (int)V1_0::ErrorStatus::NONE);
242 DOCTEST_CHECK(supported.size() == (size_t)3);
243 DOCTEST_CHECK(supported[0] == false);
244 DOCTEST_CHECK(supported[1] == true);
245 DOCTEST_CHECK(supported[2] == false);
surmeh0149b9e102018-05-17 14:11:25 +0100246}
247
248// The purpose of this test is to ensure that when encountering an failure
telsoa01ce3e84a2018-08-31 09:31:35 +0100249// during mem pool mapping we properly report an error to the framework via a callback
Mike Kellye2d611e2021-10-14 12:35:58 +0100250DOCTEST_TEST_CASE("ModelToINetworkConverterMemPoolFail")
surmeh0149b9e102018-05-17 14:11:25 +0100251{
Nikhil Raj77605822018-09-03 11:25:56 +0100252 auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
surmeh0149b9e102018-05-17 14:11:25 +0100253
Kevin Mayec1e5b82020-02-26 17:00:39 +0000254 V1_0::ErrorStatus errorStatus;
telsoa01ce3e84a2018-08-31 09:31:35 +0100255 std::vector<bool> supported;
surmeh0149b9e102018-05-17 14:11:25 +0100256
Kevin Mayec1e5b82020-02-26 17:00:39 +0000257 auto cb = [&](V1_0::ErrorStatus _errorStatus, const std::vector<bool>& _supported)
surmeh0149b9e102018-05-17 14:11:25 +0100258 {
telsoa01ce3e84a2018-08-31 09:31:35 +0100259 errorStatus = _errorStatus;
260 supported = _supported;
surmeh0149b9e102018-05-17 14:11:25 +0100261 };
262
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100263 HalPolicy::Model model = {};
surmeh0149b9e102018-05-17 14:11:25 +0100264
265 model.pools = hidl_vec<hidl_memory>{hidl_memory("Unsuported hidl memory type", nullptr, 0)};
266
telsoa01ce3e84a2018-08-31 09:31:35 +0100267 // Memory pool mapping should fail, we should report an error
surmeh0149b9e102018-05-17 14:11:25 +0100268 driver->getSupportedOperations(model, cb);
Mike Kellye2d611e2021-10-14 12:35:58 +0100269 DOCTEST_CHECK((int)errorStatus != (int)V1_0::ErrorStatus::NONE);
270 DOCTEST_CHECK(supported.empty());
surmeh0149b9e102018-05-17 14:11:25 +0100271}
272
Sadik Armagan9150bff2021-05-26 15:40:53 +0100273}