surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | 93e4898 | 2018-09-05 13:05:09 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 4 | // |
| 5 | #include "DriverTestHelpers.hpp" |
| 6 | #include <boost/test/unit_test.hpp> |
| 7 | #include <log/log.h> |
| 8 | |
| 9 | BOOST_AUTO_TEST_SUITE(GenericLayerTests) |
| 10 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 11 | using namespace android::hardware; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 12 | using namespace driverTestHelpers; |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 13 | using namespace armnn_driver; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 14 | |
| 15 | BOOST_AUTO_TEST_CASE(GetSupportedOperations) |
| 16 | { |
| 17 | auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef)); |
| 18 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 19 | ErrorStatus errorStatus; |
| 20 | std::vector<bool> supported; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 21 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 22 | auto cb = [&](ErrorStatus _errorStatus, const std::vector<bool>& _supported) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 23 | { |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 24 | errorStatus = _errorStatus; |
| 25 | supported = _supported; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 26 | }; |
| 27 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 28 | neuralnetworks::V1_0::Model model0 = {}; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 29 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 30 | // Add operands |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 31 | int32_t actValue = 0; |
| 32 | float weightValue[] = {2, 4, 1}; |
| 33 | float biasValue[] = {4}; |
| 34 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 35 | AddInputOperand (model0, hidl_vec<uint32_t>{1, 3}); |
| 36 | AddTensorOperand(model0, hidl_vec<uint32_t>{1, 3}, weightValue); |
| 37 | AddTensorOperand(model0, hidl_vec<uint32_t>{1}, biasValue); |
| 38 | AddIntOperand (model0, actValue); |
| 39 | AddOutputOperand(model0, hidl_vec<uint32_t>{1, 1}); |
| 40 | |
| 41 | model0.operations.resize(1); |
| 42 | |
| 43 | // Make a correct fully connected operation |
| 44 | model0.operations[0].type = neuralnetworks::V1_0::OperationType::FULLY_CONNECTED; |
| 45 | model0.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2, 3}; |
| 46 | model0.operations[0].outputs = hidl_vec<uint32_t>{4}; |
| 47 | |
| 48 | driver->getSupportedOperations(model0, cb); |
| 49 | BOOST_TEST((int)errorStatus == (int)ErrorStatus::NONE); |
| 50 | BOOST_TEST(supported.size() == (size_t)1); |
| 51 | BOOST_TEST(supported[0] == true); |
| 52 | |
| 53 | neuralnetworks::V1_0::Model model1 = {}; |
| 54 | |
| 55 | AddInputOperand (model1, hidl_vec<uint32_t>{1, 3}); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 56 | AddTensorOperand(model1, hidl_vec<uint32_t>{1, 3}, weightValue); |
| 57 | AddTensorOperand(model1, hidl_vec<uint32_t>{1}, biasValue); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 58 | AddIntOperand (model1, actValue); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 59 | AddOutputOperand(model1, hidl_vec<uint32_t>{1, 1}); |
| 60 | |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 61 | model1.operations.resize(2); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 62 | |
| 63 | // Make a correct fully connected operation |
| 64 | model1.operations[0].type = neuralnetworks::V1_0::OperationType::FULLY_CONNECTED; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 65 | model1.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2, 3}; |
| 66 | model1.operations[0].outputs = hidl_vec<uint32_t>{4}; |
| 67 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 68 | // Add an incorrect fully connected operation |
| 69 | AddIntOperand (model1, actValue); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 70 | AddOutputOperand(model1, hidl_vec<uint32_t>{1, 1}); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 71 | model1.operations[1].type = neuralnetworks::V1_0::OperationType::FULLY_CONNECTED; |
| 72 | model1.operations[1].inputs = hidl_vec<uint32_t>{4}; // Only 1 input operand, expected 4 |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 73 | model1.operations[1].outputs = hidl_vec<uint32_t>{5}; |
| 74 | |
| 75 | driver->getSupportedOperations(model1, cb); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 76 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 77 | #if defined(ARMNN_ANDROID_P) |
| 78 | // In Android P, android::nn::validateModel returns INVALID_ARGUMENT, because of the wrong number of inputs for the |
| 79 | // fully connected layer (1 instead of 4) |
| 80 | BOOST_TEST((int)errorStatus == (int)ErrorStatus::INVALID_ARGUMENT); |
| 81 | BOOST_TEST(supported.empty()); |
| 82 | #else |
| 83 | // In Android O, android::nn::validateModel indicates that the second (wrong) fully connected layer in unsupported |
| 84 | // in the vector of flags returned by the callback |
| 85 | BOOST_TEST((int)errorStatus == (int)ErrorStatus::NONE); |
| 86 | BOOST_TEST(supported.size() == (size_t)2); |
| 87 | BOOST_TEST(supported[0] == true); |
| 88 | BOOST_TEST(supported[1] == false); |
| 89 | #endif |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 90 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 91 | // Test Broadcast on add/mul operators |
| 92 | neuralnetworks::V1_0::Model model2 = {}; |
| 93 | |
| 94 | AddInputOperand (model2, hidl_vec<uint32_t>{1, 1, 3, 4}); |
| 95 | AddInputOperand (model2, hidl_vec<uint32_t>{4}); |
| 96 | AddIntOperand (model2, actValue); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 97 | AddOutputOperand(model2, hidl_vec<uint32_t>{1, 1, 3, 4}); |
| 98 | AddOutputOperand(model2, hidl_vec<uint32_t>{1, 1, 3, 4}); |
| 99 | |
| 100 | model2.operations.resize(2); |
| 101 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 102 | model2.operations[0].type = neuralnetworks::V1_0::OperationType::ADD; |
| 103 | model2.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2}; |
| 104 | model2.operations[0].outputs = hidl_vec<uint32_t>{3}; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 105 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 106 | model2.operations[1].type = neuralnetworks::V1_0::OperationType::MUL; |
| 107 | model2.operations[1].inputs = hidl_vec<uint32_t>{0, 1, 2}; |
| 108 | model2.operations[1].outputs = hidl_vec<uint32_t>{4}; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 109 | |
| 110 | driver->getSupportedOperations(model2, cb); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 111 | BOOST_TEST((int)errorStatus == (int)ErrorStatus::NONE); |
| 112 | BOOST_TEST(supported.size() == (size_t)2); |
| 113 | BOOST_TEST(supported[0] == true); |
| 114 | BOOST_TEST(supported[1] == true); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 115 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 116 | neuralnetworks::V1_0::Model model3 = {}; |
| 117 | |
| 118 | AddInputOperand (model3, hidl_vec<uint32_t>{1, 1, 1, 8}); |
| 119 | AddIntOperand (model3, 2); |
| 120 | AddOutputOperand(model3, hidl_vec<uint32_t>{1, 2, 2, 2}); |
| 121 | |
| 122 | model3.operations.resize(1); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 123 | |
| 124 | // Add unsupported operation, should return no error but we don't support it |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 125 | model3.operations[0].type = neuralnetworks::V1_0::OperationType::DEPTH_TO_SPACE; |
| 126 | model3.operations[0].inputs = hidl_vec<uint32_t>{0, 1}; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 127 | model3.operations[0].outputs = hidl_vec<uint32_t>{2}; |
| 128 | |
| 129 | driver->getSupportedOperations(model3, cb); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 130 | BOOST_TEST((int)errorStatus == (int)ErrorStatus::NONE); |
| 131 | BOOST_TEST(supported.size() == (size_t)1); |
| 132 | BOOST_TEST(supported[0] == false); |
| 133 | |
| 134 | neuralnetworks::V1_0::Model model4 = {}; |
| 135 | |
| 136 | AddIntOperand(model4, 0); |
| 137 | |
| 138 | model4.operations.resize(1); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 139 | |
| 140 | // Add invalid operation |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 141 | model4.operations[0].type = static_cast<neuralnetworks::V1_0::OperationType>(100); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 142 | model4.operations[0].outputs = hidl_vec<uint32_t>{0}; |
| 143 | |
| 144 | driver->getSupportedOperations(model4, cb); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 145 | BOOST_TEST((int)errorStatus == (int)ErrorStatus::INVALID_ARGUMENT); |
| 146 | BOOST_TEST(supported.empty()); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | // The purpose of this test is to ensure that when encountering an unsupported operation |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 150 | // it is skipped and getSupportedOperations() continues (rather than failing and stopping). |
| 151 | // As per IVGCVSW-710. |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 152 | BOOST_AUTO_TEST_CASE(UnsupportedLayerContinueOnFailure) |
| 153 | { |
| 154 | auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef)); |
| 155 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 156 | ErrorStatus errorStatus; |
| 157 | std::vector<bool> supported; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 158 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 159 | auto cb = [&](ErrorStatus _errorStatus, const std::vector<bool>& _supported) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 160 | { |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 161 | errorStatus = _errorStatus; |
| 162 | supported = _supported; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 163 | }; |
| 164 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 165 | neuralnetworks::V1_0::Model model = {}; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 166 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 167 | // Operands |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 168 | int32_t actValue = 0; |
| 169 | float weightValue[] = {2, 4, 1}; |
| 170 | float biasValue[] = {4}; |
| 171 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 172 | // HASHTABLE_LOOKUP is unsupported at the time of writing this test, but any unsupported layer will do |
| 173 | AddInputOperand (model, hidl_vec<uint32_t>{1, 1, 3, 4}, neuralnetworks::V1_0::OperandType::TENSOR_INT32); |
| 174 | AddInputOperand (model, hidl_vec<uint32_t>{4}, neuralnetworks::V1_0::OperandType::TENSOR_INT32); |
| 175 | AddInputOperand (model, hidl_vec<uint32_t>{1, 1, 3, 4}); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 176 | AddOutputOperand(model, hidl_vec<uint32_t>{1, 1, 3, 4}); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 177 | AddOutputOperand(model, hidl_vec<uint32_t>{1, 1, 3, 4}, neuralnetworks::V1_0::OperandType::TENSOR_QUANT8_ASYMM); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 178 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 179 | // Fully connected is supported |
| 180 | AddInputOperand (model, hidl_vec<uint32_t>{1, 3}); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 181 | AddTensorOperand(model, hidl_vec<uint32_t>{1, 3}, weightValue); |
| 182 | AddTensorOperand(model, hidl_vec<uint32_t>{1}, biasValue); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 183 | AddIntOperand (model, actValue); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 184 | AddOutputOperand(model, hidl_vec<uint32_t>{1, 1}); |
| 185 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 186 | // EMBEDDING_LOOKUP is unsupported |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 187 | AddOutputOperand(model, hidl_vec<uint32_t>{1, 1, 3, 4}); |
| 188 | |
| 189 | model.operations.resize(3); |
| 190 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 191 | // Unsupported |
| 192 | model.operations[0].type = neuralnetworks::V1_0::OperationType::HASHTABLE_LOOKUP; |
| 193 | model.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2}; |
| 194 | model.operations[0].outputs = hidl_vec<uint32_t>{3, 4}; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 195 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 196 | // Supported |
| 197 | model.operations[1].type = neuralnetworks::V1_0::OperationType::FULLY_CONNECTED; |
| 198 | model.operations[1].inputs = hidl_vec<uint32_t>{5, 6, 7, 8}; |
| 199 | model.operations[1].outputs = hidl_vec<uint32_t>{9}; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 200 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 201 | // Unsupported |
| 202 | model.operations[2].type = neuralnetworks::V1_0::OperationType::EMBEDDING_LOOKUP; |
| 203 | model.operations[2].inputs = hidl_vec<uint32_t>{1, 2}; |
| 204 | model.operations[2].outputs = hidl_vec<uint32_t>{10}; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 205 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 206 | // We are testing that the unsupported layers return false and the test continues rather than failing and stopping |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 207 | driver->getSupportedOperations(model, cb); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 208 | BOOST_TEST((int)errorStatus == (int)ErrorStatus::NONE); |
| 209 | BOOST_TEST(supported.size() == (size_t)3); |
| 210 | BOOST_TEST(supported[0] == false); |
| 211 | BOOST_TEST(supported[1] == true); |
| 212 | BOOST_TEST(supported[2] == false); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | // The purpose of this test is to ensure that when encountering an failure |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 216 | // during mem pool mapping we properly report an error to the framework via a callback |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 217 | BOOST_AUTO_TEST_CASE(ModelToINetworkConverterMemPoolFail) |
| 218 | { |
Nikhil Raj | 7760582 | 2018-09-03 11:25:56 +0100 | [diff] [blame^] | 219 | auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef)); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 220 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 221 | ErrorStatus errorStatus; |
| 222 | std::vector<bool> supported; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 223 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 224 | auto cb = [&](ErrorStatus _errorStatus, const std::vector<bool>& _supported) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 225 | { |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 226 | errorStatus = _errorStatus; |
| 227 | supported = _supported; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 228 | }; |
| 229 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 230 | neuralnetworks::V1_0::Model model = {}; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 231 | |
| 232 | model.pools = hidl_vec<hidl_memory>{hidl_memory("Unsuported hidl memory type", nullptr, 0)}; |
| 233 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 234 | // Memory pool mapping should fail, we should report an error |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 235 | driver->getSupportedOperations(model, cb); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 236 | BOOST_TEST((int)errorStatus != (int)ErrorStatus::NONE); |
| 237 | BOOST_TEST(supported.empty()); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | BOOST_AUTO_TEST_SUITE_END() |