blob: 961ab166baf2a1264eb13bc5234c07278332f3b7 [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
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010090 AddInputOperand<HalPolicy>(model2, hidl_vec<uint32_t>{1, 1, 3, 4});
91 AddInputOperand<HalPolicy>(model2, hidl_vec<uint32_t>{4});
92 AddIntOperand<HalPolicy>(model2, actValue);
93 AddOutputOperand<HalPolicy>(model2, hidl_vec<uint32_t>{1, 1, 3, 4});
94 AddOutputOperand<HalPolicy>(model2, hidl_vec<uint32_t>{1, 1, 3, 4});
surmeh0149b9e102018-05-17 14:11:25 +010095
96 model2.operations.resize(2);
97
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010098 model2.operations[0].type = HalPolicy::OperationType::ADD;
telsoa01ce3e84a2018-08-31 09:31:35 +010099 model2.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2};
100 model2.operations[0].outputs = hidl_vec<uint32_t>{3};
surmeh0149b9e102018-05-17 14:11:25 +0100101
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100102 model2.operations[1].type = HalPolicy::OperationType::MUL;
telsoa01ce3e84a2018-08-31 09:31:35 +0100103 model2.operations[1].inputs = hidl_vec<uint32_t>{0, 1, 2};
104 model2.operations[1].outputs = hidl_vec<uint32_t>{4};
surmeh0149b9e102018-05-17 14:11:25 +0100105
106 driver->getSupportedOperations(model2, cb);
Kevin Mayec1e5b82020-02-26 17:00:39 +0000107 BOOST_TEST((int)errorStatus == (int)V1_0::ErrorStatus::NONE);
telsoa01ce3e84a2018-08-31 09:31:35 +0100108 BOOST_TEST(supported.size() == (size_t)2);
109 BOOST_TEST(supported[0] == true);
110 BOOST_TEST(supported[1] == true);
surmeh0149b9e102018-05-17 14:11:25 +0100111
Matteo Martincigh8b287c22018-09-07 09:25:10 +0100112 V1_0::Model model3 = {};
telsoa01ce3e84a2018-08-31 09:31:35 +0100113
Aron Virginas-Tar8edb16d2019-10-01 13:34:59 +0100114 AddInputOperand<HalPolicy>(model3,
115 hidl_vec<uint32_t>{1, 1, 3, 4},
116 HalPolicy::OperandType::TENSOR_INT32);
117 AddInputOperand<HalPolicy>(model3,
118 hidl_vec<uint32_t>{4},
119 HalPolicy::OperandType::TENSOR_INT32);
120 AddInputOperand<HalPolicy>(model3, hidl_vec<uint32_t>{1, 1, 3, 4});
121
122 AddOutputOperand<HalPolicy>(model3, hidl_vec<uint32_t>{1, 1, 3, 4});
123 AddOutputOperand<HalPolicy>(model3,
124 hidl_vec<uint32_t>{1, 1, 3, 4},
125 HalPolicy::OperandType::TENSOR_QUANT8_ASYMM,
126 1.f / 225.f);
telsoa01ce3e84a2018-08-31 09:31:35 +0100127
128 model3.operations.resize(1);
surmeh0149b9e102018-05-17 14:11:25 +0100129
130 // Add unsupported operation, should return no error but we don't support it
Aron Virginas-Tar8edb16d2019-10-01 13:34:59 +0100131 model3.operations[0].type = HalPolicy::OperationType::HASHTABLE_LOOKUP;
132 model3.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2};
133 model3.operations[0].outputs = hidl_vec<uint32_t>{3, 4};
surmeh0149b9e102018-05-17 14:11:25 +0100134
135 driver->getSupportedOperations(model3, cb);
Kevin Mayec1e5b82020-02-26 17:00:39 +0000136 BOOST_TEST((int)errorStatus == (int)V1_0::ErrorStatus::NONE);
telsoa01ce3e84a2018-08-31 09:31:35 +0100137 BOOST_TEST(supported.size() == (size_t)1);
138 BOOST_TEST(supported[0] == false);
139
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100140 HalPolicy::Model model4 = {};
telsoa01ce3e84a2018-08-31 09:31:35 +0100141
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100142 AddIntOperand<HalPolicy>(model4, 0);
telsoa01ce3e84a2018-08-31 09:31:35 +0100143
144 model4.operations.resize(1);
surmeh0149b9e102018-05-17 14:11:25 +0100145
146 // Add invalid operation
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100147 model4.operations[0].type = static_cast<HalPolicy::OperationType>(100);
surmeh0149b9e102018-05-17 14:11:25 +0100148 model4.operations[0].outputs = hidl_vec<uint32_t>{0};
149
150 driver->getSupportedOperations(model4, cb);
Kevin Mayec1e5b82020-02-26 17:00:39 +0000151 BOOST_TEST((int)errorStatus == (int)V1_0::ErrorStatus::INVALID_ARGUMENT);
telsoa01ce3e84a2018-08-31 09:31:35 +0100152 BOOST_TEST(supported.empty());
surmeh0149b9e102018-05-17 14:11:25 +0100153}
154
155// The purpose of this test is to ensure that when encountering an unsupported operation
telsoa01ce3e84a2018-08-31 09:31:35 +0100156// it is skipped and getSupportedOperations() continues (rather than failing and stopping).
157// As per IVGCVSW-710.
surmeh0149b9e102018-05-17 14:11:25 +0100158BOOST_AUTO_TEST_CASE(UnsupportedLayerContinueOnFailure)
159{
160 auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
161
Kevin Mayec1e5b82020-02-26 17:00:39 +0000162 V1_0::ErrorStatus errorStatus;
telsoa01ce3e84a2018-08-31 09:31:35 +0100163 std::vector<bool> supported;
surmeh0149b9e102018-05-17 14:11:25 +0100164
Kevin Mayec1e5b82020-02-26 17:00:39 +0000165 auto cb = [&](V1_0::ErrorStatus _errorStatus, const std::vector<bool>& _supported)
surmeh0149b9e102018-05-17 14:11:25 +0100166 {
telsoa01ce3e84a2018-08-31 09:31:35 +0100167 errorStatus = _errorStatus;
168 supported = _supported;
surmeh0149b9e102018-05-17 14:11:25 +0100169 };
170
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100171 HalPolicy::Model model = {};
surmeh0149b9e102018-05-17 14:11:25 +0100172
telsoa01ce3e84a2018-08-31 09:31:35 +0100173 // Operands
surmeh0149b9e102018-05-17 14:11:25 +0100174 int32_t actValue = 0;
175 float weightValue[] = {2, 4, 1};
176 float biasValue[] = {4};
177
telsoa01ce3e84a2018-08-31 09:31:35 +0100178 // 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 +0100179 AddInputOperand<HalPolicy>(model,
180 hidl_vec<uint32_t>{1, 1, 3, 4},
181 HalPolicy::OperandType::TENSOR_INT32);
182 AddInputOperand<HalPolicy>(model,
183 hidl_vec<uint32_t>{4},
184 HalPolicy::OperandType::TENSOR_INT32);
185 AddInputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 1, 3, 4});
186
187 AddOutputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 1, 3, 4});
188 AddOutputOperand<HalPolicy>(model,
189 hidl_vec<uint32_t>{1, 1, 3, 4},
Ellen Norris-Thompson976ad3e2019-08-21 15:21:14 +0100190 HalPolicy::OperandType::TENSOR_QUANT8_ASYMM,
191 1.f / 225.f);
surmeh0149b9e102018-05-17 14:11:25 +0100192
telsoa01ce3e84a2018-08-31 09:31:35 +0100193 // Fully connected is supported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100194 AddInputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 3});
195
196 AddTensorOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 3}, weightValue);
197 AddTensorOperand<HalPolicy>(model, hidl_vec<uint32_t>{1}, biasValue);
198
199 AddIntOperand<HalPolicy>(model, actValue);
200
201 AddOutputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 1});
surmeh0149b9e102018-05-17 14:11:25 +0100202
telsoa01ce3e84a2018-08-31 09:31:35 +0100203 // EMBEDDING_LOOKUP is unsupported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100204 AddOutputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 1, 3, 4});
surmeh0149b9e102018-05-17 14:11:25 +0100205
206 model.operations.resize(3);
207
telsoa01ce3e84a2018-08-31 09:31:35 +0100208 // Unsupported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100209 model.operations[0].type = HalPolicy::OperationType::HASHTABLE_LOOKUP;
telsoa01ce3e84a2018-08-31 09:31:35 +0100210 model.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2};
211 model.operations[0].outputs = hidl_vec<uint32_t>{3, 4};
surmeh0149b9e102018-05-17 14:11:25 +0100212
telsoa01ce3e84a2018-08-31 09:31:35 +0100213 // Supported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100214 model.operations[1].type = HalPolicy::OperationType::FULLY_CONNECTED;
telsoa01ce3e84a2018-08-31 09:31:35 +0100215 model.operations[1].inputs = hidl_vec<uint32_t>{5, 6, 7, 8};
216 model.operations[1].outputs = hidl_vec<uint32_t>{9};
surmeh0149b9e102018-05-17 14:11:25 +0100217
telsoa01ce3e84a2018-08-31 09:31:35 +0100218 // Unsupported
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100219 model.operations[2].type = HalPolicy::OperationType::EMBEDDING_LOOKUP;
telsoa01ce3e84a2018-08-31 09:31:35 +0100220 model.operations[2].inputs = hidl_vec<uint32_t>{1, 2};
221 model.operations[2].outputs = hidl_vec<uint32_t>{10};
surmeh0149b9e102018-05-17 14:11:25 +0100222
telsoa01ce3e84a2018-08-31 09:31:35 +0100223 // We are testing that the unsupported layers return false and the test continues rather than failing and stopping
surmeh0149b9e102018-05-17 14:11:25 +0100224 driver->getSupportedOperations(model, cb);
Kevin Mayec1e5b82020-02-26 17:00:39 +0000225 BOOST_TEST((int)errorStatus == (int)V1_0::ErrorStatus::NONE);
telsoa01ce3e84a2018-08-31 09:31:35 +0100226 BOOST_TEST(supported.size() == (size_t)3);
227 BOOST_TEST(supported[0] == false);
228 BOOST_TEST(supported[1] == true);
229 BOOST_TEST(supported[2] == false);
surmeh0149b9e102018-05-17 14:11:25 +0100230}
231
232// The purpose of this test is to ensure that when encountering an failure
telsoa01ce3e84a2018-08-31 09:31:35 +0100233// during mem pool mapping we properly report an error to the framework via a callback
surmeh0149b9e102018-05-17 14:11:25 +0100234BOOST_AUTO_TEST_CASE(ModelToINetworkConverterMemPoolFail)
235{
Nikhil Raj77605822018-09-03 11:25:56 +0100236 auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
surmeh0149b9e102018-05-17 14:11:25 +0100237
Kevin Mayec1e5b82020-02-26 17:00:39 +0000238 V1_0::ErrorStatus errorStatus;
telsoa01ce3e84a2018-08-31 09:31:35 +0100239 std::vector<bool> supported;
surmeh0149b9e102018-05-17 14:11:25 +0100240
Kevin Mayec1e5b82020-02-26 17:00:39 +0000241 auto cb = [&](V1_0::ErrorStatus _errorStatus, const std::vector<bool>& _supported)
surmeh0149b9e102018-05-17 14:11:25 +0100242 {
telsoa01ce3e84a2018-08-31 09:31:35 +0100243 errorStatus = _errorStatus;
244 supported = _supported;
surmeh0149b9e102018-05-17 14:11:25 +0100245 };
246
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +0100247 HalPolicy::Model model = {};
surmeh0149b9e102018-05-17 14:11:25 +0100248
249 model.pools = hidl_vec<hidl_memory>{hidl_memory("Unsuported hidl memory type", nullptr, 0)};
250
telsoa01ce3e84a2018-08-31 09:31:35 +0100251 // Memory pool mapping should fail, we should report an error
surmeh0149b9e102018-05-17 14:11:25 +0100252 driver->getSupportedOperations(model, cb);
Kevin Mayec1e5b82020-02-26 17:00:39 +0000253 BOOST_TEST((int)errorStatus != (int)V1_0::ErrorStatus::NONE);
telsoa01ce3e84a2018-08-31 09:31:35 +0100254 BOOST_TEST(supported.empty());
surmeh0149b9e102018-05-17 14:11:25 +0100255}
256
257BOOST_AUTO_TEST_SUITE_END()