blob: 188c7b1c0afab7bc6fdd8bc6dc1745dd3279c91f [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(GenericLayerTests)
14
telsoa01ce3e84a2018-08-31 09:31:35 +010015using namespace android::hardware;
surmeh0149b9e102018-05-17 14:11:25 +010016using namespace driverTestHelpers;
telsoa01ce3e84a2018-08-31 09:31:35 +010017using namespace armnn_driver;
surmeh0149b9e102018-05-17 14:11:25 +010018
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010019using HalPolicy = hal_1_0::HalPolicy;
20
surmeh0149b9e102018-05-17 14:11:25 +010021BOOST_AUTO_TEST_CASE(GetSupportedOperations)
22{
23 auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
24
Kevin Mayec1e5b82020-02-26 17:00:39 +000025 V1_0::ErrorStatus errorStatus;
telsoa01ce3e84a2018-08-31 09:31:35 +010026 std::vector<bool> supported;
surmeh0149b9e102018-05-17 14:11:25 +010027
Kevin Mayec1e5b82020-02-26 17:00:39 +000028 auto cb = [&](V1_0::ErrorStatus _errorStatus, const std::vector<bool>& _supported)
surmeh0149b9e102018-05-17 14:11:25 +010029 {
telsoa01ce3e84a2018-08-31 09:31:35 +010030 errorStatus = _errorStatus;
31 supported = _supported;
surmeh0149b9e102018-05-17 14:11:25 +010032 };
33
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010034 HalPolicy::Model model0 = {};
surmeh0149b9e102018-05-17 14:11:25 +010035
telsoa01ce3e84a2018-08-31 09:31:35 +010036 // Add operands
surmeh0149b9e102018-05-17 14:11:25 +010037 int32_t actValue = 0;
38 float weightValue[] = {2, 4, 1};
39 float biasValue[] = {4};
40
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010041 AddInputOperand<HalPolicy>(model0, hidl_vec<uint32_t>{1, 3});
42 AddTensorOperand<HalPolicy>(model0, hidl_vec<uint32_t>{1, 3}, weightValue);
43 AddTensorOperand<HalPolicy>(model0, hidl_vec<uint32_t>{1}, biasValue);
44 AddIntOperand<HalPolicy>(model0, actValue);
45 AddOutputOperand<HalPolicy>(model0, hidl_vec<uint32_t>{1, 1});
telsoa01ce3e84a2018-08-31 09:31:35 +010046
47 model0.operations.resize(1);
48
49 // Make a correct fully connected operation
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010050 model0.operations[0].type = HalPolicy::OperationType::FULLY_CONNECTED;
telsoa01ce3e84a2018-08-31 09:31:35 +010051 model0.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2, 3};
52 model0.operations[0].outputs = hidl_vec<uint32_t>{4};
53
54 driver->getSupportedOperations(model0, cb);
Kevin Mayec1e5b82020-02-26 17:00:39 +000055 BOOST_TEST((int)errorStatus == (int)V1_0::ErrorStatus::NONE);
telsoa01ce3e84a2018-08-31 09:31:35 +010056 BOOST_TEST(supported.size() == (size_t)1);
57 BOOST_TEST(supported[0] == true);
58
Matteo Martincigh8b287c22018-09-07 09:25:10 +010059 V1_0::Model model1 = {};
telsoa01ce3e84a2018-08-31 09:31:35 +010060
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010061 AddInputOperand<HalPolicy>(model1, hidl_vec<uint32_t>{1, 3});
62 AddTensorOperand<HalPolicy>(model1, hidl_vec<uint32_t>{1, 3}, weightValue);
63 AddTensorOperand<HalPolicy>(model1, hidl_vec<uint32_t>{1}, biasValue);
64 AddIntOperand<HalPolicy>(model1, actValue);
65 AddOutputOperand<HalPolicy>(model1, hidl_vec<uint32_t>{1, 1});
surmeh0149b9e102018-05-17 14:11:25 +010066
surmeh0149b9e102018-05-17 14:11:25 +010067 model1.operations.resize(2);
telsoa01ce3e84a2018-08-31 09:31:35 +010068
69 // Make a correct fully connected operation
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010070 model1.operations[0].type = HalPolicy::OperationType::FULLY_CONNECTED;
surmeh0149b9e102018-05-17 14:11:25 +010071 model1.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2, 3};
72 model1.operations[0].outputs = hidl_vec<uint32_t>{4};
73
telsoa01ce3e84a2018-08-31 09:31:35 +010074 // Add an incorrect fully connected operation
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010075 AddIntOperand<HalPolicy>(model1, actValue);
76 AddOutputOperand<HalPolicy>(model1, hidl_vec<uint32_t>{1, 1});
77
78 model1.operations[1].type = HalPolicy::OperationType::FULLY_CONNECTED;
telsoa01ce3e84a2018-08-31 09:31:35 +010079 model1.operations[1].inputs = hidl_vec<uint32_t>{4}; // Only 1 input operand, expected 4
surmeh0149b9e102018-05-17 14:11:25 +010080 model1.operations[1].outputs = hidl_vec<uint32_t>{5};
81
82 driver->getSupportedOperations(model1, cb);
surmeh0149b9e102018-05-17 14:11:25 +010083
Kevin Mayec1e5b82020-02-26 17:00:39 +000084 BOOST_TEST((int)errorStatus == (int)V1_0::ErrorStatus::INVALID_ARGUMENT);
telsoa01ce3e84a2018-08-31 09:31:35 +010085 BOOST_TEST(supported.empty());
surmeh0149b9e102018-05-17 14:11:25 +010086
telsoa01ce3e84a2018-08-31 09:31:35 +010087 // Test Broadcast on add/mul operators
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010088 HalPolicy::Model model2 = {};
telsoa01ce3e84a2018-08-31 09:31:35 +010089
David Monahanc60d0fd2020-05-19 14:58:34 +010090 AddInputOperand<HalPolicy>(model2,
91 hidl_vec<uint32_t>{1, 1, 3, 4},
92 HalPolicy::OperandType::TENSOR_FLOAT32,
93 0.0f,
94 0,
95 2);
96 AddInputOperand<HalPolicy>(model2,
97 hidl_vec<uint32_t>{4},
98 HalPolicy::OperandType::TENSOR_FLOAT32,
99 0.0f,
100 0,
101 2);
102 AddIntOperand<HalPolicy>(model2, actValue, 2);
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100103 AddOutputOperand<HalPolicy>(model2, hidl_vec<uint32_t>{1, 1, 3, 4});
104 AddOutputOperand<HalPolicy>(model2, hidl_vec<uint32_t>{1, 1, 3, 4});
surmeh0149b9e102018-05-17 14:11:25 +0100105
106 model2.operations.resize(2);
107
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100108 model2.operations[0].type = HalPolicy::OperationType::ADD;
telsoa01ce3e84a2018-08-31 09:31:35 +0100109 model2.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2};
110 model2.operations[0].outputs = hidl_vec<uint32_t>{3};
surmeh0149b9e102018-05-17 14:11:25 +0100111
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100112 model2.operations[1].type = HalPolicy::OperationType::MUL;
telsoa01ce3e84a2018-08-31 09:31:35 +0100113 model2.operations[1].inputs = hidl_vec<uint32_t>{0, 1, 2};
114 model2.operations[1].outputs = hidl_vec<uint32_t>{4};
surmeh0149b9e102018-05-17 14:11:25 +0100115
116 driver->getSupportedOperations(model2, cb);
Kevin Mayec1e5b82020-02-26 17:00:39 +0000117 BOOST_TEST((int)errorStatus == (int)V1_0::ErrorStatus::NONE);
telsoa01ce3e84a2018-08-31 09:31:35 +0100118 BOOST_TEST(supported.size() == (size_t)2);
119 BOOST_TEST(supported[0] == true);
120 BOOST_TEST(supported[1] == true);
surmeh0149b9e102018-05-17 14:11:25 +0100121
Matteo Martincigh8b287c22018-09-07 09:25:10 +0100122 V1_0::Model model3 = {};
telsoa01ce3e84a2018-08-31 09:31:35 +0100123
Aron Virginas-Tar8edb16d2019-10-01 13:34:59 +0100124 AddInputOperand<HalPolicy>(model3,
125 hidl_vec<uint32_t>{1, 1, 3, 4},
126 HalPolicy::OperandType::TENSOR_INT32);
127 AddInputOperand<HalPolicy>(model3,
128 hidl_vec<uint32_t>{4},
129 HalPolicy::OperandType::TENSOR_INT32);
130 AddInputOperand<HalPolicy>(model3, hidl_vec<uint32_t>{1, 1, 3, 4});
131
132 AddOutputOperand<HalPolicy>(model3, hidl_vec<uint32_t>{1, 1, 3, 4});
133 AddOutputOperand<HalPolicy>(model3,
134 hidl_vec<uint32_t>{1, 1, 3, 4},
135 HalPolicy::OperandType::TENSOR_QUANT8_ASYMM,
136 1.f / 225.f);
telsoa01ce3e84a2018-08-31 09:31:35 +0100137
138 model3.operations.resize(1);
surmeh0149b9e102018-05-17 14:11:25 +0100139
140 // Add unsupported operation, should return no error but we don't support it
Aron Virginas-Tar8edb16d2019-10-01 13:34:59 +0100141 model3.operations[0].type = HalPolicy::OperationType::HASHTABLE_LOOKUP;
142 model3.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2};
143 model3.operations[0].outputs = hidl_vec<uint32_t>{3, 4};
surmeh0149b9e102018-05-17 14:11:25 +0100144
145 driver->getSupportedOperations(model3, cb);
Kevin Mayec1e5b82020-02-26 17:00:39 +0000146 BOOST_TEST((int)errorStatus == (int)V1_0::ErrorStatus::NONE);
telsoa01ce3e84a2018-08-31 09:31:35 +0100147 BOOST_TEST(supported.size() == (size_t)1);
148 BOOST_TEST(supported[0] == false);
149
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100150 HalPolicy::Model model4 = {};
telsoa01ce3e84a2018-08-31 09:31:35 +0100151
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100152 AddIntOperand<HalPolicy>(model4, 0);
telsoa01ce3e84a2018-08-31 09:31:35 +0100153
154 model4.operations.resize(1);
surmeh0149b9e102018-05-17 14:11:25 +0100155
156 // Add invalid operation
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100157 model4.operations[0].type = static_cast<HalPolicy::OperationType>(100);
surmeh0149b9e102018-05-17 14:11:25 +0100158 model4.operations[0].outputs = hidl_vec<uint32_t>{0};
159
160 driver->getSupportedOperations(model4, cb);
Kevin Mayec1e5b82020-02-26 17:00:39 +0000161 BOOST_TEST((int)errorStatus == (int)V1_0::ErrorStatus::INVALID_ARGUMENT);
telsoa01ce3e84a2018-08-31 09:31:35 +0100162 BOOST_TEST(supported.empty());
surmeh0149b9e102018-05-17 14:11:25 +0100163}
164
165// The purpose of this test is to ensure that when encountering an unsupported operation
telsoa01ce3e84a2018-08-31 09:31:35 +0100166// it is skipped and getSupportedOperations() continues (rather than failing and stopping).
167// As per IVGCVSW-710.
surmeh0149b9e102018-05-17 14:11:25 +0100168BOOST_AUTO_TEST_CASE(UnsupportedLayerContinueOnFailure)
169{
170 auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
171
Kevin Mayec1e5b82020-02-26 17:00:39 +0000172 V1_0::ErrorStatus errorStatus;
telsoa01ce3e84a2018-08-31 09:31:35 +0100173 std::vector<bool> supported;
surmeh0149b9e102018-05-17 14:11:25 +0100174
Kevin Mayec1e5b82020-02-26 17:00:39 +0000175 auto cb = [&](V1_0::ErrorStatus _errorStatus, const std::vector<bool>& _supported)
surmeh0149b9e102018-05-17 14:11:25 +0100176 {
telsoa01ce3e84a2018-08-31 09:31:35 +0100177 errorStatus = _errorStatus;
178 supported = _supported;
surmeh0149b9e102018-05-17 14:11:25 +0100179 };
180
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100181 HalPolicy::Model model = {};
surmeh0149b9e102018-05-17 14:11:25 +0100182
telsoa01ce3e84a2018-08-31 09:31:35 +0100183 // Operands
surmeh0149b9e102018-05-17 14:11:25 +0100184 int32_t actValue = 0;
185 float weightValue[] = {2, 4, 1};
186 float biasValue[] = {4};
187
telsoa01ce3e84a2018-08-31 09:31:35 +0100188 // 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 +0100189 AddInputOperand<HalPolicy>(model,
190 hidl_vec<uint32_t>{1, 1, 3, 4},
191 HalPolicy::OperandType::TENSOR_INT32);
192 AddInputOperand<HalPolicy>(model,
193 hidl_vec<uint32_t>{4},
David Monahanc60d0fd2020-05-19 14:58:34 +0100194 HalPolicy::OperandType::TENSOR_INT32,
195 0.0f,
196 0,
197 2);
198 AddInputOperand<HalPolicy>(model,
199 hidl_vec<uint32_t>{1, 1, 3, 4},
200 HalPolicy::OperandType::TENSOR_FLOAT32,
201 0.0f,
202 0,
203 2);
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100204
205 AddOutputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 1, 3, 4});
206 AddOutputOperand<HalPolicy>(model,
207 hidl_vec<uint32_t>{1, 1, 3, 4},
Ellen Norris-Thompson976ad3e2019-08-21 15:21:14 +0100208 HalPolicy::OperandType::TENSOR_QUANT8_ASYMM,
209 1.f / 225.f);
surmeh0149b9e102018-05-17 14:11:25 +0100210
telsoa01ce3e84a2018-08-31 09:31:35 +0100211 // Fully connected is supported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100212 AddInputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 3});
213
214 AddTensorOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 3}, weightValue);
215 AddTensorOperand<HalPolicy>(model, hidl_vec<uint32_t>{1}, biasValue);
216
217 AddIntOperand<HalPolicy>(model, actValue);
218
219 AddOutputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 1});
surmeh0149b9e102018-05-17 14:11:25 +0100220
telsoa01ce3e84a2018-08-31 09:31:35 +0100221 // EMBEDDING_LOOKUP is unsupported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100222 AddOutputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 1, 3, 4});
surmeh0149b9e102018-05-17 14:11:25 +0100223
224 model.operations.resize(3);
225
telsoa01ce3e84a2018-08-31 09:31:35 +0100226 // Unsupported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100227 model.operations[0].type = HalPolicy::OperationType::HASHTABLE_LOOKUP;
telsoa01ce3e84a2018-08-31 09:31:35 +0100228 model.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2};
229 model.operations[0].outputs = hidl_vec<uint32_t>{3, 4};
surmeh0149b9e102018-05-17 14:11:25 +0100230
telsoa01ce3e84a2018-08-31 09:31:35 +0100231 // Supported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100232 model.operations[1].type = HalPolicy::OperationType::FULLY_CONNECTED;
telsoa01ce3e84a2018-08-31 09:31:35 +0100233 model.operations[1].inputs = hidl_vec<uint32_t>{5, 6, 7, 8};
234 model.operations[1].outputs = hidl_vec<uint32_t>{9};
surmeh0149b9e102018-05-17 14:11:25 +0100235
telsoa01ce3e84a2018-08-31 09:31:35 +0100236 // Unsupported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100237 model.operations[2].type = HalPolicy::OperationType::EMBEDDING_LOOKUP;
telsoa01ce3e84a2018-08-31 09:31:35 +0100238 model.operations[2].inputs = hidl_vec<uint32_t>{1, 2};
239 model.operations[2].outputs = hidl_vec<uint32_t>{10};
surmeh0149b9e102018-05-17 14:11:25 +0100240
telsoa01ce3e84a2018-08-31 09:31:35 +0100241 // We are testing that the unsupported layers return false and the test continues rather than failing and stopping
surmeh0149b9e102018-05-17 14:11:25 +0100242 driver->getSupportedOperations(model, cb);
Kevin Mayec1e5b82020-02-26 17:00:39 +0000243 BOOST_TEST((int)errorStatus == (int)V1_0::ErrorStatus::NONE);
telsoa01ce3e84a2018-08-31 09:31:35 +0100244 BOOST_TEST(supported.size() == (size_t)3);
245 BOOST_TEST(supported[0] == false);
246 BOOST_TEST(supported[1] == true);
247 BOOST_TEST(supported[2] == false);
surmeh0149b9e102018-05-17 14:11:25 +0100248}
249
250// The purpose of this test is to ensure that when encountering an failure
telsoa01ce3e84a2018-08-31 09:31:35 +0100251// during mem pool mapping we properly report an error to the framework via a callback
surmeh0149b9e102018-05-17 14:11:25 +0100252BOOST_AUTO_TEST_CASE(ModelToINetworkConverterMemPoolFail)
253{
Nikhil Raj77605822018-09-03 11:25:56 +0100254 auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
surmeh0149b9e102018-05-17 14:11:25 +0100255
Kevin Mayec1e5b82020-02-26 17:00:39 +0000256 V1_0::ErrorStatus errorStatus;
telsoa01ce3e84a2018-08-31 09:31:35 +0100257 std::vector<bool> supported;
surmeh0149b9e102018-05-17 14:11:25 +0100258
Kevin Mayec1e5b82020-02-26 17:00:39 +0000259 auto cb = [&](V1_0::ErrorStatus _errorStatus, const std::vector<bool>& _supported)
surmeh0149b9e102018-05-17 14:11:25 +0100260 {
telsoa01ce3e84a2018-08-31 09:31:35 +0100261 errorStatus = _errorStatus;
262 supported = _supported;
surmeh0149b9e102018-05-17 14:11:25 +0100263 };
264
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100265 HalPolicy::Model model = {};
surmeh0149b9e102018-05-17 14:11:25 +0100266
267 model.pools = hidl_vec<hidl_memory>{hidl_memory("Unsuported hidl memory type", nullptr, 0)};
268
telsoa01ce3e84a2018-08-31 09:31:35 +0100269 // Memory pool mapping should fail, we should report an error
surmeh0149b9e102018-05-17 14:11:25 +0100270 driver->getSupportedOperations(model, cb);
Kevin Mayec1e5b82020-02-26 17:00:39 +0000271 BOOST_TEST((int)errorStatus != (int)V1_0::ErrorStatus::NONE);
telsoa01ce3e84a2018-08-31 09:31:35 +0100272 BOOST_TEST(supported.empty());
surmeh0149b9e102018-05-17 14:11:25 +0100273}
274
275BOOST_AUTO_TEST_SUITE_END()