blob: 0316ea185baeb6bbf09117fe49a4c9536c0a717f [file] [log] [blame]
Aron Virginas-Tare89ebad2019-08-27 18:14:26 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "DivisionTestImpl.hpp"
7
8#include "ElementwiseTestImpl.hpp"
9
10template<>
11std::unique_ptr<armnn::IWorkload> CreateWorkload<armnn::DivisionQueueDescriptor>(
12 const armnn::IWorkloadFactory& workloadFactory,
13 const armnn::WorkloadInfo& info,
14 const armnn::DivisionQueueDescriptor& descriptor)
15{
16 return workloadFactory.CreateDivision(descriptor, info);
17}
18
19LayerTestResult<float, 4> DivisionByZeroTest(
20 armnn::IWorkloadFactory& workloadFactory,
21 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
22{
23 const unsigned int width = 2u;
24 const unsigned int height = 2u;
25 const unsigned int channelCount = 2u;
26 const unsigned int batchSize = 2u;
27
28 unsigned int shape[] = { batchSize, channelCount, height, width };
29
30 std::vector<float> input0 =
31 {
32 1.f, 1.f, 1.f, 1.f, 0.f, 0.f, 0.f, 0.f,
33 -1.f, -1.f, -1.f, -1.f, 5.f, 5.f, 5.f, 5.f
34 };
35
36 std::vector<float> input1 =
37 {
38 0.f, 0.f, -0.f, -0.f, 0.f, 0.f, -0.f, -0.f,
39 0.f, 0.f, -0.f, -0.f, 5.f, 5.f, 5.f, 5.f
40 };
41
42 std::vector<float> output =
43 {
44 INFINITY, INFINITY, -INFINITY, -INFINITY, NAN, NAN, -NAN, -NAN,
45 -INFINITY, -INFINITY, INFINITY, INFINITY, 1, 1, 1, 1
46 };
47
48 return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::Float32>(
49 workloadFactory,
50 memoryManager,
51 shape,
52 input0,
53 shape,
54 input1,
55 shape,
56 output);
57}
58
59LayerTestResult<float, 4> DivisionTest(
60 armnn::IWorkloadFactory& workloadFactory,
61 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
62{
63 const unsigned int width = 2u;
64 const unsigned int height = 2u;
65 const unsigned int channelCount = 2u;
66 const unsigned int batchSize = 2u;
67
68 unsigned int shape[] = { batchSize, channelCount, height, width };
69
70 std::vector<float> input0 =
71 {
72 2.f, 2.f, 2.f, 2.f, 3.f, 3.f, 3.f, 3.f,
73 4.f, 4.f, 4.f, 4.f, 5.f, 5.f, 5.f, 5.f
74 };
75
76 std::vector<float> input1 =
77 {
78 1.f, 1.f, 1.f, 1.f, 2.f, 2.f, 2.f, 2.f,
79 4.f, 4.f, 4.f, 4.f, 4.f, 4.f, 4.f, 4.f
80 };
81
82 std::vector<float> output =
83 {
84 2.f, 2.f, 2.f, 2.f, 1.50f, 1.50f, 1.50f, 1.50f,
85 1.f, 1.f, 1.f, 1.f, 1.25f, 1.25f, 1.25f, 1.25f
86 };
87
88 return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::Float32>(
89 workloadFactory,
90 memoryManager,
91 shape,
92 input0,
93 shape,
94 input1,
95 shape,
96 output);
97}
98
99LayerTestResult<float, 4> DivisionBroadcast1ElementTest(
100 armnn::IWorkloadFactory& workloadFactory,
101 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
102{
103 unsigned int shape0[] = { 1, 2, 2, 2 };
104 unsigned int shape1[] = { 1, 1, 1, 1 };
105
106 std::vector<float> input0({ 2, 4, 6, 8, 10, 12, 14, 16});
107
108 std::vector<float> input1({ 2 });
109
110 std::vector<float> output({ 1, 2, 3, 4, 5, 6, 7, 8});
111
112 return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::Float32>(
113 workloadFactory,
114 memoryManager,
115 shape0,
116 input0,
117 shape1,
118 input1,
119 shape0,
120 output);
121}
122
123LayerTestResult<float, 4> DivisionBroadcast1DVectorTest(
124 armnn::IWorkloadFactory& workloadFactory,
125 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
126{
127 unsigned int shape0[] = { 1, 3, 3, 2 };
128 unsigned int shape1[] = { 1, 1, 1, 2 };
129
130 std::vector<float> input0 =
131 {
132 1.f, 4.f, 3.f, 8.f, 5.f, 12.f,
133 7.f, 16.f, 9.f, 20.f, 11.f, 24.f,
134 13.f, 28.f, 15.f, 32.f, 17.f, 36.f
135 };
136
137 std::vector<float> input1 = { 1.f, 2.f };
138
139 std::vector<float> output =
140 {
141 1.f, 2.f, 3.f, 4.f, 5.f, 6.f,
142 7.f, 8.f, 9.f, 10.f, 11.f, 12.f,
143 13.f, 14.f, 15.f, 16.f, 17.f, 18.f
144 };
145
146 return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::Float32>(
147 workloadFactory,
148 memoryManager,
149 shape0,
150 input0,
151 shape1,
152 input1,
153 shape0,
154 output);
155}
156
157LayerTestResult<uint8_t, 4> DivisionUint8Test(
158 armnn::IWorkloadFactory& workloadFactory,
159 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
160{
161 const unsigned int width = 2u;
162 const unsigned int height = 2u;
163 const unsigned int channelCount = 2u;
164 const unsigned int batchSize = 2u;
165
166 unsigned int shape[] = { batchSize, channelCount, height, width };
167
168 std::vector<uint8_t> input0 =
169 {
170 2, 2, 2, 2, 3, 3, 3, 3,
171 4, 4, 4, 4, 5, 5, 5, 5
172 };
173
174 std::vector<uint8_t> input1 =
175 {
176 1, 1, 1, 1, 2, 2, 2, 2,
177 4, 4, 4, 4, 4, 4, 4, 4
178 };
179
180 std::vector<uint8_t> output =
181 {
182 8, 8, 8, 8, 6, 6, 6, 6,
183 4, 4, 4, 4, 5, 5, 5, 5
184 };
185
186 return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::QuantisedAsymm8>(
187 workloadFactory,
188 memoryManager,
189 shape,
190 input0,
191 shape,
192 input1,
193 shape,
194 output,
195 0.25f,
196 0);
197}
198
199LayerTestResult<uint8_t, 4> DivisionBroadcast1ElementUint8Test(
200 armnn::IWorkloadFactory& workloadFactory,
201 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
202{
203 unsigned int shape0[] = { 1, 2, 2, 2 };
204 unsigned int shape1[] = { 1, 1, 1, 1 };
205
206 std::vector<uint8_t> input0 = { 2, 4, 6, 8, 10, 12, 14, 16};
207
208 std::vector<uint8_t> input1 = { 2 };
209
210 std::vector<uint8_t> output = { 1, 2, 3, 4, 5, 6, 7, 8};
211
212 return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::QuantisedAsymm8>(
213 workloadFactory,
214 memoryManager,
215 shape0,
216 input0,
217 shape1,
218 input1,
219 shape0,
220 output);
221}
222
223LayerTestResult<uint8_t, 4> DivisionBroadcast1DVectorUint8Test(
224 armnn::IWorkloadFactory& workloadFactory,
225 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
226{
227 unsigned int shape0[] = { 1, 3, 3, 2 };
228 unsigned int shape1[] = { 1, 1, 1, 2 };
229
230 std::vector<uint8_t> input0 =
231 {
232 1, 4, 3, 8, 5, 12,
233 7, 16, 9, 20, 11, 24,
234 13, 28, 15, 32, 17, 36
235 };
236
237 std::vector<uint8_t> input1 = { 1, 2 };
238
239 std::vector<uint8_t> output =
240 {
241 1, 2, 3, 4, 5, 6,
242 7, 8, 9, 10, 11, 12,
243 13, 14, 15, 16, 17, 18
244 };
245
246 return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::QuantisedAsymm8>(
247 workloadFactory,
248 memoryManager,
249 shape0,
250 input0,
251 shape1,
252 input1,
253 shape0,
254 output);
255}
256
257LayerTestResult<int16_t,4> DivisionInt16Test(
258 armnn::IWorkloadFactory& workloadFactory,
259 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
260{
261 unsigned int shape[] = { 2, 2, 2, 2 };
262
263 std::vector<int16_t> input0 =
264 {
265 2, 2, 2, 2, 3, 3, 3, 3,
266 4, 4, 4, 4, 5, 5, 5, 5
267 };
268
269 std::vector<int16_t> input1 =
270 {
271 1, 1, 1, 1, 2, 2, 2, 2,
272 4, 4, 4, 4, 4, 4, 4, 4
273 };
274
275 std::vector<int16_t> output =
276 {
277 8, 8, 8, 8, 6, 6, 6, 6,
278 4, 4, 4, 4, 5, 5, 5, 5
279 };
280
281 return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::QuantisedSymm16>(
282 workloadFactory,
283 memoryManager,
284 shape,
285 input0,
286 shape,
287 input1,
288 shape,
289 output,
290 0.25f,
291 0);
292}
293
294LayerTestResult<int16_t, 4> DivisionBroadcast1ElementInt16Test(
295 armnn::IWorkloadFactory& workloadFactory,
296 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
297{
298 unsigned int shape0[] = { 1, 2, 2, 2 };
299 unsigned int shape1[] = { 1, 1, 1, 1 };
300
301 std::vector<int16_t> input0 = { 2, 4, 6, 8, 10, 12, 14, 16};
302
303 std::vector<int16_t> input1 = { 2 };
304
305 std::vector<int16_t> output = { 1, 2, 3, 4, 5, 6, 7, 8};
306
307 return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::QuantisedSymm16>(
308 workloadFactory,
309 memoryManager,
310 shape0,
311 input0,
312 shape1,
313 input1,
314 shape0,
315 output);
316}
317
318LayerTestResult<int16_t, 4> DivisionBroadcast1DVectorInt16Test(
319 armnn::IWorkloadFactory& workloadFactory,
320 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
321{
322 unsigned int shape0[] = { 1, 3, 3, 2 };
323 unsigned int shape1[] = { 1, 1, 1, 2 };
324
325 std::vector<int16_t> input0 =
326 {
327 1, 4, 3, 8, 5, 12,
328 7, 16, 9, 20, 11, 24,
329 13, 28, 15, 32, 17, 36
330 };
331
332 std::vector<int16_t> input1 = { 1, 2 };
333
334 std::vector<int16_t> output =
335 {
336 1, 2, 3, 4, 5, 6,
337 7, 8, 9, 10, 11, 12,
338 13, 14, 15, 16, 17, 18
339 };
340
341 return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::QuantisedSymm16>(
342 workloadFactory,
343 memoryManager,
344 shape0,
345 input0,
346 shape1,
347 input1,
348 shape0,
349 output);
350}