blob: 5c6c041d3544be2a5a3a8c52132e1576a5454ba3 [file] [log] [blame]
surmeh0149b9e102018-05-17 14:11:25 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// See LICENSE file in the project root for full license information.
4//
5#include "DriverTestHelpers.hpp"
6#include <boost/test/unit_test.hpp>
7#include <log/log.h>
8
9BOOST_AUTO_TEST_SUITE(GenericLayerTests)
10
11using ArmnnDriver = armnn_driver::ArmnnDriver;
12using DriverOptions = armnn_driver::DriverOptions;
13using namespace driverTestHelpers;
14
15BOOST_AUTO_TEST_CASE(GetSupportedOperations)
16{
17 auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
18
19 ErrorStatus error;
20 std::vector<bool> sup;
21
22 ArmnnDriver::getSupportedOperations_cb cb = [&](ErrorStatus status, const std::vector<bool>& supported)
23 {
24 error = status;
25 sup = supported;
26 };
27
28 Model model1 = {};
29
30 // add operands
31 int32_t actValue = 0;
32 float weightValue[] = {2, 4, 1};
33 float biasValue[] = {4};
34
35 AddInputOperand(model1, hidl_vec<uint32_t>{1, 3});
36 AddTensorOperand(model1, hidl_vec<uint32_t>{1, 3}, weightValue);
37 AddTensorOperand(model1, hidl_vec<uint32_t>{1}, biasValue);
38 AddIntOperand(model1, actValue);
39 AddOutputOperand(model1, hidl_vec<uint32_t>{1, 1});
40
41 // make a correct fully connected operation
42 model1.operations.resize(2);
43 model1.operations[0].type = OperationType::FULLY_CONNECTED;
44 model1.operations[0].inputs = hidl_vec<uint32_t>{0, 1, 2, 3};
45 model1.operations[0].outputs = hidl_vec<uint32_t>{4};
46
47 // make an incorrect fully connected operation
48 AddIntOperand(model1, actValue);
49 AddOutputOperand(model1, hidl_vec<uint32_t>{1, 1});
50 model1.operations[1].type = OperationType::FULLY_CONNECTED;
51 model1.operations[1].inputs = hidl_vec<uint32_t>{4};
52 model1.operations[1].outputs = hidl_vec<uint32_t>{5};
53
54 driver->getSupportedOperations(model1, cb);
55 BOOST_TEST((int)error == (int)ErrorStatus::NONE);
56 BOOST_TEST(sup[0] == true);
57 BOOST_TEST(sup[1] == false);
58
59 // Broadcast add/mul are not supported
60 Model model2 = {};
61
62 AddInputOperand(model2, hidl_vec<uint32_t>{1, 1, 3, 4});
63 AddInputOperand(model2, hidl_vec<uint32_t>{4});
64 AddOutputOperand(model2, hidl_vec<uint32_t>{1, 1, 3, 4});
65 AddOutputOperand(model2, hidl_vec<uint32_t>{1, 1, 3, 4});
66
67 model2.operations.resize(2);
68
69 model2.operations[0].type = OperationType::ADD;
70 model2.operations[0].inputs = hidl_vec<uint32_t>{0,1};
71 model2.operations[0].outputs = hidl_vec<uint32_t>{2};
72
73 model2.operations[1].type = OperationType::MUL;
74 model2.operations[1].inputs = hidl_vec<uint32_t>{0,1};
75 model2.operations[1].outputs = hidl_vec<uint32_t>{3};
76
77 driver->getSupportedOperations(model2, cb);
78 BOOST_TEST((int)error == (int)ErrorStatus::NONE);
79 BOOST_TEST(sup[0] == false);
80 BOOST_TEST(sup[1] == false);
81
82 Model model3 = {};
83
84 // Add unsupported operation, should return no error but we don't support it
85 AddInputOperand(model3, hidl_vec<uint32_t>{1, 1, 1, 8});
86 AddIntOperand(model3, 2);
87 AddOutputOperand(model3, hidl_vec<uint32_t>{1, 2, 2, 2});
88 model3.operations.resize(1);
89 model3.operations[0].type = OperationType::DEPTH_TO_SPACE;
90 model1.operations[0].inputs = hidl_vec<uint32_t>{0, 1};
91 model3.operations[0].outputs = hidl_vec<uint32_t>{2};
92
93 driver->getSupportedOperations(model3, cb);
94 BOOST_TEST((int)error == (int)ErrorStatus::NONE);
95 BOOST_TEST(sup[0] == false);
96
97 // Add invalid operation
98 Model model4 = {};
99 AddIntOperand(model4, 0);
100 model4.operations.resize(1);
101 model4.operations[0].type = static_cast<OperationType>(100);
102 model4.operations[0].outputs = hidl_vec<uint32_t>{0};
103
104 driver->getSupportedOperations(model4, cb);
105 BOOST_TEST((int)error == (int)ErrorStatus::INVALID_ARGUMENT);
106}
107
108// The purpose of this test is to ensure that when encountering an unsupported operation
109// it is skipped and getSupportedOperations() continues (rather than failing and stopping).
110// As per IVGCVSW-710.
111BOOST_AUTO_TEST_CASE(UnsupportedLayerContinueOnFailure)
112{
113 auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
114
115 ErrorStatus error;
116 std::vector<bool> sup;
117
118 ArmnnDriver::getSupportedOperations_cb cb = [&](ErrorStatus status, const std::vector<bool>& supported)
119 {
120 error = status;
121 sup = supported;
122 };
123
124 Model model = {};
125
126 // operands
127 int32_t actValue = 0;
128 float weightValue[] = {2, 4, 1};
129 float biasValue[] = {4};
130
131 // broadcast add is unsupported at the time of writing this test, but any unsupported layer will do
132 AddInputOperand(model, hidl_vec<uint32_t>{1, 1, 3, 4});
133 AddInputOperand(model, hidl_vec<uint32_t>{4});
134 AddOutputOperand(model, hidl_vec<uint32_t>{1, 1, 3, 4});
135
136 // fully connected
137 AddInputOperand(model, hidl_vec<uint32_t>{1, 3});
138 AddTensorOperand(model, hidl_vec<uint32_t>{1, 3}, weightValue);
139 AddTensorOperand(model, hidl_vec<uint32_t>{1}, biasValue);
140 AddIntOperand(model, actValue);
141 AddOutputOperand(model, hidl_vec<uint32_t>{1, 1});
142
143 // broadcast mul is unsupported
144 AddOutputOperand(model, hidl_vec<uint32_t>{1, 1, 3, 4});
145
146 model.operations.resize(3);
147
148 // unsupported
149 model.operations[0].type = OperationType::ADD;
150 model.operations[0].inputs = hidl_vec<uint32_t>{0,1};
151 model.operations[0].outputs = hidl_vec<uint32_t>{2};
152
153 // supported
154 model.operations[1].type = OperationType::FULLY_CONNECTED;
155 model.operations[1].inputs = hidl_vec<uint32_t>{3, 4, 5, 6};
156 model.operations[1].outputs = hidl_vec<uint32_t>{7};
157
158 // unsupported
159 model.operations[2].type = OperationType::MUL;
160 model.operations[2].inputs = hidl_vec<uint32_t>{0,1};
161 model.operations[2].outputs = hidl_vec<uint32_t>{8};
162
163 // we are testing that the unsupported layers return false and the test continues
164 // rather than failing and stopping.
165 driver->getSupportedOperations(model, cb);
166 BOOST_TEST((int)error == (int)ErrorStatus::NONE);
167 BOOST_TEST(sup[0] == false);
168 BOOST_TEST(sup[1] == true);
169 BOOST_TEST(sup[2] == false);
170}
171
172// The purpose of this test is to ensure that when encountering an failure
173// during mem pool mapping we properly report an error to the framework via a callback
174BOOST_AUTO_TEST_CASE(ModelToINetworkConverterMemPoolFail)
175{
176 auto driver = std::make_unique<ArmnnDriver>(armnn::Compute::CpuRef);
177
178 ErrorStatus error;
179 std::vector<bool> sup;
180
181 ArmnnDriver::getSupportedOperations_cb cb = [&](ErrorStatus status, const std::vector<bool>& supported)
182 {
183 error = status;
184 sup = supported;
185 };
186
187 Model model = {};
188
189 model.pools = hidl_vec<hidl_memory>{hidl_memory("Unsuported hidl memory type", nullptr, 0)};
190
191 //memory pool mapping should fail, we should report an error
192 driver->getSupportedOperations(model, cb);
193 BOOST_TEST((int)error == (int)ErrorStatus::GENERAL_FAILURE);
194}
195
196BOOST_AUTO_TEST_SUITE_END()