blob: 0bf56e24459a52699b931c0222a23607ec0d55fe [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5#include "LayerTests.hpp"
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006#include "WorkloadTestUtils.hpp"
Nina Drozdd41b2592018-11-19 13:03:36 +00007#include "TensorUtils.hpp"
telsoa014fcda012018-03-09 14:13:49 +00008
9#include "test/TensorHelpers.hpp"
10#include "TensorCopyUtils.hpp"
surmeh013537c2c2018-05-18 16:31:43 +010011#include "Permute.hpp"
telsoa014fcda012018-03-09 14:13:49 +000012
13#include <boost/test/unit_test.hpp>
surmeh013537c2c2018-05-18 16:31:43 +010014#include <boost/assert.hpp>
telsoa014fcda012018-03-09 14:13:49 +000015
David Beck711fa312018-09-24 10:46:38 +010016#include <armnn/LayerSupport.hpp>
telsoa014fcda012018-03-09 14:13:49 +000017
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000018#include <backendsCommon/CpuTensorHandle.hpp>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +000019#include <backendsCommon/IBackendInternal.hpp>
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000020#include <backendsCommon/WorkloadFactory.hpp>
telsoa014fcda012018-03-09 14:13:49 +000021
Éanna Ó Catháinde705582018-12-03 13:04:22 +000022#include <reference/workloads/RefWorkloads.hpp>
23
telsoa014fcda012018-03-09 14:13:49 +000024#include <algorithm>
25#include <boost/cast.hpp>
26
27#include "WorkloadTestUtils.hpp"
28#include "Conv2dTestImpl.hpp"
29#include "BatchNormTestImpl.hpp"
30#include "ActivationTestImpl.hpp"
31#include "Pooling2dTestImpl.hpp"
32#include "ReshapeTestImpl.hpp"
33#include "FullyConnectedTestImpl.hpp"
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +000034#include "SpaceToBatchNdTestImpl.hpp"
telsoa014fcda012018-03-09 14:13:49 +000035#include "SplitterTestImpl.hpp"
36#include "SoftmaxTestImpl.hpp"
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +000037#include "StridedSliceTestImpl.hpp"
telsoa014fcda012018-03-09 14:13:49 +000038#include "NormTestImpl.hpp"
39#include "PermuteTestImpl.hpp"
Matteo Martincigh49124022019-01-11 13:25:59 +000040#include "PreCompiledTestImpl.hpp"
telsoa01c577f2c2018-08-31 09:22:23 +010041#include "LstmTestImpl.hpp"
42#include "ConvertFp16ToFp32TestImpl.hpp"
43#include "ConvertFp32ToFp16TestImpl.hpp"
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000044#include "DebugTestImpl.hpp"
telsoa014fcda012018-03-09 14:13:49 +000045
telsoa01c577f2c2018-08-31 09:22:23 +010046// 3-channel 16x8 image used as common input data for a number of Conv2d tests.
telsoa014fcda012018-03-09 14:13:49 +000047static std::vector<float> ConvInput3x8x16({
48 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f,
49 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
50 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f,
51 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f,
52 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f,
53 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f,
54 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f,
55 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f,
56 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
58 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
59 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
60 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
61 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
62 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
63 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
64 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
65 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
66 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
67 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
68 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
69 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
70 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
71 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
72});
73
telsoa01c577f2c2018-08-31 09:22:23 +010074// 2-channel bias used by a number of Conv2d tests.
telsoa014fcda012018-03-09 14:13:49 +000075static std::vector<float> Bias2({0, 2});
76
telsoa01c577f2c2018-08-31 09:22:23 +010077// Helper function that returns either Bias2 or an empty vector depending on whether bias is enabled.
telsoa014fcda012018-03-09 14:13:49 +000078template<typename T>
79boost::multi_array<T, 1> GetBias2(bool biasEnabled, float qScale, int32_t qOffset)
80{
81 if(biasEnabled)
82 {
83 armnn::TensorInfo biasDesc({static_cast<unsigned int>(Bias2.size())}, armnn::GetDataType<T>());
84 boost::multi_array<T, 1> bias = MakeTensor<T, 1>(biasDesc, QuantizedVector<T>(qScale, qOffset, Bias2));
85 return bias;
86 }
87 else
88 {
89 return boost::multi_array<T, 1>();
90 }
91}
92
93template<typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +000094LayerTestResult<T, 4> SimpleConvolution2d3x5TestCommon(
95 armnn::IWorkloadFactory& workloadFactory,
96 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
97 float qScale,
98 int32_t qOffset,
99 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000100 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000101{
telsoa01c577f2c2018-08-31 09:22:23 +0100102 // Use common single-batch 3-channel 16x8 image.
telsoa014fcda012018-03-09 14:13:49 +0000103 armnn::TensorInfo inputDesc({1, 3, 8, 16}, armnn::GetDataType<T>());
104 boost::multi_array<T, 4> input = MakeTensor<T, 4>(inputDesc, QuantizedVector<T>(qScale, qOffset, ConvInput3x8x16));
105
telsoa01c577f2c2018-08-31 09:22:23 +0100106 // Use a 2-element batch with 3-channel 3x5 kernels.
telsoa014fcda012018-03-09 14:13:49 +0000107 armnn::TensorInfo kernelDesc({2, 3, 5, 3}, armnn::GetDataType<T>());
108 boost::multi_array<T, 4> kernel = MakeTensor<T, 4>(kernelDesc, std::vector<T>(
109 QuantizedVector<T>(qScale, qOffset, {
110 1, 1, 1,
111 1, -1, 1,
112 1, 1, 1,
113 1, 1, 1,
114 1, 1, 1,
115
116 0, 0, 0,
117 0, 0, 0,
118 0, 0, 0,
119 0, 0, 0,
120 0, 0, 0,
121
122 2, 2, 2,
123 2, 2, 2,
124 2, 2, 2,
125 2, 2, 2,
126 2, 2, 2,
127
128
129 0, 0, 0,
130 0, 0, 0,
131 0, 0, 0,
132 0, 0, 0,
133 0, 0, 0,
134
135 1, 1, 1,
136 1, 1, 1,
137 1, 1, 1,
138 1, 1, 1,
139 1, 1, 1,
140
141 0, 0, 0,
142 0, 0, 0,
143 0, 0, 0,
144 0, 0, 0,
145 0, 0, 0
146 })));
147
telsoa01c577f2c2018-08-31 09:22:23 +0100148 // Expected output is 2 batch elements of a 1-channel 14x4 image.
telsoa014fcda012018-03-09 14:13:49 +0000149 armnn::TensorInfo outputDesc({1, 2, 4, 14}, armnn::GetDataType<T>());
150 boost::multi_array<T, 4> expectedOutput = MakeTensor<T, 4>(outputDesc, std::vector<T>(
151 QuantizedVector<T>(qScale, qOffset, {
152 -24, -24, -24, -24, -24, -24, -24, -24, -24, -24, -24, -24, -24, -24,
153 -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, -25,
154 -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f,
155 -23.5f, -23.5f, -23.5f,
156 -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f,
157 -23.5f, -23.5f, -23.5f,
158
159 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
160 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
161 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
162 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
163 })));
164
165 return SimpleConvolution2dTestImpl<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000166 memoryManager,
telsoa014fcda012018-03-09 14:13:49 +0000167 input,
168 kernel,
169 GetBias2<typename FullyConnectedBiasTypeForInputType<T>::Type>(biasEnabled, qScale, qOffset),
170 expectedOutput,
171 qScale,
jimfly010a088a62018-10-25 17:05:05 +0100172 qOffset,
173 layout);
telsoa014fcda012018-03-09 14:13:49 +0000174}
175
176template<typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000177LayerTestResult<T, 4> SimpleConvolution2d3x3TestCommon(
178 armnn::IWorkloadFactory& workloadFactory,
179 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
180 float qScale,
181 int32_t qOffset,
182 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000183 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000184{
telsoa01c577f2c2018-08-31 09:22:23 +0100185 // Use a 3x3 kernel, which exercises ArmCompute's direct convolution path.
telsoa014fcda012018-03-09 14:13:49 +0000186
telsoa01c577f2c2018-08-31 09:22:23 +0100187 // Use common single-batch 3-channel 16x8 image.
telsoa014fcda012018-03-09 14:13:49 +0000188 armnn::TensorInfo inputDesc({1, 3, 8, 16}, armnn::GetDataType<T>());
189 boost::multi_array<T, 4> input = MakeTensor<T, 4>(inputDesc, QuantizedVector<T>(qScale, qOffset, ConvInput3x8x16));
190
telsoa01c577f2c2018-08-31 09:22:23 +0100191 // Use a 2-element batch of 3-channel 3x3 kernels.
telsoa014fcda012018-03-09 14:13:49 +0000192 armnn::TensorInfo kernelDesc({2, 3, 3, 3}, armnn::GetDataType<T>());
193 boost::multi_array<T, 4> kernel = MakeTensor<T, 4>(kernelDesc, std::vector<T>(
194 QuantizedVector<T>(qScale, qOffset, {
195 1, 1, 1,
196 1, -1, 1,
197 1, 1, 1,
198
199 0, 0, 0,
200 0, 0, 0,
201 0, 0, 0,
202
203 2, 2, 2,
204 2, 2, 2,
205 2, 2, 2,
206
207
208 0, 0, 0,
209 0, 0, 0,
210 0, 0, 0,
211
212 1, 1, 1,
213 1, 1, 1,
214 1, 1, 1,
215
216 0, 0, 0,
217 0, 0, 0,
218 0, 0, 0
219 })));
220
telsoa01c577f2c2018-08-31 09:22:23 +0100221 // Expected output is 1 batch of a 2-channel 14x6 image.
telsoa014fcda012018-03-09 14:13:49 +0000222 armnn::TensorInfo outputDesc({1, 2, 6, 14}, armnn::GetDataType<T>());
223 boost::multi_array<T, 4> expectedOutput = MakeTensor<T, 4>(outputDesc, std::vector<T>(
224 QuantizedVector<T>(qScale, qOffset, {
225 -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15,
226 -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
227 -14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,
228 -14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,
229 -14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,
230 -14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,-14.5f,
231
232 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
233 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
234 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
235 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
236 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
237 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
238 })));
239
240 return SimpleConvolution2dTestImpl<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000241 memoryManager,
telsoa014fcda012018-03-09 14:13:49 +0000242 input,
243 kernel,
244 GetBias2<typename FullyConnectedBiasTypeForInputType<T>::Type>(biasEnabled, qScale, qOffset),
245 expectedOutput,
246 qScale,
narpra015f703182018-10-26 16:24:58 +0100247 qOffset,
248 layout);
telsoa014fcda012018-03-09 14:13:49 +0000249}
250
Francis Murtaghd59116e2018-10-04 16:03:07 +0100251template<typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000252LayerTestResult<T, 4> SimpleConvolution2d3x3NhwcTestCommon(
253 armnn::IWorkloadFactory& workloadFactory,
254 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
255 float qScale,
256 int32_t qOffset,
257 bool biasEnabled,
258 armnn::DataLayout dataLayout)
Francis Murtaghd59116e2018-10-04 16:03:07 +0100259{
260 // Use common single-batch 5x5 image.
261
262 armnn::TensorInfo inputDesc({1, 3, 4, 1}, armnn::GetDataType<T>());
263 boost::multi_array<T, 4> input = MakeTensor<T, 4>(inputDesc,
264 {
265 1, 5, 2, 3,
266 8, 7, 3, 6,
267 3, 3, 9, 1
268 });
269
270
271 // Use a 2-element batch of 3-channel 3x3 kernels.
272 armnn::TensorInfo kernelDesc({1, 3, 3, 1}, armnn::GetDataType<T>());
273 boost::multi_array<T, 4> kernel = MakeTensor<T, 4>(kernelDesc, {
274 4, 5, 6,
275 0, 0, 0,
276 3, 2, 1
277 });
278
279 // Expected output is 1 batch of a 5x5 image.
280 armnn::TensorInfo outputDesc({1, 3, 4, 1}, armnn::GetDataType<T>());
281
282 const std::vector<float> outputData =
283 {
284 23, 41, 33, 21,
285 44, 65, 76, 52,
286 82, 85, 79, 42
287 };
288
289 boost::multi_array<T, 4> expectedOutput = MakeTensor<T, 4>(outputDesc, outputData);
290
291 return SimpleConvolution2dNhwcTestImpl<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000292 memoryManager,
Francis Murtaghd59116e2018-10-04 16:03:07 +0100293 input,
294 kernel,
295 boost::multi_array<T, 1>(),
296 expectedOutput,
297 dataLayout,
298 qScale,
299 qOffset);
300}
301
Mike Kelly7332ed82018-12-20 17:03:06 +0000302template<typename T>
303LayerTestResult<T, 4> SimpleConvolution2d3x3Stride2x2TestCommon(
304 armnn::IWorkloadFactory& workloadFactory,
305 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
306 float qScale,
307 int32_t qOffset,
308 bool biasEnabled,
309 const armnn::DataLayout& dataLayout)
310{
311 // Input is a single-batch, 1 channel, 5x5 image.
312 armnn::TensorInfo inputDesc({1, 5, 5, 1}, armnn::GetDataType<T>());
313 boost::multi_array<T, 4> input = MakeTensor<T, 4>(inputDesc,
314 {
315 1, 5, 2, 3, 5,
316 8, 7, 3, 6, 3,
317 3, 3, 9, 1, 9,
318 4, 1, 8, 1, 3,
319 6, 8, 1, 9, 2
320 });
321
322 // Use a 3x3 kernel.
323 armnn::TensorInfo kernelDesc({1, 3, 3, 1}, armnn::GetDataType<T>());
324 boost::multi_array<T, 4> kernel = MakeTensor<T, 4>(kernelDesc,
325 {
326 4, 5, 6,
327 0, 0, 0,
328 3, 2, 1
329 });
330
331 // Expected output is a single-batch, 1 channel, 3x3 image.
332 armnn::TensorInfo outputDesc({1, 3, 3, 1}, armnn::GetDataType<T>());
333
334 const std::vector<T> outputData =
335 {
336 23, 33, 24,
337 91, 99, 48,
338 26, 50, 19
339 };
340
341 boost::multi_array<T, 4> expectedOutput = MakeTensor<T, 4>(outputDesc, outputData);
342
343 uint32_t padLeft = 1;
344 uint32_t padTop = 1;
345 uint32_t padRight = 1;
346 uint32_t padBottom = 1;
347 uint32_t strideX = 2;
348 uint32_t strideY = 2;
349
350 return SimpleConvolution2dNhwcTestImpl<T>(workloadFactory,
351 memoryManager,
352 input,
353 kernel,
354 boost::multi_array<T, 1>(),
355 expectedOutput,
356 dataLayout,
357 qScale,
358 qOffset,
359 padLeft,
360 padTop,
361 padRight,
362 padBottom,
363 strideX,
364 strideY);
365}
366
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000367LayerTestResult<float, 4> SimpleConvolution2d3x5Test(
368 armnn::IWorkloadFactory& workloadFactory,
369 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
370 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000371 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000372{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000373 return SimpleConvolution2d3x5TestCommon<float>(workloadFactory, memoryManager, 0.f, 0, biasEnabled, layout);
telsoa014fcda012018-03-09 14:13:49 +0000374}
375
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000376LayerTestResult<uint8_t, 4> SimpleConvolution2d3x5Uint8Test(
377 armnn::IWorkloadFactory& workloadFactory,
378 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
379 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000380 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000381{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000382 return SimpleConvolution2d3x5TestCommon<uint8_t>(workloadFactory, memoryManager, 0.5f, 50, biasEnabled, layout);
telsoa014fcda012018-03-09 14:13:49 +0000383}
384
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000385LayerTestResult<float, 4> SimpleConvolution2d3x3Test(
386 armnn::IWorkloadFactory& workloadFactory,
387 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
388 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000389 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000390{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000391 return SimpleConvolution2d3x3TestCommon<float>(workloadFactory, memoryManager, 0.f, 0, biasEnabled, layout);
telsoa014fcda012018-03-09 14:13:49 +0000392}
393
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000394LayerTestResult<float, 4> SimpleConvolution2d3x3NhwcTest(
395 armnn::IWorkloadFactory& workloadFactory,
396 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
397 bool biasEnabled)
Francis Murtaghd59116e2018-10-04 16:03:07 +0100398{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000399 return SimpleConvolution2d3x3NhwcTestCommon<float>(workloadFactory,
400 memoryManager,
401 0.f,
402 0,
403 biasEnabled,
404 armnn::DataLayout::NHWC);
Francis Murtaghd59116e2018-10-04 16:03:07 +0100405}
406
Mike Kelly7332ed82018-12-20 17:03:06 +0000407LayerTestResult<float, 4> SimpleConvolution2d3x3Stride2x2Test(
408 armnn::IWorkloadFactory& workloadFactory,
409 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
410 bool biasEnabled,
411 const armnn::DataLayout layout)
412{
413 return SimpleConvolution2d3x3Stride2x2TestCommon<float>(workloadFactory,
414 memoryManager,
415 0.f,
416 0,
417 biasEnabled,
418 layout);
419}
420
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000421LayerTestResult<uint8_t, 4> SimpleConvolution2d3x3Uint8Test(
422 armnn::IWorkloadFactory& workloadFactory,
423 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
424 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000425 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000426{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000427 return SimpleConvolution2d3x3TestCommon<uint8_t>(workloadFactory, memoryManager, 0.5f, 50, biasEnabled, layout);
telsoa014fcda012018-03-09 14:13:49 +0000428}
429
430template<typename T>
431LayerTestResult<T, 4> Convolution2dAsymmetricPaddingLargerThanHalfKernelSizeTestCommon(
432 armnn::IWorkloadFactory& workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000433 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +0000434 const armnn::DataLayout layout,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000435 float qScale,
436 int32_t qOffset)
telsoa014fcda012018-03-09 14:13:49 +0000437{
telsoa01c577f2c2018-08-31 09:22:23 +0100438 // Use a single-batch 1-channel 3x3 image as input.
telsoa014fcda012018-03-09 14:13:49 +0000439 armnn::TensorInfo inputDesc({1, 1, 3, 3}, armnn::GetDataType<T>());
440 boost::multi_array<T, 4> input = MakeTensor<T, 4>(inputDesc, std::vector<T>(
441 QuantizedVector<T>(qScale, qOffset, {
442 11,21,31,
443 12,22,32,
444 13,23,33
445 })));
446
telsoa01c577f2c2018-08-31 09:22:23 +0100447 // Use 1 batch of a 1-channel 2x2 kernel.
telsoa014fcda012018-03-09 14:13:49 +0000448 armnn::TensorInfo kernelDesc({1, 1, 2, 2}, armnn::GetDataType<T>());
449 boost::multi_array<T, 4> kernel = MakeTensor<T, 4>(kernelDesc, std::vector<T>(
450 QuantizedVector<T>(qScale, qOffset, {
451 -11,-21,
452 -12,-22,
453 })));
454
telsoa01c577f2c2018-08-31 09:22:23 +0100455// Expected output is 1 batch of a 1-channel 6x8 image.
telsoa014fcda012018-03-09 14:13:49 +0000456// Manually calculated like this:
457//[-11*0 -21*0 -12*0 -22*0 ; -11*0 -21*0 -12*0 -22*0 ; -11*0 -21*0 -12*0 -22*0 ; -11*0 -21*0 -12*0 -22*0 ..]
458//[-11*0 -21*0 -12*0 -22*11 ; -11*0 -21*0 -12*11 -22*21 ; -11*0 -21*0 -12*21 -22*31 ; -11*0 -21*0 -12*31 -22*0 ..]
459//[-11*0 -21*11 -12*0 -22*12 ; -11*11 -21*21 -12*12 -22*22 ; -11*21 -21*31 -12*22 -22*32 ; -11*31 -21*0 -12*32 -22*0 ..]
460//[-11*0 -21*12 -12*0 -22*13 ; -11*12 -21*22 -12*13 -22*23 ; -11*22 -21*32 -12*23 -22*33 ; -11*32 -21*0 -12*33 -22*0 ..]
461//[-11*0 -21*13 -12*0 -22*0 ; -11*13 -21*23 -12*0 -22*0 ; -11*23 -21*33 -12*0 -22*0 ; -11*33 -21*0 -12*0 -22*0 ..]
462//[-11*0 -21*0 -12*0 -22*0 ; -11*0 -21*0 -12*0 -22*0 ; -11*0 -21*0 -12*0 -22*0 ; -11*0 -21*0 -12*0 -22*0 ..]
463//[..... ..... ..... ..... ; ..... ..... ..... ..... ; ..... ..... ..... ..... ; ..... ..... ..... ..... ..]
464 armnn::TensorInfo outputDesc({1, 1, 8, 6}, armnn::GetDataType<T>());
465 boost::multi_array<T, 4> expectedOutput = MakeTensor<T, 4>(outputDesc, std::vector<T>(
466 QuantizedVector<T>(qScale, qOffset, {
467 0, 0, 0, 0, 0, 0,
468 -242, -594, -934, -372, 0, 0,
469 -495, -1190, -1850, -725, 0, 0,
470 -538, -1256, -1916, -748, 0, 0,
471 -273, -626, -946, -363, 0, 0,
472 0, 0, 0, 0, 0, 0,
473 0, 0, 0, 0, 0, 0,
474 0, 0, 0, 0, 0, 0
475 })));
476
477 return SimpleConvolution2dTestImpl<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000478 memoryManager,
telsoa014fcda012018-03-09 14:13:49 +0000479 input,
480 kernel,
481 GetBias2<typename FullyConnectedBiasTypeForInputType<T>::Type>(false, qScale, qOffset),
482 expectedOutput,
483 qScale,
484 qOffset,
narpra015f703182018-10-26 16:24:58 +0100485 layout,
telsoa01c577f2c2018-08-31 09:22:23 +0100486 1, // Padding left.
487 2, // Padding top.
488 3, // Padding right.
489 4); // Padding bottom.
telsoa014fcda012018-03-09 14:13:49 +0000490}
491
492template<typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000493LayerTestResult<T, 4> SimpleConvolution2dAsymmetricPaddingTestCommon(
494 armnn::IWorkloadFactory& workloadFactory,
495 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +0000496 const armnn::DataLayout layout,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000497 float qScale,
498 int32_t qOffset)
telsoa014fcda012018-03-09 14:13:49 +0000499{
telsoa01c577f2c2018-08-31 09:22:23 +0100500 // Use a single-batch 1-channel 5x5 image as input.
telsoa014fcda012018-03-09 14:13:49 +0000501 armnn::TensorInfo inputDesc({ 1, 1, 5, 5 }, armnn::GetDataType<T>());
502 boost::multi_array<T, 4> input = MakeTensor<T, 4>(inputDesc, std::vector<T>(
503 QuantizedVector<T>(qScale, qOffset, {
504 11,21,31,41,51,
505 12,22,32,42,52,
506 13,23,33,43,53,
507 14,24,34,44,54,
508 15,25,35,45,55,
509 })));
510
telsoa01c577f2c2018-08-31 09:22:23 +0100511 // Use 1 batch of a 1-channel 4x4 kernel.
telsoa014fcda012018-03-09 14:13:49 +0000512 armnn::TensorInfo kernelDesc({ 1, 1, 4, 4 }, armnn::GetDataType<T>());
513 boost::multi_array<T, 4> kernel = MakeTensor<T, 4>(kernelDesc, std::vector<T>(
514 QuantizedVector<T>(qScale, qOffset, {
515 -11,-21,-31,-41,
516 -12,-22,-32,-42,
517 -13,-23,-33,-43,
518 -14,-24,-34,-44,
519 })));
520
telsoa01c577f2c2018-08-31 09:22:23 +0100521 // Expected output is 1 batch of a 1-channel 5x5 image.
telsoa014fcda012018-03-09 14:13:49 +0000522 armnn::TensorInfo outputDesc({ 1, 1, 5, 5 }, armnn::GetDataType<T>());
523 std::vector<T> myVec(outputDesc.GetNumElements(), 0);
524 boost::multi_array<T, 4> expectedOutput = MakeTensor<T, 4>(outputDesc, std::vector<T>(
525 QuantizedVector<T>(qScale, qOffset, {
telsoa014fcda012018-03-09 14:13:49 +0000526 -7140, -10580, -13940, -9300, -5230,
527 -9590, -14120, -18520, -12290, -6860,
528 -9980, -14560, -18960, -12560, -7000,
529 -7518, -10904, -14144, -9318, -5152,
surmeh013537c2c2018-05-18 16:31:43 +0100530 -5032, -7256, -9376, -6142, -3368,
telsoa014fcda012018-03-09 14:13:49 +0000531 })));
532
533 return SimpleConvolution2dTestImpl<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000534 memoryManager,
telsoa014fcda012018-03-09 14:13:49 +0000535 input,
536 kernel,
537 GetBias2<typename FullyConnectedBiasTypeForInputType<T>::Type>(false, qScale, qOffset),
538 expectedOutput,
539 qScale,
540 qOffset,
narpra015f703182018-10-26 16:24:58 +0100541 layout,
telsoa01c577f2c2018-08-31 09:22:23 +0100542 1, // Padding left.
543 1, // Padding top.
544 2, // Padding right.
545 2); // Padding bottom.
surmeh013537c2c2018-05-18 16:31:43 +0100546}
547
548template<typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000549LayerTestResult<T, 4> DepthwiseConvolution2dAsymmetricTestCommon(
550 armnn::IWorkloadFactory& workloadFactory,
551 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
552 float qScale,
553 int32_t qOffset,
554 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000555 const armnn::DataLayout layout)
surmeh013537c2c2018-05-18 16:31:43 +0100556{
telsoa01c577f2c2018-08-31 09:22:23 +0100557 // Use a single-batch 2-channel 5x5 image as input.
surmeh013537c2c2018-05-18 16:31:43 +0100558 armnn::TensorInfo inputTensorInfo({ 1, 2, 5, 5 }, armnn::GetDataType<T>());
559 auto input = MakeTensor<T, 4>(inputTensorInfo, std::vector<T>(
560 QuantizedVector<T>(inputTensorInfo.GetQuantizationScale(), inputTensorInfo.GetQuantizationOffset(), {
561 0, 1, 2, 3, 4,
562 5, 6, 7, 8, 9,
563 10, 11, 12, 13, 14,
564 15, 16, 17, 18, 19,
565 20, 21, 22, 23, 24,
566
567 25, 26, 27, 28, 29,
568 30, 31, 32, 33, 34,
569 35, 36, 37, 38, 39,
570 40, 41, 42, 43, 44,
571 45, 46, 47, 48, 49
572 })));
573
telsoa01c577f2c2018-08-31 09:22:23 +0100574 // Use a depth multiplier of 1 on a 2-channel 4x4 kernel.
surmeh013537c2c2018-05-18 16:31:43 +0100575 armnn::TensorInfo kernelTensorInfo({ 1, 2, 4, 4 }, armnn::GetDataType<T>());
576 auto kernel = MakeTensor<T, 4>(kernelTensorInfo, std::vector<T>(
577 QuantizedVector<T>(kernelTensorInfo.GetQuantizationScale(), kernelTensorInfo.GetQuantizationOffset(), {
578 32, 31, 30, 29,
579 28, 27, 26, 25,
580 24, 23, 22, 21,
581 20, 19, 18, 17,
582
583 16, 15, 14, 13,
584 12, 11, 10, 9,
585 8, 7, 6, 5,
586 4, 3, 2, 1
587 })));
588
telsoa01c577f2c2018-08-31 09:22:23 +0100589 // Expected output is 1 batch of a 2-channel 5x5 image.
590 // Calculated using the python tensorflow library with strideX=1, strideY=1.
surmeh013537c2c2018-05-18 16:31:43 +0100591 armnn::TensorInfo outputTensorInfo({ 1, 2, 5, 5 }, armnn::GetDataType<T>());
592 boost::multi_array<T, 4> expectedOutput = MakeTensor<T, 4>(outputTensorInfo, std::vector<T>(
593 QuantizedVector<T>(outputTensorInfo.GetQuantizationScale(), outputTensorInfo.GetQuantizationOffset(), {
594 1062, 1580, 1850, 1530, 1117,
595 2140, 3108, 3500, 2842, 2042,
596 3580, 5068, 5460, 4342, 3062,
597 3618, 5072, 5390, 4248, 2971,
598 3074, 4282, 4510, 3533, 2457,
599 1550, 2284, 2362, 1955, 1428,
600 2910, 4206, 4342, 3528, 2536,
601 3390, 4886, 5022, 4068, 2916,
602 3566, 5056, 5182, 4133, 2922,
603 3100, 4352, 4452, 3517, 2465
604 })));
605
606 return DepthwiseConvolution2dAsymmetricTestImpl<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000607 memoryManager,
surmeh013537c2c2018-05-18 16:31:43 +0100608 input,
609 kernel,
610 GetBias2<typename FullyConnectedBiasTypeForInputType<T>::Type>(biasEnabled, qScale, qOffset),
611 expectedOutput,
612 qScale,
613 qOffset,
jimfly01382a91d2018-10-26 15:55:50 +0100614 layout,
telsoa01c577f2c2018-08-31 09:22:23 +0100615 1, // Padding left.
616 1, // Padding top.
617 2, // Padding right.
618 2, // Padding bottom.
surmeh013537c2c2018-05-18 16:31:43 +0100619 1, // strideX
620 1); // strideY
telsoa014fcda012018-03-09 14:13:49 +0000621}
622
Nikhil Rajcec6b652018-10-12 13:51:57 +0100623template<typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000624LayerTestResult<T, 4> DepthwiseConvolution2dNhwcTestCommon(
625 armnn::IWorkloadFactory& workloadFactory,
626 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
627 float qScale,
628 int32_t qOffset,
629 bool biasEnabled)
Nikhil Rajcec6b652018-10-12 13:51:57 +0100630{
631 armnn::TensorInfo inputTensorInfo({ 1, 5, 5, 2}, armnn::GetDataType<T>());
632 auto input = MakeTensor<T, 4>(inputTensorInfo, std::vector<T>(
633 QuantizedVector<T>(inputTensorInfo.GetQuantizationScale(), inputTensorInfo.GetQuantizationOffset(), {
634 0, 25,
635 1, 26,
636 2, 27,
637 3, 28,
638 4, 29,
639
640 5, 30,
641 6, 31,
642 7, 32,
643 8, 33,
644 9, 34,
645
646 10, 35,
647 11, 36,
648 12, 37,
649 13, 38,
650 14, 39,
651
652 15, 40,
653 16, 41,
654 17, 42,
655 18, 43,
656 19, 44,
657
658 20, 45,
659 21, 46,
660 22, 47,
661 23, 48,
662 24, 49
663 })));
664
Matteo Martincigh747ef822018-12-18 09:26:39 +0000665 armnn::TensorInfo kernelTensorInfo({ 1, 2, 4, 4 }, armnn::GetDataType<T>());
Nikhil Rajcec6b652018-10-12 13:51:57 +0100666 auto kernel = MakeTensor<T, 4>(kernelTensorInfo, std::vector<T>(
667 QuantizedVector<T>(kernelTensorInfo.GetQuantizationScale(), kernelTensorInfo.GetQuantizationOffset(), {
Matteo Martincigh747ef822018-12-18 09:26:39 +0000668 32, 31, 30, 29,
669 28, 27, 26, 25,
670 24, 23, 22, 21,
671 20, 19, 18, 17,
Nikhil Rajcec6b652018-10-12 13:51:57 +0100672
Matteo Martincigh747ef822018-12-18 09:26:39 +0000673 16, 15, 14, 13,
674 12, 11, 10, 9,
675 8, 7, 6, 5,
676 4, 3, 2, 1
Nikhil Rajcec6b652018-10-12 13:51:57 +0100677 })));
678
679 armnn::TensorInfo outputTensorInfo({ 1, 5, 5, 2}, armnn::GetDataType<T>());
680 boost::multi_array<T, 4> expectedOutput = MakeTensor<T, 4>(outputTensorInfo, std::vector<T>(
681 QuantizedVector<T>(outputTensorInfo.GetQuantizationScale(), outputTensorInfo.GetQuantizationOffset(), {
682 1062, 1550,
683 1580, 2284,
684 1850, 2362,
685 1530, 1955,
686 1117, 1428,
687
688 2140, 2910,
689 3108, 4206,
690 3500, 4342,
691 2842, 3528,
692 2042, 2536,
693
694 3580, 3390,
695 5068, 4886,
696 5460, 5022,
697 4342, 4068,
698 3062, 2916,
699
700 3618, 3566,
701 5072, 5056,
702 5390, 5182,
703 4248, 4133,
704 2971, 2922,
705
706 3074, 3100,
707 4282, 4352,
708 4510, 4452,
709 3533, 3517,
710 2457, 2465
711 })));
712
713 return DepthwiseConvolution2dNhwcTestImpl<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000714 memoryManager,
Nikhil Rajcec6b652018-10-12 13:51:57 +0100715 input,
716 kernel,
717 GetBias2<typename FullyConnectedBiasTypeForInputType<T>::Type>(biasEnabled, qScale, qOffset),
718 expectedOutput,
719 qScale,
720 qOffset,
721 1, // Padding left.
722 1, // Padding top.
723 2, // Padding right.
724 2, // Padding bottom.
725 1, // strideX
726 1); // strideY
727}
728
telsoa014fcda012018-03-09 14:13:49 +0000729LayerTestResult<float, 4>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000730Convolution2dAsymmetricPaddingLargerThanHalfKernelSizeTest(
731 armnn::IWorkloadFactory& workloadFactory,
732 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +0000733 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000734{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000735 return Convolution2dAsymmetricPaddingLargerThanHalfKernelSizeTestCommon<float>(
736 workloadFactory, memoryManager, layout, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +0000737}
738
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000739LayerTestResult<float, 4> Convolution2dAsymmetricPaddingTest(
740 armnn::IWorkloadFactory& workloadFactory,
741 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +0000742 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000743{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000744 return SimpleConvolution2dAsymmetricPaddingTestCommon<float>(
745 workloadFactory, memoryManager, layout, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +0000746}
747
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000748LayerTestResult<float, 4> DepthwiseConvolution2dTest(
749 armnn::IWorkloadFactory& workloadFactory,
750 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
751 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000752 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000753{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000754 return DepthwiseConvolution2dTestImpl<float, float>(
755 workloadFactory, memoryManager, 0.0f, 0, biasEnabled, layout);
telsoa014fcda012018-03-09 14:13:49 +0000756}
757
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000758LayerTestResult<float, 4> DepthwiseConvolution2dDepthNhwcTest(
759 armnn::IWorkloadFactory& workloadFactory,
760 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
761 bool biasEnabled)
Nikhil Rajcec6b652018-10-12 13:51:57 +0100762{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000763 return DepthwiseConvolution2dNhwcTestCommon<float>(workloadFactory, memoryManager, 0.0f, 0, biasEnabled);
Nikhil Rajcec6b652018-10-12 13:51:57 +0100764}
765
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000766LayerTestResult<float, 4> DepthwiseConvolution2dDepthMul1Test(
767 armnn::IWorkloadFactory& workloadFactory,
768 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
769 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000770 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000771{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000772 return DepthwiseConvolution2dDepthMul1TestImpl<float, float>(
773 workloadFactory, memoryManager, 0.0f, 0, biasEnabled, layout);
telsoa014fcda012018-03-09 14:13:49 +0000774}
775
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000776LayerTestResult<float, 4> DepthwiseConvolution2dAsymmetricTest(
777 armnn::IWorkloadFactory& workloadFactory,
778 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
779 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000780 const armnn::DataLayout layout)
surmeh013537c2c2018-05-18 16:31:43 +0100781{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000782 return DepthwiseConvolution2dAsymmetricTestCommon<float>(
783 workloadFactory, memoryManager, 0.0f, 0, biasEnabled, layout);
surmeh013537c2c2018-05-18 16:31:43 +0100784}
785
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000786LayerTestResult<uint8_t, 4> DepthwiseConvolution2dUint8Test(
787 armnn::IWorkloadFactory& workloadFactory,
788 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
789 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000790 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000791{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000792 return DepthwiseConvolution2dTestImpl<uint8_t, int32_t>(
793 workloadFactory, memoryManager, 0.5f, 50, biasEnabled, layout);
telsoa014fcda012018-03-09 14:13:49 +0000794}
795
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000796LayerTestResult<uint8_t, 4> DepthwiseConvolution2dDepthMul1Uint8Test(
797 armnn::IWorkloadFactory& workloadFactory,
798 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
799 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000800 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000801{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000802 return DepthwiseConvolution2dDepthMul1TestImpl<uint8_t, int32_t>(
803 workloadFactory, memoryManager, 0.5f, 50, biasEnabled, layout);
telsoa014fcda012018-03-09 14:13:49 +0000804}
805
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000806LayerTestResult<float, 4> Convolution1dTest(
807 armnn::IWorkloadFactory& workloadFactory,
808 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
809 bool biasEnabled)
telsoa014fcda012018-03-09 14:13:49 +0000810{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000811 return Convolution1dTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0, biasEnabled);
telsoa014fcda012018-03-09 14:13:49 +0000812}
813
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000814LayerTestResult<uint8_t, 4> Convolution1dUint8Test(
815 armnn::IWorkloadFactory& workloadFactory,
816 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
817 bool biasEnabled)
telsoa014fcda012018-03-09 14:13:49 +0000818{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000819 return Convolution1dTestImpl<uint8_t>(workloadFactory, memoryManager, 0.1f, 128, biasEnabled);
telsoa014fcda012018-03-09 14:13:49 +0000820}
821
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000822LayerTestResult<float,4> CompareConvolution2dTest(
823 armnn::IWorkloadFactory& workloadFactory,
824 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
825 armnn::IWorkloadFactory& refWorkloadFactory)
telsoa014fcda012018-03-09 14:13:49 +0000826{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000827 return CompareConvolution2dTestImpl<float>(workloadFactory, memoryManager, refWorkloadFactory);
telsoa014fcda012018-03-09 14:13:49 +0000828}
829
830template<typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000831LayerTestResult<T,4> CompareDepthwiseConvolution2dTest(
832 armnn::IWorkloadFactory& workloadFactory,
833 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
834 armnn::IWorkloadFactory& refWorkloadFactory,
Matthew Bentham8800c002018-11-19 13:19:28 +0000835 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000836{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000837 return CompareDepthwiseConvolution2dTestImpl<T>(workloadFactory, memoryManager, refWorkloadFactory, layout);
telsoa014fcda012018-03-09 14:13:49 +0000838}
839
840template LayerTestResult<float, 4> CompareDepthwiseConvolution2dTest<float>(
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000841 armnn::IWorkloadFactory&,
842 const armnn::IBackendInternal::IMemoryManagerSharedPtr&,
843 armnn::IWorkloadFactory&,
Matthew Bentham8800c002018-11-19 13:19:28 +0000844 const armnn::DataLayout);
telsoa014fcda012018-03-09 14:13:49 +0000845
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000846template LayerTestResult<uint8_t, 4> CompareDepthwiseConvolution2dTest<uint8_t>(
847 armnn::IWorkloadFactory&,
848 const armnn::IBackendInternal::IMemoryManagerSharedPtr&,
849 armnn::IWorkloadFactory&,
Matthew Bentham8800c002018-11-19 13:19:28 +0000850 const armnn::DataLayout);
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000851
852LayerTestResult<float,4> SimpleNormalizationAcrossTest(
853 armnn::IWorkloadFactory& workloadFactory,
854 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +0000855{
856 auto normMethod = armnn::NormalizationAlgorithmMethod::LocalBrightness;
857 auto normChannel = armnn::NormalizationAlgorithmChannel::Across;
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000858 return SimpleNormalizationTestImpl(workloadFactory, memoryManager, normChannel, normMethod);
telsoa014fcda012018-03-09 14:13:49 +0000859}
860
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000861LayerTestResult<float,4> SimpleNormalizationWithinTest(
862 armnn::IWorkloadFactory& workloadFactory,
863 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +0000864{
865 auto normMethod = armnn::NormalizationAlgorithmMethod::LocalBrightness;
866 auto normChannel = armnn::NormalizationAlgorithmChannel::Within;
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000867 return SimpleNormalizationTestImpl(workloadFactory, memoryManager, normChannel, normMethod);
telsoa014fcda012018-03-09 14:13:49 +0000868}
869
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000870LayerTestResult<float,4> SimpleNormalizationAcrossNhwcTest(
871 armnn::IWorkloadFactory& workloadFactory,
872 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra0155a97bc2018-10-02 14:35:53 +0100873{
874 auto normMethod = armnn::NormalizationAlgorithmMethod::LocalBrightness;
875 auto normChannel = armnn::NormalizationAlgorithmChannel::Across;
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000876 return SimpleNormalizationNhwcTestImpl(workloadFactory, memoryManager, normChannel, normMethod);
narpra0155a97bc2018-10-02 14:35:53 +0100877}
878
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000879LayerTestResult<float,2> SimpleSoftmaxTest(
880 armnn::IWorkloadFactory& workloadFactory,
881 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
882 float beta)
telsoa014fcda012018-03-09 14:13:49 +0000883{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000884 return SimpleSoftmaxTestImpl<float>(workloadFactory, memoryManager, beta);
telsoa014fcda012018-03-09 14:13:49 +0000885}
886
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000887LayerTestResult<uint8_t,2> SimpleSoftmaxUint8Test(
888 armnn::IWorkloadFactory& workloadFactory,
889 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
890 float beta)
telsoa014fcda012018-03-09 14:13:49 +0000891{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000892 return SimpleSoftmaxTestImpl<uint8_t>(workloadFactory, memoryManager, beta);
telsoa014fcda012018-03-09 14:13:49 +0000893}
894
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000895LayerTestResult<float,4> CompareNormalizationTest(
896 armnn::IWorkloadFactory& workloadFactory,
897 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
898 armnn::IWorkloadFactory& refWorkloadFactory,
899 armnn::NormalizationAlgorithmChannel normChannel,
900 armnn::NormalizationAlgorithmMethod normMethod)
telsoa014fcda012018-03-09 14:13:49 +0000901{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000902 return CompareNormalizationTestImpl(workloadFactory, memoryManager, refWorkloadFactory, normChannel, normMethod);
telsoa014fcda012018-03-09 14:13:49 +0000903}
904
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000905LayerTestResult<float,2> CompareSoftmaxTest(
906 armnn::IWorkloadFactory& workloadFactory,
907 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
telsoa014fcda012018-03-09 14:13:49 +0000908 armnn::IWorkloadFactory& refWorkloadFactory,
909 float beta)
910{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000911 return CompareSoftmaxTestImpl<float>(workloadFactory, memoryManager, refWorkloadFactory, beta);
telsoa014fcda012018-03-09 14:13:49 +0000912}
913
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000914LayerTestResult<uint8_t,2> CompareSoftmaxUint8Test(
915 armnn::IWorkloadFactory& workloadFactory,
916 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
telsoa014fcda012018-03-09 14:13:49 +0000917 armnn::IWorkloadFactory& refWorkloadFactory,
918 float beta)
919{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000920 return CompareSoftmaxTestImpl<uint8_t>(workloadFactory, memoryManager, refWorkloadFactory, beta);
telsoa014fcda012018-03-09 14:13:49 +0000921}
922
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000923std::vector<LayerTestResult<float,3>> SplitterTest(
924 armnn::IWorkloadFactory& workloadFactory,
925 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +0000926{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000927 return SplitterTestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +0000928}
929
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000930std::vector<LayerTestResult<uint8_t,3>> SplitterUint8Test(
931 armnn::IWorkloadFactory& workloadFactory,
932 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +0000933{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000934 return SplitterTestCommon<uint8_t>(workloadFactory, memoryManager, 1.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +0000935}
936
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000937LayerTestResult<float, 3> CopyViaSplitterTest(
938 armnn::IWorkloadFactory& workloadFactory,
939 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +0000940{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000941 return CopyViaSplitterTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +0000942}
943
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000944LayerTestResult<uint8_t, 3> CopyViaSplitterUint8Test(
945 armnn::IWorkloadFactory& workloadFactory,
946 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +0000947{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000948 return CopyViaSplitterTestImpl<uint8_t>(workloadFactory, memoryManager, 1.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +0000949}
950
telsoa01c577f2c2018-08-31 09:22:23 +0100951LayerTestResult<float, 2> LstmLayerFloat32WithCifgWithPeepholeNoProjectionTest(
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000952 armnn::IWorkloadFactory& workloadFactory,
953 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa01c577f2c2018-08-31 09:22:23 +0100954{
955 armnn::TensorInfo inputDesc({ 2, 2 }, armnn::GetDataType<float>());
956 boost::multi_array<float, 2> input = MakeTensor<float, 2>(inputDesc, std::vector<float>(
957 { 2., 3., 3., 4. }));
958
959 armnn::TensorInfo outputDesc({ 2, 4 }, armnn::GetDataType<float>());
960 boost::multi_array<float, 2> expectedOutput = MakeTensor<float, 2>(outputDesc, std::vector<float>(
961 {-0.36444446f, -0.00352185f, 0.12886585f, -0.05163646f,
962 -0.42734814f, -0.00478661f, 0.13455015f, -0.03560682f}));
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000963 return LstmLayerWithCifgWithPeepholeNoProjectionTestImpl(
964 workloadFactory, memoryManager, input, expectedOutput);
telsoa01c577f2c2018-08-31 09:22:23 +0100965}
966
967LayerTestResult<float, 2> LstmLayerFloat32NoCifgWithPeepholeWithProjectionTest(
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000968 armnn::IWorkloadFactory& workloadFactory,
969 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa01c577f2c2018-08-31 09:22:23 +0100970{
971 armnn::TensorInfo inputDesc({ 2, 5 }, armnn::GetDataType<float>());
972 boost::multi_array<float, 2> input = MakeTensor<float, 2>(inputDesc, std::vector<float>(
973 {0.787926f, 0.151646f, 0.071352f, 0.118426f, 0.458058f,
974 0.295743f, 0.544053f, 0.690064f, 0.858138f, 0.497181f}));
975
976 armnn::TensorInfo outputDesc({ 2, 16 }, armnn::GetDataType<float>());
977 boost::multi_array<float, 2> expectedOutput = MakeTensor<float, 2>(outputDesc, std::vector<float>(
978 {-0.00396806f, 0.029352f, -0.00279226f, 0.0159977f, -0.00835576f,
979 -0.0211779f, 0.0283512f, -0.0114597f, 0.00907307f, -0.0244004f,
980 -0.0152191f, -0.0259063f, 0.00914318f, 0.00415118f, 0.017147f,
981 0.0134203f, -0.013869f, 0.0287268f, -0.00334693f, 0.00733398f, -0.0287926f,
982 -0.0186926f, 0.0193662f, -0.0115437f, 0.00422612f, -0.0345232f,
983 0.00223253f, -0.00957321f, 0.0210624f, 0.013331f, 0.0150954f,
984 0.02168f}));
Matteo Martincigha65b7ae2018-11-14 12:39:55 +0000985 return LstmLayerNoCifgWithPeepholeWithProjectionTestImpl(workloadFactory, memoryManager, input, expectedOutput);
telsoa01c577f2c2018-08-31 09:22:23 +0100986}
987
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000988LayerTestResult<float, 2> LstmLayerFloat32NoCifgNoPeepholeNoProjectionTest(
989 armnn::IWorkloadFactory& workloadFactory,
990 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa01c577f2c2018-08-31 09:22:23 +0100991{
992 armnn::TensorInfo inputDesc({2, 2}, armnn::GetDataType<float>());
993 boost::multi_array<float, 2> input = MakeTensor<float, 2>(inputDesc, std::vector<float>(
994 {2., 3., 3., 4.}));
995
996
997 armnn::TensorInfo outputDesc({2, 4}, armnn::GetDataType<float>());
998 boost::multi_array<float, 2> expectedOutput = MakeTensor<float, 2>(outputDesc, std::vector<float>(
999 {{-0.02973187f, 0.1229473f, 0.20885126f, -0.15358765f,
1000 -0.0185422f, 0.11281417f, 0.24466537f, -0.1826292f}}));
1001
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001002 return LstmNoCifgNoPeepholeNoProjectionTestImpl(
1003 workloadFactory, memoryManager, input, expectedOutput);
telsoa01c577f2c2018-08-31 09:22:23 +01001004}
1005
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001006LayerTestResult<float,3> MergerTest(
1007 armnn::IWorkloadFactory& workloadFactory,
1008 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00001009{
surmeh013537c2c2018-05-18 16:31:43 +01001010 unsigned int outputWidth = 3;
telsoa014fcda012018-03-09 14:13:49 +00001011 unsigned int outputHeight = 6;
1012 unsigned int outputChannels = 3;
1013
surmeh013537c2c2018-05-18 16:31:43 +01001014 unsigned int inputWidth1 = 3;
1015 unsigned int inputHeight1 = 6;
1016 unsigned int inputChannels1 = 2;
telsoa014fcda012018-03-09 14:13:49 +00001017
surmeh013537c2c2018-05-18 16:31:43 +01001018 unsigned int inputWidth2 = 3;
1019 unsigned int inputHeight2 = 6;
1020 unsigned int inputChannels2 = 1;
telsoa014fcda012018-03-09 14:13:49 +00001021
telsoa01c577f2c2018-08-31 09:22:23 +01001022 // Define the tensor descriptors.
telsoa014fcda012018-03-09 14:13:49 +00001023 armnn::TensorInfo outputTensorInfo({ outputChannels, outputHeight, outputWidth }, armnn::DataType::Float32);
1024 armnn::TensorInfo inputTensorInfo1({ inputChannels1, inputHeight1, inputWidth1 }, armnn::DataType::Float32);
1025 armnn::TensorInfo inputTensorInfo2({ inputChannels2, inputHeight2, inputWidth2 }, armnn::DataType::Float32);
telsoa014fcda012018-03-09 14:13:49 +00001026
1027 LayerTestResult<float,3> ret(outputTensorInfo);
1028
telsoa014fcda012018-03-09 14:13:49 +00001029 ret.outputExpected = MakeTensor<float, 3>(outputTensorInfo, std::vector<float>(
surmeh013537c2c2018-05-18 16:31:43 +01001030 {
1031 1.0f, 2.0f, 3.0f,
1032 4.0f, 5.0f, 6.0f,
1033 7.0f, 8.0f, 9.0f,
1034 10.0f, 11.0f, 12.0f,
1035 13.0f, 14.0f, 15.0f,
1036 16.0f, 17.0f, 18.0f,
telsoa014fcda012018-03-09 14:13:49 +00001037
surmeh013537c2c2018-05-18 16:31:43 +01001038 19.0f, 20.0f, 21.0f,
1039 22.0f, 23.0f, 24.0f,
1040 25.0f, 26.0f, 27.0f,
1041 28.0f, 29.0f, 30.0f,
1042 31.0f, 32.0f, 33.0f,
1043 34.0f, 35.0f, 36.0f,
telsoa014fcda012018-03-09 14:13:49 +00001044
surmeh013537c2c2018-05-18 16:31:43 +01001045 37.0f, 38.0f, 39.0f,
1046 40.0f, 41.0f, 42.0f,
1047 43.0f, 44.0f, 45.0f,
1048 46.0f, 47.0f, 48.0f,
1049 49.0f, 50.0f, 51.0f,
1050 52.0f, 53.0f, 54.0f,
telsoa014fcda012018-03-09 14:13:49 +00001051 })
1052 );
1053
telsoa014fcda012018-03-09 14:13:49 +00001054 auto input1 = MakeTensor<float, 3>(inputTensorInfo1, std::vector<float>(
1055 {
surmeh013537c2c2018-05-18 16:31:43 +01001056 1.0f, 2.0f, 3.0f,
1057 4.0f, 5.0f, 6.0f,
1058 7.0f, 8.0f, 9.0f,
1059 10.0f, 11.0f, 12.0f,
1060 13.0f, 14.0f, 15.0f,
1061 16.0f, 17.0f, 18.0f,
telsoa014fcda012018-03-09 14:13:49 +00001062
surmeh013537c2c2018-05-18 16:31:43 +01001063 19.0f, 20.0f, 21.0f,
1064 22.0f, 23.0f, 24.0f,
1065 25.0f, 26.0f, 27.0f,
1066 28.0f, 29.0f, 30.0f,
1067 31.0f, 32.0f, 33.0f,
1068 34.0f, 35.0f, 36.0f,
telsoa014fcda012018-03-09 14:13:49 +00001069 })
1070 );
1071
1072 auto input2 = MakeTensor<float, 3>(inputTensorInfo2, std::vector<float>(
1073 {
surmeh013537c2c2018-05-18 16:31:43 +01001074 37.0f, 38.0f, 39.0f,
1075 40.0f, 41.0f, 42.0f,
telsoa014fcda012018-03-09 14:13:49 +00001076 43.0f, 44.0f, 45.0f,
surmeh013537c2c2018-05-18 16:31:43 +01001077 46.0f, 47.0f, 48.0f,
1078 49.0f, 50.0f, 51.0f,
1079 52.0f, 53.0f, 54.0f,
telsoa014fcda012018-03-09 14:13:49 +00001080 })
1081 );
1082
telsoa01c577f2c2018-08-31 09:22:23 +01001083 std::vector<unsigned int> wOrigin1 = {0, 0, 0}; //Extent of the window is defined by size of input[0].
telsoa014fcda012018-03-09 14:13:49 +00001084 armnn::MergerQueueDescriptor::ViewOrigin window1(wOrigin1);
1085
telsoa01c577f2c2018-08-31 09:22:23 +01001086 std::vector<unsigned int> wOrigin2 = {2, 0, 0}; //Extent of the window is defined by size of input[1].
telsoa014fcda012018-03-09 14:13:49 +00001087 armnn::MergerQueueDescriptor::ViewOrigin window2(wOrigin2);
1088
telsoa014fcda012018-03-09 14:13:49 +00001089 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
1090
1091 bool subTensorsSupported = workloadFactory.SupportsSubTensors();
1092
1093 std::unique_ptr<armnn::ITensorHandle> inputHandle1 =
1094 subTensorsSupported ?
1095 workloadFactory.CreateSubTensorHandle(*outputHandle, inputTensorInfo1.GetShape(), wOrigin1.data()) :
1096 workloadFactory.CreateTensorHandle(inputTensorInfo1);
1097
1098 std::unique_ptr<armnn::ITensorHandle> inputHandle2 =
1099 subTensorsSupported ?
1100 workloadFactory.CreateSubTensorHandle(*outputHandle, inputTensorInfo2.GetShape(), wOrigin2.data()) :
1101 workloadFactory.CreateTensorHandle(inputTensorInfo2);
1102
telsoa014fcda012018-03-09 14:13:49 +00001103 armnn::MergerQueueDescriptor data;
1104 armnn::WorkloadInfo info;
1105 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
1106 AddInputToWorkload(data, info, inputTensorInfo2, inputHandle2.get());
telsoa014fcda012018-03-09 14:13:49 +00001107 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1108
1109 data.m_ViewOrigins.push_back(window1);
1110 data.m_ViewOrigins.push_back(window2);
telsoa014fcda012018-03-09 14:13:49 +00001111
1112 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateMerger(data, info);
1113
1114 inputHandle1->Allocate();
1115 inputHandle2->Allocate();
telsoa014fcda012018-03-09 14:13:49 +00001116 outputHandle->Allocate();
1117
1118 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0]);
1119 CopyDataToITensorHandle(inputHandle2.get(), &input2[0][0][0]);
telsoa014fcda012018-03-09 14:13:49 +00001120
1121 workload->Execute();
1122
1123 CopyDataFromITensorHandle(&ret.output[0][0][0], outputHandle.get());
1124
1125 return ret;
1126}
1127
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001128LayerTestResult<float,4> AdditionTest(
1129 armnn::IWorkloadFactory& workloadFactory,
1130 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00001131{
1132 unsigned int batchSize = 2;
1133 unsigned int channels = 2;
1134 unsigned int height = 2;
1135 unsigned int width = 3;
1136
1137 armnn::TensorInfo inputTensorInfo1, inputTensorInfo2;
1138 armnn::TensorInfo outputTensorInfo;
1139
1140 unsigned int shape[] = {batchSize, channels, height, width};
1141
1142 inputTensorInfo1 = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
1143 inputTensorInfo2 = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
1144 outputTensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
1145
1146
1147 auto input1 = MakeTensor<float, 4>(inputTensorInfo1, std::vector<float>(
1148 {
1149 0.0f, 2.0f, 1.0f,
1150 0.2f, 1.0f, 2.0f,
1151
1152 1.0f, 2.0f, 1.0f,
1153 0.2f, 1.0f, 2.0f,
1154
1155 0.0f, 2.0f, 1.0f,
1156 4.2f, 1.0f, 2.0f,
1157
1158 0.0f, 0.0f, 1.0f,
1159 0.2f, 1.0f, 2.0f,
1160 }));
1161
1162 auto input2 = MakeTensor<float, 4>(inputTensorInfo2, std::vector<float>(
1163 {
1164 1.0f, 2.0f, 1.0f,
1165 0.0f, 1.0f, 2.0f,
1166
1167 1.0f, 2.0f, -2.0f,
1168 0.2f, 1.0f, 2.0f,
1169
1170 0.0f, 2.0f, 1.0f,
1171 4.2f, 0.0f, -3.0f,
1172
1173 0.0f, 0.0f, 1.0f,
1174 0.7f, 1.0f, 5.0f,
1175 }));
1176
1177 LayerTestResult<float,4> ret(outputTensorInfo);
1178 ret.outputExpected = MakeTensor<float, 4>(outputTensorInfo, std::vector<float>(
1179 {
1180 1.0f, 4.0f, 2.0f,
1181 0.2f, 2.0f, 4.0f,
1182
1183 2.0f, 4.0f, -1.0f,
1184 0.4f, 2.0f, 4.0f,
1185
1186 0.0f, 4.0f, 2.0f,
1187 8.4f, 1.0f, -1.0f,
1188
1189 0.0f, 0.0f, 2.0f,
1190 0.9f, 2.0f, 7.0f,
1191 }));
1192
1193 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
1194 std::unique_ptr<armnn::ITensorHandle> inputHandle2 = workloadFactory.CreateTensorHandle(inputTensorInfo2);
1195 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
1196
1197 armnn::AdditionQueueDescriptor data;
1198 armnn::WorkloadInfo info;
1199 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
1200 AddInputToWorkload(data, info, inputTensorInfo2, inputHandle2.get());
1201 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1202
1203 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateAddition(data, info);
1204
1205 inputHandle1->Allocate();
1206 inputHandle2->Allocate();
1207 outputHandle->Allocate();
1208
1209 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
1210 CopyDataToITensorHandle(inputHandle2.get(), &input2[0][0][0][0]);
1211
1212 workload->Execute();
1213
1214 CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
1215
1216 return ret;
1217}
1218
1219template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001220LayerTestResult<T, 4> AdditionBroadcastTestImpl(
1221 armnn::IWorkloadFactory& workloadFactory,
1222 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
telsoa014fcda012018-03-09 14:13:49 +00001223 float qScale,
1224 int32_t qOffset)
1225{
1226 armnn::TensorInfo inputTensorInfo1 = armnn::TensorInfo({1, 3, 2, 1}, armnn::GetDataType<T>());
1227 armnn::TensorInfo inputTensorInfo2 = armnn::TensorInfo({1, 1, 2, 3}, armnn::GetDataType<T>());
1228 armnn::TensorInfo outputTensorInfo = armnn::TensorInfo({1, 3, 2, 3}, armnn::GetDataType<T>());
1229
1230 if (armnn::IsQuantizedType<T>())
1231 {
1232 inputTensorInfo1.SetQuantizationScale(qScale);
1233 inputTensorInfo1.SetQuantizationOffset(qOffset);
1234 inputTensorInfo2.SetQuantizationScale(qScale);
1235 inputTensorInfo2.SetQuantizationOffset(qOffset);
1236 outputTensorInfo.SetQuantizationScale(qScale);
1237 outputTensorInfo.SetQuantizationOffset(qOffset);
1238 }
1239
1240 auto input1 = MakeTensor<T, 4>(inputTensorInfo1, QuantizedVector<T>(qScale, qOffset,
1241 {
1242 0.0f,
1243 1.0f,
1244
1245 2.0f,
1246 3.0f,
1247
1248 4.0f,
1249 5.0f,
1250 }));
1251
1252 auto input2 = MakeTensor<T, 4>(inputTensorInfo2, QuantizedVector<T>(qScale, qOffset,
1253 {
1254 0.5f, 1.5f, 2.5f,
1255 3.5f, 4.5f, 5.5f,
1256 }));
1257
1258 LayerTestResult<T,4> ret(outputTensorInfo);
1259 ret.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset,
1260 {
1261 0.5f, 1.5f, 2.5f,
1262 4.5f, 5.5f, 6.5f,
1263
1264 2.5f, 3.5f, 4.5f,
1265 6.5f, 7.5f, 8.5f,
1266
1267 4.5f, 5.5f, 6.5f,
1268 8.5f, 9.5f, 10.5f,
1269 }));
1270
1271 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
1272 std::unique_ptr<armnn::ITensorHandle> inputHandle2 = workloadFactory.CreateTensorHandle(inputTensorInfo2);
1273 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
1274
1275 armnn::AdditionQueueDescriptor data;
1276 armnn::WorkloadInfo info;
1277 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
1278 AddInputToWorkload(data, info, inputTensorInfo2, inputHandle2.get());
1279 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1280
1281 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateAddition(data, info);
1282
1283 inputHandle1->Allocate();
1284 inputHandle2->Allocate();
1285 outputHandle->Allocate();
1286
1287 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
1288 CopyDataToITensorHandle(inputHandle2.get(), &input2[0][0][0][0]);
1289
1290 workload->Execute();
1291
1292 CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
1293
1294 return ret;
1295}
1296
1297template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001298LayerTestResult<T, 4> AdditionBroadcast1ElementTestImpl(
1299 armnn::IWorkloadFactory& workloadFactory,
1300 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
telsoa014fcda012018-03-09 14:13:49 +00001301 float qScale,
1302 int32_t qOffset)
1303{
1304 armnn::TensorInfo inputTensorInfo1 = armnn::TensorInfo({1, 3, 2, 3}, armnn::GetDataType<T>());
1305 armnn::TensorInfo inputTensorInfo2 = armnn::TensorInfo({1, 1, 1, 1}, armnn::GetDataType<T>());
1306 armnn::TensorInfo outputTensorInfo = armnn::TensorInfo({1, 3, 2, 3}, armnn::GetDataType<T>());
1307
1308 if (armnn::IsQuantizedType<T>())
1309 {
1310 inputTensorInfo1.SetQuantizationScale(qScale);
1311 inputTensorInfo1.SetQuantizationOffset(qOffset);
1312 inputTensorInfo2.SetQuantizationScale(qScale);
1313 inputTensorInfo2.SetQuantizationOffset(qOffset);
1314 outputTensorInfo.SetQuantizationScale(qScale);
1315 outputTensorInfo.SetQuantizationOffset(qOffset);
1316 }
1317
1318 auto input1 = MakeTensor<T, 4>(inputTensorInfo1, QuantizedVector<T>(qScale, qOffset,
1319 {
1320 0.0f, 1.0f, 2.0f,
1321 3.0f, 4.0f, 5.0f,
1322 6.0f, 7.0f, 8.0f,
1323 9.0f, 10.0f, 11.0f,
1324 12.0f, 13.0f, 14.0f,
1325 15.0f, 16.0f, 17.0f,
1326 }));
1327
1328 auto input2 = MakeTensor<T, 4>(inputTensorInfo2, QuantizedVector<T>(qScale, qOffset,
1329 {
1330 0.5f,
1331 }));
1332
1333 LayerTestResult<T,4> ret(outputTensorInfo);
1334 ret.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset,
1335 {
1336 0.5f, 1.5f, 2.5f,
1337 3.5f, 4.5f, 5.5f,
1338 6.5f, 7.5f, 8.5f,
1339 9.5f, 10.5f, 11.5f,
1340 12.5f, 13.5f, 14.5f,
1341 15.5f, 16.5f, 17.5f,
1342 }));
1343
1344 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
1345 std::unique_ptr<armnn::ITensorHandle> inputHandle2 = workloadFactory.CreateTensorHandle(inputTensorInfo2);
1346 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
1347
1348 armnn::AdditionQueueDescriptor data;
1349 armnn::WorkloadInfo info;
1350 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
1351 AddInputToWorkload(data, info, inputTensorInfo2, inputHandle2.get());
1352 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1353
1354 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateAddition(data, info);
1355
1356 inputHandle1->Allocate();
1357 inputHandle2->Allocate();
1358 outputHandle->Allocate();
1359
1360 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
1361 CopyDataToITensorHandle(inputHandle2.get(), &input2[0][0][0][0]);
1362
1363 workload->Execute();
1364
1365 CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
1366
1367 return ret;
1368}
1369
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001370LayerTestResult<float, 4> AdditionBroadcastTest(
1371 armnn::IWorkloadFactory& workloadFactory,
1372 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00001373{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001374 return AdditionBroadcastTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00001375}
1376
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001377LayerTestResult<uint8_t, 4> AdditionBroadcastUint8Test(
1378 armnn::IWorkloadFactory& workloadFactory,
1379 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00001380{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001381 return AdditionBroadcastTestImpl<uint8_t>(workloadFactory, memoryManager, 2.f, 0);
telsoa014fcda012018-03-09 14:13:49 +00001382}
1383
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001384LayerTestResult<float, 4> AdditionBroadcast1ElementTest(
1385 armnn::IWorkloadFactory& workloadFactory,
1386 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00001387{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001388 return AdditionBroadcast1ElementTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00001389}
1390
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001391LayerTestResult<uint8_t, 4> AdditionBroadcast1ElementUint8Test(
1392 armnn::IWorkloadFactory& workloadFactory,
1393 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00001394{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001395 return AdditionBroadcast1ElementTestImpl<uint8_t>(workloadFactory, memoryManager, 0.1333333f, 128);
telsoa014fcda012018-03-09 14:13:49 +00001396}
1397
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001398LayerTestResult<float,4> CompareAdditionTest(
1399 armnn::IWorkloadFactory& workloadFactory,
1400 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1401 armnn::IWorkloadFactory& refWorkloadFactory)
telsoa014fcda012018-03-09 14:13:49 +00001402{
1403 unsigned int batchSize = 4;
1404 unsigned int channels = 1;
1405 unsigned int height = 2;
1406 unsigned int width = 3;
1407
1408 armnn::TensorInfo inputTensorInfo1, inputTensorInfo2;
1409 armnn::TensorInfo outputTensorInfo;
1410
1411 unsigned int shape[] = {batchSize, channels, height, width};
1412
1413 inputTensorInfo1 = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
1414 inputTensorInfo2 = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
1415 outputTensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
1416
1417 auto input1 = MakeRandomTensor<float, 4>(inputTensorInfo1, 1232);
1418 auto input2 = MakeRandomTensor<float, 4>(inputTensorInfo2, 456);
1419
1420 LayerTestResult<float,4> ret(outputTensorInfo);
1421
1422 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
1423 std::unique_ptr<armnn::ITensorHandle> inputHandle2 = workloadFactory.CreateTensorHandle(inputTensorInfo2);
1424 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
1425
1426 std::unique_ptr<armnn::ITensorHandle> inputHandle1Ref = refWorkloadFactory.CreateTensorHandle(inputTensorInfo1);
1427 std::unique_ptr<armnn::ITensorHandle> inputHandle2Ref = refWorkloadFactory.CreateTensorHandle(inputTensorInfo2);
1428 std::unique_ptr<armnn::ITensorHandle> outputHandleRef = refWorkloadFactory.CreateTensorHandle(outputTensorInfo);
1429
1430 armnn::AdditionQueueDescriptor data;
1431 armnn::WorkloadInfo info;
1432 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
1433 AddInputToWorkload(data, info, inputTensorInfo2, inputHandle2.get());
1434 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1435
1436 armnn::AdditionQueueDescriptor refData = data;
1437 armnn::WorkloadInfo refInfo = info;
1438 SetWorkloadInput(refData, refInfo, 0, inputTensorInfo1, inputHandle1Ref.get());
1439 SetWorkloadInput(refData, refInfo, 1, inputTensorInfo2, inputHandle2Ref.get());
1440 SetWorkloadOutput(refData, refInfo, 0, outputTensorInfo, outputHandleRef.get());
1441
1442 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateAddition(data, info);
1443 std::unique_ptr<armnn::IWorkload> workloadRef = refWorkloadFactory.CreateAddition(refData, refInfo);
1444
1445 inputHandle1->Allocate();
1446 inputHandle2->Allocate();
1447 outputHandle->Allocate();
1448 inputHandle1Ref->Allocate();
1449 inputHandle2Ref->Allocate();
1450 outputHandleRef->Allocate();
1451
1452 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
1453 CopyDataToITensorHandle(inputHandle2.get(), &input2[0][0][0][0]);
1454 CopyDataToITensorHandle(inputHandle1Ref.get(), &input1[0][0][0][0]);
1455 CopyDataToITensorHandle(inputHandle2Ref.get(), &input2[0][0][0][0]);
1456
1457 workload->Execute();
1458 workloadRef->Execute();
1459
1460 CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
1461 CopyDataFromITensorHandle(&ret.outputExpected[0][0][0][0], outputHandleRef.get());
1462
1463 return ret;
1464}
1465
surmeh01bceff2f2018-03-29 16:29:27 +01001466namespace {
David Beck5cd01f32018-09-12 16:00:08 +01001467template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001468LayerTestResult<T, 4> DivisionTestHelper(
1469 armnn::IWorkloadFactory& workloadFactory,
1470 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1471 const unsigned int shape0[4],
1472 const std::vector<T>& values0,
1473 float scale0,
1474 int32_t offset0,
1475 const unsigned int shape1[4],
1476 const std::vector<T> & values1,
1477 float scale1,
1478 int32_t offset1,
1479 const unsigned int outShape[4],
1480 const std::vector<T> & outValues,
1481 float outScale,
1482 int32_t outOffset)
David Beck5cd01f32018-09-12 16:00:08 +01001483{
1484 auto dataType = (std::is_same<T, uint8_t>::value ?
1485 armnn::DataType::QuantisedAsymm8 :
1486 armnn::DataType::Float32);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001487
David Beck5cd01f32018-09-12 16:00:08 +01001488 armnn::TensorInfo inputTensorInfo0(4, shape0, dataType);
1489 armnn::TensorInfo inputTensorInfo1(4, shape1, dataType);
1490 armnn::TensorInfo outputTensorInfo(4, outShape, dataType);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001491
David Beck5cd01f32018-09-12 16:00:08 +01001492 inputTensorInfo0.SetQuantizationScale(scale0);
1493 inputTensorInfo0.SetQuantizationOffset(offset0);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001494
David Beck5cd01f32018-09-12 16:00:08 +01001495 inputTensorInfo1.SetQuantizationScale(scale1);
1496 inputTensorInfo1.SetQuantizationOffset(offset1);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001497
David Beck5cd01f32018-09-12 16:00:08 +01001498 outputTensorInfo.SetQuantizationScale(outScale);
1499 outputTensorInfo.SetQuantizationOffset(outOffset);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001500
David Beck5cd01f32018-09-12 16:00:08 +01001501 auto input0 = MakeTensor<T, 4>(inputTensorInfo0, values0);
1502 auto input1 = MakeTensor<T, 4>(inputTensorInfo1, values1);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001503
David Beck5cd01f32018-09-12 16:00:08 +01001504 LayerTestResult<T, 4> result(outputTensorInfo);
1505 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, outValues);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001506
David Beck5cd01f32018-09-12 16:00:08 +01001507 std::unique_ptr<armnn::ITensorHandle> inputHandle0 = workloadFactory.CreateTensorHandle(inputTensorInfo0);
1508 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
1509 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001510
David Beck5cd01f32018-09-12 16:00:08 +01001511 armnn::DivisionQueueDescriptor data;
1512 armnn::WorkloadInfo info;
1513 AddInputToWorkload(data, info, inputTensorInfo0, inputHandle0.get());
1514 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
1515 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001516
David Beck5cd01f32018-09-12 16:00:08 +01001517 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateDivision(data, info);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001518
David Beck5cd01f32018-09-12 16:00:08 +01001519 inputHandle0->Allocate();
1520 inputHandle1->Allocate();
1521 outputHandle->Allocate();
1522
1523 CopyDataToITensorHandle(inputHandle0.get(), &input0[0][0][0][0]);
1524 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
1525
David Beck5cd01f32018-09-12 16:00:08 +01001526 workload->Execute();
1527
1528 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
1529
1530 return result;
1531}
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001532} // anonymous namespace
1533
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001534LayerTestResult<float,4> DivisionByZeroTest(
1535 armnn::IWorkloadFactory& workloadFactory,
1536 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Francis Murtagh8c5e3dc2018-08-30 17:18:37 +01001537{
1538 const unsigned int width = 2;
1539 const unsigned int height = 2;
1540 const unsigned int channelCount = 2;
1541 const unsigned int batchSize = 2;
1542
1543 unsigned int shape[] = { batchSize, channelCount, height, width };
1544
1545 std::vector<float> input0({
1546 1.f, 1.f, 1.f, 1.f, 0.f, 0.f, 0.f, 0.f,
1547 -1.f, -1.f, -1.f, -1.f, 5.f, 5.f, 5.f, 5.f });
1548
1549 std::vector<float> input1({
1550 0.f, 0.f, -0.f, -0.f, 0.f, 0.f, -0.f, -0.f,
1551 0.f, 0.f, -0.f, -0.f, 5.f, 5.f, 5.f, 5.f });
1552
1553 std::vector<float> output({
1554 INFINITY, INFINITY, -INFINITY, -INFINITY, NAN, NAN, -NAN, -NAN,
1555 -INFINITY, -INFINITY, INFINITY, INFINITY, 1, 1, 1, 1 });
1556
David Beck5cd01f32018-09-12 16:00:08 +01001557 return DivisionTestHelper<float>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001558 memoryManager,
David Beck5cd01f32018-09-12 16:00:08 +01001559 shape, input0, 1.0f, 0,
1560 shape, input1, 1.0f, 0,
1561 shape, output, 1.0f, 0);
Francis Murtagh8c5e3dc2018-08-30 17:18:37 +01001562}
1563
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001564LayerTestResult<float,4> DivisionTest(
1565 armnn::IWorkloadFactory& workloadFactory,
1566 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001567{
1568 const unsigned int width = 2;
1569 const unsigned int height = 2;
1570 const unsigned int channelCount = 2;
1571 const unsigned int batchSize = 2;
1572
1573 unsigned int shape[] = { batchSize, channelCount, height, width };
1574
1575 std::vector<float> input0({
1576 2, 2, 2, 2, 3, 3, 3, 3,
1577 4, 4, 4, 4, 5, 5, 5, 5 });
1578
1579 std::vector<float> input1({
1580 1, 1, 1, 1, 2, 2, 2, 2,
1581 4, 4, 4, 4, 4, 4, 4, 4 });
1582
1583 std::vector<float> output({
1584 2, 2, 2, 2, 1.5, 1.5, 1.5, 1.5,
1585 1, 1, 1, 1, 1.25, 1.25, 1.25, 1.25 });
1586
David Beck5cd01f32018-09-12 16:00:08 +01001587
1588 return DivisionTestHelper<float>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001589 memoryManager,
David Beck5cd01f32018-09-12 16:00:08 +01001590 shape, input0, 1.0f, 0,
1591 shape, input1, 1.0f, 0,
1592 shape, output, 1.0f, 0);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001593}
1594
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001595LayerTestResult<float, 4> DivisionBroadcast1ElementTest(
1596 armnn::IWorkloadFactory& workloadFactory,
1597 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001598{
1599 unsigned int shape0[] = { 1, 2, 2, 2 };
1600 std::vector<float> input0({ 2, 4, 6, 8, 10, 12, 14, 16});
1601
1602 unsigned int shape1[] = { 1, 1, 1, 1 };
1603 std::vector<float> input1({ 2 });
1604
1605 std::vector<float> output({ 1, 2, 3, 4, 5, 6, 7, 8});
1606
David Beck5cd01f32018-09-12 16:00:08 +01001607
1608 return DivisionTestHelper<float>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001609 memoryManager,
David Beck5cd01f32018-09-12 16:00:08 +01001610 shape0, input0, 1.0f, 0,
1611 shape1, input1, 1.0f, 0,
1612 shape0, output, 1.0f, 0);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001613}
1614
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001615LayerTestResult<float, 4> DivisionBroadcast1DVectorTest(
1616 armnn::IWorkloadFactory& workloadFactory,
1617 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001618{
1619 unsigned int shape0[] = { 1, 3, 3, 2 };
1620 std::vector<float> input0({
1621 1, 4, 3, 8, 5, 12,
1622 7, 16, 9, 20, 11, 24,
1623 13, 28, 15, 32, 17, 36});
1624
1625 unsigned int shape1[] = { 1, 1, 1, 2 };
1626 std::vector<float> input1({ 1, 2 });
1627
1628 std::vector<float> output({
1629 1, 2, 3, 4, 5, 6,
1630 7, 8, 9, 10, 11, 12,
1631 13, 14, 15, 16, 17, 18});
1632
David Beck5cd01f32018-09-12 16:00:08 +01001633 return DivisionTestHelper<float>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001634 memoryManager,
David Beck5cd01f32018-09-12 16:00:08 +01001635 shape0, input0, 1.0f, 0,
1636 shape1, input1, 1.0f, 0,
1637 shape0, output, 1.0f, 0);
1638}
1639
1640
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001641LayerTestResult<uint8_t,4> DivisionUint8Test(
1642 armnn::IWorkloadFactory& workloadFactory,
1643 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beck5cd01f32018-09-12 16:00:08 +01001644{
1645 const unsigned int width = 2;
1646 const unsigned int height = 2;
1647 const unsigned int channelCount = 2;
1648 const unsigned int batchSize = 2;
1649
1650 unsigned int shape[] = { batchSize, channelCount, height, width };
1651
1652 std::vector<uint8_t> input0({2, 2, 2, 2, 3, 3, 3, 3,
1653 4, 4, 4, 4, 5, 5, 5, 5 });
1654
1655 std::vector<uint8_t> input1({1, 1, 1, 1, 2, 2, 2, 2,
1656 4, 4, 4, 4, 4, 4, 4, 4 });
1657
1658 std::vector<uint8_t> output({8, 8, 8, 8, 6, 6, 6, 6,
1659 4, 4, 4, 4, 5, 5, 5, 5});
1660
1661
1662 return DivisionTestHelper<uint8_t>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001663 memoryManager,
1664 shape, input0, 1.0f, 0,
1665 shape, input1, 1.0f, 0,
1666 shape, output, 0.25f, 0);
David Beck5cd01f32018-09-12 16:00:08 +01001667}
1668
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001669LayerTestResult<uint8_t, 4> DivisionBroadcast1ElementUint8Test(
1670 armnn::IWorkloadFactory& workloadFactory,
1671 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beck5cd01f32018-09-12 16:00:08 +01001672{
1673 unsigned int shape0[] = { 1, 2, 2, 2 };
1674 std::vector<uint8_t> input0({ 2, 4, 6, 8, 10, 12, 14, 16});
1675
1676 unsigned int shape1[] = { 1, 1, 1, 1 };
1677 std::vector<uint8_t> input1({ 2 });
1678
1679 std::vector<uint8_t> output({ 1, 2, 3, 4, 5, 6, 7, 8});
1680
1681 return DivisionTestHelper<uint8_t>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001682 memoryManager,
1683 shape0, input0, 1.0f, 0,
1684 shape1, input1, 1.0f, 0,
1685 shape0, output, 1.0f, 0);
David Beck5cd01f32018-09-12 16:00:08 +01001686}
1687
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001688LayerTestResult<uint8_t, 4> DivisionBroadcast1DVectorUint8Test(
1689 armnn::IWorkloadFactory& workloadFactory,
1690 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beck5cd01f32018-09-12 16:00:08 +01001691{
1692 unsigned int shape0[] = { 1, 3, 3, 2 };
1693 std::vector<uint8_t> input0({1, 4, 3, 8, 5, 12,
1694 7, 16, 9, 20, 11, 24,
1695 13, 28, 15, 32, 17, 36});
1696
1697 unsigned int shape1[] = { 1, 1, 1, 2 };
1698 std::vector<uint8_t> input1({ 1, 2 });
1699
1700 std::vector<uint8_t> output({1, 2, 3, 4, 5, 6,
1701 7, 8, 9, 10, 11, 12,
1702 13, 14, 15, 16, 17, 18});
1703
1704 return DivisionTestHelper<uint8_t>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001705 memoryManager,
1706 shape0, input0, 1.0f, 0,
1707 shape1, input1, 1.0f, 0,
1708 shape0, output, 1.0f, 0);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001709}
1710
Éanna Ó Catháinde705582018-12-03 13:04:22 +00001711template<typename DescriptorType>
1712std::unique_ptr<armnn::IWorkload> CreateWorkload(
1713 const armnn::IWorkloadFactory& workloadFactory,
1714 const armnn::WorkloadInfo& info,
1715 const DescriptorType& descriptor)
1716{
1717 return CreateWorkload(workloadFactory, info, descriptor);
1718};
1719
1720template<>
1721std::unique_ptr<armnn::IWorkload> CreateWorkload<armnn::MaximumQueueDescriptor>(
1722 const armnn::IWorkloadFactory& workloadFactory,
1723 const armnn::WorkloadInfo& info,
1724 const armnn::MaximumQueueDescriptor& descriptor)
1725{
1726 return workloadFactory.CreateMaximum(descriptor, info);
1727}
1728
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001729template<>
1730std::unique_ptr<armnn::IWorkload> CreateWorkload<armnn::MinimumQueueDescriptor>(
1731 const armnn::IWorkloadFactory& workloadFactory,
1732 const armnn::WorkloadInfo& info,
1733 const armnn::MinimumQueueDescriptor& descriptor)
1734{
1735 return workloadFactory.CreateMinimum(descriptor, info);
1736}
1737
FrancisMurtagh30cdfca2018-12-18 12:57:35 +00001738template<>
1739std::unique_ptr<armnn::IWorkload> CreateWorkload<armnn::EqualQueueDescriptor>(
1740 const armnn::IWorkloadFactory& workloadFactory,
1741 const armnn::WorkloadInfo& info,
1742 const armnn::EqualQueueDescriptor& descriptor)
1743{
1744 return workloadFactory.CreateEqual(descriptor, info);
1745}
1746
FrancisMurtagh878f0232018-12-19 10:56:15 +00001747template<>
1748std::unique_ptr<armnn::IWorkload> CreateWorkload<armnn::GreaterQueueDescriptor>(
1749 const armnn::IWorkloadFactory& workloadFactory,
1750 const armnn::WorkloadInfo& info,
1751 const armnn::GreaterQueueDescriptor& descriptor)
1752{
1753 return workloadFactory.CreateGreater(descriptor, info);
1754}
1755
Éanna Ó Catháinde705582018-12-03 13:04:22 +00001756namespace {
1757 template <typename Descriptor, typename dataType>
1758 LayerTestResult<dataType, 4> ElementwiseTestHelper
1759 (armnn::IWorkloadFactory & workloadFactory,
1760 const armnn::IBackendInternal::IMemoryManagerSharedPtr & memoryManager,
1761 const unsigned int shape0[4], std::vector<dataType> values0,
1762 const unsigned int shape1[4], std::vector<dataType> values1,
1763 const unsigned int outShape[4], std::vector<dataType> outValues,
1764 float qScale = 0.0f, int qOffset = 0)
1765 {
1766 const size_t dimensionCount = 4;
1767 armnn::TensorInfo inputTensorInfo0{dimensionCount, shape0, armnn::GetDataType<dataType>()};
1768 armnn::TensorInfo inputTensorInfo1{dimensionCount, shape1, armnn::GetDataType<dataType>()};
1769 armnn::TensorInfo outputTensorInfo{dimensionCount, outShape, armnn::GetDataType<dataType>()};
1770
1771 auto input0 = MakeTensor<dataType, 4>(inputTensorInfo0, values0);
1772 auto input1 = MakeTensor<dataType, 4>(inputTensorInfo1, values1);
1773
1774 if (armnn::IsQuantizedType<dataType>())
1775 {
1776 inputTensorInfo0.SetQuantizationScale(qScale);
1777 inputTensorInfo0.SetQuantizationOffset(qOffset);
1778
1779 inputTensorInfo1.SetQuantizationScale(qScale);
1780 inputTensorInfo1.SetQuantizationOffset(qOffset);
1781
1782 outputTensorInfo.SetQuantizationScale(qScale);
1783 outputTensorInfo.SetQuantizationOffset(qOffset);
1784 }
1785
1786 LayerTestResult<dataType,4> ret(outputTensorInfo);
1787
1788 std::unique_ptr<armnn::ITensorHandle> inputHandle0 = workloadFactory.CreateTensorHandle(inputTensorInfo0);
1789 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
1790 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
1791
1792 Descriptor data;
1793 armnn::WorkloadInfo info;
1794 AddInputToWorkload(data, info, inputTensorInfo0, inputHandle0.get());
1795 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
1796 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1797 auto workload = CreateWorkload<Descriptor>(workloadFactory, info, data);
1798
1799 inputHandle0->Allocate();
1800 inputHandle1->Allocate();
1801 outputHandle->Allocate();
1802
1803 CopyDataToITensorHandle(inputHandle0.get(), &input0[0][0][0][0]);
1804 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
1805
1806 ExecuteWorkload(*workload, memoryManager);
1807
1808 CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
1809
1810 ret.outputExpected = MakeTensor<dataType, 4>(outputTensorInfo, outValues);
1811 return ret;
1812 }
1813}
1814
FrancisMurtagh30cdfca2018-12-18 12:57:35 +00001815LayerTestResult<float, 4> EqualSimpleTest(armnn::IWorkloadFactory& workloadFactory,
1816 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
1817{
1818 const unsigned int width = 2;
1819 const unsigned int height = 2;
1820 const unsigned int channelCount = 2;
1821 const unsigned int batchSize = 2;
1822
1823 unsigned int shape[] = { batchSize, channelCount, height, width };
1824
1825 std::vector<float> input0({ 1, 1, 1, 1, 5, 5, 5, 5,
1826 3, 3, 3, 3, 4, 4, 4, 4 });
1827
1828 std::vector<float> input1({ 1, 1, 1, 1, 3, 3, 3, 3,
1829 5, 5, 5, 5, 4, 4, 4, 4 });
1830
1831 std::vector<float> output({ 1, 1, 1, 1, 0, 0, 0, 0,
1832 0, 0, 0, 0, 1, 1, 1, 1 });
1833
1834 return ElementwiseTestHelper<armnn::EqualQueueDescriptor, float>
1835 (workloadFactory,
1836 memoryManager,
1837 shape,
1838 input0,
1839 shape,
1840 input1,
1841 shape,
1842 output);
1843}
1844
1845LayerTestResult<float, 4> EqualBroadcast1ElementTest(
1846 armnn::IWorkloadFactory& workloadFactory,
1847 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
1848{
1849 unsigned int shape0[] = { 1, 2, 2, 2 };
1850 std::vector<float> input0({ 1, 2, 3, 4, 5, 6, 7, 8});
1851
1852 unsigned int shape1[] = { 1, 1, 1, 1 };
1853 std::vector<float> input1({ 1 });
1854
1855 std::vector<float> output({ 1, 0, 0, 0, 0, 0, 0, 0});
1856
1857 return ElementwiseTestHelper<armnn::EqualQueueDescriptor, float>
1858 (workloadFactory,
1859 memoryManager,
1860 shape0,
1861 input0,
1862 shape1,
1863 input1,
1864 shape0,
1865 output);
1866}
1867
1868LayerTestResult<float, 4> EqualBroadcast1DVectorTest(
1869 armnn::IWorkloadFactory& workloadFactory,
1870 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
1871{
1872 const unsigned int shape0[] = { 1, 2, 2, 3 };
1873 const unsigned int shape1[] = { 1, 1, 1, 3 };
1874
1875 std::vector<float> input0({ 1, 2, 3, 4, 5, 6,
1876 7, 8, 9, 10, 11, 12 });
1877
1878 std::vector<float> input1({ 1, 2, 3});
1879
1880 std::vector<float> output({ 1, 1, 1, 0, 0, 0,
1881 0, 0, 0, 0, 0, 0 });
1882
1883 return ElementwiseTestHelper<armnn::EqualQueueDescriptor, float>
1884 (workloadFactory,
1885 memoryManager,
1886 shape0,
1887 input0,
1888 shape1,
1889 input1,
1890 shape0,
1891 output);
1892}
1893
1894LayerTestResult<uint8_t, 4> EqualUint8Test(
1895 armnn::IWorkloadFactory& workloadFactory,
1896 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
1897{
1898 unsigned int shape[] = { 2, 2, 2, 2 };
1899
1900 // See dequantized values to the right.
1901 std::vector<uint8_t> input0({ 1, 1, 1, 1, 6, 6, 6, 6,
1902 3, 3, 3, 3, 5, 5, 5, 5 });
1903
1904 std::vector<uint8_t> input1({ 2, 2, 2, 2, 6, 6, 6, 6,
1905 3, 3, 3, 3, 5, 5, 5, 5 });
1906
1907 std::vector<uint8_t> output({ 0, 0, 0, 0, 1, 1, 1, 1,
1908 1, 1, 1, 1, 0, 0, 0, 0 });
1909
1910 return ElementwiseTestHelper<armnn::EqualQueueDescriptor, uint8_t >
1911 (workloadFactory,
1912 memoryManager,
1913 shape,
1914 input0,
1915 shape,
1916 input1,
1917 shape,
1918 output,
1919 1.0f,
1920 0);
1921}
1922
1923LayerTestResult<uint8_t, 4> EqualBroadcast1ElementUint8Test(
1924 armnn::IWorkloadFactory& workloadFactory,
1925 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
1926{
1927 const unsigned int shape0[] = { 1, 2, 2, 3 };
1928 const unsigned int shape1[] = { 1, 1, 1, 1 };
1929
1930 std::vector<uint8_t> input0({ 1, 2, 3, 4, 5, 6,
1931 7, 8, 9, 10, 11, 12 });
1932
1933 std::vector<uint8_t> input1({ 1 });
1934
1935 std::vector<uint8_t> output({ 1, 0, 0, 0, 0, 0,
1936 0, 0, 0, 0, 0, 0 });
1937
1938 return ElementwiseTestHelper<armnn::EqualQueueDescriptor, uint8_t >
1939 (workloadFactory,
1940 memoryManager,
1941 shape0,
1942 input0,
1943 shape1,
1944 input1,
1945 shape0,
1946 output,
1947 1.0f,
1948 0);
1949}
1950
1951LayerTestResult<uint8_t, 4> EqualBroadcast1DVectorUint8Test(
1952 armnn::IWorkloadFactory& workloadFactory,
1953 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
1954{
1955 const unsigned int shape0[] = { 1, 2, 2, 3 };
1956 const unsigned int shape1[] = { 1, 1, 1, 3 };
1957
1958 std::vector<uint8_t> input0({ 1, 2, 3, 4, 5, 6,
1959 7, 8, 9, 10, 11, 12 });
1960
1961 std::vector<uint8_t> input1({ 1, 1, 3});
1962
1963 std::vector<uint8_t> output({ 1, 0, 1, 0, 0, 0,
1964 0, 0, 0, 0, 0, 0 });
1965
1966 return ElementwiseTestHelper<armnn::EqualQueueDescriptor, uint8_t>
1967 (workloadFactory,
1968 memoryManager,
1969 shape0,
1970 input0,
1971 shape1,
1972 input1,
1973 shape0,
1974 output,
1975 1.0f,
1976 0);
1977}
Éanna Ó Catháinde705582018-12-03 13:04:22 +00001978
FrancisMurtagh878f0232018-12-19 10:56:15 +00001979LayerTestResult<float, 4> GreaterSimpleTest(armnn::IWorkloadFactory& workloadFactory,
1980 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
1981{
1982 const unsigned int width = 2;
1983 const unsigned int height = 2;
1984 const unsigned int channelCount = 2;
1985 const unsigned int batchSize = 2;
1986
1987 unsigned int shape[] = { batchSize, channelCount, height, width };
1988
1989 std::vector<float> input0({ 1, 1, 1, 1, 5, 5, 5, 5,
1990 3, 3, 3, 3, 4, 4, 4, 4 });
1991
1992 std::vector<float> input1({ 1, 1, 1, 1, 3, 3, 3, 3,
1993 5, 5, 5, 5, 4, 4, 4, 4 });
1994
1995 std::vector<float> output({ 0, 0, 0, 0, 1, 1, 1, 1,
1996 0, 0, 0, 0, 0, 0, 0, 0 });
1997
1998 return ElementwiseTestHelper<armnn::GreaterQueueDescriptor, float>
1999 (workloadFactory,
2000 memoryManager,
2001 shape,
2002 input0,
2003 shape,
2004 input1,
2005 shape,
2006 output);
2007}
2008
2009LayerTestResult<float, 4> GreaterBroadcast1ElementTest(
2010 armnn::IWorkloadFactory& workloadFactory,
2011 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
2012{
2013 unsigned int shape0[] = { 1, 2, 2, 2 };
2014 std::vector<float> input0({ 1, 2, 3, 4, 5, 6, 7, 8});
2015
2016 unsigned int shape1[] = { 1, 1, 1, 1 };
2017 std::vector<float> input1({ 1 });
2018
2019 std::vector<float> output({ 0, 1, 1, 1, 1, 1, 1, 1});
2020
2021 return ElementwiseTestHelper<armnn::GreaterQueueDescriptor, float>
2022 (workloadFactory,
2023 memoryManager,
2024 shape0,
2025 input0,
2026 shape1,
2027 input1,
2028 shape0,
2029 output);
2030}
2031
2032LayerTestResult<float, 4> GreaterBroadcast1DVectorTest(
2033 armnn::IWorkloadFactory& workloadFactory,
2034 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
2035{
2036 const unsigned int shape0[] = { 1, 2, 2, 3 };
2037 const unsigned int shape1[] = { 1, 1, 1, 3 };
2038
2039 std::vector<float> input0({ 1, 2.9f, 2.1f, 4, 5, 6,
2040 7, 8, 9, 10, 11, 12 });
2041
2042 std::vector<float> input1({ 1, 3, 2});
2043
2044 std::vector<float> output({ 0, 0, 1, 1, 1, 1,
2045 1, 1, 1, 1, 1, 1 });
2046
2047 return ElementwiseTestHelper<armnn::GreaterQueueDescriptor, float>
2048 (workloadFactory,
2049 memoryManager,
2050 shape0,
2051 input0,
2052 shape1,
2053 input1,
2054 shape0,
2055 output);
2056}
2057
2058LayerTestResult<uint8_t, 4> GreaterUint8Test(
2059 armnn::IWorkloadFactory& workloadFactory,
2060 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
2061{
2062 unsigned int shape[] = { 2, 2, 2, 2 };
2063
2064 // See dequantized values to the right.
2065 std::vector<uint8_t> input0({ 1, 1, 1, 1, 6, 6, 6, 6,
2066 3, 3, 3, 3, 5, 5, 5, 5 });
2067
2068 std::vector<uint8_t> input1({ 2, 2, 2, 2, 6, 6, 6, 6,
2069 2, 2, 2, 2, 5, 5, 5, 5 });
2070
2071 std::vector<uint8_t> output({ 0, 0, 0, 0, 0, 0, 0, 0,
2072 1, 1, 1, 1, 0, 0, 0, 0 });
2073
2074 return ElementwiseTestHelper<armnn::GreaterQueueDescriptor, uint8_t >
2075 (workloadFactory,
2076 memoryManager,
2077 shape,
2078 input0,
2079 shape,
2080 input1,
2081 shape,
2082 output,
2083 1.0f,
2084 0);
2085}
2086
2087LayerTestResult<uint8_t, 4> GreaterBroadcast1ElementUint8Test(
2088 armnn::IWorkloadFactory& workloadFactory,
2089 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
2090{
2091 const unsigned int shape0[] = { 1, 2, 2, 3 };
2092 const unsigned int shape1[] = { 1, 1, 1, 1 };
2093
2094 std::vector<uint8_t> input0({ 1, 2, 3, 4, 5, 6,
2095 7, 8, 9, 10, 11, 12 });
2096
2097 std::vector<uint8_t> input1({ 1 });
2098
2099 std::vector<uint8_t> output({ 0, 1, 1, 1, 1, 1,
2100 1, 1, 1, 1, 1, 1 });
2101
2102 return ElementwiseTestHelper<armnn::GreaterQueueDescriptor, uint8_t >
2103 (workloadFactory,
2104 memoryManager,
2105 shape0,
2106 input0,
2107 shape1,
2108 input1,
2109 shape0,
2110 output,
2111 1.0f,
2112 0);
2113}
2114
2115LayerTestResult<uint8_t, 4> GreaterBroadcast1DVectorUint8Test(
2116 armnn::IWorkloadFactory& workloadFactory,
2117 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
2118{
2119 const unsigned int shape0[] = { 1, 2, 2, 3 };
2120 const unsigned int shape1[] = { 1, 1, 1, 3 };
2121
2122 std::vector<uint8_t> input0({ 1, 2, 3, 4, 5, 6,
2123 7, 8, 9, 10, 11, 12 });
2124
2125 std::vector<uint8_t> input1({ 1, 1, 3});
2126
2127 std::vector<uint8_t> output({ 0, 1, 0, 1, 1, 1,
2128 1, 1, 1, 1, 1, 1 });
2129
2130 return ElementwiseTestHelper<armnn::GreaterQueueDescriptor, uint8_t>
2131 (workloadFactory,
2132 memoryManager,
2133 shape0,
2134 input0,
2135 shape1,
2136 input1,
2137 shape0,
2138 output,
2139 1.0f,
2140 0);
2141}
2142
Éanna Ó Catháinde705582018-12-03 13:04:22 +00002143LayerTestResult<float, 4> MaximumSimpleTest(armnn::IWorkloadFactory& workloadFactory,
2144 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
2145{
2146 const unsigned int width = 2;
2147 const unsigned int height = 2;
2148 const unsigned int channelCount = 2;
2149 const unsigned int batchSize = 2;
2150
2151 unsigned int shape[] = { batchSize, channelCount, height, width };
2152
2153 std::vector<float> input0({ 1, 1, 1, 1, 5, 5, 5, 5,
2154 3, 3, 3, 3, 4, 4, 4, 4 });
2155
2156 std::vector<float> input1({ 2, 2, 2, 2, 3, 3, 3, 3,
2157 4, 4, 4, 4, 5, 5, 5, 5 });
2158
2159 std::vector<float> output({ 2, 2, 2, 2, 5, 5, 5, 5,
2160 4, 4, 4, 4, 5, 5, 5, 5 });
2161
2162 return ElementwiseTestHelper<armnn::MaximumQueueDescriptor, float>
2163 (workloadFactory,
2164 memoryManager,
2165 shape,
2166 input0,
2167 shape,
2168 input1,
2169 shape,
2170 output);
2171}
2172
2173LayerTestResult<float, 4> MaximumBroadcast1ElementTest(
2174 armnn::IWorkloadFactory& workloadFactory,
2175 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
2176{
2177 unsigned int shape0[] = { 1, 2, 2, 2 };
2178 std::vector<float> input0({ 1, 2, 3, 4, 5, 6, 7, 8});
2179
2180 unsigned int shape1[] = { 1, 1, 1, 1 };
2181 std::vector<float> input1({ 2 });
2182
2183 std::vector<float> output({ 2, 2, 3, 4, 5, 6, 7, 8});
2184
2185 return ElementwiseTestHelper<armnn::MaximumQueueDescriptor, float>
2186 (workloadFactory,
2187 memoryManager,
2188 shape0,
2189 input0,
2190 shape1,
2191 input1,
2192 shape0,
2193 output);
2194}
2195
2196LayerTestResult<float, 4> MaximumBroadcast1DVectorTest(
2197 armnn::IWorkloadFactory& workloadFactory,
2198 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
2199{
2200 const unsigned int shape0[] = { 1, 2, 2, 3 };
2201 const unsigned int shape1[] = { 1, 1, 1, 3 };
2202
2203 std::vector<float> input0({ 1, 2, 3, 4, 5, 6,
2204 7, 8, 9, 10, 11, 12 });
2205
2206 std::vector<float> input1({ 1, 2, 3});
2207
2208 std::vector<float> output({ 1, 2, 3, 4, 5, 6,
2209 7, 8, 9, 10, 11, 12 });
2210
2211 return ElementwiseTestHelper<armnn::MaximumQueueDescriptor, float>
2212 (workloadFactory,
2213 memoryManager,
2214 shape0,
2215 input0,
2216 shape1,
2217 input1,
2218 shape0,
2219 output);
2220}
2221
2222LayerTestResult<uint8_t, 4> MaximumUint8Test(
2223 armnn::IWorkloadFactory& workloadFactory,
2224 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
2225{
2226 unsigned int shape[] = { 2, 2, 2, 2 };
2227
2228 // See dequantized values to the right.
2229 std::vector<uint8_t> input0({ 1, 1, 1, 1, 6, 6, 6, 6,
2230 3, 3, 3, 3, 4, 4, 4, 4 });
2231
2232 std::vector<uint8_t> input1({ 2, 2, 2, 2, 3, 3, 3, 3,
2233 4, 4, 4, 4, 5, 5, 5, 5 });
2234
2235 std::vector<uint8_t> output({ 2, 2, 2, 2, 6, 6, 6, 6,
2236 4, 4, 4, 4, 5, 5, 5, 5 });
2237
2238 return ElementwiseTestHelper<armnn::MaximumQueueDescriptor, uint8_t >
2239 (workloadFactory,
2240 memoryManager,
2241 shape,
2242 input0,
2243 shape,
2244 input1,
2245 shape,
2246 output,
2247 1.0f,
2248 0);
2249}
2250
2251LayerTestResult<uint8_t, 4> MaximumBroadcast1ElementUint8Test(
2252 armnn::IWorkloadFactory& workloadFactory,
2253 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
2254{
2255 const unsigned int shape0[] = { 1, 2, 2, 3 };
2256 const unsigned int shape1[] = { 1, 1, 1, 1 };
2257
2258 std::vector<uint8_t> input0({ 1, 2, 3, 4, 5, 6,
2259 7, 8, 9, 10, 11, 12 });
2260
2261 std::vector<uint8_t> input1({2});
2262
2263 std::vector<uint8_t> output({ 2, 2, 3, 4, 5, 6,
2264 7, 8, 9, 10, 11, 12 });
2265
2266 return ElementwiseTestHelper<armnn::MaximumQueueDescriptor, uint8_t >
2267 (workloadFactory,
2268 memoryManager,
2269 shape0,
2270 input0,
2271 shape1,
2272 input1,
2273 shape0,
2274 output,
2275 1.0f,
2276 0);
2277}
2278
2279LayerTestResult<uint8_t, 4> MaximumBroadcast1DVectorUint8Test(
2280 armnn::IWorkloadFactory& workloadFactory,
2281 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
2282{
2283 const unsigned int shape0[] = { 1, 2, 2, 3 };
2284 const unsigned int shape1[] = { 1, 1, 1, 3 };
2285
2286 std::vector<uint8_t> input0({ 1, 2, 3, 4, 5, 6,
2287 7, 8, 9, 10, 11, 12 });
2288
2289 std::vector<uint8_t> input1({ 1, 10, 3});
2290
2291 std::vector<uint8_t> output({ 1, 10, 3, 4, 10, 6,
2292 7, 10, 9, 10, 11, 12 });
2293
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00002294 return ElementwiseTestHelper<armnn::MaximumQueueDescriptor, uint8_t>
Éanna Ó Catháinde705582018-12-03 13:04:22 +00002295 (workloadFactory,
2296 memoryManager,
2297 shape0,
2298 input0,
2299 shape1,
2300 input1,
2301 shape0,
2302 output,
2303 1.0f,
2304 0);
2305}
2306
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00002307LayerTestResult<float, 4> MinimumBroadcast1ElementTest1(
2308 armnn::IWorkloadFactory& workloadFactory,
2309 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
2310{
2311 unsigned int shape0[] = { 1, 2, 2, 2 };
2312 std::vector<float> input0({ 1, 2, 3, 4, 5, 6, 7, 8});
2313
2314 unsigned int shape1[] = { 1, 1, 1, 1 };
2315 std::vector<float> input1({ 2 });
2316
2317 std::vector<float> output({ 1, 2, 2, 2, 2, 2, 2, 2});
2318
2319 return ElementwiseTestHelper<armnn::MinimumQueueDescriptor, float>(workloadFactory,
2320 memoryManager,
2321 shape0,
2322 input0,
2323 shape1,
2324 input1,
2325 shape0,
2326 output);
2327}
2328
2329
2330LayerTestResult<float, 4> MinimumBroadcast1ElementTest2(
2331 armnn::IWorkloadFactory& workloadFactory,
2332 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
2333{
2334 unsigned int shape0[] = { 1, 2, 2, 2 };
2335 std::vector<float> input0({ 1, 6, 3, 2, 8, 9, 1, 10});
2336
2337 unsigned int shape1[] = { 1, 1, 1, 1 };
2338 std::vector<float> input1({ 5 });
2339
2340 std::vector<float> output({ 1, 5, 3, 2, 5, 5, 1, 5});
2341
2342 return ElementwiseTestHelper<armnn::MinimumQueueDescriptor, float>(workloadFactory,
2343 memoryManager,
2344 shape0,
2345 input0,
2346 shape1,
2347 input1,
2348 shape0,
2349 output);
2350}
2351
2352LayerTestResult<uint8_t, 4> MinimumBroadcast1DVectorUint8Test(
2353 armnn::IWorkloadFactory & workloadFactory,
2354 const armnn::IBackendInternal::IMemoryManagerSharedPtr & memoryManager)
2355{
2356 const unsigned int shape0[] = { 1, 2, 2, 3 };
2357 const unsigned int shape1[] = { 1, 1, 1, 3 };
2358
2359 std::vector<uint8_t> input0({ 1, 2, 3, 3, 2, 1,
2360 7, 1, 2, 3, 4, 5 });
2361
2362 std::vector<uint8_t> input1({ 1, 2, 3});
2363
2364 std::vector<uint8_t> output({ 1, 2, 3, 1, 2, 1,
2365 1, 1, 2, 1, 2, 3 });
2366
2367 return ElementwiseTestHelper<armnn::MinimumQueueDescriptor, uint8_t>(workloadFactory,
2368 memoryManager,
2369 shape0,
2370 input0,
2371 shape1,
2372 input1,
2373 shape0,
2374 output,
2375 1.0f,
2376 0);
2377}
2378
Francis Murtaghe7a86a42018-08-29 12:42:10 +01002379namespace {
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002380LayerTestResult<float,4> MultiplicationTestHelper(
2381 armnn::IWorkloadFactory& workloadFactory,
2382 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
2383 const unsigned int shape0[4],
2384 const std::vector<float> & values0,
2385 const unsigned int shape1[4],
2386 const std::vector<float> & values1,
2387 const unsigned int outShape[4],
2388 const std::vector<float> & outValues)
telsoa014fcda012018-03-09 14:13:49 +00002389{
surmeh01bceff2f2018-03-29 16:29:27 +01002390 const size_t dimensionCount = 4;
2391 armnn::TensorInfo inputTensorInfo0{dimensionCount, shape0, armnn::DataType::Float32};
2392 armnn::TensorInfo inputTensorInfo1{dimensionCount, shape1, armnn::DataType::Float32};
2393 armnn::TensorInfo outputTensorInfo{dimensionCount, outShape, armnn::DataType::Float32};
telsoa014fcda012018-03-09 14:13:49 +00002394
surmeh01bceff2f2018-03-29 16:29:27 +01002395 auto input0 = MakeTensor<float, 4>(inputTensorInfo0, values0);
2396 auto input1 = MakeTensor<float, 4>(inputTensorInfo1, values1);
telsoa014fcda012018-03-09 14:13:49 +00002397
2398 LayerTestResult<float,4> ret(outputTensorInfo);
2399
2400 std::unique_ptr<armnn::ITensorHandle> inputHandle0 = workloadFactory.CreateTensorHandle(inputTensorInfo0);
2401 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
2402 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
2403
2404 armnn::MultiplicationQueueDescriptor data;
2405 armnn::WorkloadInfo info;
2406 AddInputToWorkload(data, info, inputTensorInfo0, inputHandle0.get());
2407 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
2408 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
2409
2410 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateMultiplication(data, info);
2411
2412 inputHandle0->Allocate();
2413 inputHandle1->Allocate();
2414 outputHandle->Allocate();
2415
2416 CopyDataToITensorHandle(inputHandle0.get(), &input0[0][0][0][0]);
2417 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
2418
2419 workload->Execute();
2420
2421 CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
2422
surmeh01bceff2f2018-03-29 16:29:27 +01002423 ret.outputExpected = MakeTensor<float, 4>(outputTensorInfo, outValues);
telsoa014fcda012018-03-09 14:13:49 +00002424 return ret;
2425}
surmeh01bceff2f2018-03-29 16:29:27 +01002426} // anonymous namespace
2427
2428
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002429LayerTestResult<float,4> MultiplicationTest(
2430 armnn::IWorkloadFactory& workloadFactory,
2431 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01002432{
2433 const unsigned int width = 2;
2434 const unsigned int height = 2;
2435 const unsigned int channelCount = 2;
2436 const unsigned int batchSize = 2;
2437
2438 unsigned int shape[] = { batchSize, channelCount, height, width };
2439
2440 std::vector<float> input0({
2441 1, 1, 1, 1, 2, 2, 2, 2,
2442 3, 3, 3, 3, 4, 4, 4, 4 });
2443
2444 std::vector<float> input1({
2445 2, 2, 2, 2, 3, 3, 3, 3,
2446 4, 4, 4, 4, 5, 5, 5, 5 });
2447
2448 std::vector<float> output({
2449 2, 2, 2, 2, 6, 6, 6, 6,
2450 12, 12, 12, 12, 20, 20, 20, 20 });
2451
2452 return MultiplicationTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002453 memoryManager,
surmeh01bceff2f2018-03-29 16:29:27 +01002454 shape,
2455 input0,
2456 shape,
2457 input1,
2458 shape,
2459 output);
2460}
2461
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002462LayerTestResult<float, 4> MultiplicationBroadcast1ElementTest(
2463 armnn::IWorkloadFactory& workloadFactory,
2464 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01002465{
2466 unsigned int shape0[] = { 1, 2, 2, 2 };
2467 std::vector<float> input0({ 1, 2, 3, 4, 5, 6, 7, 8});
2468
2469 unsigned int shape1[] = { 1, 1, 1, 1 };
2470 std::vector<float> input1({ 2 });
2471
2472 std::vector<float> output({ 2, 4, 6, 8, 10, 12, 14, 16});
2473
2474 return MultiplicationTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002475 memoryManager,
surmeh01bceff2f2018-03-29 16:29:27 +01002476 shape0,
2477 input0,
2478 shape1,
2479 input1,
2480 shape0,
2481 output);
2482}
2483
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002484LayerTestResult<float, 4> MultiplicationBroadcast1DVectorTest(
2485 armnn::IWorkloadFactory& workloadFactory,
2486 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01002487{
2488 unsigned int shape0[] = { 1, 3, 3, 2 };
2489 std::vector<float> input0({
2490 1, 2, 3, 4, 5, 6,
2491 7, 8, 9, 10, 11, 12,
2492 13, 14, 15, 16, 17, 18});
2493
2494 unsigned int shape1[] = { 1, 1, 1, 2 };
2495 std::vector<float> input1({ 1, 2 });
2496
2497 std::vector<float> output({
2498 1, 4, 3, 8, 5, 12,
2499 7, 16, 9, 20, 11, 24,
2500 13, 28, 15, 32, 17, 36});
2501
2502 return MultiplicationTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002503 memoryManager,
surmeh01bceff2f2018-03-29 16:29:27 +01002504 shape0,
2505 input0,
2506 shape1,
2507 input1,
2508 shape0,
2509 output);
2510}
telsoa014fcda012018-03-09 14:13:49 +00002511
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002512LayerTestResult<float,4> CompareMultiplicationTest(
2513 armnn::IWorkloadFactory& workloadFactory,
2514 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
2515 armnn::IWorkloadFactory& refWorkloadFactory)
telsoa014fcda012018-03-09 14:13:49 +00002516{
2517 const unsigned int width = 16;
2518 const unsigned int height = 32;
2519 const unsigned int channelCount = 2;
2520 const unsigned int batchSize = 5;
2521
2522 armnn::TensorInfo inputTensorInfo0;
2523 armnn::TensorInfo inputTensorInfo1;
2524 armnn::TensorInfo outputTensorInfo;
2525
2526 constexpr unsigned int shape[] = { batchSize, channelCount, height, width };
2527
2528 inputTensorInfo0 = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
2529 inputTensorInfo1 = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
2530 outputTensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
2531
2532 LayerTestResult<float,4> comparisonResult(outputTensorInfo);
2533
2534 auto input0 = MakeRandomTensor<float, 4>(inputTensorInfo0, 803506992);
2535 auto input1 = MakeRandomTensor<float, 4>(inputTensorInfo1, 54902257);
2536
2537 std::unique_ptr<armnn::ITensorHandle> inputHandle0 = workloadFactory.CreateTensorHandle(inputTensorInfo0);
2538 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
2539 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
2540
2541 std::unique_ptr<armnn::ITensorHandle> inputHandle0Ref = refWorkloadFactory.CreateTensorHandle(inputTensorInfo0);
2542 std::unique_ptr<armnn::ITensorHandle> inputHandle1Ref = refWorkloadFactory.CreateTensorHandle(inputTensorInfo1);
2543 std::unique_ptr<armnn::ITensorHandle> outputHandleRef = refWorkloadFactory.CreateTensorHandle(outputTensorInfo);
2544
2545 armnn::MultiplicationQueueDescriptor data;
2546 armnn::WorkloadInfo info;
2547 AddInputToWorkload(data, info, inputTensorInfo0, inputHandle0.get());
2548 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
2549 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
2550
2551 armnn::MultiplicationQueueDescriptor refData = data;
2552 armnn::WorkloadInfo refInfo = info;
2553 SetWorkloadInput(refData, refInfo, 0, inputTensorInfo0, inputHandle0Ref.get());
2554 SetWorkloadInput(refData, refInfo, 1, inputTensorInfo1, inputHandle1Ref.get());
2555 SetWorkloadOutput(refData, refInfo, 0, outputTensorInfo, outputHandleRef.get());
2556
2557 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateMultiplication(data, info);
2558 std::unique_ptr<armnn::IWorkload> workloadRef = refWorkloadFactory.CreateMultiplication(refData, refInfo);
2559
2560 inputHandle0->Allocate();
2561 inputHandle1->Allocate();
2562 outputHandle->Allocate();
2563 inputHandle0Ref->Allocate();
2564 inputHandle1Ref->Allocate();
2565 outputHandleRef->Allocate();
2566
2567 CopyDataToITensorHandle(inputHandle0.get(), &input0[0][0][0][0]);
2568 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
2569 CopyDataToITensorHandle(inputHandle0Ref.get(), &input0[0][0][0][0]);
2570 CopyDataToITensorHandle(inputHandle1Ref.get(), &input1[0][0][0][0]);
2571
2572 workload->Execute();
2573 workloadRef->Execute();
2574
2575 CopyDataFromITensorHandle(&comparisonResult.output[0][0][0][0], outputHandle.get());
2576 CopyDataFromITensorHandle(&comparisonResult.outputExpected[0][0][0][0], outputHandleRef.get());
2577
2578 return comparisonResult;
2579}
2580
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002581LayerTestResult<float,4> CompareBatchNormTest(
2582 armnn::IWorkloadFactory& workloadFactory,
2583 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
2584 armnn::IWorkloadFactory& refWorkloadFactory)
telsoa014fcda012018-03-09 14:13:49 +00002585{
2586 const unsigned int width = 2;
2587 const unsigned int height = 3;
2588 const unsigned int channels = 5;
2589 const unsigned int batchSize = 3;
2590
2591 armnn::TensorInfo inputTensorInfo;
2592 armnn::TensorInfo outputTensorInfo;
2593 armnn::TensorInfo tensorInfo;
2594
2595 constexpr unsigned int shape[] = {batchSize, channels, height, width};
2596 constexpr unsigned int tensorShape[] = {channels};
2597
2598 inputTensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
2599 outputTensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
2600 tensorInfo = armnn::TensorInfo(1, tensorShape, armnn::DataType::Float32);
2601
2602 auto input = MakeRandomTensor<float, 4>(inputTensorInfo, 21312);
2603
2604 auto mean = MakeRandomTensor<float, 1>(tensorInfo, 123);
2605 auto variance = MakeRandomTensor<float, 1>(tensorInfo, 234, 0.0f);
2606 auto beta = MakeRandomTensor<float, 1>(tensorInfo, 123);
2607 auto gamma = MakeRandomTensor<float, 1>(tensorInfo, 345);
2608
2609 LayerTestResult<float,4> ret(outputTensorInfo);
2610
2611 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
2612 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
2613
2614 std::unique_ptr<armnn::ITensorHandle> inputHandleRef = refWorkloadFactory.CreateTensorHandle(inputTensorInfo);
2615 std::unique_ptr<armnn::ITensorHandle> outputHandleRef = refWorkloadFactory.CreateTensorHandle(outputTensorInfo);
2616
2617 armnn::BatchNormalizationQueueDescriptor data;
2618 armnn::WorkloadInfo info;
2619 armnn::ScopedCpuTensorHandle meanTensor(tensorInfo);
2620 armnn::ScopedCpuTensorHandle varianceTensor(tensorInfo);
2621 armnn::ScopedCpuTensorHandle betaTensor(tensorInfo);
2622 armnn::ScopedCpuTensorHandle gammaTensor(tensorInfo);
2623
2624 AllocateAndCopyDataToITensorHandle(&meanTensor, &mean[0]);
2625 AllocateAndCopyDataToITensorHandle(&varianceTensor, &variance[0]);
2626 AllocateAndCopyDataToITensorHandle(&betaTensor, &beta[0]);
2627 AllocateAndCopyDataToITensorHandle(&gammaTensor, &gamma[0]);
2628
2629 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
2630 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
2631 data.m_Mean = &meanTensor;
2632 data.m_Variance = &varianceTensor;
2633 data.m_Beta = &betaTensor;
2634 data.m_Gamma = &gammaTensor;
2635 data.m_Parameters.m_Eps = 0.01f;
2636
2637 armnn::BatchNormalizationQueueDescriptor refData = data;
2638 armnn::WorkloadInfo refInfo = info;
2639 SetWorkloadInput(refData, refInfo, 0, inputTensorInfo, inputHandleRef.get());
2640 SetWorkloadOutput(refData, refInfo, 0, outputTensorInfo, outputHandleRef.get());
2641
2642 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateBatchNormalization(data, info);
2643 std::unique_ptr<armnn::IWorkload> workloadRef = refWorkloadFactory.CreateBatchNormalization(refData, refInfo);
2644
2645 inputHandle->Allocate();
2646 outputHandle->Allocate();
2647 inputHandleRef->Allocate();
2648 outputHandleRef->Allocate();
2649
2650 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
2651 CopyDataToITensorHandle(inputHandleRef.get(), &input[0][0][0][0]);
2652
2653 workload->Execute();
2654 workloadRef->Execute();
2655
2656 CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
2657 CopyDataFromITensorHandle(&ret.outputExpected[0][0][0][0], outputHandleRef.get());
2658
2659 return ret;
2660}
2661
surmeh013537c2c2018-05-18 16:31:43 +01002662template<typename T>
2663void PermuteTensorData(
2664 armnn::IWorkloadFactory& workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002665 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
surmeh013537c2c2018-05-18 16:31:43 +01002666 const armnn::PermutationVector& mappings,
2667 armnn::TensorInfo & inputTensorInfo,
2668 const T * inputData,
2669 std::vector<T>& outputData)
telsoa014fcda012018-03-09 14:13:49 +00002670{
surmeh013537c2c2018-05-18 16:31:43 +01002671 BOOST_ASSERT_MSG(inputData != nullptr, "inputData must not be null");
2672 if (inputData == nullptr)
2673 {
2674 // Nullptr is an error in the test. By returning without doing the concatenation
2675 // I expect the caller to fail the test. It still makes sense to report this as
2676 // an assert for Debug builds.
2677 return;
2678 }
telsoa014fcda012018-03-09 14:13:49 +00002679
surmeh013537c2c2018-05-18 16:31:43 +01002680 armnn::TensorInfo outputTensorInfo = armnnUtils::Permuted(inputTensorInfo, mappings);
2681
2682 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
2683 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
2684
2685 armnn::PermuteQueueDescriptor queueDescriptor;
2686 queueDescriptor.m_Parameters = armnn::PermuteDescriptor{mappings};
2687 armnn::WorkloadInfo workloadInfo;
2688 AddInputToWorkload(queueDescriptor, workloadInfo, inputTensorInfo, inputHandle.get());
2689 AddOutputToWorkload(queueDescriptor, workloadInfo, outputTensorInfo, outputHandle.get());
2690
2691 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreatePermute(queueDescriptor, workloadInfo);
2692
2693 inputHandle->Allocate();
2694 outputHandle->Allocate();
2695
2696 CopyDataToITensorHandle(inputHandle.get(), inputData);
2697
2698 workload->Execute();
2699
2700 outputData.resize(outputTensorInfo.GetNumElements());
2701 CopyDataFromITensorHandle(&outputData[0], outputHandle.get());
2702 inputTensorInfo = outputTensorInfo;
2703}
2704
2705armnn::OriginsDescriptor CreateMergerDescriptorForConcatenation(
2706 const std::vector<armnn::TensorInfo> & inputTensorInfos,
2707 unsigned int concatDim)
2708{
telsoa014fcda012018-03-09 14:13:49 +00002709 std::vector<armnn::TensorShape> shapes;
2710 shapes.reserve(inputTensorInfos.size());
2711 for (const armnn::TensorInfo& it: inputTensorInfos)
2712 {
2713 shapes.push_back(it.GetShape());
2714 }
surmeh013537c2c2018-05-18 16:31:43 +01002715
2716 return armnn::CreateMergerDescriptorForConcatenation(shapes.begin(),
2717 shapes.end(),
2718 concatDim);
2719}
2720
2721//
narpra015cdda352018-11-19 15:30:27 +00002722// Concatenation is only supported for N and C dimensions for NCHW and the inner most dimension
2723// In case of <4 dimensions we need to make sure that the concat dimensions are at least
2724// the 3rd slowest iterating one or the inner most dimension.
surmeh013537c2c2018-05-18 16:31:43 +01002725//
2726
2727bool NeedPermuteForConcat(
2728 const std::vector<armnn::TensorInfo> & inputTensorInfos,
2729 unsigned int concatDim)
2730{
2731 // See note above. Additionally we expect the input shapes to have the
2732 // same number of dimensions.
2733 unsigned int nDimensions = 0;
2734
telsoa01c577f2c2018-08-31 09:22:23 +01002735 // Determine the number of dimensions as well as sanity check them
2736 // agains test implementation issues.
surmeh013537c2c2018-05-18 16:31:43 +01002737 for (auto && tensorInfo : inputTensorInfos)
2738 {
2739 if (!nDimensions)
2740 {
2741 nDimensions = tensorInfo.GetShape().GetNumDimensions();
2742 }
2743 else
2744 {
2745 BOOST_ASSERT_MSG(nDimensions == tensorInfo.GetShape().GetNumDimensions(),
2746 "Input shapes must have the same number of dimensions");
2747 }
2748 }
2749
narpra015cdda352018-11-19 15:30:27 +00002750 return (nDimensions < 3 || (nDimensions == 3 && (nDimensions-concatDim) < 3 && (nDimensions-concatDim) != 1));
surmeh013537c2c2018-05-18 16:31:43 +01002751}
2752
2753armnn::TensorShape ExpandTensorShapeTo3dForPermute(const armnn::TensorShape & inputShape)
2754{
2755 unsigned int numDims = inputShape.GetNumDimensions();
2756 if (numDims >= 3)
2757 {
2758 // Nothing to do if the inputShape has at least 3 dimensions.
2759 return inputShape;
2760 }
2761
2762 std::vector<unsigned int> newDims(size_t(3), 1u);
2763 unsigned int expandedBy = 3 - numDims;
2764 for (unsigned int i=0; i<numDims; ++i)
2765 {
2766 newDims[expandedBy+i] = inputShape[i];
2767 }
2768 return armnn::TensorShape(3u, &newDims[0]);
2769}
2770
2771void Generate3dPermuteVectorForConcat(
2772 unsigned int numDimensions,
2773 unsigned int & concatDim,
2774 std::pair<armnn::PermutationVector, armnn::PermutationVector> & permutations)
2775{
2776 BOOST_ASSERT_MSG(numDimensions <= 3,
2777 "Only dimensions 1,2 and 3 are supported by this helper");
surmeh013537c2c2018-05-18 16:31:43 +01002778 unsigned int expandedBy = 3 - numDimensions;
2779 unsigned int expandedConcatAxis = concatDim + expandedBy;
2780
2781 if (expandedConcatAxis == 2)
2782 {
2783 concatDim = 0;
2784 armnn::PermutationVector forwardPermutation({1, 2, 0});
2785 armnn::PermutationVector reversePermutation({2, 0, 1});
2786 permutations = std::make_pair(forwardPermutation, reversePermutation);
2787 }
2788 else if (expandedConcatAxis == 1)
2789 {
2790 concatDim = 0;
2791 armnn::PermutationVector forwardPermutation({2, 0, 1});
2792 armnn::PermutationVector reversePermutation({1, 2, 0});
2793 permutations = std::make_pair(forwardPermutation, reversePermutation);
2794 }
2795 else
2796 {
2797 BOOST_ASSERT(expandedConcatAxis == 0);
2798 concatDim = 0;
2799 }
2800}
2801
2802//
2803// Permute the input tensors so we can do a supported concatenation.
2804// Also treat lower than 3d tensors as 3d by adding dummy 1 dimensions
2805// at the front. Finally this function tells what the output shape
2806// of the permuted concatenated tensor is going to be.
2807//
2808template <typename T>
2809void PermuteInputsForConcat(
2810 armnn::IWorkloadFactory& workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002811 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
surmeh013537c2c2018-05-18 16:31:43 +01002812 std::vector<armnn::TensorInfo> & inputTensorInfos,
2813 std::vector<T *> & inputData,
2814 std::vector<std::vector<T>> & inputDataStorage,
2815 armnn::PermutationVector & permuteVector,
2816 unsigned int & concatDim,
2817 armnn::TensorInfo & outputTensorInfo)
2818{
2819 BOOST_ASSERT_MSG(inputTensorInfos.size() > 1,
2820 "Expecting more than one tensor to be concatenated here");
2821
2822 unsigned int numDims = 0;
2823 unsigned int nthInput = 0;
2824 const armnn::PermutationVector identity({0, 1, 2});
2825
2826 std::pair<armnn::PermutationVector, armnn::PermutationVector> permutations =
2827 std::make_pair(identity, identity);
2828
2829 inputDataStorage.resize(inputData.size());
2830
2831 for (auto && tensorInfo : inputTensorInfos)
2832 {
2833 if (numDims == 0)
2834 {
2835 numDims = tensorInfo.GetShape().GetNumDimensions();
2836 Generate3dPermuteVectorForConcat(numDims, concatDim, permutations);
narpra015cdda352018-11-19 15:30:27 +00002837
telsoa01c577f2c2018-08-31 09:22:23 +01002838 // Store the reverese permutation.
surmeh013537c2c2018-05-18 16:31:43 +01002839 permuteVector = permutations.second;
2840 BOOST_ASSERT_MSG(!permuteVector.IsEqual(identity),
2841 "Test logic error, we don't need permutation, so we shouldn't arrive here");
2842 }
2843 else
2844 {
2845 BOOST_ASSERT_MSG(numDims == tensorInfo.GetShape().GetNumDimensions(),
2846 "All inputs must have the same number of dimensions");
2847 }
2848
2849 armnn::TensorInfo newTensorInfo = tensorInfo;
2850 newTensorInfo.SetShape(ExpandTensorShapeTo3dForPermute(tensorInfo.GetShape()));
2851
2852 PermuteTensorData<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002853 memoryManager,
surmeh013537c2c2018-05-18 16:31:43 +01002854 permutations.first,
2855 newTensorInfo,
2856 inputData[nthInput],
2857 inputDataStorage[nthInput]);
2858
2859 inputData[nthInput] = inputDataStorage[nthInput].data();
2860 inputTensorInfos[nthInput] = newTensorInfo;
2861
2862 ++nthInput;
2863 }
2864
2865 outputTensorInfo.SetShape(
2866 armnnUtils::Permuted(
2867 ExpandTensorShapeTo3dForPermute(outputTensorInfo.GetShape()),
2868 permutations.first));
2869}
2870
2871
2872//
2873// This is the pair of PermuteInputsForConcat(...) which permutes back
telsoa01c577f2c2018-08-31 09:22:23 +01002874// the output of the concatenation so we can check it against an expected
surmeh013537c2c2018-05-18 16:31:43 +01002875// output.
2876//
2877template <typename T>
2878void PermuteOutputForConcat(
2879 armnn::IWorkloadFactory& workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002880 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
surmeh013537c2c2018-05-18 16:31:43 +01002881 const armnn::TensorInfo & tensorInfo,
2882 const armnn::PermutationVector & permuteVector,
2883 std::unique_ptr<armnn::ITensorHandle> && inputDataHandle,
2884 T * data)
2885{
2886 BOOST_ASSERT_MSG(data != nullptr, "data must not be null");
2887 if (data == nullptr)
2888 {
2889 // Nullptr is an error in the test. By returning without doing the permutation
2890 // I expect the caller to fail the test. It still makes sense to report this as
2891 // an assert for Debug builds.
2892 return;
2893 }
2894
2895 armnn::TensorInfo resultTensorInfo = tensorInfo;
2896 std::vector<T> inputData(tensorInfo.GetNumElements());
2897 std::vector<T> outputData;
2898
2899 CopyDataFromITensorHandle(&inputData[0], inputDataHandle.get());
2900
2901 PermuteTensorData<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002902 memoryManager,
surmeh013537c2c2018-05-18 16:31:43 +01002903 permuteVector,
2904 resultTensorInfo,
2905 &inputData[0],
2906 outputData);
2907
2908 ::memcpy(data, &outputData[0], sizeof(T)*outputData.size());
2909}
2910
2911template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002912void Concatenate(
2913 armnn::IWorkloadFactory& workloadFactory,
2914 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
2915 std::initializer_list<const armnn::TensorInfo> inputTensorInfosOrig,
2916 std::initializer_list<T *> inputsOrig,
2917 const armnn::TensorInfo& outputTensorInfoOrig,
2918 T * output,
narpra015cdda352018-11-19 15:30:27 +00002919 unsigned int concatDim,
2920 bool useSubtensor)
surmeh013537c2c2018-05-18 16:31:43 +01002921{
2922 BOOST_ASSERT_MSG(output != nullptr, "output must not be null");
2923 if (output == nullptr)
2924 {
2925 // Nullptr is an error in the test. By returning without doing the permutation
2926 // I expect the caller to fail the test. It still makes sense to report this as
2927 // an assert for Debug builds.
2928 return;
2929 }
2930
telsoa01c577f2c2018-08-31 09:22:23 +01002931 // Saves a copy of the parameters which we might need to change.
surmeh013537c2c2018-05-18 16:31:43 +01002932 std::vector<armnn::TensorInfo> inputTensorInfos(inputTensorInfosOrig.begin(), inputTensorInfosOrig.end());
2933 std::vector<T *> inputs = inputsOrig;
2934 armnn::TensorInfo outputTensorInfo = outputTensorInfoOrig;
2935
2936 armnn::PermutationVector permuteVector{0, 1, 2};
2937
telsoa01c577f2c2018-08-31 09:22:23 +01002938 // Holds and automatically releases memory for the reshaped input data.
surmeh013537c2c2018-05-18 16:31:43 +01002939 std::vector<std::vector<T>> tmpInputDataStorage;
2940
2941 const size_t inputCount = inputTensorInfos.size();
2942
2943 bool needPermuteForConcat = NeedPermuteForConcat(inputTensorInfos, concatDim);
2944
2945 if (needPermuteForConcat)
2946 {
2947 //
2948 // We need to permute the inputs, because concatenation along
telsoa01c577f2c2018-08-31 09:22:23 +01002949 // the requested axis is not supported.
surmeh013537c2c2018-05-18 16:31:43 +01002950 //
2951 PermuteInputsForConcat<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002952 memoryManager,
surmeh013537c2c2018-05-18 16:31:43 +01002953 inputTensorInfos,
2954 inputs,
2955 tmpInputDataStorage,
2956 permuteVector,
2957 concatDim,
2958 outputTensorInfo);
2959 }
2960
narpra015cdda352018-11-19 15:30:27 +00002961 armnn::WorkloadInfo workloadInfo;
telsoa014fcda012018-03-09 14:13:49 +00002962
2963 std::vector<std::unique_ptr<armnn::ITensorHandle>> inputHandles;
2964 inputHandles.reserve(inputCount);
2965
narpra015cdda352018-11-19 15:30:27 +00002966 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
2967
2968 armnn::MergerQueueDescriptor queueDescriptor;
2969 armnn::OriginsDescriptor viewsDescriptor = CreateMergerDescriptorForConcatenation(inputTensorInfos, concatDim);
2970 queueDescriptor.m_Parameters = viewsDescriptor;
2971
2972 if (useSubtensor)
telsoa014fcda012018-03-09 14:13:49 +00002973 {
narpra015cdda352018-11-19 15:30:27 +00002974 queueDescriptor.m_ViewOrigins.reserve(viewsDescriptor.GetNumViews());
2975 for (unsigned int i = 0; i < viewsDescriptor.GetNumViews(); ++i)
2976 {
2977 queueDescriptor.m_ViewOrigins.emplace_back(std::vector<unsigned int>(viewsDescriptor.GetViewOrigin(i),
2978 viewsDescriptor.GetViewOrigin(i) + viewsDescriptor.GetNumDimensions()));
2979 }
telsoa014fcda012018-03-09 14:13:49 +00002980
narpra015cdda352018-11-19 15:30:27 +00002981 outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
telsoa014fcda012018-03-09 14:13:49 +00002982
narpra015cdda352018-11-19 15:30:27 +00002983 const bool subTensorsSupported = workloadFactory.SupportsSubTensors();
2984 for (unsigned int i = 0; i < inputCount; ++i)
2985 {
2986 const armnn::TensorInfo& inputTensorInfo = inputTensorInfos[i];
2987 std::unique_ptr<armnn::ITensorHandle> inputHandle =
2988 subTensorsSupported ?
2989 workloadFactory.CreateSubTensorHandle(*outputHandle,
2990 inputTensorInfo.GetShape(),
2991 queueDescriptor.m_ViewOrigins[i].m_Origin.data()) :
2992 workloadFactory.CreateTensorHandle(inputTensorInfo);
2993
2994 inputHandles.emplace_back(std::move(inputHandle));
2995 }
2996
telsoa014fcda012018-03-09 14:13:49 +00002997 }
narpra015cdda352018-11-19 15:30:27 +00002998 else
2999 {
3000 for (unsigned int i = 0; i < inputCount; ++i)
3001 {
3002 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfos[i]);
3003 inputHandles.emplace_back(std::move(inputHandle));
3004 }
3005 }
telsoa014fcda012018-03-09 14:13:49 +00003006
3007 for (unsigned int i = 0; i < inputCount; ++i)
3008 {
surmeh013537c2c2018-05-18 16:31:43 +01003009 AddInputToWorkload(queueDescriptor, workloadInfo, inputTensorInfos[i], inputHandles[i].get());
telsoa014fcda012018-03-09 14:13:49 +00003010 }
3011
3012 AddOutputToWorkload(queueDescriptor, workloadInfo, outputTensorInfo, outputHandle.get());
3013
3014 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateMerger(queueDescriptor, workloadInfo);
3015
3016 for (auto& inputHandle : inputHandles)
3017 {
3018 inputHandle->Allocate();
3019 }
3020
3021 outputHandle->Allocate();
3022
3023 unsigned int nextInputId = 0;
3024 for (auto& inputHandle : inputHandles)
3025 {
surmeh013537c2c2018-05-18 16:31:43 +01003026 CopyDataToITensorHandle(inputHandle.get(), inputs[nextInputId]);
3027 ++nextInputId;
telsoa014fcda012018-03-09 14:13:49 +00003028 }
3029
3030 workload->Execute();
3031
surmeh013537c2c2018-05-18 16:31:43 +01003032 if (needPermuteForConcat)
3033 {
3034 PermuteOutputForConcat<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003035 memoryManager,
surmeh013537c2c2018-05-18 16:31:43 +01003036 outputTensorInfo,
3037 permuteVector,
3038 std::move(outputHandle),
3039 output);
3040 }
3041 else
3042 {
3043 CopyDataFromITensorHandle(output, outputHandle.get());
3044 }
telsoa014fcda012018-03-09 14:13:49 +00003045}
3046
3047template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003048LayerTestResult<T, 1> Concatenation1dTestImpl(
3049 armnn::IWorkloadFactory& workloadFactory,
3050 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3051 float qScale,
3052 int32_t qOffset)
telsoa014fcda012018-03-09 14:13:49 +00003053{
3054 armnn::TensorInfo inputTensorInfo({ 3 }, armnn::GetDataType<T>());
3055
3056 auto input0 = MakeTensor<T, 1>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, { 1.0f, 2.0f, 3.0f }));
3057 auto input1 = MakeTensor<T, 1>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, { 4.0f, 5.0f, 6.0f }));
3058 auto input2 = MakeTensor<T, 1>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, { 7.0f, 8.0f, 9.0f }));
3059
3060 armnn::TensorInfo outputTensorInfo({ 9 }, armnn::GetDataType<T>());
3061
3062 LayerTestResult<T, 1> result(outputTensorInfo);
3063
3064 std::vector<T> output;
3065 output.resize(outputTensorInfo.GetNumElements());
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003066 Concatenate<T>(workloadFactory, memoryManager,
narpra015cdda352018-11-19 15:30:27 +00003067 { inputTensorInfo, inputTensorInfo, inputTensorInfo },
3068 { input0.data(), input1.data(), input2.data() },
3069 outputTensorInfo,
3070 output.data(),
3071 0,
3072 true);
telsoa014fcda012018-03-09 14:13:49 +00003073
3074 result.output = MakeTensor<T, 1>(outputTensorInfo, output);
3075 result.outputExpected = MakeTensor<T, 1>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3076 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f
3077 }));
3078
3079 return result;
3080}
3081
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003082LayerTestResult<float, 1> Concatenation1dTest(
3083 armnn::IWorkloadFactory& workloadFactory,
3084 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00003085{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003086 return Concatenation1dTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00003087}
3088
3089template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003090LayerTestResult<T, 2> Concatenation2dTestImpl(
3091 armnn::IWorkloadFactory& workloadFactory,
3092 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
telsoa014fcda012018-03-09 14:13:49 +00003093 const armnn::TensorInfo& outputTensorInfo,
3094 unsigned int dimension,
3095 const float qScale,
3096 const int32_t qOffset)
3097{
3098 armnn::TensorInfo inputTensorInfo({ 2, 3 }, armnn::GetDataType<T>());
3099
3100 auto input0 = MakeTensor<T, 2>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3101 // Batch 0
3102 1.0f, 2.0f, 3.0f,
3103
3104 // Batch 1
3105 10.0f, 11.0f, 12.0f,
3106 }));
3107
3108 auto input1 = MakeTensor<T, 2>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3109 // Batch 0
3110 4.0f, 5.0f, 6.0f,
3111
3112 // Batch 1
3113 13.0f, 14.0f, 15.0f,
3114 }));
3115
3116 auto input2 = MakeTensor<T, 2>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3117 // Batch 0
3118 7.0f, 8.0f, 9.0f,
3119
3120 // Batch 1
3121 16.0f, 17.0f, 18.0f,
3122 }));
3123
3124 LayerTestResult<T, 2> result(outputTensorInfo);
3125
3126 std::vector<T> output;
3127 output.resize(outputTensorInfo.GetNumElements());
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003128 Concatenate<T>(workloadFactory, memoryManager,
narpra015cdda352018-11-19 15:30:27 +00003129 { inputTensorInfo, inputTensorInfo, inputTensorInfo },
3130 { input0.data(), input1.data(), input2.data() },
3131 outputTensorInfo,
3132 output.data(),
3133 dimension,
3134 true);
telsoa014fcda012018-03-09 14:13:49 +00003135
3136 result.output = MakeTensor<T, 2>(outputTensorInfo, output);
3137 return result;
3138}
3139
3140template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003141LayerTestResult<T, 2> Concatenation2dDim0TestImpl(
3142 armnn::IWorkloadFactory& workloadFactory,
3143 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3144 float qScale,
3145 int32_t qOffset)
telsoa014fcda012018-03-09 14:13:49 +00003146{
3147 armnn::TensorInfo outputTensorInfo({ 6, 3 }, armnn::GetDataType<T>());
3148
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003149 LayerTestResult<T, 2> result =
3150 Concatenation2dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 0, qScale, qOffset);
telsoa014fcda012018-03-09 14:13:49 +00003151 result.outputExpected = MakeTensor<T, 2>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3152 // Batch 0
3153 1.0f, 2.0f, 3.0f,
3154
3155 // Batch 1
3156 10.0f, 11.0f, 12.0f,
3157
3158 // Batch 2
3159 4.0f, 5.0f, 6.0f,
3160
3161 // Batch 3
3162 13.0f, 14.0f, 15.0f,
3163
3164 // Batch 4
3165 7.0f, 8.0f, 9.0f,
3166
3167 // Batch 5
3168 16.0f, 17.0f, 18.0f,
3169 }));
3170
3171 return result;
3172}
3173
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003174LayerTestResult<float, 2> Concatenation2dDim0Test(
3175 armnn::IWorkloadFactory& workloadFactory,
3176 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00003177{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003178 return Concatenation2dDim0TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00003179}
3180
3181template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003182LayerTestResult<T, 2> Concatenation2dDim1TestImpl(
3183 armnn::IWorkloadFactory& workloadFactory,
3184 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3185 float qScale,
3186 int32_t qOffset)
telsoa014fcda012018-03-09 14:13:49 +00003187{
3188 armnn::TensorInfo outputTensorInfo({ 2, 9 }, armnn::GetDataType<T>());
3189
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003190 LayerTestResult<T, 2> result =
3191 Concatenation2dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 1, qScale, qOffset);
telsoa014fcda012018-03-09 14:13:49 +00003192 result.outputExpected = MakeTensor<T, 2>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3193 // Batch 0
3194 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f,
3195
3196 // Batch 1
3197 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f
3198 }));
3199
3200 return result;
3201}
3202
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003203LayerTestResult<float, 2> Concatenation2dDim1Test(
3204 armnn::IWorkloadFactory& workloadFactory,
3205 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00003206{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003207 return Concatenation2dDim1TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00003208}
3209
3210template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003211LayerTestResult<T, 2> Concatenation2dDim0DiffInputDimsTestImpl(
3212 armnn::IWorkloadFactory& workloadFactory,
3213 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3214 float qScale,
telsoa014fcda012018-03-09 14:13:49 +00003215 int32_t qOffset)
3216{
3217 armnn::TensorInfo input0TensorInfo({ 2, 3 }, armnn::GetDataType<T>());
3218 auto input0 = MakeTensor<T, 2>(input0TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3219 // Batch 0
3220 1.0f, 2.0f, 3.0f,
3221
3222 // Batch 1
3223 10.0f, 11.0f, 12.0f,
3224 }));
3225
3226 armnn::TensorInfo input1TensorInfo({ 3, 3 }, armnn::GetDataType<T>());
3227 auto input1 = MakeTensor<T, 2>(input1TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3228 // Batch 0
3229 4.0f, 5.0f, 6.0f,
3230
3231 // Batch 1
3232 13.0f, 14.0f, 15.0f,
3233
3234 // Batch 0
3235 7.0f, 8.0f, 9.0f,
3236 }));
3237
3238 armnn::TensorInfo input2TensorInfo({ 1, 3 }, armnn::GetDataType<T>());
3239 auto input2 = MakeTensor<T, 2>(input2TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3240 // Batch 1
3241 16.0f, 17.0f, 18.0f,
3242 }));
3243
3244 armnn::TensorInfo outputTensorInfo({ 6, 3 }, armnn::GetDataType<T>());
3245 LayerTestResult<T, 2> result(outputTensorInfo);
3246
3247 std::vector<T> output;
3248 output.resize(outputTensorInfo.GetNumElements());
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003249 Concatenate<T>(workloadFactory, memoryManager,
narpra015cdda352018-11-19 15:30:27 +00003250 { input0TensorInfo, input1TensorInfo, input2TensorInfo },
3251 { input0.data(), input1.data(), input2.data() },
3252 outputTensorInfo,
3253 output.data(),
3254 0,
3255 true);
telsoa014fcda012018-03-09 14:13:49 +00003256
3257 result.output = MakeTensor<T, 2>(outputTensorInfo, output);
3258 result.outputExpected = MakeTensor<T, 2>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3259 // Batch 0
3260 1.0f, 2.0f, 3.0f,
3261
3262 // Batch 1
3263 10.0f, 11.0f, 12.0f,
3264
3265 // Batch 2
3266 4.0f, 5.0f, 6.0f,
3267
3268 // Batch 3
3269 13.0f, 14.0f, 15.0f,
3270
3271 // Batch 4
3272 7.0f, 8.0f, 9.0f,
3273
3274 // Batch 5
3275 16.0f, 17.0f, 18.0f,
3276 }));
3277
3278 return result;
3279}
3280
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003281LayerTestResult<float, 2> Concatenation2dDim0DiffInputDimsTest(
3282 armnn::IWorkloadFactory& workloadFactory,
3283 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00003284{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003285 return Concatenation2dDim0DiffInputDimsTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00003286}
3287
3288template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003289LayerTestResult<T, 2> Concatenation2dDim1DiffInputDimsTestImpl(
3290 armnn::IWorkloadFactory& workloadFactory,
3291 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3292 float qScale,
telsoa014fcda012018-03-09 14:13:49 +00003293 int32_t qOffset)
3294{
3295 armnn::TensorInfo input0TensorInfo({ 2, 3 }, armnn::GetDataType<T>());
3296 auto input0 = MakeTensor<T, 2>(input0TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3297 // Batch 0
3298 1.0f, 2.0f, 3.0f,
3299
3300 // Batch 1
3301 10.0f, 11.0f, 12.0f,
3302 }));
3303
3304 armnn::TensorInfo input1TensorInfo({ 2, 5 }, armnn::GetDataType<T>());
3305 auto input1 = MakeTensor<T, 2>(input1TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3306 // Batch 0
3307 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
3308
3309 // Batch 1
3310 13.0f, 14.0f, 15.0f, 16.0f, 17.0f,
3311 }));
3312
3313 armnn::TensorInfo input2TensorInfo({ 2, 1 }, armnn::GetDataType<T>());
3314 auto input2 = MakeTensor<T, 2>(input2TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3315 // Batch 0
3316 9.0f,
3317
3318 // Batch 1
3319 18.0f
3320 }));
3321
3322 armnn::TensorInfo outputTensorInfo({ 2, 9 }, armnn::GetDataType<T>());
3323 LayerTestResult<T, 2> result(outputTensorInfo);
3324
3325 std::vector<T> output;
3326 output.resize(outputTensorInfo.GetNumElements());
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003327 Concatenate<T>(workloadFactory, memoryManager,
narpra015cdda352018-11-19 15:30:27 +00003328 { input0TensorInfo, input1TensorInfo, input2TensorInfo },
3329 { input0.data(), input1.data(), input2.data() },
3330 outputTensorInfo,
3331 output.data(),
3332 1,
3333 true);
telsoa014fcda012018-03-09 14:13:49 +00003334
3335 result.output = MakeTensor<T, 2>(outputTensorInfo, output);
3336 result.outputExpected = MakeTensor<T, 2>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3337 // Batch 0
3338 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f,
3339
3340 // Batch 1
3341 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f,
3342 }));
3343
3344 return result;
3345}
3346
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003347LayerTestResult<float, 2> Concatenation2dDim1DiffInputDimsTest(
3348 armnn::IWorkloadFactory& workloadFactory,
3349 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00003350{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003351 return Concatenation2dDim1DiffInputDimsTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00003352}
3353
3354template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003355LayerTestResult<T, 3> Concatenation3dTestImpl(
3356 armnn::IWorkloadFactory& workloadFactory,
3357 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
telsoa014fcda012018-03-09 14:13:49 +00003358 const armnn::TensorInfo& outputTensorInfo,
3359 unsigned int dimension,
narpra015cdda352018-11-19 15:30:27 +00003360 bool useSubtensor,
telsoa014fcda012018-03-09 14:13:49 +00003361 float qScale,
3362 int32_t qOffset)
3363{
3364 armnn::TensorInfo inputTensorInfo({ 2, 3, 2 }, armnn::GetDataType<T>());
3365
3366 auto input0 = MakeTensor<T, 3>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3367 // Batch 0, Channel 0
3368 1.0f, 2.0f,
3369
3370 // Batch 0, Channel 1
3371 3.0f, 4.0f,
3372
3373 // Batch 0, Channel 2
3374 5.0f, 6.0f,
3375
3376 // Batch 1, Channel 0
3377 19.0f, 20.0f,
3378
3379 // Batch 1, Channel 1
3380 21.0f, 22.0f,
3381
3382 // Batch 1, Channel 2
3383 23.0f, 24.0f
3384 }));
3385
3386 auto input1 = MakeTensor<T, 3>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3387 // Batch 0, Channel 0
3388 7.0f, 8.0f,
3389
3390 // Batch 0, Channel 1
3391 9.0f, 10.0f,
3392
3393 // Batch 0, Channel 2
3394 11.0f, 12.0f,
3395
3396 // Batch 1, Channel 0
3397 25.0f, 26.0f,
3398
3399 // Batch 1, Channel 1
3400 27.0f, 28.0f,
3401
3402 // Batch 1, Channel 2
3403 29.0f, 30.0f
3404 }));
3405
3406 auto input2 = MakeTensor<T, 3>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3407 // Batch 0, Channel 0
3408 13.0f, 14.0f,
3409
3410 // Batch 0, Channel 1
3411 15.0f, 16.0f,
3412
3413 // Batch 0, Channel 2
3414 17.0f, 18.0f,
3415
3416 // Batch 1, Channel 0
3417 31.0f, 32.0f,
3418
3419 // Batch 1, Channel 1
3420 33.0f, 34.0f,
3421
3422 // Batch 1, Channel 2
3423 35.0f, 36.0f
3424 }));
3425
3426 LayerTestResult<T, 3> result(outputTensorInfo);
3427
3428 std::vector<T> output;
3429 output.resize(outputTensorInfo.GetNumElements());
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003430 Concatenate<T>(workloadFactory, memoryManager,
narpra015cdda352018-11-19 15:30:27 +00003431 { inputTensorInfo, inputTensorInfo, inputTensorInfo },
3432 { input0.data(), input1.data(), input2.data() },
3433 outputTensorInfo,
3434 output.data(),
3435 dimension,
3436 useSubtensor);
telsoa014fcda012018-03-09 14:13:49 +00003437
3438 result.output = MakeTensor<T, 3>(outputTensorInfo, output);
3439 return result;
3440}
3441
3442template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003443LayerTestResult<T, 3> Concatenation3dDim0TestImpl(
3444 armnn::IWorkloadFactory& workloadFactory,
3445 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3446 float qScale,
telsoa014fcda012018-03-09 14:13:49 +00003447 int32_t qOffset)
3448{
3449 armnn::TensorInfo outputTensorInfo({ 6, 3, 2 }, armnn::GetDataType<T>());
3450
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003451 LayerTestResult<T, 3> result =
narpra015cdda352018-11-19 15:30:27 +00003452 Concatenation3dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 0, true, qScale, qOffset);
telsoa014fcda012018-03-09 14:13:49 +00003453 result.outputExpected = MakeTensor<T, 3>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3454 // Batch 0, Channel 0
3455 1.0f, 2.0f,
3456
3457 // Batch 0, Channel 1
3458 3.0f, 4.0f,
3459
3460 // Batch 0, Channel 2
3461 5.0f, 6.0f,
3462
3463 // Batch 1, Channel 0
3464 19.0f, 20.0f,
3465
3466 // Batch 1, Channel 1
3467 21.0f, 22.0f,
3468
3469 // Batch 1, Channel 2
3470 23.0f, 24.0f,
3471
3472 // Batch 2, Channel 0
3473 7.0f, 8.0f,
3474
3475 // Batch 2, Channel 1
3476 9.0f, 10.0f,
3477
3478 // Batch 2, Channel 2
3479 11.0f, 12.0f,
3480
3481 // Batch 3, Channel 0
3482 25.0f, 26.0f,
3483
3484 // Batch 3, Channel 1
3485 27.0f, 28.0f,
3486
3487 // Batch 3, Channel 2
3488 29.0f, 30.0f,
3489
3490 // Batch 4, Channel 0
3491 13.0f, 14.0f,
3492
3493 // Batch 4, Channel 1
3494 15.0f, 16.0f,
3495
3496 // Batch 4, Channel 2
3497 17.0f, 18.0f,
3498
3499 // Batch 5, Channel 0
3500 31.0f, 32.0f,
3501
3502 // Batch 5, Channel 1
3503 33.0f, 34.0f,
3504
3505 // Batch 5, Channel 2
3506 35.0f, 36.0f
3507 }));
narpra015cdda352018-11-19 15:30:27 +00003508
telsoa014fcda012018-03-09 14:13:49 +00003509 return result;
3510}
3511
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003512LayerTestResult<float, 3> Concatenation3dDim0Test(
3513 armnn::IWorkloadFactory& workloadFactory,
3514 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00003515{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003516 return Concatenation3dDim0TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00003517}
3518
3519template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003520LayerTestResult<T, 3> Concatenation3dDim1TestImpl(
3521 armnn::IWorkloadFactory& workloadFactory,
3522 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3523 float qScale,
3524 int32_t qOffset)
telsoa014fcda012018-03-09 14:13:49 +00003525{
3526 armnn::TensorInfo outputTensorInfo({ 2, 9, 2 }, armnn::GetDataType<T>());
3527
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003528 LayerTestResult<T, 3> result =
narpra015cdda352018-11-19 15:30:27 +00003529 Concatenation3dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 1, true, qScale, qOffset);
3530
telsoa014fcda012018-03-09 14:13:49 +00003531 result.outputExpected = MakeTensor<T, 3>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3532 // Batch 0, Channel 0
3533 1.0f, 2.0f,
3534
3535 // Batch 0, Channel 1
3536 3.0f, 4.0f,
3537
3538 // Batch 0, Channel 2
3539 5.0f, 6.0f,
3540
3541 // Batch 0, Channel 3
3542 7.0f, 8.0f,
3543
3544 // Batch 0, Channel 4
3545 9.0f, 10.0f,
3546
3547 // Batch 0, Channel 5
3548 11.0f, 12.0f,
3549
3550 // Batch 0, Channel 6
3551 13.0f, 14.0f,
3552
3553 // Batch 0, Channel 7
3554 15.0f, 16.0f,
3555
3556 // Batch 0, Channel 8
3557 17.0f, 18.0f,
3558
3559 // Batch 1, Channel 0
3560 19.0f, 20.0f,
3561
3562 // Batch 1, Channel 1
3563 21.0f, 22.0f,
3564
3565 // Batch 1, Channel 2
3566 23.0f, 24.0f,
3567
3568 // Batch 1, Channel 3
3569 25.0f, 26.0f,
3570
3571 // Batch 1, Channel 4
3572 27.0f, 28.0f,
3573
3574 // Batch 1, Channel 5
3575 29.0f, 30.0f,
3576
3577 // Batch 1, Channel 6
3578 31.0f, 32.0f,
3579
3580 // Batch 1, Channel 7
3581 33.0f, 34.0f,
3582
3583 // Batch 1, Channel 8
3584 35.0f, 36.0f
3585 }));
3586
3587 return result;
3588}
3589
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003590LayerTestResult<float, 3> Concatenation3dDim1Test(
3591 armnn::IWorkloadFactory& workloadFactory,
3592 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00003593{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003594 return Concatenation3dDim1TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00003595}
3596
3597template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003598LayerTestResult<T, 3> Concatenation3dDim2TestImpl(
3599 armnn::IWorkloadFactory& workloadFactory,
3600 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
narpra015cdda352018-11-19 15:30:27 +00003601 bool useSubtensor,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003602 float qScale,
3603 int32_t qOffset)
telsoa014fcda012018-03-09 14:13:49 +00003604{
3605 armnn::TensorInfo outputTensorInfo({ 2, 3, 6 }, armnn::GetDataType<T>());
3606
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003607 LayerTestResult<T, 3> result =
narpra015cdda352018-11-19 15:30:27 +00003608 Concatenation3dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 2, useSubtensor, qScale, qOffset);
3609
telsoa014fcda012018-03-09 14:13:49 +00003610 result.outputExpected = MakeTensor<T, 3>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3611 // Batch 0, Channel 0
3612 1.0f, 2.0f, 7.0f, 8.0f, 13.0f, 14.0f,
3613
3614 // Batch 0, Channel 1
3615 3.0f, 4.0f, 9.0f, 10.0f, 15.0f, 16.0f,
3616
3617 // Batch 0, Channel 2
3618 5.0f, 6.0f, 11.0f, 12.0f, 17.0f, 18.0f,
3619
3620 // Batch 1, Channel 0
3621 19.0f, 20.0f, 25.0f, 26.0f, 31.0f, 32.0f,
3622
3623 // Batch 1, Channel 1
3624 21.0f, 22.0f, 27.0f, 28.0f, 33.0f, 34.0f,
3625
3626 // Batch 1, Channel 2
3627 23.0f, 24.0f, 29.0f, 30.0f, 35.0f, 36.0f,
3628 }));
3629
3630 return result;
3631}
3632
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003633LayerTestResult<float, 3> Concatenation3dDim2Test(
3634 armnn::IWorkloadFactory& workloadFactory,
narpra015cdda352018-11-19 15:30:27 +00003635 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3636 bool useSubtensor)
telsoa014fcda012018-03-09 14:13:49 +00003637{
narpra015cdda352018-11-19 15:30:27 +00003638 return Concatenation3dDim2TestImpl<float>(workloadFactory, memoryManager, useSubtensor, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00003639}
3640
3641template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003642LayerTestResult<T, 3> Concatenation3dDim0DiffInputDimsTestImpl(
3643 armnn::IWorkloadFactory& workloadFactory,
3644 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3645 float qScale,
telsoa014fcda012018-03-09 14:13:49 +00003646 int32_t qOffset)
3647{
3648 armnn::TensorInfo input0TensorInfo({ 2, 3, 2 }, armnn::GetDataType<T>());
3649 auto input0 = MakeTensor<T, 3>(input0TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3650 // Batch 0, Channel 0
3651 1.0f, 2.0f,
3652
3653 // Batch 0, Channel 1
3654 3.0f, 4.0f,
3655
3656 // Batch 0, Channel 2
3657 5.0f, 6.0f,
3658
3659 // Batch 1, Channel 0
3660 19.0f, 20.0f,
3661
3662 // Batch 1, Channel 1
3663 21.0f, 22.0f,
3664
3665 // Batch 1, Channel 2
3666 23.0f, 24.0f
3667 }));
3668
3669 armnn::TensorInfo input1TensorInfo({ 1, 3, 2 }, armnn::GetDataType<T>());
3670 auto input1 = MakeTensor<T, 3>(input1TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3671 // Batch 0, Channel 0
3672 7.0f, 8.0f,
3673
3674 // Batch 0, Channel 1
3675 9.0f, 10.0f,
3676
3677 // Batch 0, Channel 2
3678 11.0f, 12.0f,
3679 }));
3680
3681 armnn::TensorInfo input2TensorInfo({ 3, 3, 2 }, armnn::GetDataType<T>());
3682 auto input2 = MakeTensor<T, 3>(input2TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3683 // Batch 0, Channel 0
3684 25.0f, 26.0f,
3685
3686 // Batch 0, Channel 1
3687 27.0f, 28.0f,
3688
3689 // Batch 0, Channel 2
3690 29.0f, 30.0f,
3691
3692 // Batch 1, Channel 0
3693 13.0f, 14.0f,
3694
3695 // Batch 1, Channel 1
3696 15.0f, 16.0f,
3697
3698 // Batch 1, Channel 2
3699 17.0f, 18.0f,
3700
3701 // Batch 2, Channel 0
3702 31.0f, 32.0f,
3703
3704 // Batch 2, Channel 1
3705 33.0f, 34.0f,
3706
3707 // Batch 2, Channel 2
3708 35.0f, 36.0f
3709 }));
3710
3711 armnn::TensorInfo outputTensorInfo({ 6, 3, 2 }, armnn::GetDataType<T>());
3712 LayerTestResult<T, 3> result(outputTensorInfo);
3713
3714 std::vector<T> output;
3715 output.resize(outputTensorInfo.GetNumElements());
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003716 Concatenate<T>(workloadFactory, memoryManager,
narpra015cdda352018-11-19 15:30:27 +00003717 { input0TensorInfo, input1TensorInfo, input2TensorInfo },
3718 { input0.data(), input1.data(), input2.data() },
3719 outputTensorInfo,
3720 output.data(),
3721 0,
3722 true);
telsoa014fcda012018-03-09 14:13:49 +00003723
3724 result.output = MakeTensor<T, 3>(outputTensorInfo, output);
3725 result.outputExpected = MakeTensor<T, 3>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3726 // Batch 0, Channel 0
3727 1.0f, 2.0f,
3728
3729 // Batch 0, Channel 1
3730 3.0f, 4.0f,
3731
3732 // Batch 0, Channel 2
3733 5.0f, 6.0f,
3734
3735 // Batch 1, Channel 0
3736 19.0f, 20.0f,
3737
3738 // Batch 1, Channel 1
3739 21.0f, 22.0f,
3740
3741 // Batch 1, Channel 2
3742 23.0f, 24.0f,
3743
3744 // Batch 2, Channel 0
3745 7.0f, 8.0f,
3746
3747 // Batch 2, Channel 1
3748 9.0f, 10.0f,
3749
3750 // Batch 2, Channel 2
3751 11.0f, 12.0f,
3752
3753 // Batch 3, Channel 0
3754 25.0f, 26.0f,
3755
3756 // Batch 3, Channel 1
3757 27.0f, 28.0f,
3758
3759 // Batch 3, Channel 2
3760 29.0f, 30.0f,
3761
3762 // Batch 4, Channel 0
3763 13.0f, 14.0f,
3764
3765 // Batch 4, Channel 1
3766 15.0f, 16.0f,
3767
3768 // Batch 4, Channel 2
3769 17.0f, 18.0f,
3770
3771 // Batch 5, Channel 0
3772 31.0f, 32.0f,
3773
3774 // Batch 5, Channel 1
3775 33.0f, 34.0f,
3776
3777 // Batch 5, Channel 2
3778 35.0f, 36.0f
3779 }));
3780
3781 return result;
3782}
3783
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003784LayerTestResult<float, 3> Concatenation3dDim0DiffInputDimsTest(
3785 armnn::IWorkloadFactory& workloadFactory,
3786 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00003787{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003788 return Concatenation3dDim0DiffInputDimsTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00003789}
3790
3791template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003792LayerTestResult<T, 3> Concatenation3dDim1DiffInputDimsTestImpl(
3793 armnn::IWorkloadFactory& workloadFactory,
3794 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3795 float qScale,
telsoa014fcda012018-03-09 14:13:49 +00003796 int32_t qOffset)
3797{
3798 armnn::TensorInfo input0TensorInfo({ 2, 3, 2 }, armnn::GetDataType<T>());
3799 auto input0 = MakeTensor<T, 3>(input0TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3800 // Batch 0, Channel 0
3801 1.0f, 2.0f,
3802
3803 // Batch 0, Channel 1
3804 3.0f, 4.0f,
3805
3806 // Batch 0, Channel 2
3807 5.0f, 6.0f,
3808
3809 // Batch 1, Channel 0
3810 19.0f, 20.0f,
3811
3812 // Batch 1, Channel 1
3813 21.0f, 22.0f,
3814
3815 // Batch 1, Channel 2
3816 23.0f, 24.0f
3817 }));
3818
3819 armnn::TensorInfo input1TensorInfo({ 2, 4, 2 }, armnn::GetDataType<T>());
3820 auto input1 = MakeTensor<T, 3>(input1TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3821 // Batch 0, Channel 0
3822 7.0f, 8.0f,
3823
3824 // Batch 0, Channel 1
3825 9.0f, 10.0f,
3826
3827 // Batch 0, Channel 2
3828 11.0f, 12.0f,
3829
3830 // Batch 0, Channel 3
3831 25.0f, 26.0f,
3832
3833 // Batch 1, Channel 0
3834 27.0f, 28.0f,
3835
3836 // Batch 1, Channel 1
3837 29.0f, 30.0f,
3838
3839 // Batch 1, Channel 2
3840 13.0f, 14.0f,
3841
3842 // Batch 1, Channel 3
3843 15.0f, 16.0f,
3844 }));
3845
3846 armnn::TensorInfo input2TensorInfo({ 2, 1, 2 }, armnn::GetDataType<T>());
3847 auto input2 = MakeTensor<T, 3>(input2TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3848 // Batch 0, Channel 0
3849 17.0f, 18.0f,
3850
3851 // Batch 1, Channel 0
3852 31.0f, 32.0f,
3853 }));
3854
3855 armnn::TensorInfo outputTensorInfo({ 2, 8, 2 }, armnn::GetDataType<T>());
3856 LayerTestResult<T, 3> result(outputTensorInfo);
3857
3858 std::vector<T> output;
3859 output.resize(outputTensorInfo.GetNumElements());
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003860 Concatenate<T>(workloadFactory, memoryManager,
narpra015cdda352018-11-19 15:30:27 +00003861 { input0TensorInfo, input1TensorInfo, input2TensorInfo },
3862 { input0.data(), input1.data(), input2.data() },
3863 outputTensorInfo,
3864 output.data(),
3865 1,
3866 true);
telsoa014fcda012018-03-09 14:13:49 +00003867
3868 result.output = MakeTensor<T, 3>(outputTensorInfo, output);
3869 result.outputExpected = MakeTensor<T, 3>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3870 // Batch 0, Channel 0
3871 1.0f, 2.0f,
3872
3873 // Batch 0, Channel 1
3874 3.0f, 4.0f,
3875
3876 // Batch 0, Channel 2
3877 5.0f, 6.0f,
3878
3879 // Batch 0, Channel 3
3880 7.0f, 8.0f,
3881
3882 // Batch 0, Channel 4
3883 9.0f, 10.0f,
3884
3885 // Batch 0, Channel 5
3886 11.0f, 12.0f,
3887
3888 // Batch 0, Channel 6
3889 25.0f, 26.0f,
3890
3891 // Batch 0, Channel 7
3892 17.0f, 18.0f,
3893
3894 // Batch 1, Channel 0
3895 19.0f, 20.0f,
3896
3897 // Batch 1, Channel 1
3898 21.0f, 22.0f,
3899
3900 // Batch 1, Channel 2
3901 23.0f, 24.0f,
3902
3903 // Batch 1, Channel 3
3904 27.0f, 28.0f,
3905
3906 // Batch 1, Channel 4
3907 29.0f, 30.0f,
3908
3909 // Batch 1, Channel 5
3910 13.0f, 14.0f,
3911
3912 // Batch 1, Channel 6
3913 15.0f, 16.0f,
3914
3915 // Batch 1, Channel 7
3916 31.0f, 32.0f,
3917 }));
3918
3919 return result;
3920}
3921
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003922LayerTestResult<float, 3> Concatenation3dDim1DiffInputDimsTest(
3923 armnn::IWorkloadFactory& workloadFactory,
3924 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00003925{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003926 return Concatenation3dDim1DiffInputDimsTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00003927}
3928
3929template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003930LayerTestResult<T, 3> Concatenation3dDim2DiffInputDimsTestImpl(
3931 armnn::IWorkloadFactory& workloadFactory,
3932 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
narpra015cdda352018-11-19 15:30:27 +00003933 bool useSubtensor,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003934 float qScale,
telsoa014fcda012018-03-09 14:13:49 +00003935 int32_t qOffset)
3936{
3937 armnn::TensorInfo input0TensorInfo({ 2, 3, 2 }, armnn::GetDataType<T>());
3938 auto input0 = MakeTensor<T, 3>(input0TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3939 // Batch 0, Channel 0
3940 1.0f, 2.0f,
3941
3942 // Batch 0, Channel 1
3943 3.0f, 4.0f,
3944
3945 // Batch 0, Channel 2
3946 5.0f, 6.0f,
3947
3948 // Batch 1, Channel 0
3949 19.0f, 20.0f,
3950
3951 // Batch 1, Channel 1
3952 21.0f, 22.0f,
3953
3954 // Batch 1, Channel 2
3955 23.0f, 24.0f
3956 }));
3957
3958 armnn::TensorInfo input1TensorInfo({ 2, 3, 1 }, armnn::GetDataType<T>());
3959 auto input1 = MakeTensor<T, 3>(input1TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3960 // Batch 0, Channel 0
3961 7.0f,
3962
3963 // Batch 0, Channel 1
3964 9.0f,
3965
3966 // Batch 0, Channel 2
3967 11.0f,
3968
3969 // Batch 1, Channel 0
3970 25.0f,
3971
3972 // Batch 1, Channel 1
3973 27.0f,
3974
3975 // Batch 1, Channel 2
3976 29.0f
3977 }));
3978
3979 armnn::TensorInfo input2TensorInfo({ 2, 3, 3 }, armnn::GetDataType<T>());
3980 auto input2 = MakeTensor<T, 3>(input2TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3981 // Batch 0, Channel 0
3982 13.0f, 14.0f, 50.0f,
3983
3984 // Batch 0, Channel 1
3985 15.0f, 16.0f, 51.0f,
3986
3987 // Batch 0, Channel 2
3988 17.0f, 18.0f, 52.0f,
3989
3990 // Batch 1, Channel 0
3991 31.0f, 32.0f, 53.0f,
3992
3993 // Batch 1, Channel 1
3994 33.0f, 34.0f, 54.0f,
3995
3996 // Batch 1, Channel 2
3997 35.0f, 36.0f, 55.0f,
3998 }));
3999
4000 armnn::TensorInfo outputTensorInfo({ 2, 3, 6 }, armnn::GetDataType<T>());
4001 LayerTestResult<T, 3> result(outputTensorInfo);
4002
4003 std::vector<T> output;
4004 output.resize(outputTensorInfo.GetNumElements());
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004005 Concatenate<T>(workloadFactory, memoryManager,
narpra015cdda352018-11-19 15:30:27 +00004006 { input0TensorInfo, input1TensorInfo, input2TensorInfo },
4007 { input0.data(), input1.data(), input2.data() },
4008 outputTensorInfo,
4009 output.data(),
4010 2,
4011 useSubtensor);
telsoa014fcda012018-03-09 14:13:49 +00004012
4013 result.output = MakeTensor<T, 3>(outputTensorInfo, output);
4014 result.outputExpected = MakeTensor<T, 3>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
4015 // Batch 0, Channel 0
4016 1.0f, 2.0f, 7.0f, 13.0f, 14.0f, 50.0f,
4017
4018 // Batch 0, Channel 1
4019 3.0f, 4.0f, 9.0f, 15.0f, 16.0f, 51.0f,
4020
4021 // Batch 0, Channel 2
4022 5.0f, 6.0f, 11.0f, 17.0f, 18.0f, 52.0f,
4023
4024 // Batch 1, Channel 0
4025 19.0f, 20.0f, 25.0f, 31.0f, 32.0f, 53.0f,
4026
4027 // Batch 1, Channel 1
4028 21.0f, 22.0f, 27.0f, 33.0f, 34.0f, 54.0f,
4029
4030 // Batch 1, Channel 2
4031 23.0f, 24.0f, 29.0f, 35.0f, 36.0f, 55.0f,
4032 }));
4033
4034 return result;
4035}
4036
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004037LayerTestResult<float, 3> Concatenation3dDim2DiffInputDimsTest(
4038 armnn::IWorkloadFactory& workloadFactory,
narpra015cdda352018-11-19 15:30:27 +00004039 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4040 bool useSubtensor)
4041{
4042 return Concatenation3dDim2DiffInputDimsTestImpl<float>(workloadFactory, memoryManager, useSubtensor, 0.0f, 0);
4043}
4044
4045template <typename T>
4046LayerTestResult<T, 4> Concatenation4dTestImpl(
4047 armnn::IWorkloadFactory& workloadFactory,
4048 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4049 const armnn::TensorInfo& outputTensorInfo,
4050 unsigned int dimension,
4051 bool useSubtensor,
4052 float qScale,
4053 int32_t qOffset)
4054{
4055 armnn::TensorInfo inputTensorInfo({ 1, 3, 2, 2 }, armnn::GetDataType<T>());
4056
4057 auto input0 = MakeTensor<T, 4>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
4058 1.0f, 2.0f,
4059 3.0f, 4.0f,
4060 5.0f, 6.0f,
4061 7.0f, 8.0f,
4062 9.0f, 10.0f,
4063 11.0f, 12.0f
4064 }));
4065
4066 auto input1 = MakeTensor<T, 4>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
4067 11.0f, 12.0f,
4068 13.0f, 14.0f,
4069 15.0f, 16.0f,
4070 17.0f, 18.0f,
4071 19.0f, 20.0f,
4072 21.0f, 22.0f
4073 }));
4074
4075 auto input2 = MakeTensor<T, 4>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
4076 21.0f, 22.0f,
4077 23.0f, 24.0f,
4078 25.0f, 26.0f,
4079 27.0f, 28.0f,
4080 29.0f, 30.0f,
4081 31.0f, 32.0f
4082 }));
4083
4084 LayerTestResult<T, 4> result(outputTensorInfo);
4085
4086 std::vector<T> output;
4087 output.resize(outputTensorInfo.GetNumElements());
4088
4089 Concatenate<T>(workloadFactory,
4090 memoryManager,
4091 {inputTensorInfo, inputTensorInfo, inputTensorInfo},
4092 {input0.data(), input1.data(), input2.data()},
4093 outputTensorInfo,
4094 output.data(),
4095 dimension,
4096 useSubtensor);
4097
4098 result.output = MakeTensor<T, 4>(outputTensorInfo, output);
4099 return result;
4100}
4101
4102template <typename T>
4103LayerTestResult<T, 4> Concatenation4dDim0TestImpl(
4104 armnn::IWorkloadFactory& workloadFactory,
4105 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4106 float qScale,
4107 int32_t qOffset)
4108{
4109 armnn::TensorInfo outputTensorInfo({ 3, 3, 2, 2 }, armnn::GetDataType<T>());
4110
4111 LayerTestResult<T, 4> result = Concatenation4dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 0,
4112 true, qScale, qOffset);
4113 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
4114 1.0f, 2.0f,
4115 3.0f, 4.0f,
4116 5.0f, 6.0f,
4117 7.0f, 8.0f,
4118 9.0f, 10.0f,
4119 11.0f, 12.0f,
4120
4121 11.0f, 12.0f,
4122 13.0f, 14.0f,
4123 15.0f, 16.0f,
4124 17.0f, 18.0f,
4125 19.0f, 20.0f,
4126 21.0f, 22.0f,
4127
4128 21.0f, 22.0f,
4129 23.0f, 24.0f,
4130 25.0f, 26.0f,
4131 27.0f, 28.0f,
4132 29.0f, 30.0f,
4133 31.0f, 32.0f
4134 }));
4135 return result;
4136}
4137
4138LayerTestResult<float, 4> Concatenation4dDim0Test(
4139 armnn::IWorkloadFactory& workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004140 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00004141{
narpra015cdda352018-11-19 15:30:27 +00004142 return Concatenation4dDim0TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
4143}
4144
4145template <typename T>
4146LayerTestResult<T, 4> Concatenation4dDim1TestImpl(
4147 armnn::IWorkloadFactory& workloadFactory,
4148 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4149 float qScale,
4150 int32_t qOffset)
4151{
4152 armnn::TensorInfo outputTensorInfo({ 1, 9, 2, 2 }, armnn::GetDataType<T>());
4153
4154 LayerTestResult<T, 4> result = Concatenation4dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 1,
4155 true, qScale, qOffset);
4156 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
4157 1.0f, 2.0f,
4158 3.0f, 4.0f,
4159 5.0f, 6.0f,
4160 7.0f, 8.0f,
4161 9.0f, 10.0f,
4162 11.0f, 12.0f,
4163
4164 11.0f, 12.0f,
4165 13.0f, 14.0f,
4166 15.0f, 16.0f,
4167 17.0f, 18.0f,
4168 19.0f, 20.0f,
4169 21.0f, 22.0f,
4170
4171 21.0f, 22.0f,
4172 23.0f, 24.0f,
4173 25.0f, 26.0f,
4174 27.0f, 28.0f,
4175 29.0f, 30.0f,
4176 31.0f, 32.0f
4177 }));
4178
4179 return result;
4180}
4181
4182LayerTestResult<float, 4> Concatenation4dDim1Test(
4183 armnn::IWorkloadFactory& workloadFactory,
4184 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
4185{
4186 return Concatenation4dDim1TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
4187}
4188
4189template <typename T>
4190LayerTestResult<T, 4> Concatenation4dDim2TestImpl(
4191 armnn::IWorkloadFactory& workloadFactory,
4192 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4193 float qScale,
4194 int32_t qOffset)
4195{
4196 armnn::TensorInfo outputTensorInfo({ 1, 3, 6, 2 }, armnn::GetDataType<T>());
4197
4198 LayerTestResult<T, 4> result = Concatenation4dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 2,
4199 true, qScale, qOffset);
4200 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
4201 1.0f, 2.0f,
4202 3.0f, 4.0f,
4203 11.0f, 12.0f,
4204 13.0f, 14.0f,
4205 21.0f, 22.0f,
4206 23.0f, 24.0f,
4207
4208 5.0f, 6.0f,
4209 7.0f, 8.0f,
4210 15.0f, 16.0f,
4211 17.0f, 18.0f,
4212 25.0f, 26.0f,
4213 27.0f, 28.0f,
4214
4215 9.0f, 10.0f,
4216 11.0f, 12.0f,
4217 19.0f, 20.0f,
4218 21.0f, 22.0f,
4219 29.0f, 30.0f,
4220 31.0f, 32.0f
4221 }));
4222
4223 return result;
4224}
4225
4226LayerTestResult<float, 4> Concatenation4dDim2Test(
4227 armnn::IWorkloadFactory& workloadFactory,
4228 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
4229{
4230 return Concatenation4dDim2TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
4231}
4232
4233template <typename T>
4234LayerTestResult<T, 4> Concatenation4dDim3TestImpl(
4235 armnn::IWorkloadFactory& workloadFactory,
4236 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4237 float qScale,
4238 int32_t qOffset,
4239 bool useSubtensor)
4240{
4241 armnn::TensorInfo outputTensorInfo({ 1, 3, 2, 6 }, armnn::GetDataType<T>());
4242
4243 LayerTestResult<T, 4> result = Concatenation4dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 3,
4244 useSubtensor, qScale, qOffset);
4245 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
4246 1.0f, 2.0f,
4247 11.0f, 12.0f,
4248 21.0f, 22.0f,
4249 3.0f, 4.0f,
4250 13.0f, 14.0f,
4251 23.0f, 24.0f,
4252
4253 5.0f, 6.0f,
4254 15.0f, 16.0f,
4255 25.0f, 26.0f,
4256 7.0f, 8.0f,
4257 17.0f, 18.0f,
4258 27.0f, 28.0f,
4259
4260 9.0f, 10.0f,
4261 19.0f, 20.0f,
4262 29.0f, 30.0f,
4263 11.0f, 12.0f,
4264 21.0f, 22.0f,
4265 31.0f, 32.0f
4266 }));
4267
4268 return result;
4269}
4270
4271LayerTestResult<float, 4> Concatenation4dDim3Test(
4272 armnn::IWorkloadFactory& workloadFactory,
4273 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4274 bool useSubtensor)
4275{
4276 return Concatenation4dDim3TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0, useSubtensor);
4277}
4278
4279template <typename T>
4280LayerTestResult<T, 4> Concatenation4dDiffShapeDim0TestImpl(
4281 armnn::IWorkloadFactory& workloadFactory,
4282 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4283 float qScale,
4284 int32_t qOffset)
4285{
4286 unsigned int dimension = 0;
4287 armnn::TensorInfo inputTensorInfo0({ 1, 3, 2, 2 }, armnn::GetDataType<T>());
4288
4289 auto input0 = MakeTensor<T, 4>(inputTensorInfo0, QuantizedVector<T>(qScale, qOffset, {
4290 1.0f, 2.0f,
4291 3.0f, 4.0f,
4292 5.0f, 6.0f,
4293 7.0f, 8.0f,
4294 9.0f, 10.0f,
4295 11.0f, 12.0f
4296 }));
4297
4298 armnn::TensorInfo inputTensorInfo1({ 2, 3, 2, 2 }, armnn::GetDataType<T>());
4299
4300 auto input1 = MakeTensor<T, 4>(inputTensorInfo1, QuantizedVector<T>(qScale, qOffset, {
4301 11.0f, 12.0f,
4302 13.0f, 14.0f,
4303 15.0f, 16.0f,
4304 17.0f, 18.0f,
4305 19.0f, 20.0f,
4306 21.0f, 22.0f,
4307
4308 21.0f, 22.0f,
4309 23.0f, 24.0f,
4310 25.0f, 26.0f,
4311 27.0f, 28.0f,
4312 29.0f, 30.0f,
4313 31.0f, 32.0f
4314
4315 }));
4316
4317 armnn::TensorInfo outputTensorInfo({ 3, 3, 2, 2 }, armnn::GetDataType<T>());
4318
4319 LayerTestResult<T, 4> result(outputTensorInfo);
4320
4321 std::vector<T> output;
4322 output.resize(outputTensorInfo.GetNumElements());
4323 Concatenate<T>(workloadFactory,
4324 memoryManager,
4325 {inputTensorInfo0, inputTensorInfo1},
4326 {input0.data(), input1.data()},
4327 outputTensorInfo,
4328 output.data(),
4329 dimension,
4330 true);
4331
4332 result.output = MakeTensor<T, 4>(outputTensorInfo, output);
4333 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
4334 1.0f, 2.0f,
4335 3.0f, 4.0f,
4336 5.0f, 6.0f,
4337 7.0f, 8.0f,
4338 9.0f, 10.0f,
4339 11.0f, 12.0f,
4340
4341 11.0f, 12.0f,
4342 13.0f, 14.0f,
4343 15.0f, 16.0f,
4344 17.0f, 18.0f,
4345 19.0f, 20.0f,
4346 21.0f, 22.0f,
4347
4348 21.0f, 22.0f,
4349 23.0f, 24.0f,
4350 25.0f, 26.0f,
4351 27.0f, 28.0f,
4352 29.0f, 30.0f,
4353 31.0f, 32.0f
4354 }));
4355
4356 return result;
4357}
4358
4359LayerTestResult<float, 4> Concatenation4dDiffShapeDim0Test(
4360 armnn::IWorkloadFactory& workloadFactory,
4361 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
4362{
4363 return Concatenation4dDiffShapeDim0TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
4364}
4365
4366template <typename T>
4367LayerTestResult<T, 4> Concatenation4dDiffShapeDim1TestImpl(
4368 armnn::IWorkloadFactory& workloadFactory,
4369 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4370 float qScale,
4371 int32_t qOffset)
4372{
4373 unsigned int dimension = 1;
4374 armnn::TensorInfo inputTensorInfo0({ 1, 3, 2, 2 }, armnn::GetDataType<T>());
4375
4376 auto input0 = MakeTensor<T, 4>(inputTensorInfo0, QuantizedVector<T>(qScale, qOffset, {
4377 1.0f, 2.0f,
4378 3.0f, 4.0f,
4379 5.0f, 6.0f,
4380 7.0f, 8.0f,
4381 9.0f, 10.0f,
4382 11.0f, 12.0f
4383 }));
4384
4385 armnn::TensorInfo inputTensorInfo1({ 1, 2, 2, 2 }, armnn::GetDataType<T>());
4386
4387 auto input1 = MakeTensor<T, 4>(inputTensorInfo1, QuantizedVector<T>(qScale, qOffset, {
4388 11.0f, 12.0f,
4389 13.0f, 14.0f,
4390 15.0f, 16.0f,
4391 17.0f, 18.0f,
4392
4393 }));
4394
4395 armnn::TensorInfo outputTensorInfo({ 1, 5, 2, 2 }, armnn::GetDataType<T>());
4396
4397 LayerTestResult<T, 4> result(outputTensorInfo);
4398
4399 std::vector<T> output;
4400 output.resize(outputTensorInfo.GetNumElements());
4401 Concatenate<T>(workloadFactory,
4402 memoryManager,
4403 {inputTensorInfo0, inputTensorInfo1},
4404 {input0.data(), input1.data()},
4405 outputTensorInfo,
4406 output.data(),
4407 dimension,
4408 true);
4409
4410 result.output = MakeTensor<T, 4>(outputTensorInfo, output);
4411 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
4412 1.0f, 2.0f,
4413 3.0f, 4.0f,
4414 5.0f, 6.0f,
4415 7.0f, 8.0f,
4416 9.0f, 10.0f,
4417 11.0f, 12.0f,
4418 11.0f, 12.0f,
4419 13.0f, 14.0f,
4420 15.0f, 16.0f,
4421 17.0f, 18.0f
4422 }));
4423
4424 return result;
4425}
4426
4427LayerTestResult<float, 4> Concatenation4dDiffShapeDim1Test(
4428 armnn::IWorkloadFactory& workloadFactory,
4429 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
4430{
4431 return Concatenation4dDiffShapeDim1TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
4432}
4433
4434template <typename T>
4435LayerTestResult<T, 4> Concatenation4dDiffShapeDim2TestImpl(
4436 armnn::IWorkloadFactory& workloadFactory,
4437 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4438 float qScale,
4439 int32_t qOffset)
4440{
4441 unsigned int dimension = 2;
4442 armnn::TensorInfo inputTensorInfo0({ 1, 3, 2, 2 }, armnn::GetDataType<T>());
4443
4444 auto input0 = MakeTensor<T, 4>(inputTensorInfo0, QuantizedVector<T>(qScale, qOffset, {
4445 1.0f, 2.0f,
4446 3.0f, 4.0f,
4447 5.0f, 6.0f,
4448 7.0f, 8.0f,
4449 9.0f, 10.0f,
4450 11.0f, 12.0f
4451 }));
4452
4453 armnn::TensorInfo inputTensorInfo1({ 1, 3, 3, 2 }, armnn::GetDataType<T>());
4454
4455 auto input1 = MakeTensor<T, 4>(inputTensorInfo1, QuantizedVector<T>(qScale, qOffset, {
4456 11.0f, 12.0f,
4457 13.0f, 14.0f,
4458 15.0f, 16.0f,
4459 17.0f, 18.0f,
4460 19.0f, 20.0f,
4461 21.0f, 22.0f,
4462 23.0f, 24.0f,
4463 25.0f, 26.0f,
4464 27.0f, 28.0f
4465 }));
4466
4467 armnn::TensorInfo outputTensorInfo({ 1, 3, 5, 2 }, armnn::GetDataType<T>());
4468
4469 LayerTestResult<T, 4> result(outputTensorInfo);
4470
4471 std::vector<T> output;
4472 output.resize(outputTensorInfo.GetNumElements());
4473 Concatenate<T>(workloadFactory,
4474 memoryManager,
4475 {inputTensorInfo0, inputTensorInfo1},
4476 {input0.data(), input1.data()},
4477 outputTensorInfo,
4478 output.data(),
4479 dimension,
4480 true);
4481
4482 result.output = MakeTensor<T, 4>(outputTensorInfo, output);
4483 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
4484 1.0f, 2.0f,
4485 3.0f, 4.0f,
4486 11.0f, 12.0f,
4487 13.0f, 14.0f,
4488 15.0f, 16.0f,
4489
4490 5.0f, 6.0f,
4491 7.0f, 8.0f,
4492 17.0f, 18.0f,
4493 19.0f, 20.0f,
4494 21.0f, 22.0f,
4495
4496 9.0f, 10.0f,
4497 11.0f, 12.0f,
4498 23.0f, 24.0f,
4499 25.0f, 26.0f,
4500 27.0f, 28.0f
4501 }));
4502
4503 return result;
4504}
4505
4506LayerTestResult<float, 4> Concatenation4dDiffShapeDim2Test(
4507 armnn::IWorkloadFactory& workloadFactory,
4508 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
4509{
4510 return Concatenation4dDiffShapeDim2TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
4511}
4512
4513template <typename T>
4514LayerTestResult<T, 4> Concatenation4dDiffShapeDim3TestImpl(
4515 armnn::IWorkloadFactory& workloadFactory,
4516 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4517 float qScale,
4518 int32_t qOffset,
4519 bool useSubtensor)
4520{
4521 unsigned int dimension = 3;
4522 armnn::TensorInfo inputTensorInfo0({ 1, 3, 2, 2 }, armnn::GetDataType<T>());
4523
4524 auto input0 = MakeTensor<T, 4>(inputTensorInfo0, QuantizedVector<T>(qScale, qOffset, {
4525 1.0f, 2.0f,
4526 3.0f, 4.0f,
4527 5.0f, 6.0f,
4528 7.0f, 8.0f,
4529 9.0f, 10.0f,
4530 11.0f, 12.0f
4531 }));
4532
4533 armnn::TensorInfo inputTensorInfo1({ 1, 3, 2, 3 }, armnn::GetDataType<T>());
4534
4535 auto input1 = MakeTensor<T, 4>(inputTensorInfo1, QuantizedVector<T>(qScale, qOffset, {
4536 11.0f, 12.0f, 13.0f,
4537 14.0f, 15.0f, 16.0f,
4538
4539 17.0f, 18.0f, 19.0f,
4540 20.0f, 21.0f, 22.0f,
4541
4542 23.0f, 24.0f, 25.0f,
4543 26.0f, 27.0f, 28.0f
4544 }));
4545
4546 armnn::TensorInfo outputTensorInfo({ 1, 3, 2, 5 }, armnn::GetDataType<T>());
4547
4548 LayerTestResult<T, 4> result(outputTensorInfo);
4549
4550 std::vector<T> output;
4551 output.resize(outputTensorInfo.GetNumElements());
4552 Concatenate<T>(workloadFactory,
4553 memoryManager,
4554 {inputTensorInfo0, inputTensorInfo1},
4555 {input0.data(), input1.data()},
4556 outputTensorInfo,
4557 output.data(),
4558 dimension,
4559 useSubtensor);
4560
4561 result.output = MakeTensor<T, 4>(outputTensorInfo, output);
4562 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
4563 1.0f, 2.0f, 11.0f, 12.0f, 13.0f,
4564 3.0f, 4.0f, 14.0f, 15.0f, 16.0f,
4565 5.0f, 6.0f, 17.0f, 18.0f, 19.0f,
4566 7.0f, 8.0f, 20.0f, 21.0f, 22.0f,
4567 9.0f, 10.0f, 23.0f, 24.0f, 25.0f,
4568 11.0f, 12.0f, 26.0f, 27.0f, 28.0f
4569 }));
4570
4571 return result;
4572}
4573
4574LayerTestResult<float, 4> Concatenation4dDiffShapeDim3Test(
4575 armnn::IWorkloadFactory& workloadFactory,
4576 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4577 bool useSubtensor)
4578{
4579 return Concatenation4dDiffShapeDim3TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0, useSubtensor);
telsoa014fcda012018-03-09 14:13:49 +00004580}
4581
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004582LayerTestResult<float, 4> ResizeBilinearNopTest(
4583 armnn::IWorkloadFactory& workloadFactory,
4584 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00004585 const armnn::DataLayout dataLayout)
telsoa014fcda012018-03-09 14:13:49 +00004586{
Nina Drozdd41b2592018-11-19 13:03:36 +00004587 const armnn::TensorInfo inputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 4, 4, dataLayout);
4588 const armnn::TensorInfo outputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 4, 4, dataLayout);
telsoa014fcda012018-03-09 14:13:49 +00004589
James Conroy6b965822018-11-01 11:33:09 +00004590 std::vector<float> inputData({
4591 1.0f, 2.0f, 3.0f, 4.0f,
4592 2.0f, 3.0f, 4.0f, 5.0f,
4593 3.0f, 4.0f, 5.0f, 6.0f,
4594 4.0f, 5.0f, 6.0f, 7.0f,
4595
telsoa014fcda012018-03-09 14:13:49 +00004596 1.0f, 2.0f, 3.0f, 4.0f,
4597 2.0f, 3.0f, 4.0f, 5.0f,
4598 3.0f, 4.0f, 5.0f, 6.0f,
4599 4.0f, 5.0f, 6.0f, 7.0f
James Conroy6b965822018-11-01 11:33:09 +00004600 });
4601
4602 const armnn::PermutationVector NCHWToNHWC = { 0, 3, 1, 2 };
Matthew Bentham8800c002018-11-19 13:19:28 +00004603 if (dataLayout == armnn::DataLayout::NHWC)
James Conroy6b965822018-11-01 11:33:09 +00004604 {
4605 std::vector<float> tmp(inputData.size());
Matteo Martincighd5b9e642019-01-04 18:01:21 +00004606 armnnUtils::Permute(inputTensorInfo.GetShape(), NCHWToNHWC, inputData.data(), tmp.data(), sizeof(float));
James Conroy6b965822018-11-01 11:33:09 +00004607 inputData = tmp;
4608 }
4609
4610 auto input = MakeTensor<float, 4>(inputTensorInfo, inputData);
telsoa014fcda012018-03-09 14:13:49 +00004611
4612 LayerTestResult<float, 4> result(outputTensorInfo);
4613 result.outputExpected = input;
4614
4615 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
4616 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
4617
4618 armnn::ResizeBilinearQueueDescriptor descriptor;
James Conroy074f3712018-10-03 09:32:03 +01004619 descriptor.m_Parameters.m_DataLayout = dataLayout;
4620 armnn::WorkloadInfo info;
4621 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
4622 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
4623
4624 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
4625
4626 inputHandle->Allocate();
4627 outputHandle->Allocate();
4628 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
4629
James Conroy074f3712018-10-03 09:32:03 +01004630 workload->Execute();
4631
4632 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
4633 return result;
4634}
4635
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004636LayerTestResult<float, 4> SimpleResizeBilinearTest(
4637 armnn::IWorkloadFactory& workloadFactory,
4638 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00004639 const armnn::DataLayout dataLayout)
James Conroy074f3712018-10-03 09:32:03 +01004640{
Nina Drozdd41b2592018-11-19 13:03:36 +00004641 const armnn::TensorInfo inputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 2, 2, dataLayout);
4642 const armnn::TensorInfo outputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 1, 1, dataLayout);
James Conroy074f3712018-10-03 09:32:03 +01004643
James Conroy6b965822018-11-01 11:33:09 +00004644 std::vector<float> inputData({
James Conroy074f3712018-10-03 09:32:03 +01004645 1.0f, 255.0f,
James Conroy6b965822018-11-01 11:33:09 +00004646 200.0f, 250.0f,
4647
4648 250.0f, 200.0f,
4649 250.0f, 1.0f
4650 });
James Conroy074f3712018-10-03 09:32:03 +01004651
4652 // The 'resize bilinear' operation projects the top-left corner of output texels into the input image,
4653 // then figures out the interpolants and weights. Note this is different to projecting the centre of the
James Conroy6b965822018-11-01 11:33:09 +00004654 // output texel. Thus, for a input matrix of 2x2, we'll expect the output 1x1 matrix to contain, as
4655 // its single element, the value that was at position (0,0) of the input matrix (rather than an average,
4656 // which we would expect if projecting the centre).
4657
4658 std::vector<float> outputData({
4659 1.0f,
4660
4661 250.0f
4662 });
4663
4664 const armnn::PermutationVector NCHWToNHWC = { 0, 3, 1, 2 };
Matthew Bentham8800c002018-11-19 13:19:28 +00004665 if (dataLayout == armnn::DataLayout::NHWC)
James Conroy6b965822018-11-01 11:33:09 +00004666 {
4667 std::vector<float> tmp(inputData.size());
Matteo Martincighd5b9e642019-01-04 18:01:21 +00004668 armnnUtils::Permute(inputTensorInfo.GetShape(), NCHWToNHWC, inputData.data(), tmp.data(), sizeof(float));
James Conroy6b965822018-11-01 11:33:09 +00004669 inputData = tmp;
4670
4671 std::vector<float> tmp1(outputData.size());
Matteo Martincighd5b9e642019-01-04 18:01:21 +00004672 armnnUtils::Permute(outputTensorInfo.GetShape(), NCHWToNHWC, outputData.data(), tmp1.data(), sizeof(float));
James Conroy6b965822018-11-01 11:33:09 +00004673 outputData = tmp1;
4674 }
4675
4676 auto input = MakeTensor<float, 4>(inputTensorInfo, inputData);
4677
James Conroy074f3712018-10-03 09:32:03 +01004678 LayerTestResult<float, 4> result(outputTensorInfo);
James Conroy6b965822018-11-01 11:33:09 +00004679 result.outputExpected = MakeTensor<float, 4>(outputTensorInfo, outputData);
James Conroy074f3712018-10-03 09:32:03 +01004680
4681 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
4682 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
4683
4684 armnn::ResizeBilinearQueueDescriptor descriptor;
4685 descriptor.m_Parameters.m_DataLayout = dataLayout;
telsoa014fcda012018-03-09 14:13:49 +00004686 armnn::WorkloadInfo info;
4687 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
4688 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
4689
4690 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
4691
4692 inputHandle->Allocate();
4693 outputHandle->Allocate();
4694 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
4695
4696 workload->Execute();
4697
4698 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
4699 return result;
4700}
4701
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004702LayerTestResult<float, 4> ResizeBilinearSqMinTest(
4703 armnn::IWorkloadFactory& workloadFactory,
4704 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00004705 const armnn::DataLayout dataLayout)
telsoa014fcda012018-03-09 14:13:49 +00004706{
Nina Drozdd41b2592018-11-19 13:03:36 +00004707 const armnn::TensorInfo inputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 4, 4, dataLayout);
4708 const armnn::TensorInfo outputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 2, 2, dataLayout);
telsoa014fcda012018-03-09 14:13:49 +00004709
James Conroy6b965822018-11-01 11:33:09 +00004710 std::vector<float> inputData({
James Conroy074f3712018-10-03 09:32:03 +01004711 1.0f, 2.0f, 3.0f, 4.0f,
4712 2.0f, 3.0f, 4.0f, 5.0f,
4713 3.0f, 4.0f, 5.0f, 6.0f,
James Conroy6b965822018-11-01 11:33:09 +00004714 4.0f, 5.0f, 6.0f, 7.0f,
4715
4716 7.0f, 6.0f, 5.0f, 4.0f,
4717 6.0f, 5.0f, 4.0f, 3.0f,
4718 5.0f, 4.0f, 3.0f, 2.0f,
4719 4.0f, 3.0f, 2.0f, 1.0f
4720 });
4721
4722 std::vector<float> outputData({
4723 1.0f, 3.0f,
4724 3.0f, 5.0f,
4725
4726 7.0f, 5.0f,
4727 5.0f, 3.0f
4728 });
4729
4730 const armnn::PermutationVector NCHWToNHWC = { 0, 3, 1, 2 };
Matthew Bentham8800c002018-11-19 13:19:28 +00004731 if (dataLayout == armnn::DataLayout::NHWC)
James Conroy6b965822018-11-01 11:33:09 +00004732 {
4733 std::vector<float> tmp(inputData.size());
Matteo Martincighd5b9e642019-01-04 18:01:21 +00004734 armnnUtils::Permute(inputTensorInfo.GetShape(), NCHWToNHWC, inputData.data(), tmp.data(), sizeof(float));
James Conroy6b965822018-11-01 11:33:09 +00004735 inputData = tmp;
4736
4737 std::vector<float> tmp1(outputData.size());
Matteo Martincighd5b9e642019-01-04 18:01:21 +00004738 armnnUtils::Permute(outputTensorInfo.GetShape(), NCHWToNHWC, outputData.data(), tmp1.data(), sizeof(float));
James Conroy6b965822018-11-01 11:33:09 +00004739 outputData = tmp1;
4740 }
4741
4742 auto input = MakeTensor<float, 4>(inputTensorInfo, inputData);
telsoa014fcda012018-03-09 14:13:49 +00004743
telsoa014fcda012018-03-09 14:13:49 +00004744 LayerTestResult<float, 4> result(outputTensorInfo);
James Conroy6b965822018-11-01 11:33:09 +00004745 result.outputExpected = MakeTensor<float, 4>(outputTensorInfo, outputData);
telsoa014fcda012018-03-09 14:13:49 +00004746
4747 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
4748 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
4749
4750 armnn::ResizeBilinearQueueDescriptor descriptor;
James Conroy074f3712018-10-03 09:32:03 +01004751 descriptor.m_Parameters.m_DataLayout = dataLayout;
telsoa014fcda012018-03-09 14:13:49 +00004752 armnn::WorkloadInfo info;
4753 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
4754 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
4755
4756 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
4757
4758 inputHandle->Allocate();
4759 outputHandle->Allocate();
4760 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
4761
4762 workload->Execute();
4763
4764 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
4765 return result;
4766}
4767
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004768LayerTestResult<float, 4> ResizeBilinearMinTest(
4769 armnn::IWorkloadFactory& workloadFactory,
4770 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00004771 const armnn::DataLayout dataLayout)
telsoa014fcda012018-03-09 14:13:49 +00004772{
Nina Drozdd41b2592018-11-19 13:03:36 +00004773 const armnn::TensorInfo inputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 3, 5, dataLayout);
4774 const armnn::TensorInfo outputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 2, 3, dataLayout);
telsoa014fcda012018-03-09 14:13:49 +00004775
James Conroy6b965822018-11-01 11:33:09 +00004776 std::vector<float> inputData({
James Conroy074f3712018-10-03 09:32:03 +01004777 1.0f, 2.0f, 3.0f, 5.0f, 8.0f,
4778 13.0f, 21.0f, 34.0f, 55.0f, 89.0f,
James Conroy6b965822018-11-01 11:33:09 +00004779 144.0f, 233.0f, 377.0f, 610.0f, 987.0f,
4780
4781 987.0f, 610.0f, 377.0f, 233.0f, 144.0f,
4782 89.0f, 55.0f, 34.0f, 21.0f, 13.0f,
4783 8.0f, 5.0f, 3.0f, 2.0f, 1.0f
4784 });
4785
4786 std::vector<float> outputData({
4787 1.0f, 2.6666f, 6.00f,
4788 78.5f, 179.3333f, 401.00f,
4789
4790 987.0f, 454.6670f, 203.33f,
4791 48.5f, 22.3333f, 10.00f
4792 });
4793
4794 const armnn::PermutationVector NCHWToNHWC = { 0, 3, 1, 2 };
Matthew Bentham8800c002018-11-19 13:19:28 +00004795 if (dataLayout == armnn::DataLayout::NHWC)
James Conroy6b965822018-11-01 11:33:09 +00004796 {
4797 std::vector<float> tmp(inputData.size());
Matteo Martincighd5b9e642019-01-04 18:01:21 +00004798 armnnUtils::Permute(inputTensorInfo.GetShape(), NCHWToNHWC, inputData.data(), tmp.data(), sizeof(float));
James Conroy6b965822018-11-01 11:33:09 +00004799 inputData = tmp;
4800
4801 std::vector<float> tmp1(outputData.size());
Matteo Martincighd5b9e642019-01-04 18:01:21 +00004802 armnnUtils::Permute(outputTensorInfo.GetShape(), NCHWToNHWC, outputData.data(), tmp1.data(), sizeof(float));
James Conroy6b965822018-11-01 11:33:09 +00004803 outputData = tmp1;
4804 }
4805
4806 auto input = MakeTensor<float, 4>(inputTensorInfo, inputData);
telsoa014fcda012018-03-09 14:13:49 +00004807
4808 LayerTestResult<float, 4> result(outputTensorInfo);
James Conroy6b965822018-11-01 11:33:09 +00004809 result.outputExpected = MakeTensor<float, 4>(outputTensorInfo, outputData);
telsoa014fcda012018-03-09 14:13:49 +00004810
4811 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
4812 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
4813
4814 armnn::ResizeBilinearQueueDescriptor descriptor;
James Conroy074f3712018-10-03 09:32:03 +01004815 descriptor.m_Parameters.m_DataLayout = dataLayout;
telsoa014fcda012018-03-09 14:13:49 +00004816 armnn::WorkloadInfo info;
4817 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
4818 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
4819
4820 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
4821
4822 inputHandle->Allocate();
4823 outputHandle->Allocate();
4824 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
4825
4826 workload->Execute();
4827
4828 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
4829 return result;
4830}
4831
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004832LayerTestResult<float, 4> ResizeBilinearMagTest(
4833 armnn::IWorkloadFactory& workloadFactory,
4834 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00004835 const armnn::DataLayout dataLayout)
telsoa014fcda012018-03-09 14:13:49 +00004836{
Nina Drozdd41b2592018-11-19 13:03:36 +00004837 const armnn::TensorInfo inputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 3, 2, dataLayout);
4838 const armnn::TensorInfo outputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 3, 5, dataLayout);
telsoa014fcda012018-03-09 14:13:49 +00004839
James Conroy6b965822018-11-01 11:33:09 +00004840 std::vector<float> inputData({
James Conroy074f3712018-10-03 09:32:03 +01004841 1.0f, 2.0f,
4842 13.0f, 21.0f,
James Conroy6b965822018-11-01 11:33:09 +00004843 144.0f, 233.0f,
telsoa014fcda012018-03-09 14:13:49 +00004844
James Conroy6b965822018-11-01 11:33:09 +00004845 233.0f, 144.0f,
4846 21.0f, 13.0f,
4847 2.0f, 1.0f
4848 });
4849
4850 std::vector<float> outputData({
James Conroy074f3712018-10-03 09:32:03 +01004851 1.0f, 1.4f, 1.8f, 2.0f, 2.0f,
4852 13.0f, 16.2f, 19.4f, 21.0f, 21.0f,
James Conroy6b965822018-11-01 11:33:09 +00004853 144.0f, 179.6f, 215.2f, 233.0f, 233.0f,
4854
4855 233.0f, 197.4f, 161.8f, 144.0f, 144.0f,
4856 21.0f, 17.8f, 14.6f, 13.0f, 13.0f,
4857 2.0f, 1.6f, 1.2f, 1.0f, 1.0f
4858 });
4859
4860 const armnn::PermutationVector NCHWToNHWC = { 0, 3, 1, 2 };
Matthew Bentham8800c002018-11-19 13:19:28 +00004861 if (dataLayout == armnn::DataLayout::NHWC)
James Conroy6b965822018-11-01 11:33:09 +00004862 {
4863 std::vector<float> tmp(inputData.size());
Matteo Martincighd5b9e642019-01-04 18:01:21 +00004864 armnnUtils::Permute(inputTensorInfo.GetShape(), NCHWToNHWC, inputData.data(), tmp.data(), sizeof(float));
James Conroy6b965822018-11-01 11:33:09 +00004865 inputData = tmp;
4866
4867 std::vector<float> tmp1(outputData.size());
Matteo Martincighd5b9e642019-01-04 18:01:21 +00004868 armnnUtils::Permute(outputTensorInfo.GetShape(), NCHWToNHWC, outputData.data(), tmp1.data(), sizeof(float));
James Conroy6b965822018-11-01 11:33:09 +00004869 outputData = tmp1;
4870 }
4871
4872 auto input = MakeTensor<float, 4>(inputTensorInfo, inputData);
4873
4874 LayerTestResult<float, 4> result(outputTensorInfo);
4875 result.outputExpected = MakeTensor<float, 4>(outputTensorInfo, outputData);
telsoa014fcda012018-03-09 14:13:49 +00004876
4877 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
4878 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
4879
4880 armnn::ResizeBilinearQueueDescriptor descriptor;
James Conroy074f3712018-10-03 09:32:03 +01004881 descriptor.m_Parameters.m_DataLayout = dataLayout;
telsoa014fcda012018-03-09 14:13:49 +00004882 armnn::WorkloadInfo info;
4883 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
4884 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
4885
4886 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
4887
4888 inputHandle->Allocate();
4889 outputHandle->Allocate();
4890 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
4891
4892 workload->Execute();
4893
4894 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
4895 return result;
4896}
4897
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004898LayerTestResult<float, 2> FakeQuantizationTest(
4899 armnn::IWorkloadFactory& workloadFactory,
4900 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00004901{
4902 constexpr unsigned int width = 2;
4903 constexpr unsigned int height = 3;
4904
4905 const armnn::TensorInfo tensorInfo({height, width },
4906 armnn::DataType::Float32);
4907 auto input = MakeTensor<float, 2>(tensorInfo, std::vector<float>({
4908 -10.0f, -5.0f,
4909 0.0f, 5.0f,
4910 10.0f, 10.0f
4911 }));
4912
4913 LayerTestResult<float, 2> ret(tensorInfo);
4914
4915 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(tensorInfo);
4916
4917 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(tensorInfo);
4918
4919 armnn::FakeQuantizationQueueDescriptor data;
4920 armnn::WorkloadInfo info;
4921
4922 AddInputToWorkload(data, info, tensorInfo, inputHandle.get());
4923 AddOutputToWorkload(data, info, tensorInfo, outputHandle.get());
4924 float min = -10.f;
4925 float max = 10.f;
4926
4927 data.m_Parameters.m_Min = min;
4928 data.m_Parameters.m_Max = max;
4929
4930 armnn::PassthroughCpuTensorHandle refHandle(tensorInfo, &ret.outputExpected[0][0]);
4931 armnn::FakeQuantizationQueueDescriptor refData = data;
4932 armnn::WorkloadInfo refInfo = info;
4933 SetWorkloadOutput(refData, refInfo, 0, tensorInfo, &refHandle);
4934
4935 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateFakeQuantization(data, info);
4936
4937 inputHandle->Allocate();
4938 outputHandle->Allocate();
4939
4940 CopyDataToITensorHandle(inputHandle.get(), &input[0][0]);
4941
4942 workload->Execute();
4943
4944 CopyDataFromITensorHandle(&ret.output[0][0], outputHandle.get());
4945
4946 ret.outputExpected = MakeTensor<float, 2>(tensorInfo, std::vector<float>({
4947 0.0f, 63.0f,
4948 128.0f, 191.0f,
4949 255.0f, 255.0f
4950 }));
4951 return ret;
4952}
4953
Matteo Martincigh539b44d2018-10-01 09:26:39 +01004954namespace
4955{
4956
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004957LayerTestResult<float, 4> L2NormalizationTestImpl(
4958 armnn::IWorkloadFactory& workloadFactory,
4959 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4960 const armnn::TensorShape& inputOutputTensorShape,
4961 const std::vector<float>& inputValues,
4962 const std::vector<float>& expectedOutputValues,
Matthew Bentham8800c002018-11-19 13:19:28 +00004963 const armnn::DataLayout layout)
Matteo Martincigh539b44d2018-10-01 09:26:39 +01004964{
4965 const armnn::TensorInfo inputTensorInfo(inputOutputTensorShape, armnn::DataType::Float32);
4966 const armnn::TensorInfo outputTensorInfo(inputOutputTensorShape, armnn::DataType::Float32);
4967
jimfly013aab7c32018-11-12 13:32:08 +00004968 // at this point if we require it permute the input data
4969 const armnn::PermutationVector NCHWToNHWC = { 0, 3, 1, 2 };
4970 std::vector<float> inputData = inputValues;
Matthew Bentham8800c002018-11-19 13:19:28 +00004971 if (layout == armnn::DataLayout::NHWC)
jimfly013aab7c32018-11-12 13:32:08 +00004972 {
4973 std::vector<float> tmp(inputData.size());
Matteo Martincighd5b9e642019-01-04 18:01:21 +00004974 armnnUtils::Permute(inputTensorInfo.GetShape(), NCHWToNHWC, inputData.data(), tmp.data(), sizeof(float));
jimfly013aab7c32018-11-12 13:32:08 +00004975 inputData = tmp;
4976 }
4977
4978 auto inputTensor = MakeTensor<float, 4>(inputTensorInfo, std::vector<float>(inputData));
Matteo Martincigh539b44d2018-10-01 09:26:39 +01004979
4980 LayerTestResult<float, 4> result(outputTensorInfo);
jimfly013aab7c32018-11-12 13:32:08 +00004981 std::vector<float> expectedOutputData = expectedOutputValues;
Matthew Bentham8800c002018-11-19 13:19:28 +00004982 if (layout == armnn::DataLayout::NHWC)
jimfly013aab7c32018-11-12 13:32:08 +00004983 {
4984 std::vector<float> tmp(expectedOutputData.size());
Matteo Martincighd5b9e642019-01-04 18:01:21 +00004985 armnnUtils::Permute(inputTensorInfo.GetShape(), NCHWToNHWC,
4986 expectedOutputData.data(), tmp.data(), sizeof(float));
jimfly013aab7c32018-11-12 13:32:08 +00004987 expectedOutputData = tmp;
4988 }
4989 result.outputExpected = MakeTensor<float, 4>(inputTensorInfo, std::vector<float>(expectedOutputData));
Matteo Martincigh539b44d2018-10-01 09:26:39 +01004990
4991 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
4992 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
4993
4994 armnn::L2NormalizationQueueDescriptor descriptor;
Matthew Bentham8800c002018-11-19 13:19:28 +00004995 descriptor.m_Parameters.m_DataLayout = layout;
Matteo Martincigh539b44d2018-10-01 09:26:39 +01004996 armnn::WorkloadInfo info;
4997
4998 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
4999 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
5000
5001 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateL2Normalization(descriptor, info);
5002
5003 inputHandle->Allocate();
5004 outputHandle->Allocate();
5005
5006 CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0][0][0]);
5007
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005008 ExecuteWorkload(*workload, memoryManager);
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005009
5010 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
5011
5012 return result;
5013}
5014
5015float CalcInvL2Norm(std::initializer_list<float> elements)
5016{
5017 const float reduction = std::accumulate(elements.begin(), elements.end(), 0.0f,
5018 [](float acc, float element) { return acc + element * element; });
5019 return 1.0f / sqrtf(reduction);
5020}
5021
5022} // anonymous namespace
5023
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005024template<typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005025LayerTestResult<T, 2> Pad2dTestCommon(
5026 armnn::IWorkloadFactory& workloadFactory,
5027 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
5028 float qScale,
5029 int32_t qOffset)
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005030{
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005031 const armnn::TensorShape inputShape{ 3, 3 };
5032 const armnn::TensorShape outputShape{ 7, 7 };
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005033
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005034 const armnn::TensorInfo inputTensorInfo(inputShape, armnn::GetDataType<T>());
5035 const armnn::TensorInfo outputTensorInfo(outputShape, armnn::GetDataType<T>());
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005036
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005037 std::vector<T> inputValues(
5038 QuantizedVector<T>(qScale, qOffset,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005039 {
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005040 // Height (3) x Width (3)
5041 4, 8, 6,
5042 7, 4, 4,
5043 3, 2, 4
5044 }));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005045
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005046 std::vector<T> expectedOutputValues(
5047 QuantizedVector<T>(qScale, qOffset,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005048 {
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005049 0, 0, 0, 0, 0, 0, 0,
5050 0, 0, 0, 0, 0, 0, 0,
5051 0, 0, 4, 8, 6, 0, 0,
5052 0, 0, 7, 4, 4, 0, 0,
5053 0, 0, 3, 2, 4, 0, 0,
5054 0, 0, 0, 0, 0, 0, 0,
5055 0, 0, 0, 0, 0, 0, 0
5056 }));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005057
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005058 auto inputTensor = MakeTensor<T, 2>(inputTensorInfo, std::vector<T>(inputValues));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005059
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005060 LayerTestResult<T, 2> result(outputTensorInfo);
5061 result.outputExpected = MakeTensor<T, 2>(outputTensorInfo, std::vector<T>(expectedOutputValues));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005062
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005063 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
5064 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005065
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005066 armnn::PadQueueDescriptor descriptor;
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005067
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005068 std::vector<std::pair<unsigned int, unsigned int>> PadList;
5069 PadList.push_back(std::pair<unsigned int, unsigned int>(2,2));
5070 PadList.push_back(std::pair<unsigned int, unsigned int>(2,2));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005071
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005072 descriptor.m_Parameters.m_PadList = PadList;
5073 armnn::WorkloadInfo info;
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005074
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005075 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
5076 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005077
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005078 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreatePad(descriptor, info);
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005079
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005080 inputHandle->Allocate();
5081 outputHandle->Allocate();
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005082
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005083 CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0]);
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005084
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005085 workload->Execute();
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005086
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005087 CopyDataFromITensorHandle(&result.output[0][0], outputHandle.get());
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005088
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005089 return result;
5090}
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005091
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005092template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005093LayerTestResult<T, 3> Pad3dTestCommon(
5094 armnn::IWorkloadFactory& workloadFactory,
5095 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
5096 float qScale,
5097 int32_t qOffset)
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005098{
5099 const armnn::TensorShape inputShape{ 2, 2, 2 };
5100 const armnn::TensorShape outputShape{ 3, 5, 6 };
5101
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005102 const armnn::TensorInfo inputTensorInfo(inputShape, armnn::GetDataType<T>());
5103 const armnn::TensorInfo outputTensorInfo(outputShape, armnn::GetDataType<T>());
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005104
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005105 std::vector<T> inputValues(
5106 QuantizedVector<T>(qScale,qOffset,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005107 {
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005108 // Channel 0, Height (2) x Width (2)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005109 0, 4,
5110 2, 5,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005111
5112 // Channel 1, Height (2) x Width (2)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005113 6, 1,
5114 5, 2
5115 }));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005116
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005117 std::vector<T> expectedOutputValues(
5118 QuantizedVector<T>(qScale,qOffset,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005119 {
5120
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005121 0, 0, 0, 0, 0, 0,
5122 0, 0, 0, 0, 0, 0,
5123 0, 0, 0, 4, 0, 0,
5124 0, 0, 2, 5, 0, 0,
5125 0, 0, 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005126
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005127 0, 0, 0, 0, 0, 0,
5128 0, 0, 0, 0, 0, 0,
5129 0, 0, 6, 1, 0, 0,
5130 0, 0, 5, 2, 0, 0,
5131 0, 0, 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005132
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005133 0, 0, 0, 0, 0, 0,
5134 0, 0, 0, 0, 0, 0,
5135 0, 0, 0, 0, 0, 0,
5136 0, 0, 0, 0, 0, 0,
5137 0, 0, 0, 0, 0, 0
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005138
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005139 }));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005140
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005141 auto inputTensor = MakeTensor<T, 3>(inputTensorInfo, std::vector<T>(inputValues));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005142
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005143 LayerTestResult<T, 3> result(outputTensorInfo);
5144 result.outputExpected = MakeTensor<T, 3>(outputTensorInfo, std::vector<T>(expectedOutputValues));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005145
5146 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
5147 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
5148
5149 armnn::PadQueueDescriptor descriptor;
5150
5151 std::vector<std::pair<unsigned int, unsigned int>> PadList;
5152 PadList.push_back(std::pair<unsigned int, unsigned int>(0,1));
5153 PadList.push_back(std::pair<unsigned int, unsigned int>(2,1));
5154 PadList.push_back(std::pair<unsigned int, unsigned int>(2,2));
5155
5156 descriptor.m_Parameters.m_PadList = PadList;
5157 armnn::WorkloadInfo info;
5158
5159 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
5160 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
5161
5162 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreatePad(descriptor, info);
5163
5164 inputHandle->Allocate();
5165 outputHandle->Allocate();
5166
5167 CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0][0]);
5168
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005169 workload->Execute();
5170
5171 CopyDataFromITensorHandle(&result.output[0][0][0], outputHandle.get());
5172
5173 return result;
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005174}
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005175
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005176template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005177LayerTestResult<T, 4> Pad4dTestCommon(
5178 armnn::IWorkloadFactory& workloadFactory,
5179 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
5180 float qScale,
5181 int32_t qOffset)
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005182{
5183 const armnn::TensorShape inputShape{ 2, 2, 3, 2 };
5184 const armnn::TensorShape outputShape{ 4, 5, 7, 4 };
5185
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005186 const armnn::TensorInfo inputTensorInfo(inputShape, armnn::GetDataType<T>());
5187 const armnn::TensorInfo outputTensorInfo(outputShape, armnn::GetDataType<T>());
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005188
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005189 std::vector<T> inputValues(
5190 QuantizedVector<T>(qScale,qOffset,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005191 {
5192 // Batch 0, Channel 0, Height (3) x Width (2)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005193 0, 1,
5194 2, 3,
5195 4, 5,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005196
5197 // Batch 0, Channel 1, Height (3) x Width (2)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005198 6, 7,
5199 8, 9,
5200 10, 11,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005201
5202 // Batch 1, Channel 0, Height (3) x Width (2)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005203 12, 13,
5204 14, 15,
5205 16, 17,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005206
5207 // Batch 1, Channel 1, Height (3) x Width (2)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005208 18, 19,
5209 20, 21,
5210 22, 23
5211 }));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005212
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005213 std::vector<T> expectedOutputValues(
5214 QuantizedVector<T>(qScale,qOffset,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005215 {
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005216 0, 0, 0, 0,
5217 0, 0, 0, 0,
5218 0, 0, 0, 0,
5219 0, 0, 0, 0,
5220 0, 0, 0, 0,
5221 0, 0, 0, 0,
5222 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005223
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005224 0, 0, 0, 0,
5225 0, 0, 0, 0,
5226 0, 0, 0, 0,
5227 0, 0, 0, 0,
5228 0, 0, 0, 0,
5229 0, 0, 0, 0,
5230 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005231
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005232 0, 0, 0, 0,
5233 0, 0, 0, 0,
5234 0, 0, 0, 0,
5235 0, 0, 0, 0,
5236 0, 0, 0, 0,
5237 0, 0, 0, 0,
5238 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005239
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005240 0, 0, 0, 0,
5241 0, 0, 0, 0,
5242 0, 0, 0, 0,
5243 0, 0, 0, 0,
5244 0, 0, 0, 0,
5245 0, 0, 0, 0,
5246 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005247
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005248 0, 0, 0, 0,
5249 0, 0, 0, 0,
5250 0, 0, 0, 0,
5251 0, 0, 0, 0,
5252 0, 0, 0, 0,
5253 0, 0, 0, 0,
5254 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005255
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005256 0, 0, 0, 0,
5257 0, 0, 0, 0,
5258 0, 0, 0, 0,
5259 0, 0, 0, 0,
5260 0, 0, 0, 0,
5261 0, 0, 0, 0,
5262 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005263
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005264 0, 0, 0, 0,
5265 0, 0, 0, 0,
5266 0, 0, 0, 0,
5267 0, 0, 0, 0,
5268 0, 0, 0, 0,
5269 0, 0, 0, 0,
5270 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005271
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005272 0, 0, 0, 0,
5273 0, 0, 0, 0,
5274 0, 0, 0, 0,
5275 0, 0, 1, 0,
5276 0, 2, 3, 0,
5277 0, 4, 5, 0,
5278 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005279
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005280 0, 0, 0, 0,
5281 0, 0, 0, 0,
5282 0, 0, 0, 0,
5283 0, 6, 7, 0,
5284 0, 8, 9, 0,
5285 0, 10, 11, 0,
5286 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005287
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005288 0, 0, 0, 0,
5289 0, 0, 0, 0,
5290 0, 0, 0, 0,
5291 0, 0, 0, 0,
5292 0, 0, 0, 0,
5293 0, 0, 0, 0,
5294 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005295
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005296 0, 0, 0, 0,
5297 0, 0, 0, 0,
5298 0, 0, 0, 0,
5299 0, 0, 0, 0,
5300 0, 0, 0, 0,
5301 0, 0, 0, 0,
5302 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005303
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005304 0, 0, 0, 0,
5305 0, 0, 0, 0,
5306 0, 0, 0, 0,
5307 0, 0, 0, 0,
5308 0, 0, 0, 0,
5309 0, 0, 0, 0,
5310 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005311
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005312 0, 0, 0, 0,
5313 0, 0, 0, 0,
5314 0, 0, 0, 0,
5315 0, 12, 13, 0,
5316 0, 14, 15, 0,
5317 0, 16, 17, 0,
5318 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005319
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005320 0, 0, 0, 0,
5321 0, 0, 0, 0,
5322 0, 0, 0, 0,
5323 0, 18, 19, 0,
5324 0, 20, 21, 0,
5325 0, 22, 23, 0,
5326 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005327
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005328 0, 0, 0, 0,
5329 0, 0, 0, 0,
5330 0, 0, 0, 0,
5331 0, 0, 0, 0,
5332 0, 0, 0, 0,
5333 0, 0, 0, 0,
5334 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005335
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005336 0, 0, 0, 0,
5337 0, 0, 0, 0,
5338 0, 0, 0, 0,
5339 0, 0, 0, 0,
5340 0, 0, 0, 0,
5341 0, 0, 0, 0,
5342 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005343
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005344 0, 0, 0, 0,
5345 0, 0, 0, 0,
5346 0, 0, 0, 0,
5347 0, 0, 0, 0,
5348 0, 0, 0, 0,
5349 0, 0, 0, 0,
5350 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005351
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005352 0, 0, 0, 0,
5353 0, 0, 0, 0,
5354 0, 0, 0, 0,
5355 0, 0, 0, 0,
5356 0, 0, 0, 0,
5357 0, 0, 0, 0,
5358 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005359
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005360 0, 0, 0, 0,
5361 0, 0, 0, 0,
5362 0, 0, 0, 0,
5363 0, 0, 0, 0,
5364 0, 0, 0, 0,
5365 0, 0, 0, 0,
5366 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005367
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005368 0, 0, 0, 0,
5369 0, 0, 0, 0,
5370 0, 0, 0, 0,
5371 0, 0, 0, 0,
5372 0, 0, 0, 0,
5373 0, 0, 0, 0,
5374 0, 0, 0, 0
5375 }));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005376
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005377 auto inputTensor = MakeTensor<T, 4>(inputTensorInfo, std::vector<T>(inputValues));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005378
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005379 LayerTestResult<T, 4> result(outputTensorInfo);
5380 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, std::vector<T>(expectedOutputValues));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005381
5382 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
5383 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
5384
5385 armnn::PadQueueDescriptor descriptor;
5386
5387 std::vector<std::pair<unsigned int, unsigned int>> PadList;
5388 PadList.push_back(std::pair<unsigned int, unsigned int>(1,1));
5389 PadList.push_back(std::pair<unsigned int, unsigned int>(2,1));
5390 PadList.push_back(std::pair<unsigned int, unsigned int>(3,1));
5391 PadList.push_back(std::pair<unsigned int, unsigned int>(1,1));
5392
5393 descriptor.m_Parameters.m_PadList = PadList;
5394 armnn::WorkloadInfo info;
5395
5396 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
5397 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
5398
5399 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreatePad(descriptor, info);
5400
5401 inputHandle->Allocate();
5402 outputHandle->Allocate();
5403
5404 CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0][0][0]);
5405
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005406 workload->Execute();
5407
5408 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
5409
5410 return result;
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005411}
5412
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005413LayerTestResult<uint8_t, 2> PadUint82dTest(
5414 armnn::IWorkloadFactory& workloadFactory,
5415 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005416{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005417 return Pad2dTestCommon<uint8_t>(workloadFactory, memoryManager, 1.0f, 0);
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005418}
5419
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005420LayerTestResult<uint8_t, 3> PadUint83dTest(
5421 armnn::IWorkloadFactory& workloadFactory,
5422 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005423{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005424 return Pad3dTestCommon<uint8_t>(workloadFactory, memoryManager, 1.0f, 0);
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005425}
5426
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005427LayerTestResult<uint8_t, 4> PadUint84dTest(
5428 armnn::IWorkloadFactory& workloadFactory,
5429 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005430{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005431 return Pad4dTestCommon<uint8_t>(workloadFactory, memoryManager, 1.0f, 0);
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005432}
5433
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005434LayerTestResult<float, 2> PadFloat322dTest(
5435 armnn::IWorkloadFactory& workloadFactory,
5436 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005437{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005438 return Pad2dTestCommon<float>(workloadFactory, memoryManager, 0.0f, 0);
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005439}
5440
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005441LayerTestResult<float, 3> PadFloat323dTest(
5442 armnn::IWorkloadFactory& workloadFactory,
5443 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005444{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005445 return Pad3dTestCommon<float>(workloadFactory, memoryManager, 0.0f, 0);
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005446}
5447
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005448LayerTestResult<float, 4> PadFloat324dTest(
5449 armnn::IWorkloadFactory& workloadFactory,
5450 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005451{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005452 return Pad4dTestCommon<float>(workloadFactory, memoryManager, 0.0f, 0);
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005453}
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005454
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005455LayerTestResult<float, 4> L2Normalization1dTest(
5456 armnn::IWorkloadFactory& workloadFactory,
5457 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00005458 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +00005459{
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005460 // Width: 1
5461 // Height: 1
5462 // Channels: 10
5463 // BatchSize: 1
jimfly013aab7c32018-11-12 13:32:08 +00005464 unsigned int numberOfBatches = 1;
5465 unsigned int numberOfChannels = 10;
5466 unsigned int height = 1;
5467 unsigned int width = 1;
telsoa014fcda012018-03-09 14:13:49 +00005468
jimfly013aab7c32018-11-12 13:32:08 +00005469
Nina Drozdd41b2592018-11-19 13:03:36 +00005470 const armnn::TensorShape inputOutputShape = armnnUtils::GetTensorShape(
jimfly013aab7c32018-11-12 13:32:08 +00005471 numberOfBatches, numberOfChannels, height, width, layout);
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005472 std::vector<float> inputValues
5473 {
5474 // Batch 0, Channel 0, Height (1) x Width (1)
5475 1.0f,
telsoa014fcda012018-03-09 14:13:49 +00005476
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005477 // Batch 0, Channel 1, Height (1) x Width (1)
5478 2.0f,
telsoa014fcda012018-03-09 14:13:49 +00005479
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005480 // Batch 0, Channel 2, Height (1) x Width (1)
5481 3.0f,
telsoa014fcda012018-03-09 14:13:49 +00005482
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005483 // Batch 0, Channel 3, Height (1) x Width (1)
5484 4.0f,
5485
5486 // Batch 0, Channel 4, Height (1) x Width (1)
5487 5.0f,
5488
5489 // Batch 0, Channel 5, Height (1) x Width (1)
5490 6.0f,
5491
5492 // Batch 0, Channel 6, Height (1) x Width (1)
5493 7.0f,
5494
5495 // Batch 0, Channel 7, Height (1) x Width (1)
5496 8.0f,
5497
5498 // Batch 0, Channel 8, Height (1) x Width (1)
5499 9.0f,
5500
5501 // Batch 0, Channel 9, Height (1) x Width (1)
5502 10.0f
5503 };
telsoa014fcda012018-03-09 14:13:49 +00005504 const float approxInvL2Norm = 0.050964719f;
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005505 std::vector<float> expectedOutputValues
5506 {
5507 // Batch 0, Channel 0, Height (1) x Width (1)
telsoa014fcda012018-03-09 14:13:49 +00005508 1.0f * approxInvL2Norm,
5509 2.0f * approxInvL2Norm,
5510 3.0f * approxInvL2Norm,
5511 4.0f * approxInvL2Norm,
5512 5.0f * approxInvL2Norm,
5513 6.0f * approxInvL2Norm,
5514 7.0f * approxInvL2Norm,
5515 8.0f * approxInvL2Norm,
5516 9.0f * approxInvL2Norm,
5517 10.0f * approxInvL2Norm
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005518 };
telsoa014fcda012018-03-09 14:13:49 +00005519
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005520
5521 return L2NormalizationTestImpl(workloadFactory, memoryManager, inputOutputShape,
jimfly013aab7c32018-11-12 13:32:08 +00005522 inputValues, expectedOutputValues, layout);
telsoa014fcda012018-03-09 14:13:49 +00005523}
5524
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005525LayerTestResult<float, 4> L2Normalization2dTest(
5526 armnn::IWorkloadFactory& workloadFactory,
5527 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00005528 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +00005529{
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005530 // Width: 5
5531 // Height: 1
5532 // Channels: 2
5533 // BatchSize: 1
jimfly013aab7c32018-11-12 13:32:08 +00005534 unsigned int numberOfBatches = 1;
5535 unsigned int numberOfChannels = 2;
5536 unsigned int height = 1;
5537 unsigned int width = 5;
telsoa014fcda012018-03-09 14:13:49 +00005538
Nina Drozdd41b2592018-11-19 13:03:36 +00005539 const armnn::TensorShape inputOutputShape = armnnUtils::GetTensorShape(
jimfly013aab7c32018-11-12 13:32:08 +00005540 numberOfBatches, numberOfChannels, height, width, layout);
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005541 std::vector<float> inputValues
5542 {
5543 // Batch 0, Channel 0, Height (1) x Width (5)
telsoa014fcda012018-03-09 14:13:49 +00005544 1.0f, 3.0f, 5.0f, 7.0f, 9.0f,
telsoa014fcda012018-03-09 14:13:49 +00005545
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005546 // Batch 0, Channel 1, Height (1) x Width (5)
5547 2.0f, 4.0f, 6.0f, 8.0f, 10.0f
5548 };
5549 std::vector<float> expectedOutputValues
5550 {
5551 // Batch 0, Channel 0, Height (1) x Width (5)
5552 1.0f * CalcInvL2Norm({ 1.0f, 2.0f }),
5553 3.0f * CalcInvL2Norm({ 3.0f, 4.0f }),
5554 5.0f * CalcInvL2Norm({ 5.0f, 6.0f }),
5555 7.0f * CalcInvL2Norm({ 7.0f, 8.0f }),
telsoa014fcda012018-03-09 14:13:49 +00005556 9.0f * CalcInvL2Norm({ 9.0f, 10.0f }),
5557
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005558 // Batch 0, Channel 1, Height (1) x Width (5)
5559 2.0f * CalcInvL2Norm({ 1.0f, 2.0f }),
5560 4.0f * CalcInvL2Norm({ 3.0f, 4.0f }),
5561 6.0f * CalcInvL2Norm({ 5.0f, 6.0f }),
5562 8.0f * CalcInvL2Norm({ 7.0f, 8.0f }),
telsoa014fcda012018-03-09 14:13:49 +00005563 10.0f * CalcInvL2Norm({ 9.0f, 10.0f })
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005564 };
telsoa014fcda012018-03-09 14:13:49 +00005565
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005566 return L2NormalizationTestImpl(workloadFactory, memoryManager, inputOutputShape,
jimfly013aab7c32018-11-12 13:32:08 +00005567 inputValues, expectedOutputValues, layout);
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005568}
telsoa014fcda012018-03-09 14:13:49 +00005569
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005570LayerTestResult<float, 4> L2Normalization3dTest(
5571 armnn::IWorkloadFactory& workloadFactory,
5572 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00005573 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +00005574{
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005575 // Width: 3
5576 // Height: 4
5577 // Channels: 2
5578 // BatchSize: 1
jimfly013aab7c32018-11-12 13:32:08 +00005579 unsigned int numberOfBatches = 1;
5580 unsigned int numberOfChannels = 2;
5581 unsigned int height = 4;
5582 unsigned int width = 3;
telsoa014fcda012018-03-09 14:13:49 +00005583
Nina Drozdd41b2592018-11-19 13:03:36 +00005584 const armnn::TensorShape inputOutputShape = armnnUtils::GetTensorShape(
jimfly013aab7c32018-11-12 13:32:08 +00005585 numberOfBatches, numberOfChannels, height, width, layout);
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005586 std::vector<float> inputValues
5587 {
5588 // Batch 0, Channel 0, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005589 119.0f, 21.0f, 150.0f,
5590 149.0f, 32.0f, 179.0f,
5591 15.0f, 227.0f, 141.0f,
5592 147.0f, 199.0f, 220.0f,
5593
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005594 // Batch 0, Channel 1, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005595 110.0f, 140.0f, 73.0f,
5596 211.0f, 212.0f, 89.0f,
5597 24.0f, 138.0f, 188.0f,
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005598 162.0f, 12.0f, 161.0f
5599 };
5600 std::vector<float> expectedOutputValues
5601 {
5602 // Batch 0, Channel 0, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005603 119.0f * CalcInvL2Norm({ 119.0f, 110.0f }),
5604 21.0f * CalcInvL2Norm({ 21.0f, 140.0f }),
5605 150.0f * CalcInvL2Norm({ 150.0f, 73.0f }),
5606 149.0f * CalcInvL2Norm({ 149.0f, 211.0f }),
5607 32.0f * CalcInvL2Norm({ 32.0f, 212.0f }),
5608 179.0f * CalcInvL2Norm({ 179.0f, 89.0f }),
5609 15.0f * CalcInvL2Norm({ 15.0f, 24.0f }),
5610 227.0f * CalcInvL2Norm({ 227.0f, 138.0f }),
5611 141.0f * CalcInvL2Norm({ 141.0f, 188.0f }),
5612 147.0f * CalcInvL2Norm({ 147.0f, 162.0f }),
5613 199.0f * CalcInvL2Norm({ 199.0f, 12.0f }),
5614 220.0f * CalcInvL2Norm({ 220.0f, 161.0f }),
5615
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005616 // Batch 0, Channel 1, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005617 110.0f * CalcInvL2Norm({ 119.0f, 110.0f }),
5618 140.0f * CalcInvL2Norm({ 21.0f, 140.0f }),
5619 73.0f * CalcInvL2Norm({ 150.0f, 73.0f }),
5620 211.0f * CalcInvL2Norm({ 149.0f, 211.0f }),
5621 212.0f * CalcInvL2Norm({ 32.0f, 212.0f }),
5622 89.0f * CalcInvL2Norm({ 179.0f, 89.0f }),
5623 24.0f * CalcInvL2Norm({ 15.0f, 24.0f }),
5624 138.0f * CalcInvL2Norm({ 227.0f, 138.0f }),
5625 188.0f * CalcInvL2Norm({ 141.0f, 188.0f }),
5626 162.0f * CalcInvL2Norm({ 147.0f, 162.0f }),
5627 12.0f * CalcInvL2Norm({ 199.0f, 12.0f }),
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005628 161.0f * CalcInvL2Norm({ 220.0f, 161.0f })
5629 };
telsoa014fcda012018-03-09 14:13:49 +00005630
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005631 return L2NormalizationTestImpl(workloadFactory, memoryManager, inputOutputShape,
jimfly013aab7c32018-11-12 13:32:08 +00005632 inputValues, expectedOutputValues, layout);
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005633}
telsoa014fcda012018-03-09 14:13:49 +00005634
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005635LayerTestResult<float, 4> L2Normalization4dTest(
5636 armnn::IWorkloadFactory& workloadFactory,
5637 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00005638 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +00005639{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005640 // Width: 3
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005641 // Height: 4
5642 // Channels: 3
5643 // BatchSize: 2
jimfly013aab7c32018-11-12 13:32:08 +00005644 unsigned int numberOfBatches = 2;
5645 unsigned int numberOfChannels = 3;
5646 unsigned int height = 4;
5647 unsigned int width = 3;
telsoa014fcda012018-03-09 14:13:49 +00005648
Nina Drozdd41b2592018-11-19 13:03:36 +00005649 const armnn::TensorShape inputOutputShape = armnnUtils::GetTensorShape(
jimfly013aab7c32018-11-12 13:32:08 +00005650 numberOfBatches, numberOfChannels, height, width, layout);
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005651 std::vector<float> inputValues
5652 {
5653 // Batch 0, Channel 0, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005654 235.0f, 46.0f, 178.0f,
5655 100.0f, 123.0f, 19.0f,
5656 172.0f, 74.0f, 250.0f,
5657 6.0f, 195.0f, 80.0f,
5658
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005659 // Batch 0, Channel 1, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005660 113.0f, 95.0f, 202.0f,
5661 77.0f, 114.0f, 71.0f,
5662 122.0f, 246.0f, 166.0f,
5663 82.0f, 28.0f, 37.0f,
5664
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005665 // Batch 0, Channel 2, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005666 56.0f, 170.0f, 162.0f,
5667 194.0f, 89.0f, 254.0f,
5668 12.0f, 209.0f, 200.0f,
5669 1.0f, 64.0f, 54.0f,
5670
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005671 // Batch 1, Channel 0, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005672 67.0f, 90.0f, 49.0f,
5673 7.0f, 163.0f, 18.0f,
5674 25.0f, 117.0f, 103.0f,
5675 247.0f, 59.0f, 189.0f,
5676
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005677 // Batch 1, Channel 1, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005678 239.0f, 104.0f, 199.0f,
5679 17.0f, 124.0f, 153.0f,
5680 222.0f, 217.0f, 75.0f,
5681 32.0f, 126.0f, 21.0f,
5682
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005683 // Batch 1, Channel 2, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005684 97.0f, 145.0f, 215.0f,
5685 115.0f, 116.0f, 238.0f,
5686 226.0f, 16.0f, 132.0f,
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005687 92.0f, 125.0f, 88.0f
5688 };
5689 std::vector<float> expectedOutputValues
5690 {
5691 // Batch 0, Channel 0, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005692 235.0f * CalcInvL2Norm({ 235.0f, 113.0f, 56.0f }),
5693 46.0f * CalcInvL2Norm({ 46.0f, 95.0f, 170.0f }),
5694 178.0f * CalcInvL2Norm({ 178.0f, 202.0F, 162.0f }),
5695 100.0f * CalcInvL2Norm({ 100.0f, 77.0f, 194.0f }),
5696 123.0f * CalcInvL2Norm({ 123.0f, 114.0f, 89.0f }),
5697 19.0f * CalcInvL2Norm({ 19.0f, 71.0f, 254.0f }),
5698 172.0f * CalcInvL2Norm({ 172.0f, 122.0f, 12.0f }),
5699 74.0f * CalcInvL2Norm({ 74.0f, 246.0f, 209.0f }),
5700 250.0f * CalcInvL2Norm({ 250.0f, 166.0f, 200.0f }),
5701 6.0f * CalcInvL2Norm({ 6.0f, 82.0f, 1.0f }),
5702 195.0f * CalcInvL2Norm({ 195.0f, 28.0f, 64.0f }),
5703 80.0f * CalcInvL2Norm({ 80.0f, 37.0f, 54.0f }),
5704
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005705 // Batch 0, Channel 1, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005706 113.0f * CalcInvL2Norm({ 235.0f, 113.0f, 56.0f }),
5707 95.0f * CalcInvL2Norm({ 46.0f, 95.0f, 170.0f }),
5708 202.0f * CalcInvL2Norm({ 178.0f, 202.0F, 162.0f }),
5709 77.0f * CalcInvL2Norm({ 100.0f, 77.0f, 194.0f }),
5710 114.0f * CalcInvL2Norm({ 123.0f, 114.0f, 89.0f }),
5711 71.0f * CalcInvL2Norm({ 19.0f, 71.0f, 254.0f }),
5712 122.0f * CalcInvL2Norm({ 172.0f, 122.0f, 12.0f }),
5713 246.0f * CalcInvL2Norm({ 74.0f, 246.0f, 209.0f }),
5714 166.0f * CalcInvL2Norm({ 250.0f, 166.0f, 200.0f }),
5715 82.0f * CalcInvL2Norm({ 6.0f, 82.0f, 1.0f }),
5716 28.0f * CalcInvL2Norm({ 195.0f, 28.0f, 64.0f }),
5717 37.0f * CalcInvL2Norm({ 80.0f, 37.0f, 54.0f }),
5718
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005719 // Batch 0, Channel 2, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005720 56.0f * CalcInvL2Norm({ 235.0f, 113.0f, 56.0f }),
5721 170.0f * CalcInvL2Norm({ 46.0f, 95.0f, 170.0f }),
5722 162.0f * CalcInvL2Norm({ 178.0f, 202.0F, 162.0f }),
5723 194.0f * CalcInvL2Norm({ 100.0f, 77.0f, 194.0f }),
5724 89.0f * CalcInvL2Norm({ 123.0f, 114.0f, 89.0f }),
5725 254.0f * CalcInvL2Norm({ 19.0f, 71.0f, 254.0f }),
5726 12.0f * CalcInvL2Norm({ 172.0f, 122.0f, 12.0f }),
5727 209.0f * CalcInvL2Norm({ 74.0f, 246.0f, 209.0f }),
5728 200.0f * CalcInvL2Norm({ 250.0f, 166.0f, 200.0f }),
5729 1.0f * CalcInvL2Norm({ 6.0f, 82.0f, 1.0f }),
5730 64.0f * CalcInvL2Norm({ 195.0f, 28.0f, 64.0f }),
5731 54.0f * CalcInvL2Norm({ 80.0f, 37.0f, 54.0f }),
5732
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005733 // Batch 1, Channel 0, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005734 67.0f * CalcInvL2Norm({ 67.0f, 239.0f, 97.0f }),
5735 90.0f * CalcInvL2Norm({ 90.0f, 104.0f, 145.0f }),
5736 49.0f * CalcInvL2Norm({ 49.0f, 199.0f, 215.0f }),
5737 7.0f * CalcInvL2Norm({ 7.0f, 17.0f, 115.0f }),
5738 163.0f * CalcInvL2Norm({ 163.0f, 124.0f, 116.0f }),
5739 18.0f * CalcInvL2Norm({ 18.0f, 153.0f, 238.0f }),
5740 25.0f * CalcInvL2Norm({ 25.0f, 222.0f, 226.0f }),
5741 117.0f * CalcInvL2Norm({ 117.0f, 217.0f, 16.0f }),
5742 103.0f * CalcInvL2Norm({ 103.0f, 75.0f, 132.0f }),
5743 247.0f * CalcInvL2Norm({ 247.0f, 32.0f, 92.0f }),
5744 59.0f * CalcInvL2Norm({ 59.0f, 126.0f, 125.0f }),
5745 189.0f * CalcInvL2Norm({ 189.0f, 21.0f, 88.0f }),
5746
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005747 // Batch 1, Channel 1, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005748 239.0f * CalcInvL2Norm({ 67.0f, 239.0f, 97.0f }),
5749 104.0f * CalcInvL2Norm({ 90.0f, 104.0f, 145.0f }),
5750 199.0f * CalcInvL2Norm({ 49.0f, 199.0f, 215.0f }),
5751 17.0f * CalcInvL2Norm({ 7.0f, 17.0f, 115.0f }),
5752 124.0f * CalcInvL2Norm({ 163.0f, 124.0f, 116.0f }),
5753 153.0f * CalcInvL2Norm({ 18.0f, 153.0f, 238.0f }),
5754 222.0f * CalcInvL2Norm({ 25.0f, 222.0f, 226.0f }),
5755 217.0f * CalcInvL2Norm({ 117.0f, 217.0f, 16.0f }),
5756 75.0f * CalcInvL2Norm({ 103.0f, 75.0f, 132.0f }),
5757 32.0f * CalcInvL2Norm({ 247.0f, 32.0f, 92.0f }),
5758 126.0f * CalcInvL2Norm({ 59.0f, 126.0f, 125.0f }),
5759 21.0f * CalcInvL2Norm({ 189.0f, 21.0f, 88.0f }),
5760
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005761 // Batch 1, Channel 2, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005762 97.0f * CalcInvL2Norm({ 67.0f, 239.0f, 97.0f }),
5763 145.0f * CalcInvL2Norm({ 90.0f, 104.0f, 145.0f }),
5764 215.0f * CalcInvL2Norm({ 49.0f, 199.0f, 215.0f }),
5765 115.0f * CalcInvL2Norm({ 7.0f, 17.0f, 115.0f }),
5766 116.0f * CalcInvL2Norm({ 163.0f, 124.0f, 116.0f }),
5767 238.0f * CalcInvL2Norm({ 18.0f, 153.0f, 238.0f }),
5768 226.0f * CalcInvL2Norm({ 25.0f, 222.0f, 226.0f }),
5769 16.0f * CalcInvL2Norm({ 117.0f, 217.0f, 16.0f }),
5770 132.0f * CalcInvL2Norm({ 103.0f, 75.0f, 132.0f }),
5771 92.0f * CalcInvL2Norm({ 247.0f, 32.0f, 92.0f }),
5772 125.0f * CalcInvL2Norm({ 59.0f, 126.0f, 125.0f }),
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005773 88.0f * CalcInvL2Norm({ 189.0f, 21.0f, 88.0f })
5774 };
telsoa014fcda012018-03-09 14:13:49 +00005775
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005776 return L2NormalizationTestImpl(workloadFactory, memoryManager, inputOutputShape,
jimfly013aab7c32018-11-12 13:32:08 +00005777 inputValues, expectedOutputValues, layout);
telsoa014fcda012018-03-09 14:13:49 +00005778}
5779
5780template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005781LayerTestResult<T, 4> ConstantTestImpl(
5782 armnn::IWorkloadFactory& workloadFactory,
5783 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
telsoa014fcda012018-03-09 14:13:49 +00005784 float qScale,
5785 int32_t qOffset)
5786{
5787 constexpr unsigned int inputWidth = 3;
5788 constexpr unsigned int inputHeight = 4;
5789 constexpr unsigned int inputChannels = 3;
5790 constexpr unsigned int inputBatchSize = 2;
5791
5792 constexpr unsigned int outputWidth = inputWidth;
5793 constexpr unsigned int outputHeight = inputHeight;
5794 constexpr unsigned int outputChannels = inputChannels;
5795 constexpr unsigned int outputBatchSize = inputBatchSize;
5796
5797 armnn::TensorInfo inputTensorInfo({ inputBatchSize, inputChannels, inputHeight, inputWidth },
5798 armnn::GetDataType<T>());
5799
5800 armnn::TensorInfo outputTensorInfo({ outputBatchSize, outputChannels, outputHeight, outputWidth },
5801 armnn::GetDataType<T>());
5802
5803 // Set quantization parameters if the requested type is a quantized type.
5804 if(armnn::IsQuantizedType<T>())
5805 {
5806 inputTensorInfo.SetQuantizationScale(qScale);
5807 inputTensorInfo.SetQuantizationOffset(qOffset);
5808 outputTensorInfo.SetQuantizationScale(qScale);
5809 outputTensorInfo.SetQuantizationOffset(qOffset);
5810 }
5811
5812 auto input = MakeTensor<T, 4>(inputTensorInfo, std::vector<T>(
5813 QuantizedVector<T>(qScale, qOffset, {
5814 // Batch 0, Channel 0
5815 235.0f, 46.0f, 178.0f,
5816 100.0f, 123.0f, 19.0f,
5817 172.0f, 74.0f, 250.0f,
5818 6.0f, 195.0f, 80.0f,
5819
5820 // Batch 0, Channel 1
5821 113.0f, 95.0f, 202.0f,
5822 77.0f, 114.0f, 71.0f,
5823 122.0f, 246.0f, 166.0f,
5824 82.0f, 28.0f, 37.0f,
5825
5826 // Batch 0, Channel 2
5827 56.0f, 170.0f, 162.0f,
5828 194.0f, 89.0f, 254.0f,
5829 12.0f, 209.0f, 200.0f,
5830 1.0f, 64.0f, 54.0f,
5831
5832 // Batch 1, Channel 0
5833 67.0f, 90.0f, 49.0f,
5834 7.0f, 163.0f, 18.0f,
5835 25.0f, 117.0f, 103.0f,
5836 247.0f, 59.0f, 189.0f,
5837
5838 // Batch 1, Channel 1
5839 239.0f, 104.0f, 199.0f,
5840 17.0f, 124.0f, 153.0f,
5841 222.0f, 217.0f, 75.0f,
5842 32.0f, 126.0f, 21.0f,
5843
5844 // Batch 1, Channel 2
5845 97.0f, 145.0f, 215.0f,
5846 115.0f, 116.0f, 238.0f,
5847 226.0f, 16.0f, 132.0f,
5848 92.0f, 125.0f, 88.0f,
5849 })));
5850
5851 LayerTestResult<T, 4> result(outputTensorInfo);
5852 result.outputExpected = input;
5853
5854 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
5855
5856 armnn::ScopedCpuTensorHandle constantTensor(inputTensorInfo);
5857 AllocateAndCopyDataToITensorHandle(&constantTensor, &input[0][0][0][0]);
5858
5859 armnn::ConstantQueueDescriptor descriptor;
5860 descriptor.m_LayerOutput = &constantTensor;
5861
5862 armnn::WorkloadInfo info;
5863 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
5864
5865 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateConstant(descriptor, info);
5866
5867 outputHandle->Allocate();
5868
5869 workload->Execute();
5870
5871 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
5872 return result;
5873}
5874
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005875LayerTestResult<float, 4> ConstantTest(
5876 armnn::IWorkloadFactory& workloadFactory,
5877 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00005878{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005879 return ConstantTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00005880}
5881
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005882LayerTestResult<uint8_t, 4> ConstantTestUint8(
5883 armnn::IWorkloadFactory& workloadFactory,
5884 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00005885{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005886 return ConstantTestImpl<uint8_t>(workloadFactory, memoryManager, 1.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00005887}
5888
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005889LayerTestResult<uint8_t, 3> MergerUint8Test(
5890 armnn::IWorkloadFactory& workloadFactory,
5891 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00005892{
surmeh013537c2c2018-05-18 16:31:43 +01005893 unsigned int outputWidth = 3;
telsoa014fcda012018-03-09 14:13:49 +00005894 unsigned int outputHeight = 6;
5895 unsigned int outputChannels = 3;
5896
surmeh013537c2c2018-05-18 16:31:43 +01005897 unsigned int inputWidth1 = 3;
5898 unsigned int inputHeight1 = 6;
5899 unsigned int inputChannels1 = 2;
telsoa014fcda012018-03-09 14:13:49 +00005900
surmeh013537c2c2018-05-18 16:31:43 +01005901 unsigned int inputWidth2 = 3;
5902 unsigned int inputHeight2 = 6;
5903 unsigned int inputChannels2 = 1;
telsoa014fcda012018-03-09 14:13:49 +00005904
telsoa01c577f2c2018-08-31 09:22:23 +01005905 // Defines the tensor descriptors.
telsoa014fcda012018-03-09 14:13:49 +00005906 armnn::TensorInfo outputTensorInfo({ outputChannels, outputHeight, outputWidth }, armnn::DataType::QuantisedAsymm8);
5907 armnn::TensorInfo inputTensorInfo1({ inputChannels1, inputHeight1, inputWidth1 }, armnn::DataType::QuantisedAsymm8);
5908 armnn::TensorInfo inputTensorInfo2({ inputChannels2, inputHeight2, inputWidth2 }, armnn::DataType::QuantisedAsymm8);
telsoa014fcda012018-03-09 14:13:49 +00005909
telsoa01c577f2c2018-08-31 09:22:23 +01005910 // Arbitrary scale and offsets. They don't really matter as the merger operator doesn't dequantize/quantize them.
telsoa014fcda012018-03-09 14:13:49 +00005911 const float scale = 0.13497836f;
5912 const int32_t offset = -7;
5913
5914 outputTensorInfo.SetQuantizationScale(scale);
5915 outputTensorInfo.SetQuantizationOffset(offset);
5916 inputTensorInfo1.SetQuantizationScale(scale);
5917 inputTensorInfo1.SetQuantizationOffset(offset);
5918 inputTensorInfo2.SetQuantizationScale(scale);
5919 inputTensorInfo2.SetQuantizationOffset(offset);
telsoa014fcda012018-03-09 14:13:49 +00005920
5921 LayerTestResult<uint8_t, 3> ret(outputTensorInfo);
5922
5923 ret.outputExpected = MakeTensor<uint8_t, 3>(outputTensorInfo, std::vector<uint8_t>(
surmeh013537c2c2018-05-18 16:31:43 +01005924 {
5925 1, 2, 3,
5926 4, 5, 6,
5927 7, 8, 9,
5928 10, 11, 12,
5929 13, 14, 15,
5930 16, 17, 18,
telsoa014fcda012018-03-09 14:13:49 +00005931
surmeh013537c2c2018-05-18 16:31:43 +01005932 19, 20, 21,
5933 22, 23, 24,
5934 25, 26, 27,
5935 28, 29, 30,
5936 31, 32, 33,
5937 34, 35, 36,
telsoa014fcda012018-03-09 14:13:49 +00005938
surmeh013537c2c2018-05-18 16:31:43 +01005939 37, 38, 39,
5940 40, 41, 42,
5941 43, 44, 45,
5942 46, 47, 48,
5943 49, 50, 51,
5944 52, 53, 54,
5945 })
telsoa014fcda012018-03-09 14:13:49 +00005946 );
5947
telsoa014fcda012018-03-09 14:13:49 +00005948 auto input1 = MakeTensor<uint8_t, 3>(inputTensorInfo1, std::vector<uint8_t>(
5949 {
surmeh013537c2c2018-05-18 16:31:43 +01005950 1, 2, 3,
5951 4, 5, 6,
5952 7, 8, 9,
5953 10, 11, 12,
5954 13, 14, 15,
5955 16, 17, 18,
telsoa014fcda012018-03-09 14:13:49 +00005956
surmeh013537c2c2018-05-18 16:31:43 +01005957 19, 20, 21,
5958 22, 23, 24,
5959 25, 26, 27,
5960 28, 29, 30,
5961 31, 32, 33,
5962 34, 35, 36,
telsoa014fcda012018-03-09 14:13:49 +00005963 })
5964 );
5965
5966 auto input2 = MakeTensor<uint8_t, 3>(inputTensorInfo2, std::vector<uint8_t>(
5967 {
surmeh013537c2c2018-05-18 16:31:43 +01005968 37, 38, 39,
5969 40, 41, 42,
telsoa014fcda012018-03-09 14:13:49 +00005970 43, 44, 45,
surmeh013537c2c2018-05-18 16:31:43 +01005971 46, 47, 48,
5972 49, 50, 51,
5973 52, 53, 54,
telsoa014fcda012018-03-09 14:13:49 +00005974 })
5975 );
5976
telsoa01c577f2c2018-08-31 09:22:23 +01005977 std::vector<unsigned int> wOrigin1 = { 0, 0, 0 }; //Extent of the window is defined by size of input[0].
telsoa014fcda012018-03-09 14:13:49 +00005978 armnn::MergerQueueDescriptor::ViewOrigin window1(wOrigin1);
5979
telsoa01c577f2c2018-08-31 09:22:23 +01005980 std::vector<unsigned int> wOrigin2 = { 2, 0, 0 }; //Extent of the window is defined by size of input[1].
telsoa014fcda012018-03-09 14:13:49 +00005981 armnn::MergerQueueDescriptor::ViewOrigin window2(wOrigin2);
5982
telsoa014fcda012018-03-09 14:13:49 +00005983
5984 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
5985
5986 bool subTensorsSupported = workloadFactory.SupportsSubTensors();
5987
5988 std::unique_ptr<armnn::ITensorHandle> inputHandle1 =
5989 subTensorsSupported ?
5990 workloadFactory.CreateSubTensorHandle(*outputHandle, inputTensorInfo1.GetShape(), wOrigin1.data()) :
5991 workloadFactory.CreateTensorHandle(inputTensorInfo1);
5992
5993 std::unique_ptr<armnn::ITensorHandle> inputHandle2 =
5994 subTensorsSupported ?
5995 workloadFactory.CreateSubTensorHandle(*outputHandle, inputTensorInfo2.GetShape(), wOrigin2.data()) :
5996 workloadFactory.CreateTensorHandle(inputTensorInfo2);
5997
telsoa014fcda012018-03-09 14:13:49 +00005998
5999 armnn::MergerQueueDescriptor data;
6000 armnn::WorkloadInfo info;
6001 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
6002 AddInputToWorkload(data, info, inputTensorInfo2, inputHandle2.get());
telsoa014fcda012018-03-09 14:13:49 +00006003 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
6004
6005 data.m_ViewOrigins.push_back(window1);
6006 data.m_ViewOrigins.push_back(window2);
telsoa014fcda012018-03-09 14:13:49 +00006007
6008 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateMerger(data, info);
6009
6010 inputHandle1->Allocate();
6011 inputHandle2->Allocate();
telsoa014fcda012018-03-09 14:13:49 +00006012 outputHandle->Allocate();
6013
6014 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0]);
6015 CopyDataToITensorHandle(inputHandle2.get(), &input2[0][0][0]);
telsoa014fcda012018-03-09 14:13:49 +00006016
6017 workload->Execute();
6018
6019 CopyDataFromITensorHandle(&ret.output[0][0][0], outputHandle.get());
6020
6021 return ret;
6022}
6023
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006024LayerTestResult<uint8_t, 4> AdditionUint8Test(
6025 armnn::IWorkloadFactory& workloadFactory,
6026 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006027{
6028 unsigned int batchSize = 1;
6029 unsigned int channels = 2;
6030 unsigned int height = 2;
6031 unsigned int width = 3;
6032
6033 const float scale = 7.0f;
6034 const int32_t offset = 3;
6035
6036 armnn::TensorInfo inputTensorInfo1, inputTensorInfo2;
6037 armnn::TensorInfo outputTensorInfo;
6038
6039 const unsigned int shape[] = { batchSize, channels, height, width };
6040 inputTensorInfo1 = armnn::TensorInfo(4, shape, armnn::DataType::QuantisedAsymm8);
6041 inputTensorInfo1.SetQuantizationScale(scale);
6042 inputTensorInfo1.SetQuantizationOffset(offset);
6043
6044 inputTensorInfo2 = armnn::TensorInfo(4, shape, armnn::DataType::QuantisedAsymm8);
6045 inputTensorInfo2.SetQuantizationScale(scale);
6046 inputTensorInfo2.SetQuantizationOffset(offset);
6047
6048 outputTensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::QuantisedAsymm8);
6049 outputTensorInfo.SetQuantizationScale(scale);
6050 outputTensorInfo.SetQuantizationOffset(offset);
6051
telsoa01c577f2c2018-08-31 09:22:23 +01006052 // See dequantized values to the right.
telsoa014fcda012018-03-09 14:13:49 +00006053 auto input1 = MakeTensor<uint8_t, 4>(inputTensorInfo1, std::vector<uint8_t>(
6054 {
6055 63, 35, 77, 70, 56, 112, // 420, 224, 518, 469, 371, 763
6056 203, 28, 252, 168, 245, 91 // 1400, 175, 1743, 1155, 1694, 616
6057 }));
6058
telsoa01c577f2c2018-08-31 09:22:23 +01006059 // See dequantized values to the right.
telsoa014fcda012018-03-09 14:13:49 +00006060 auto input2 = MakeTensor<uint8_t, 4>(inputTensorInfo1, std::vector<uint8_t>(
6061 {
6062 21, 7, 175, 231, 175, 210, // 126, 28, 1204, 1596, 1204, 1449
6063 126, 161, 63, 21, 105, 126 // 861, 1106, 420, 126, 714, 861
6064 }));
6065
telsoa01c577f2c2018-08-31 09:22:23 +01006066 // See dequantized values to the right.
telsoa014fcda012018-03-09 14:13:49 +00006067 LayerTestResult<uint8_t, 4> result(outputTensorInfo);
6068 result.outputExpected = MakeTensor<uint8_t, 4>(outputTensorInfo, std::vector<uint8_t>(
6069 {
6070 81, 39, 249, 255, 228, 255, // 546, 252, 1722, 2065(clamped), 1575, 2212(clamped)
6071 255, 186, 255, 186, 255, 214, // 2261(clamped), 1281, 2163(clamped), 1281, 2408(clamped), 1477
6072 }));
6073
6074 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
6075 std::unique_ptr<armnn::ITensorHandle> inputHandle2 = workloadFactory.CreateTensorHandle(inputTensorInfo2);
6076 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
6077
6078 armnn::AdditionQueueDescriptor data;
6079 armnn::WorkloadInfo info;
6080 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
6081 AddInputToWorkload(data, info, inputTensorInfo2, inputHandle2.get());
6082 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
6083
6084 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateAddition(data, info);
6085
6086 inputHandle1->Allocate();
6087 inputHandle2->Allocate();
6088 outputHandle->Allocate();
6089
6090 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
6091 CopyDataToITensorHandle(inputHandle2.get(), &input2[0][0][0][0]);
6092
6093 workload->Execute();
6094
6095 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
6096
6097 return result;
6098}
6099
surmeh01bceff2f2018-03-29 16:29:27 +01006100namespace
telsoa014fcda012018-03-09 14:13:49 +00006101{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006102LayerTestResult<uint8_t, 4> MultiplicationUint8TestHelper(
6103 armnn::IWorkloadFactory& workloadFactory,
6104 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
6105 const unsigned int shape0[4],
6106 const std::vector<uint8_t> & values0,
6107 float scale0,
6108 int32_t offset0,
6109 const unsigned int shape1[4],
6110 const std::vector<uint8_t> & values1,
6111 float scale1,
6112 int32_t offset1,
6113 const unsigned int outShape[4],
6114 const std::vector<uint8_t> & outValues,
6115 float outScale,
6116 int32_t outOffset)
surmeh01bceff2f2018-03-29 16:29:27 +01006117{
6118 armnn::TensorInfo inputTensorInfo0(4, shape0, armnn::DataType::QuantisedAsymm8);
6119 armnn::TensorInfo inputTensorInfo1(4, shape1, armnn::DataType::QuantisedAsymm8);
6120 armnn::TensorInfo outputTensorInfo(4, outShape, armnn::DataType::QuantisedAsymm8);
telsoa014fcda012018-03-09 14:13:49 +00006121
surmeh01bceff2f2018-03-29 16:29:27 +01006122 inputTensorInfo0.SetQuantizationScale(scale0);
6123 inputTensorInfo0.SetQuantizationOffset(offset0);
telsoa014fcda012018-03-09 14:13:49 +00006124
surmeh01bceff2f2018-03-29 16:29:27 +01006125 inputTensorInfo1.SetQuantizationScale(scale1);
6126 inputTensorInfo1.SetQuantizationOffset(offset1);
telsoa014fcda012018-03-09 14:13:49 +00006127
surmeh01bceff2f2018-03-29 16:29:27 +01006128 outputTensorInfo.SetQuantizationScale(outScale);
6129 outputTensorInfo.SetQuantizationOffset(outOffset);
telsoa014fcda012018-03-09 14:13:49 +00006130
surmeh01bceff2f2018-03-29 16:29:27 +01006131 auto input0 = MakeTensor<uint8_t, 4>(inputTensorInfo0, values0);
6132 auto input1 = MakeTensor<uint8_t, 4>(inputTensorInfo1, values1);
telsoa014fcda012018-03-09 14:13:49 +00006133
telsoa014fcda012018-03-09 14:13:49 +00006134 LayerTestResult<uint8_t, 4> result(outputTensorInfo);
surmeh01bceff2f2018-03-29 16:29:27 +01006135 result.outputExpected = MakeTensor<uint8_t, 4>(outputTensorInfo, outValues);
telsoa014fcda012018-03-09 14:13:49 +00006136
surmeh01bceff2f2018-03-29 16:29:27 +01006137 std::unique_ptr<armnn::ITensorHandle> inputHandle0 = workloadFactory.CreateTensorHandle(inputTensorInfo0);
telsoa014fcda012018-03-09 14:13:49 +00006138 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
telsoa014fcda012018-03-09 14:13:49 +00006139 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
6140
6141 armnn::MultiplicationQueueDescriptor data;
6142 armnn::WorkloadInfo info;
surmeh01bceff2f2018-03-29 16:29:27 +01006143 AddInputToWorkload(data, info, inputTensorInfo0, inputHandle0.get());
6144 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
telsoa014fcda012018-03-09 14:13:49 +00006145 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
6146
6147 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateMultiplication(data, info);
6148
surmeh01bceff2f2018-03-29 16:29:27 +01006149 inputHandle0->Allocate();
telsoa014fcda012018-03-09 14:13:49 +00006150 inputHandle1->Allocate();
telsoa014fcda012018-03-09 14:13:49 +00006151 outputHandle->Allocate();
6152
surmeh01bceff2f2018-03-29 16:29:27 +01006153 CopyDataToITensorHandle(inputHandle0.get(), &input0[0][0][0][0]);
telsoa014fcda012018-03-09 14:13:49 +00006154 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
telsoa014fcda012018-03-09 14:13:49 +00006155
6156 workload->Execute();
6157
6158 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
6159
6160 return result;
6161}
surmeh01bceff2f2018-03-29 16:29:27 +01006162} // anonymous namespace
6163
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006164LayerTestResult<uint8_t, 4> MultiplicationUint8Test(
6165 armnn::IWorkloadFactory& workloadFactory,
6166 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01006167{
6168 unsigned int batchSize = 1;
6169 unsigned int channels = 2;
6170 unsigned int height = 2;
6171 unsigned int width = 3;
6172 const unsigned int shape[] = { batchSize, channels, height, width };
6173
telsoa01c577f2c2018-08-31 09:22:23 +01006174 // See dequantized values to the right.
surmeh01bceff2f2018-03-29 16:29:27 +01006175 std::vector<uint8_t> input0({
6176 62, 37, 3, 172, 13, 111, // 244, 144, 8, 684, 48, 440,
6177 188, 20, 73, 31, 23, 31 // 748, 76, 288, 120, 88, 120
6178 });
6179
telsoa01c577f2c2018-08-31 09:22:23 +01006180 // See dequantized values to the right.
surmeh01bceff2f2018-03-29 16:29:27 +01006181 std::vector<uint8_t> input1({
6182 126, 240, 252, 183, 121, 247, // 384, 726, 762, 555, 369, 747,
6183 48, 115, 151, 79, 78, 97 // 150, 351, 459, 243, 240, 297
6184 });
6185
telsoa01c577f2c2018-08-31 09:22:23 +01006186 // See dequantized values to the right.
surmeh01bceff2f2018-03-29 16:29:27 +01006187 std::vector<uint8_t> output(
6188 {
6189 64, 72, 0, 255, 8, 236, // 93696, 104544, 6096(clamped), 379620(clamped), 17712, 328680,
6190 77, 15, 92, 16, 10, 21, // 112200, 26676, 132192, 29160, 21120, 35640
6191 });
6192
6193 return MultiplicationUint8TestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006194 memoryManager,
surmeh01bceff2f2018-03-29 16:29:27 +01006195 shape,
6196 input0,
6197 4.0f,
6198 1,
6199 shape,
6200 input1,
6201 3.0f,
6202 -2,
6203 shape,
6204 output,
telsoa01c577f2c2018-08-31 09:22:23 +01006205 1366.255f, // Scale/offset chosen to have output values out of range.
surmeh01bceff2f2018-03-29 16:29:27 +01006206 -5);
6207}
6208
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006209LayerTestResult<uint8_t, 4> MultiplicationBroadcast1ElementUint8Test(
6210 armnn::IWorkloadFactory& workloadFactory,
6211 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01006212{
6213 const unsigned int shape0[] = { 1, 2, 2, 3 };
6214 const unsigned int shape1[] = { 1, 1, 1, 1 };
6215
6216 std::vector<uint8_t> input0({
6217 1, 2, 3, 4, 5, 6,
6218 7, 8, 9, 10, 11, 12
6219 });
6220
6221 std::vector<uint8_t> input1({2});
6222
6223 std::vector<uint8_t> output({
6224 2, 4, 6, 8, 10, 12,
6225 14, 16, 18, 20, 22, 24
6226 });
6227
6228 return MultiplicationUint8TestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006229 memoryManager,
surmeh01bceff2f2018-03-29 16:29:27 +01006230 shape0,
6231 input0,
6232 1.0f,
6233 0,
6234 shape1,
6235 input1,
6236 1.0f,
6237 0,
6238 shape0,
6239 output,
6240 1.0f,
6241 0);
6242}
6243
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006244LayerTestResult<uint8_t, 4> MultiplicationBroadcast1DVectorUint8Test(
6245 armnn::IWorkloadFactory& workloadFactory,
6246 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01006247{
6248 const unsigned int shape0[] = { 1, 2, 2, 3 };
6249 const unsigned int shape1[] = { 1, 1, 1, 3 };
6250
6251 std::vector<uint8_t> input0({
6252 1, 2, 3, 4, 5, 6,
6253 7, 8, 9, 10, 11, 12
6254 });
6255
6256 std::vector<uint8_t> input1({1, 2, 3});
6257
6258 std::vector<uint8_t> output({
6259 1, 4, 9, 4, 10, 18,
6260 7, 16, 27, 10, 22, 36
6261 });
6262
6263 return MultiplicationUint8TestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006264 memoryManager,
surmeh01bceff2f2018-03-29 16:29:27 +01006265 shape0,
6266 input0,
6267 1.0f,
6268 0,
6269 shape1,
6270 input1,
6271 1.0f,
6272 0,
6273 shape0,
6274 output,
6275 1.0f,
6276 0);
6277}
telsoa014fcda012018-03-09 14:13:49 +00006278
David Beckf195f032018-09-06 16:46:34 +01006279namespace
6280{
6281template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006282LayerTestResult<T, 4> SubtractionTestHelper(
6283 armnn::IWorkloadFactory& workloadFactory,
6284 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
6285 const unsigned int shape0[4],
6286 const std::vector<T>& values0,
6287 float scale0,
6288 int32_t offset0,
6289 const unsigned int shape1[4],
6290 const std::vector<T> & values1,
6291 float scale1,
6292 int32_t offset1,
6293 const unsigned int outShape[4],
6294 const std::vector<T> & outValues,
6295 float outScale,
6296 int32_t outOffset)
David Beckf195f032018-09-06 16:46:34 +01006297{
6298 auto dataType = (std::is_same<T, uint8_t>::value ?
6299 armnn::DataType::QuantisedAsymm8 :
6300 armnn::DataType::Float32);
6301
6302 armnn::TensorInfo inputTensorInfo0(4, shape0, dataType);
6303 armnn::TensorInfo inputTensorInfo1(4, shape1, dataType);
6304 armnn::TensorInfo outputTensorInfo(4, outShape, dataType);
6305
6306 inputTensorInfo0.SetQuantizationScale(scale0);
6307 inputTensorInfo0.SetQuantizationOffset(offset0);
6308
6309 inputTensorInfo1.SetQuantizationScale(scale1);
6310 inputTensorInfo1.SetQuantizationOffset(offset1);
6311
6312 outputTensorInfo.SetQuantizationScale(outScale);
6313 outputTensorInfo.SetQuantizationOffset(outOffset);
6314
6315 auto input0 = MakeTensor<T, 4>(inputTensorInfo0, values0);
6316 auto input1 = MakeTensor<T, 4>(inputTensorInfo1, values1);
6317
6318 LayerTestResult<T, 4> result(outputTensorInfo);
6319 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, outValues);
6320
6321 std::unique_ptr<armnn::ITensorHandle> inputHandle0 = workloadFactory.CreateTensorHandle(inputTensorInfo0);
6322 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
6323 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
6324
6325 armnn::SubtractionQueueDescriptor data;
6326 armnn::WorkloadInfo info;
6327 AddInputToWorkload(data, info, inputTensorInfo0, inputHandle0.get());
6328 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
6329 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
6330
6331 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateSubtraction(data, info);
6332
6333 inputHandle0->Allocate();
6334 inputHandle1->Allocate();
6335 outputHandle->Allocate();
6336
6337 CopyDataToITensorHandle(inputHandle0.get(), &input0[0][0][0][0]);
6338 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
6339
David Beckf195f032018-09-06 16:46:34 +01006340 workload->Execute();
6341
6342 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
6343
6344 return result;
6345}
6346} // anonymous namespace
6347
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006348LayerTestResult<uint8_t, 4> SubtractionUint8Test(
6349 armnn::IWorkloadFactory& workloadFactory,
6350 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beckf195f032018-09-06 16:46:34 +01006351{
6352 const unsigned int shape0[] = { 1, 1, 2, 2 };
6353 const unsigned int shape1[] = { 1, 1, 2, 2 };
6354
6355 std::vector<uint8_t> input0({ 10, 12, 14, 16 });
6356 std::vector<uint8_t> input1({ 1, 2, 1, 2 });
6357 std::vector<uint8_t> output({ 3, 3, 5, 5 });
6358
6359 return SubtractionTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006360 memoryManager,
David Beckf195f032018-09-06 16:46:34 +01006361 shape0, input0, 0.5f, 2,
6362 shape1, input1, 1.0f, 0,
6363 shape0, output, 1.0f, 0);
6364}
6365
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006366LayerTestResult<uint8_t, 4> SubtractionBroadcast1ElementUint8Test(
6367 armnn::IWorkloadFactory& workloadFactory,
6368 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beckf195f032018-09-06 16:46:34 +01006369{
6370 const unsigned int shape0[] = { 1, 1, 2, 2 };
6371 const unsigned int shape1[] = { 1, 1, 1, 1 };
6372
6373 std::vector<uint8_t> input0({ 10, 12, 14, 16 });
6374 std::vector<uint8_t> input1({ 2 });
6375 std::vector<uint8_t> output({ 5, 6, 7, 8 });
6376
6377 return SubtractionTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006378 memoryManager,
David Beckf195f032018-09-06 16:46:34 +01006379 shape0, input0, 0.5f, 2,
6380 shape1, input1, 1.0f, 0,
6381 shape0, output, 1.0f, 3);
6382}
6383
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006384LayerTestResult<uint8_t, 4> SubtractionBroadcastUint8Test(
6385 armnn::IWorkloadFactory& workloadFactory,
6386 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beckf195f032018-09-06 16:46:34 +01006387{
6388 const unsigned int shape0[] = { 1, 1, 2, 2 };
6389 const unsigned int shape1[] = { 1, 1, 2, 1 };
6390
6391 std::vector<uint8_t> input0({ 10, 12, 14, 16 });
6392 std::vector<uint8_t> input1({ 2, 1 });
6393 std::vector<uint8_t> output({ 8, 11, 12, 15 });
6394
6395 return SubtractionTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006396 memoryManager,
David Beckf195f032018-09-06 16:46:34 +01006397 shape0, input0, 1.0f, 0,
6398 shape1, input1, 1.0f, 0,
6399 shape0, output, 1.0f, 0);
6400}
6401
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006402LayerTestResult<float, 4> SubtractionTest(
6403 armnn::IWorkloadFactory& workloadFactory,
6404 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beckf195f032018-09-06 16:46:34 +01006405{
6406 const unsigned int shape0[] = { 1, 1, 2, 2 };
6407 const unsigned int shape1[] = { 1, 1, 2, 2 };
6408
6409 std::vector<float> input0({ 1, 2, 3, 4 });
6410 std::vector<float> input1({ 1, -1, 0, 2 });
6411 std::vector<float> output({ 0, 3, 3, 2 });
6412
6413 return SubtractionTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006414 memoryManager,
David Beckf195f032018-09-06 16:46:34 +01006415 shape0, input0, 1.0f, 0,
6416 shape1, input1, 1.0f, 0,
6417 shape0, output, 1.0f, 0);
6418}
6419
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006420LayerTestResult<float, 4> SubtractionBroadcast1ElementTest(
6421 armnn::IWorkloadFactory& workloadFactory,
6422 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beckf195f032018-09-06 16:46:34 +01006423{
6424 const unsigned int shape0[] = { 1, 1, 2, 2 };
6425 const unsigned int shape1[] = { 1, 1, 1, 1 };
6426
6427 std::vector<float> input0({ 1, 2, 3, 4 });
6428 std::vector<float> input1({ 10 });
6429 std::vector<float> output({ -9, -8, -7, -6 });
6430
6431 return SubtractionTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006432 memoryManager,
David Beckf195f032018-09-06 16:46:34 +01006433 shape0, input0, 1.0f, 0,
6434 shape1, input1, 1.0f, 0,
6435 shape0, output, 1.0f, 0);
6436}
6437
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006438LayerTestResult<float, 4> SubtractionBroadcastTest(
6439 armnn::IWorkloadFactory& workloadFactory,
6440 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beckf195f032018-09-06 16:46:34 +01006441{
6442 const unsigned int shape0[] = { 1, 1, 2, 2 };
6443 const unsigned int shape1[] = { 1, 1, 1, 2 };
6444
6445 std::vector<float> input0({ 1, 2, 3, 4 });
6446 std::vector<float> input1({ 10, -5 });
6447 std::vector<float> output({ -9, 7, -7, 9 });
6448
6449 return SubtractionTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006450 memoryManager,
David Beckf195f032018-09-06 16:46:34 +01006451 shape0, input0, 1.0f, 0,
6452 shape1, input1, 1.0f, 0,
6453 shape0, output, 1.0f, 0);
6454}
6455
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006456LayerTestResult<uint8_t, 4> ResizeBilinearNopUint8Test(
6457 armnn::IWorkloadFactory& workloadFactory,
6458 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006459{
6460 constexpr unsigned int inputWidth = 4;
6461 constexpr unsigned int inputHeight = 4;
6462 constexpr unsigned int inputChannels = 1;
6463 constexpr unsigned int inputBatchSize = 1;
6464
6465 constexpr unsigned int outputWidth = inputWidth;
6466 constexpr unsigned int outputHeight = inputHeight;
6467 constexpr unsigned int outputChannels = inputChannels;
6468 constexpr unsigned int outputBatchSize = inputBatchSize;
6469
6470 armnn::TensorInfo inputTensorInfo({ inputBatchSize, inputChannels, inputHeight, inputWidth },
6471 armnn::DataType::QuantisedAsymm8);
6472 inputTensorInfo.SetQuantizationScale(1.5f);
6473 inputTensorInfo.SetQuantizationOffset(-3);
6474
6475 armnn::TensorInfo outputTensorInfo({ outputBatchSize, outputChannels, outputHeight, outputWidth },
6476 armnn::DataType::QuantisedAsymm8);
6477 outputTensorInfo.SetQuantizationScale(1.5f);
6478 outputTensorInfo.SetQuantizationOffset(-3);
6479
6480 auto input = MakeTensor<uint8_t, 4>(inputTensorInfo, std::vector<uint8_t>({
6481 1, 2, 3, 4,
6482 2, 3, 4, 5,
6483 3, 4, 5, 6,
6484 4, 5, 6, 7
6485 }));
6486
6487 LayerTestResult<uint8_t, 4> result(outputTensorInfo);
6488 result.outputExpected = input;
6489
6490 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
6491 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
6492
6493 armnn::ResizeBilinearQueueDescriptor descriptor;
6494 armnn::WorkloadInfo info;
6495 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
6496 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
6497
6498 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
6499
6500 inputHandle->Allocate();
6501 outputHandle->Allocate();
6502 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
6503
6504 workload->Execute();
6505
6506 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
6507 return result;
6508}
6509
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006510LayerTestResult<uint8_t, 4> SimpleResizeBilinearUint8Test(
6511 armnn::IWorkloadFactory& workloadFactory,
6512 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006513{
6514 constexpr unsigned int inputWidth = 2;
6515 constexpr unsigned int inputHeight = 2;
6516 constexpr unsigned int inputChannels = 1;
6517 constexpr unsigned int inputBatchSize = 1;
6518
6519 constexpr unsigned int outputWidth = inputWidth / 2;
6520 constexpr unsigned int outputHeight = inputHeight / 2;
6521 constexpr unsigned int outputChannels = inputChannels;
6522 constexpr unsigned int outputBatchSize = inputBatchSize;
6523
6524 armnn::TensorInfo inputTensorInfo({ inputBatchSize, inputChannels, inputHeight, inputWidth },
6525 armnn::DataType::QuantisedAsymm8);
6526 inputTensorInfo.SetQuantizationScale(0.1567f);
6527 inputTensorInfo.SetQuantizationOffset(1);
6528
6529 armnn::TensorInfo outputTensorInfo({ outputBatchSize, outputChannels, outputHeight, outputWidth },
6530 armnn::DataType::QuantisedAsymm8);
6531 outputTensorInfo.SetQuantizationScale(0.1567f);
6532 outputTensorInfo.SetQuantizationOffset(1);
6533
6534 auto input = MakeTensor<uint8_t, 4>(inputTensorInfo, std::vector<uint8_t>({
6535 1, 255,
6536 200, 250
6537 }));
6538
6539 // The 'resize bilinear' operation projects the top-left corner of output texels into the input image,
6540 // then figures out the interpolants and weights. Note this is different to projecting the centre of the
telsoa01c577f2c2018-08-31 09:22:23 +01006541 // output texel - and thus we'll expect the output 1x1 matrix to contain, as its single element, the value
telsoa014fcda012018-03-09 14:13:49 +00006542 // that was at position (0,0) of the input matrix (rather than an average, which we would expect if projecting
6543 // the centre).
6544 LayerTestResult<uint8_t, 4> result(outputTensorInfo);
6545 result.outputExpected = MakeTensor<uint8_t, 4>(outputTensorInfo, std::vector<uint8_t>({
6546 1
6547 }));
6548
6549 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
6550 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
6551
6552 armnn::ResizeBilinearQueueDescriptor descriptor;
6553 armnn::WorkloadInfo info;
6554 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
6555 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
6556
6557 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
6558
6559 inputHandle->Allocate();
6560 outputHandle->Allocate();
6561 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
6562
6563 workload->Execute();
6564
6565 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
6566 return result;
6567}
6568
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006569LayerTestResult<uint8_t, 4> ResizeBilinearSqMinUint8Test(
6570 armnn::IWorkloadFactory& workloadFactory,
6571 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006572{
6573 constexpr unsigned int inputWidth = 4;
6574 constexpr unsigned int inputHeight = 4;
6575 constexpr unsigned int inputChannels = 1;
6576 constexpr unsigned int inputBatchSize = 1;
6577
6578 constexpr unsigned int outputWidth = inputWidth / 2;
6579 constexpr unsigned int outputHeight = inputHeight / 2;
6580 constexpr unsigned int outputChannels = inputChannels;
6581 constexpr unsigned int outputBatchSize = inputBatchSize;
6582
6583 armnn::TensorInfo inputTensorInfo({ inputBatchSize, inputChannels, inputHeight, inputWidth },
6584 armnn::DataType::QuantisedAsymm8);
6585 inputTensorInfo.SetQuantizationScale(3.141592f);
6586 inputTensorInfo.SetQuantizationOffset(3);
6587
6588 armnn::TensorInfo outputTensorInfo({ outputBatchSize, outputChannels, outputHeight, outputWidth },
6589 armnn::DataType::QuantisedAsymm8);
6590 outputTensorInfo.SetQuantizationScale(3.141592f);
6591 outputTensorInfo.SetQuantizationOffset(3);
6592
6593 auto input = MakeTensor<uint8_t, 4>(inputTensorInfo, std::vector<uint8_t>({
6594 1, 2, 3, 4,
6595 2, 3, 4, 5,
6596 3, 4, 5, 6,
6597 4, 5, 6, 7
6598 }));
6599
6600 LayerTestResult<uint8_t, 4> result(outputTensorInfo);
6601 result.outputExpected = MakeTensor<uint8_t, 4>(outputTensorInfo, std::vector<uint8_t>({
6602 1, 3,
6603 3, 5
6604 }));
6605
6606 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
6607 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
6608
6609 armnn::ResizeBilinearQueueDescriptor descriptor;
6610 armnn::WorkloadInfo info;
6611 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
6612 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
6613
6614 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
6615
6616 inputHandle->Allocate();
6617 outputHandle->Allocate();
6618 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
6619
6620 workload->Execute();
6621
6622 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
6623 return result;
6624}
6625
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006626LayerTestResult<uint8_t, 4> ResizeBilinearMinUint8Test(
6627 armnn::IWorkloadFactory& workloadFactory,
6628 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006629{
6630 constexpr unsigned int inputWidth = 3;
6631 constexpr unsigned int inputHeight = 2;
6632 constexpr unsigned int inputChannels = 1;
6633 constexpr unsigned int inputBatchSize = 1;
6634
6635 constexpr unsigned int outputWidth = 2;
6636 constexpr unsigned int outputHeight = 1;
6637 constexpr unsigned int outputChannels = inputChannels;
6638 constexpr unsigned int outputBatchSize = inputBatchSize;
6639
6640 armnn::TensorInfo inputTensorInfo({ inputBatchSize, inputChannels, inputHeight, inputWidth },
6641 armnn::DataType::QuantisedAsymm8);
6642 inputTensorInfo.SetQuantizationScale(1.5f);
6643 inputTensorInfo.SetQuantizationOffset(-1);
6644
6645 armnn::TensorInfo outputTensorInfo({ outputBatchSize, outputChannels, outputHeight, outputWidth },
6646 armnn::DataType::QuantisedAsymm8);
6647 outputTensorInfo.SetQuantizationScale(1.5f);
6648 outputTensorInfo.SetQuantizationOffset(-1);
6649
6650 auto input = MakeTensor<uint8_t, 4>(inputTensorInfo, std::vector<uint8_t>({
6651 1, 2, 3, // 3.0, 4.5, 6.0
6652 5, 8, 13 // 9.0, 13.5, 21.0
6653 }));
6654
6655 LayerTestResult<uint8_t, 4> result(outputTensorInfo);
6656 result.outputExpected = MakeTensor<uint8_t, 4>(outputTensorInfo, std::vector<uint8_t>({
6657 1, 3 // 3.0, 5.25
6658 }));
6659
6660 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
6661 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
6662
6663 armnn::ResizeBilinearQueueDescriptor descriptor;
6664 armnn::WorkloadInfo info;
6665 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
6666 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
6667
6668 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
6669
6670 inputHandle->Allocate();
6671 outputHandle->Allocate();
6672
6673 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
6674
6675 workload->Execute();
6676
6677 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
6678 return result;
6679}
6680
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006681LayerTestResult<uint8_t, 4> ResizeBilinearMagUint8Test(
6682 armnn::IWorkloadFactory& workloadFactory,
6683 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006684{
6685 constexpr unsigned int inputWidth = 2;
6686 constexpr unsigned int inputHeight = 3;
6687 constexpr unsigned int inputChannels = 1;
6688 constexpr unsigned int inputBatchSize = 1;
6689
6690 constexpr unsigned int outputWidth = 5;
6691 constexpr unsigned int outputHeight = 3;
6692 constexpr unsigned int outputChannels = inputChannels;
6693 constexpr unsigned int outputBatchSize = inputBatchSize;
6694
6695 armnn::TensorInfo inputTensorInfo({ inputBatchSize, inputChannels, inputHeight, inputWidth },
6696 armnn::DataType::QuantisedAsymm8);
6697 inputTensorInfo.SetQuantizationScale(0.010765f);
6698 inputTensorInfo.SetQuantizationOffset(7);
6699
6700 armnn::TensorInfo outputTensorInfo({ outputBatchSize, outputChannels, outputHeight, outputWidth },
6701 armnn::DataType::QuantisedAsymm8);
6702 outputTensorInfo.SetQuantizationScale(0.010132f);
6703 outputTensorInfo.SetQuantizationOffset(-18);
6704
6705 auto input = MakeTensor<uint8_t, 4>(inputTensorInfo, std::vector<uint8_t>({
6706 24, 228, // 0.183005, 2.379065,
6707 105, 128, // 1.05497, 1.302565
6708 230, 71 // 2.400595, 0.68896
6709 }));
6710
6711 LayerTestResult<uint8_t, 4> result(outputTensorInfo);
6712 result.outputExpected = MakeTensor<uint8_t, 4>(outputTensorInfo, std::vector<uint8_t>({
6713 0, 87, 173, 217, 217, // 0.18300501, 1.06142902, 1.93985295, 2.37906504, 2.37906504
6714 86, 96, 106, 111, 111, // 1.05497003, 1.15400803, 1.25304604, 1.30256498, 1.30256498
6715 219, 151, 84, 50, 50 // 2.40059495, 1.71594095, 1.03128707, 0.68896002, 0.68896002
6716 }));
6717
6718 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
6719 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
6720
6721 armnn::ResizeBilinearQueueDescriptor descriptor;
6722 armnn::WorkloadInfo info;
6723 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
6724 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
6725
6726 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
6727
6728 inputHandle->Allocate();
6729 outputHandle->Allocate();
6730 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
6731
6732 workload->Execute();
6733
6734 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
6735 return result;
6736}
6737
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00006738LayerTestResult<float, 2> Rsqrt2dTestCommon(
6739 armnn::IWorkloadFactory& workloadFactory,
6740 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
6741 const armnn::TensorInfo inputTensorInfo,
6742 const armnn::TensorInfo outputTensorInfo,
6743 std::vector<float> inputValues,
6744 std::vector<float> expectedOutputValues)
6745{
6746 auto inputTensor = MakeTensor<float, 2>(inputTensorInfo, std::vector<float>(inputValues));
6747
6748 LayerTestResult<float, 2> result(outputTensorInfo);
6749 result.outputExpected = MakeTensor<float, 2>(outputTensorInfo, std::vector<float>(expectedOutputValues));
6750
6751 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
6752 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
6753
6754 armnn::RsqrtQueueDescriptor descriptor;
6755
6756 armnn::WorkloadInfo info;
6757
6758 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
6759 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
6760
6761 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateRsqrt(descriptor, info);
6762
6763 inputHandle->Allocate();
6764 outputHandle->Allocate();
6765
6766 CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0]);
6767
6768 workload->Execute();
6769
6770 CopyDataFromITensorHandle(&result.output[0][0], outputHandle.get());
6771
6772 return result;
6773}
6774LayerTestResult<float, 2> Rsqrt2dTest(
6775 armnn::IWorkloadFactory& workloadFactory,
6776 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
6777{
6778 const armnn::TensorShape inputShape{ 2, 2 };
6779 const armnn::TensorShape outputShape{ 2, 2 };
6780
6781 const armnn::TensorInfo inputTensorInfo(inputShape, armnn::DataType::Float32);
6782 const armnn::TensorInfo outputTensorInfo(outputShape, armnn::DataType::Float32);
6783
6784 std::vector<float> inputValues
6785 {
6786 1.f, 4.f,
6787 16.f, 25.f
6788 };
6789
6790 std::vector<float> expectedOutputValues
6791 {
6792 1.f, 0.5f,
6793 0.25f, 0.2f
6794 };
6795
6796 return Rsqrt2dTestCommon(workloadFactory, memoryManager,
6797 inputTensorInfo, outputTensorInfo,
6798 inputValues, expectedOutputValues);
6799}
6800
6801LayerTestResult<float, 3> Rsqrt3dTest(
6802 armnn::IWorkloadFactory& workloadFactory,
6803 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
6804{
6805 const armnn::TensorShape inputShape{ 3, 1, 2 };
6806 const armnn::TensorShape outputShape{ 3, 1, 2 };
6807
6808 const armnn::TensorInfo inputTensorInfo(inputShape, armnn::DataType::Float32);
6809 const armnn::TensorInfo outputTensorInfo(outputShape, armnn::DataType::Float32);
6810
6811 std::vector<float> inputValues
6812 {
6813 1.f, 4.f, 16.f,
6814 25.f, 64.f, 100.f
6815 };
6816
6817 std::vector<float> expectedOutputValues
6818 {
6819 1.f, 0.5f, 0.25f,
6820 0.2f, 0.125f, 0.1f
6821 };
6822
6823 auto inputTensor = MakeTensor<float, 3>(inputTensorInfo, std::vector<float>(inputValues));
6824
6825 LayerTestResult<float, 3> result(outputTensorInfo);
6826 result.outputExpected = MakeTensor<float, 3>(outputTensorInfo, std::vector<float >(expectedOutputValues));
6827
6828 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
6829 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
6830
6831 armnn::RsqrtQueueDescriptor descriptor;
6832
6833 armnn::WorkloadInfo info;
6834
6835 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
6836 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
6837
6838 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateRsqrt(descriptor, info);
6839
6840 inputHandle->Allocate();
6841 outputHandle->Allocate();
6842
6843 CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0][0]);
6844
6845 workload->Execute();
6846
6847 CopyDataFromITensorHandle(&result.output[0][0][0], outputHandle.get());
6848
6849 return result;
6850}
6851
6852LayerTestResult<float, 2> RsqrtZeroTest(
6853 armnn::IWorkloadFactory& workloadFactory,
6854 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
6855{
6856 const armnn::TensorShape inputShape{ 1, 2 };
6857 const armnn::TensorShape outputShape{ 1, 2 };
6858
6859 const armnn::TensorInfo inputTensorInfo(inputShape, armnn::DataType::Float32);
6860 const armnn::TensorInfo outputTensorInfo(outputShape, armnn::DataType::Float32);
6861
6862 std::vector<float> inputValues
6863 {
6864 0.f, -0.f
6865 };
6866
6867 std::vector<float> expectedOutputValues
6868 {
6869 INFINITY, -INFINITY
6870 };
6871
6872 return Rsqrt2dTestCommon(workloadFactory, memoryManager,
6873 inputTensorInfo, outputTensorInfo,
6874 inputValues, expectedOutputValues);
6875}
6876
6877LayerTestResult<float, 2> RsqrtNegativeTest(
6878 armnn::IWorkloadFactory& workloadFactory,
6879 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
6880{
6881 const armnn::TensorShape inputShape{ 1, 2 };
6882 const armnn::TensorShape outputShape{ 1, 2 };
6883
6884 const armnn::TensorInfo inputTensorInfo(inputShape, armnn::DataType::Float32);
6885 const armnn::TensorInfo outputTensorInfo(outputShape, armnn::DataType::Float32);
6886
6887 std::vector<float> inputValues
6888 {
6889 -25.f, -16.f
6890 };
6891
6892 std::vector<float> expectedOutputValues
6893 {
6894 -NAN, -NAN
6895 };
6896
6897 return Rsqrt2dTestCommon(workloadFactory, memoryManager,
6898 inputTensorInfo, outputTensorInfo,
6899 inputValues, expectedOutputValues);
6900}
6901
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006902LayerTestResult<float, 4> BatchNormTest(
6903 armnn::IWorkloadFactory& workloadFactory,
6904 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006905{
Matteo Martincigh8eb675e2018-10-17 14:43:29 +01006906 // BatchSize: 1
6907 // Channels: 2
6908 // Height: 3
6909 // Width: 2
6910
6911 const armnn::TensorShape inputOutputShape{ 1, 2, 3, 2 };
6912 std::vector<float> inputValues
6913 {
6914 // Batch 0, Channel 0, Height (3) x Width (2)
6915 1.f, 4.f,
6916 4.f, 2.f,
6917 1.f, 6.f,
6918
6919 // Batch 0, Channel 1, Height (3) x Width (2)
6920 1.f, 1.f,
6921 4.f, 1.f,
6922 -2.f, 4.f
6923 };
6924 std::vector<float> expectedOutputValues
6925 {
6926 // Batch 0, Channel 0, Height (3) x Width (2)
6927 1.f, 4.f,
6928 4.f, 2.f,
6929 1.f, 6.f,
6930
6931 // Batch 0, Channel 1, Height (3) x Width (2)
6932 3.f, 3.f,
6933 4.f, 3.f,
6934 2.f, 4.f
6935 };
6936
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006937 return BatchNormTestImpl<float>(workloadFactory, memoryManager,
6938 inputOutputShape, inputValues, expectedOutputValues,
Matteo Martincigh8eb675e2018-10-17 14:43:29 +01006939 0.f, 0, armnn::DataLayout::NCHW);
6940}
6941
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006942LayerTestResult<float, 4> BatchNormNhwcTest(
6943 armnn::IWorkloadFactory& workloadFactory,
6944 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Matteo Martincigh8eb675e2018-10-17 14:43:29 +01006945{
6946 // BatchSize: 1
6947 // Height: 3
6948 // Width: 2
6949 // Channels: 2
6950
6951 const armnn::TensorShape inputOutputShape{ 1, 3, 2, 2 };
6952 std::vector<float> inputValues
6953 {
6954 // Batch 0, Height 0, Width (2) x Channel (2)
6955 1.f, 1.f,
6956 4.f, 1.f,
6957
6958 // Batch 0, Height 1, Width (2) x Channel (2)
6959 4.f, 4.f,
6960 2.f, 1.f,
6961
6962 // Batch 0, Height 2, Width (2) x Channel (2)
6963 1.f, -2.f,
6964 6.f, 4.f
6965 };
6966 std::vector<float> expectedOutputValues
6967 {
6968 // Batch 0, Height 0, Width (2) x Channel (2)
6969 1.f, 3.f,
6970 4.f, 3.f,
6971
6972 // Batch 0, Height 1, Width (2) x Channel (2)
6973 4.f, 4.f,
6974 2.f, 3.f,
6975
6976 // Batch 0, Height 2, Width (2) x Channel (2)
6977 1.f, 2.f,
6978 6.f, 4.f
6979 };
6980
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006981 return BatchNormTestImpl<float>(workloadFactory, memoryManager,
6982 inputOutputShape, inputValues, expectedOutputValues,
Matteo Martincigh8eb675e2018-10-17 14:43:29 +01006983 0.f, 0, armnn::DataLayout::NHWC);
telsoa014fcda012018-03-09 14:13:49 +00006984}
6985
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006986LayerTestResult<uint8_t, 4> BatchNormUint8Test(
6987 armnn::IWorkloadFactory& workloadFactory,
6988 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006989{
Matteo Martincigh8eb675e2018-10-17 14:43:29 +01006990 // BatchSize: 1
6991 // Channels: 2
6992 // Height: 3
6993 // Width: 2
6994
6995 const armnn::TensorShape inputOutputShape{ 1, 2, 3, 2 };
6996 std::vector<float> inputValues
6997 {
6998 // Batch 0, Channel 0, Height (3) x Width (2)
6999 1.f, 4.f,
7000 4.f, 2.f,
7001 1.f, 6.f,
7002
7003 // Batch 0, Channel 1, Height (3) x Width (2)
7004 1.f, 1.f,
7005 4.f, 1.f,
7006 -2.f, 4.f
7007 };
7008 std::vector<float> expectedOutputValues
7009 {
7010 // Batch 0, Channel 0, Height (3) x Width (2)
7011 1.f, 4.f,
7012 4.f, 2.f,
7013 1.f, 6.f,
7014
7015 // Batch 0, Channel 1, Height (3) x Width (2)
7016 3.f, 3.f,
7017 4.f, 3.f,
7018 2.f, 4.f
7019 };
7020
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007021 return BatchNormTestImpl<uint8_t>(workloadFactory, memoryManager,
7022 inputOutputShape, inputValues, expectedOutputValues,
Matteo Martincigh8eb675e2018-10-17 14:43:29 +01007023 1.f/20.f, 50, armnn::DataLayout::NCHW);
7024}
7025
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007026LayerTestResult<uint8_t, 4> BatchNormUint8NhwcTest(
7027 armnn::IWorkloadFactory& workloadFactory,
7028 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Matteo Martincigh8eb675e2018-10-17 14:43:29 +01007029{
7030 // BatchSize: 1
7031 // Height: 3
7032 // Width: 2
7033 // Channels: 2
7034
7035 const armnn::TensorShape inputOutputShape{ 1, 3, 2, 2 };
7036 std::vector<float> inputValues
7037 {
7038 // Batch 0, Height 0, Width (2) x Channel (2)
7039 1.f, 1.f,
7040 4.f, 1.f,
7041
7042 // Batch 0, Height 1, Width (2) x Channel (2)
7043 4.f, 4.f,
7044 2.f, 1.f,
7045
7046 // Batch 0, Height 2, Width (2) x Channel (2)
7047 1.f, -2.f,
7048 6.f, 4.f
7049 };
7050 std::vector<float> expectedOutputValues
7051 {
7052 // Batch 0, Height 0, Width (2) x Channel (2)
7053 1.f, 3.f,
7054 4.f, 3.f,
7055
7056 // Batch 0, Height 1, Width (2) x Channel (2)
7057 4.f, 4.f,
7058 2.f, 3.f,
7059
7060 // Batch 0, Height 2, Width (2) x Channel (2)
7061 1.f, 2.f,
7062 6.f, 4.f
7063 };
7064
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007065 return BatchNormTestImpl<uint8_t>(workloadFactory, memoryManager,
7066 inputOutputShape, inputValues, expectedOutputValues,
Matteo Martincigh8eb675e2018-10-17 14:43:29 +01007067 1.f/20.f, 50, armnn::DataLayout::NHWC);
telsoa014fcda012018-03-09 14:13:49 +00007068}
7069
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007070LayerTestResult<uint8_t, 4> ConstantUint8Test(
7071 armnn::IWorkloadFactory& workloadFactory,
7072 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007073{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007074 return ConstantTestImpl<uint8_t>(workloadFactory, memoryManager, 2e-6f, 1);
telsoa014fcda012018-03-09 14:13:49 +00007075}
7076
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007077LayerTestResult<uint8_t, 1> Concatenation1dUint8Test(
7078 armnn::IWorkloadFactory& workloadFactory,
7079 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007080{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007081 return Concatenation1dTestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00007082}
7083
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007084LayerTestResult<uint8_t, 2> Concatenation2dDim0Uint8Test(
7085 armnn::IWorkloadFactory& workloadFactory,
7086 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007087{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007088 return Concatenation2dDim0TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00007089}
7090
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007091LayerTestResult<uint8_t, 2> Concatenation2dDim1Uint8Test(
7092 armnn::IWorkloadFactory& workloadFactory,
7093 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007094{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007095 return Concatenation2dDim1TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00007096}
7097
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007098LayerTestResult<uint8_t, 2> Concatenation2dDim0DiffInputDimsUint8Test(
7099 armnn::IWorkloadFactory& workloadFactory,
7100 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007101{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007102 return Concatenation2dDim0DiffInputDimsTestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00007103}
7104
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007105LayerTestResult<uint8_t, 2> Concatenation2dDim1DiffInputDimsUint8Test(
7106 armnn::IWorkloadFactory& workloadFactory,
7107 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007108{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007109 return Concatenation2dDim1DiffInputDimsTestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00007110}
7111
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007112LayerTestResult<uint8_t, 3> Concatenation3dDim0Uint8Test(
7113 armnn::IWorkloadFactory& workloadFactory,
7114 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007115{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007116 return Concatenation3dDim0TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00007117}
7118
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007119LayerTestResult<uint8_t, 3> Concatenation3dDim1Uint8Test(
7120 armnn::IWorkloadFactory& workloadFactory,
7121 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007122{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007123 return Concatenation3dDim1TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00007124}
7125
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007126LayerTestResult<uint8_t, 3> Concatenation3dDim2Uint8Test(
7127 armnn::IWorkloadFactory& workloadFactory,
narpra015cdda352018-11-19 15:30:27 +00007128 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
7129 bool useSubtensor)
telsoa014fcda012018-03-09 14:13:49 +00007130{
narpra015cdda352018-11-19 15:30:27 +00007131 return Concatenation3dDim2TestImpl<uint8_t>(workloadFactory, memoryManager, useSubtensor, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00007132}
7133
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007134LayerTestResult<uint8_t, 3> Concatenation3dDim0DiffInputDimsUint8Test(
7135 armnn::IWorkloadFactory& workloadFactory,
7136 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007137{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007138 return Concatenation3dDim0TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00007139}
7140
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007141LayerTestResult<uint8_t, 3> Concatenation3dDim1DiffInputDimsUint8Test(
7142 armnn::IWorkloadFactory& workloadFactory,
7143 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007144{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007145 return Concatenation3dDim1DiffInputDimsTestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00007146}
7147
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007148LayerTestResult<uint8_t, 3> Concatenation3dDim2DiffInputDimsUint8Test(
7149 armnn::IWorkloadFactory& workloadFactory,
narpra015cdda352018-11-19 15:30:27 +00007150 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
7151 bool useSubtensor)
7152{
7153 return Concatenation3dDim2DiffInputDimsTestImpl<uint8_t>(workloadFactory, memoryManager, useSubtensor, 0.5f, -1);
7154}
7155
7156LayerTestResult<uint8_t, 4> Concatenation4dDim0Uint8Test(
7157 armnn::IWorkloadFactory& workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007158 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007159{
narpra015cdda352018-11-19 15:30:27 +00007160 return Concatenation4dDim0TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
7161}
7162
7163LayerTestResult<uint8_t, 4> Concatenation4dDim1Uint8Test(
7164 armnn::IWorkloadFactory& workloadFactory,
7165 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7166{
7167 return Concatenation4dDim1TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
7168}
7169
7170LayerTestResult<uint8_t, 4> Concatenation4dDim2Uint8Test(
7171 armnn::IWorkloadFactory& workloadFactory,
7172 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7173{
7174 return Concatenation4dDim2TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
7175}
7176
7177LayerTestResult<uint8_t, 4> Concatenation4dDim3Uint8Test(
7178 armnn::IWorkloadFactory& workloadFactory,
7179 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, bool useSubtensor)
7180{
7181 return Concatenation4dDim3TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1, useSubtensor);
7182}
7183
7184LayerTestResult<uint8_t, 4> Concatenation4dDiffShapeDim0Uint8Test(
7185 armnn::IWorkloadFactory& workloadFactory,
7186 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7187{
7188 return Concatenation4dDiffShapeDim0TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
7189}
7190
7191LayerTestResult<uint8_t, 4> Concatenation4dDiffShapeDim1Uint8Test(
7192 armnn::IWorkloadFactory& workloadFactory,
7193 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7194{
7195 return Concatenation4dDiffShapeDim1TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
7196}
7197
7198LayerTestResult<uint8_t, 4> Concatenation4dDiffShapeDim2Uint8Test(
7199 armnn::IWorkloadFactory& workloadFactory,
7200 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7201{
7202 return Concatenation4dDiffShapeDim2TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
7203}
7204
7205LayerTestResult<uint8_t, 4> Concatenation4dDiffShapeDim3Uint8Test(
7206 armnn::IWorkloadFactory& workloadFactory,
7207 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
7208 bool useSubtensor)
7209{
7210 return Concatenation4dDiffShapeDim3TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1, useSubtensor);
telsoa014fcda012018-03-09 14:13:49 +00007211}
7212
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007213LayerTestResult<float, 4> SimpleMaxPooling2dSize2x2Stride2x2Test(
7214 armnn::IWorkloadFactory& workloadFactory,
7215 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
7216 bool forceNoPadding)
telsoa014fcda012018-03-09 14:13:49 +00007217{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007218 return SimpleMaxPooling2dSize2x2Stride2x2TestCommon<float>(workloadFactory, memoryManager, forceNoPadding);
telsoa014fcda012018-03-09 14:13:49 +00007219}
7220
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007221LayerTestResult<uint8_t, 4> SimpleMaxPooling2dSize2x2Stride2x2Uint8Test(
7222 armnn::IWorkloadFactory& workloadFactory,
7223 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
7224 bool forceNoPadding)
telsoa014fcda012018-03-09 14:13:49 +00007225{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007226 return SimpleMaxPooling2dSize2x2Stride2x2TestCommon<uint8_t>(
7227 workloadFactory, memoryManager, forceNoPadding, 3.0f, -5);
telsoa014fcda012018-03-09 14:13:49 +00007228}
7229
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007230LayerTestResult<float, 4> SimpleMaxPooling2dSize3x3Stride2x4Test(
7231 armnn::IWorkloadFactory& workloadFactory,
7232 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
7233 bool forceNoPadding)
telsoa014fcda012018-03-09 14:13:49 +00007234{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007235 return SimpleMaxPooling2dSize3x3Stride2x4TestCommon<float>(workloadFactory, memoryManager, forceNoPadding);
telsoa014fcda012018-03-09 14:13:49 +00007236}
7237
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007238LayerTestResult<uint8_t, 4> SimpleMaxPooling2dSize3x3Stride2x4Uint8Test(
7239 armnn::IWorkloadFactory& workloadFactory,
7240 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
7241 bool forceNoPadding)
telsoa014fcda012018-03-09 14:13:49 +00007242{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007243 return SimpleMaxPooling2dSize3x3Stride2x4TestCommon<uint8_t>(
7244 workloadFactory, memoryManager, forceNoPadding, 0.1f, 128);
telsoa014fcda012018-03-09 14:13:49 +00007245}
7246
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007247LayerTestResult<float, 4> SimpleMaxPooling2dTest(
7248 armnn::IWorkloadFactory& workloadFactory,
7249 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00007250 const armnn::DataLayout dataLayout)
telsoa014fcda012018-03-09 14:13:49 +00007251{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007252 return SimpleMaxPooling2dTestCommon<float>(workloadFactory, memoryManager, dataLayout);
telsoa014fcda012018-03-09 14:13:49 +00007253}
7254
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007255LayerTestResult<uint8_t, 4> SimpleMaxPooling2dUint8Test(
7256 armnn::IWorkloadFactory& workloadFactory,
7257 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00007258 const armnn::DataLayout dataLayout)
Francis Murtagh043d0d02018-10-05 14:08:48 +01007259{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007260 return SimpleMaxPooling2dTestCommon<uint8_t>(workloadFactory, memoryManager, dataLayout);
Francis Murtagh043d0d02018-10-05 14:08:48 +01007261}
7262
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007263LayerTestResult<float, 4> SimpleAveragePooling2dTest(
7264 armnn::IWorkloadFactory& workloadFactory,
7265 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00007266 const armnn::DataLayout dataLayout)
telsoa014fcda012018-03-09 14:13:49 +00007267{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007268 return SimpleAveragePooling2dTestCommon<float>(workloadFactory, memoryManager, dataLayout);
James Conroy69482272018-10-19 10:41:35 +01007269}
7270
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007271LayerTestResult<uint8_t, 4> SimpleAveragePooling2dUint8Test(
7272 armnn::IWorkloadFactory& workloadFactory,
7273 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00007274 const armnn::DataLayout dataLayout)
James Conroy69482272018-10-19 10:41:35 +01007275{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007276 return SimpleAveragePooling2dTestCommon<uint8_t>(
7277 workloadFactory, memoryManager, dataLayout, 0.5, -1);
telsoa014fcda012018-03-09 14:13:49 +00007278}
7279
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007280LayerTestResult<float, 4> IgnorePaddingAveragePooling2dSize3x2Stride2x2Test(
7281 armnn::IWorkloadFactory& workloadFactory,
7282 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
7283 bool forceNoPadding)
surmeh01bceff2f2018-03-29 16:29:27 +01007284{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007285 return IgnorePaddingAveragePooling2dSize3x2Stride2x2TestCommon<float>(
7286 workloadFactory, memoryManager, forceNoPadding);
surmeh01bceff2f2018-03-29 16:29:27 +01007287}
7288
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007289LayerTestResult<float, 4> LargeTensorsAveragePooling2dTest(
7290 armnn::IWorkloadFactory& workloadFactory,
7291 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007292{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007293 return LargeTensorsAveragePooling2dTestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007294}
7295
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007296LayerTestResult<uint8_t, 4> LargeTensorsAveragePooling2dUint8Test(
7297 armnn::IWorkloadFactory& workloadFactory,
7298 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007299{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007300 return LargeTensorsAveragePooling2dTestCommon<uint8_t>(workloadFactory, memoryManager, 0.5, -1);
telsoa014fcda012018-03-09 14:13:49 +00007301}
7302
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007303LayerTestResult<float, 4> SimpleL2Pooling2dTest(
7304 armnn::IWorkloadFactory& workloadFactory,
7305 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00007306 const armnn::DataLayout dataLayout)
telsoa014fcda012018-03-09 14:13:49 +00007307{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007308 return SimpleL2Pooling2dTestCommon<float>(workloadFactory, memoryManager, dataLayout);
telsoa014fcda012018-03-09 14:13:49 +00007309}
7310
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007311LayerTestResult<uint8_t, 4> SimpleL2Pooling2dUint8Test(
7312 armnn::IWorkloadFactory& workloadFactory,
7313 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00007314 const armnn::DataLayout dataLayout)
telsoa014fcda012018-03-09 14:13:49 +00007315{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007316 return SimpleL2Pooling2dTestCommon<uint8_t>(workloadFactory, memoryManager, dataLayout);
telsoa014fcda012018-03-09 14:13:49 +00007317}
7318
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007319LayerTestResult<float, 4> L2Pooling2dSize3Stride1Test(
7320 armnn::IWorkloadFactory& workloadFactory,
7321 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007322{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007323 return L2Pooling2dSize3Stride1TestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007324}
7325
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007326LayerTestResult<uint8_t, 4> L2Pooling2dSize3Stride1Uint8Test(
7327 armnn::IWorkloadFactory& workloadFactory,
7328 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007329{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007330 return L2Pooling2dSize3Stride1TestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007331}
7332
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007333LayerTestResult<float, 4> L2Pooling2dSize3Stride3Test(
7334 armnn::IWorkloadFactory& workloadFactory,
7335 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007336{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007337 return L2Pooling2dSize3Stride3TestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007338}
7339
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007340LayerTestResult<uint8_t, 4> L2Pooling2dSize3Stride3Uint8Test(
7341 armnn::IWorkloadFactory& workloadFactory,
7342 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007343{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007344 return L2Pooling2dSize3Stride3TestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007345}
7346
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007347LayerTestResult<float, 4> L2Pooling2dSize3Stride4Test(
7348 armnn::IWorkloadFactory& workloadFactory,
7349 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007350{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007351 return L2Pooling2dSize3Stride4TestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007352}
7353
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007354LayerTestResult<uint8_t, 4> L2Pooling2dSize3Stride4Uint8Test(
7355 armnn::IWorkloadFactory& workloadFactory,
7356 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007357{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007358 return L2Pooling2dSize3Stride4TestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007359}
7360
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007361LayerTestResult<float, 4> L2Pooling2dSize7Test(
7362 armnn::IWorkloadFactory& workloadFactory,
7363 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007364{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007365 return L2Pooling2dSize7TestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007366}
7367
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007368LayerTestResult<uint8_t, 4> L2Pooling2dSize7Uint8Test(
7369 armnn::IWorkloadFactory& workloadFactory,
7370 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007371{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007372 return L2Pooling2dSize7TestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007373}
7374
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007375LayerTestResult<float, 4> L2Pooling2dSize9Test(
7376 armnn::IWorkloadFactory& workloadFactory,
7377 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007378{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007379 return L2Pooling2dSize9TestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007380}
7381
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007382LayerTestResult<uint8_t, 4> L2Pooling2dSize9Uint8Test(
7383 armnn::IWorkloadFactory& workloadFactory,
7384 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007385{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007386 return L2Pooling2dSize9TestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007387}
7388
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007389LayerTestResult<float, 4> AsymmetricNonSquarePooling2dTest(
7390 armnn::IWorkloadFactory& workloadFactory,
7391 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007392{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007393 return AsymmetricNonSquarePooling2dTestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007394}
7395
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007396LayerTestResult<uint8_t, 4> AsymmetricNonSquarePooling2dUint8Test(
7397 armnn::IWorkloadFactory& workloadFactory,
7398 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007399{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007400 return AsymmetricNonSquarePooling2dTestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007401}
7402
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007403LayerTestResult<float, 4> ComparePooling2dTest(
7404 armnn::IWorkloadFactory& workloadFactory,
7405 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
7406 armnn::IWorkloadFactory& refWorkloadFactory,
7407 armnn::PoolingAlgorithm poolingType)
telsoa014fcda012018-03-09 14:13:49 +00007408{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007409 return ComparePooling2dTestCommon<float>(
7410 workloadFactory, memoryManager, refWorkloadFactory, poolingType);
telsoa014fcda012018-03-09 14:13:49 +00007411}
7412
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007413LayerTestResult<uint8_t, 4> ComparePooling2dUint8Test(
7414 armnn::IWorkloadFactory& workloadFactory,
7415 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
7416 armnn::IWorkloadFactory& refWorkloadFactory,
7417 armnn::PoolingAlgorithm poolingType)
telsoa014fcda012018-03-09 14:13:49 +00007418{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007419 return ComparePooling2dTestCommon<uint8_t>(
7420 workloadFactory, memoryManager, refWorkloadFactory, poolingType, 0.1f, 128);
telsoa014fcda012018-03-09 14:13:49 +00007421}
7422
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007423LayerTestResult<float, 2> FullyConnectedLargeTest(
7424 armnn::IWorkloadFactory& workloadFactory,
7425 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
7426 bool transposeWeights)
telsoa014fcda012018-03-09 14:13:49 +00007427{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007428 return FullyConnectedLargeTestCommon<float>(workloadFactory, memoryManager, transposeWeights);
telsoa014fcda012018-03-09 14:13:49 +00007429}
7430
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007431LayerTestResult<float, 4> IgnorePaddingSimpleMaxPooling2dTest(
7432 armnn::IWorkloadFactory& workloadFactory,
7433 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007434{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007435 return IgnorePaddingSimpleMaxPooling2dTestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007436}
7437
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007438LayerTestResult<uint8_t, 4> IgnorePaddingSimpleMaxPooling2dUint8Test(
7439 armnn::IWorkloadFactory& workloadFactory,
7440 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007441{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007442 return IgnorePaddingSimpleMaxPooling2dTestCommon<uint8_t>(workloadFactory, memoryManager, 1.0f, -5);
telsoa014fcda012018-03-09 14:13:49 +00007443}
7444
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007445LayerTestResult<float, 4> IgnorePaddingMaxPooling2dSize3Test(
7446 armnn::IWorkloadFactory& workloadFactory,
7447 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007448{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007449 return IgnorePaddingMaxPooling2dSize3TestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007450}
7451
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007452LayerTestResult<uint8_t, 4> IgnorePaddingMaxPooling2dSize3Uint8Test(
7453 armnn::IWorkloadFactory& workloadFactory,
7454 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007455{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007456 return IgnorePaddingMaxPooling2dSize3TestCommon<uint8_t>(workloadFactory, memoryManager, 1.0f, -5);
telsoa014fcda012018-03-09 14:13:49 +00007457}
7458
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007459LayerTestResult<float, 4> IgnorePaddingSimpleAveragePooling2dTest(
7460 armnn::IWorkloadFactory& workloadFactory,
7461 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007462{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007463 return IgnorePaddingSimpleAveragePooling2dTestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007464}
7465
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007466LayerTestResult<uint8_t, 4> IgnorePaddingSimpleAveragePooling2dUint8Test(
7467 armnn::IWorkloadFactory& workloadFactory,
7468 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007469{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007470 return IgnorePaddingSimpleAveragePooling2dTestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007471}
7472
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007473LayerTestResult<float, 4> IgnorePaddingSimpleAveragePooling2dNoPaddingTest(
7474 armnn::IWorkloadFactory& workloadFactory,
7475 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007476{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007477 return IgnorePaddingSimpleAveragePooling2dNoPaddingTestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007478}
7479
7480LayerTestResult<uint8_t, 4> IgnorePaddingSimpleAveragePooling2dNoPaddingUint8Test(
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007481 armnn::IWorkloadFactory& workloadFactory,
7482 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007483{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007484 return IgnorePaddingSimpleAveragePooling2dNoPaddingTestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007485}
7486
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007487LayerTestResult<float, 4> IgnorePaddingAveragePooling2dSize3Test(
7488 armnn::IWorkloadFactory& workloadFactory,
7489 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007490{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007491 return IgnorePaddingAveragePooling2dSize3TestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007492}
7493
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007494LayerTestResult<uint8_t, 4> IgnorePaddingAveragePooling2dSize3Uint8Test(
7495 armnn::IWorkloadFactory& workloadFactory,
7496 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007497{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007498 return IgnorePaddingAveragePooling2dSize3TestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007499}
7500
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007501LayerTestResult<float, 4> IgnorePaddingSimpleL2Pooling2dTest(
7502 armnn::IWorkloadFactory& workloadFactory,
7503 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007504{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007505 return IgnorePaddingSimpleL2Pooling2dTestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007506}
7507
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007508LayerTestResult<uint8_t, 4> IgnorePaddingSimpleL2Pooling2dUint8Test(
7509 armnn::IWorkloadFactory& workloadFactory,
7510 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007511{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007512 return IgnorePaddingSimpleL2Pooling2dTestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007513}
7514
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007515LayerTestResult<float, 4> IgnorePaddingL2Pooling2dSize3Test(
7516 armnn::IWorkloadFactory& workloadFactory,
7517 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007518{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007519 return IgnorePaddingL2Pooling2dSize3TestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007520}
7521
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007522LayerTestResult<uint8_t, 4> IgnorePaddingL2Pooling2dSize3Uint8Test(
7523 armnn::IWorkloadFactory& workloadFactory,
7524 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007525{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007526 return IgnorePaddingL2Pooling2dSize3TestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007527}
7528
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007529LayerTestResult<float, 4> SimplePermuteFloat32Test(
7530 armnn::IWorkloadFactory& workloadFactory,
7531 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007532{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007533 return SimplePermuteFloat32TestCommon(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007534};
7535
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007536LayerTestResult<uint8_t, 4> SimplePermuteUint8Test(
7537 armnn::IWorkloadFactory& workloadFactory,
7538 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00007539{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007540 return SimplePermuteUint8TestCommon(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00007541};
surmeh01bceff2f2018-03-29 16:29:27 +01007542
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007543LayerTestResult<float, 4> PermuteFloat32ValueSet1Test(
7544 armnn::IWorkloadFactory& workloadFactory,
7545 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01007546{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007547 return PermuteFloat32ValueSet1TestCommon(workloadFactory, memoryManager);
surmeh01bceff2f2018-03-29 16:29:27 +01007548};
7549
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007550LayerTestResult<float, 4> PermuteFloat32ValueSet2Test(
7551 armnn::IWorkloadFactory& workloadFactory,
7552 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01007553{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007554 return PermuteFloat32ValueSet2TestCommon(workloadFactory, memoryManager);
surmeh01bceff2f2018-03-29 16:29:27 +01007555};
7556
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007557LayerTestResult<float, 4> PermuteFloat32ValueSet3Test(
7558 armnn::IWorkloadFactory& workloadFactory,
7559 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01007560{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007561 return PermuteFloat32ValueSet3TestCommon(workloadFactory, memoryManager);
narpra011e4c31d2018-09-28 11:07:51 +01007562};
7563
7564namespace
7565{
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007566
narpra011e4c31d2018-09-28 11:07:51 +01007567template <typename T, std::size_t InputDim, std::size_t OutputDim>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007568LayerTestResult<T, OutputDim> MeanTestHelper(
7569 armnn::IWorkloadFactory& workloadFactory,
7570 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
7571 const unsigned int* inputShape,
7572 const std::vector<T>& inputData,
7573 const std::vector<unsigned int>& axis,
7574 bool keepDims,
7575 const unsigned int* outputShape,
7576 const std::vector<T>& outputData,
7577 float scale = 1.0f,
7578 int32_t offset = 0)
narpra011e4c31d2018-09-28 11:07:51 +01007579{
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007580 auto dataType = (std::is_same<T, uint8_t>::value ? armnn::DataType::QuantisedAsymm8 : armnn::DataType::Float32);
narpra011e4c31d2018-09-28 11:07:51 +01007581
7582 armnn::TensorInfo inputTensorInfo(InputDim, inputShape, dataType);
7583 armnn::TensorInfo outputTensorInfo(OutputDim, outputShape, dataType);
7584
7585 inputTensorInfo.SetQuantizationScale(scale);
7586 inputTensorInfo.SetQuantizationOffset(offset);
7587
7588 outputTensorInfo.SetQuantizationScale(scale);
7589 outputTensorInfo.SetQuantizationOffset(offset);
7590
7591 auto input = MakeTensor<T, InputDim>(inputTensorInfo, inputData);
7592
7593 LayerTestResult<T, OutputDim> result(outputTensorInfo);
7594 result.outputExpected = MakeTensor<T, OutputDim>(outputTensorInfo, outputData);
7595
7596 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
7597 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
7598
7599 armnn::MeanQueueDescriptor data;
7600 data.m_Parameters.m_Axis = axis;
7601 data.m_Parameters.m_KeepDims = keepDims;
7602 armnn::WorkloadInfo info;
7603 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
7604 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
7605
7606 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateMean(data, info);
7607
7608 inputHandle->Allocate();
7609 outputHandle->Allocate();
7610
7611 CopyDataToITensorHandle(inputHandle.get(), input.origin());
7612
narpra011e4c31d2018-09-28 11:07:51 +01007613 workload->Execute();
7614
7615 CopyDataFromITensorHandle(result.output.origin(), outputHandle.get());
7616
7617 return result;
7618}
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007619
narpra011e4c31d2018-09-28 11:07:51 +01007620} // anonymous namespace
7621
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007622LayerTestResult<uint8_t, 1> MeanUint8SimpleTest(
7623 armnn::IWorkloadFactory& workloadFactory,
7624 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007625{
7626 const unsigned int inputShape[] = { 3, 2 };
7627 const unsigned int outputShape[] = { 1 };
7628
7629 std::vector<uint8_t> input({ 1, 1, 2, 2, 3, 3 });
7630 std::vector<uint8_t> output({ 2 });
7631
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007632 return MeanTestHelper<uint8_t, 2, 1>(
7633 workloadFactory, memoryManager, inputShape, input, {}, false, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007634}
7635
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007636LayerTestResult<uint8_t, 3> MeanUint8SimpleAxisTest(
7637 armnn::IWorkloadFactory& workloadFactory,
7638 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007639{
7640 const unsigned int inputShape[] = { 1, 1, 3, 2 };
7641 const unsigned int outputShape[] = { 1, 1, 2 };
7642
7643 std::vector<uint8_t> input({ 1, 1, 2, 2, 3, 3 });
7644 std::vector<uint8_t> output({ 2, 2 });
7645
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007646 return MeanTestHelper<uint8_t, 4, 3>(
7647 workloadFactory, memoryManager, inputShape, input, { 2 }, false, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007648}
7649
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007650LayerTestResult<uint8_t, 4> MeanUint8KeepDimsTest(
7651 armnn::IWorkloadFactory& workloadFactory,
7652 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007653{
7654 const unsigned int inputShape[] = { 1, 1, 3, 2 };
7655 const unsigned int outputShape[] = { 1, 1, 1, 2 };
7656
7657 std::vector<uint8_t> input({ 1, 1, 2, 2, 3, 3 });
7658 std::vector<uint8_t> output({ 2, 2 });
7659
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007660 return MeanTestHelper<uint8_t, 4, 4>(
7661 workloadFactory, memoryManager, inputShape, input, { 2 }, true, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007662}
7663
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007664LayerTestResult<uint8_t, 4> MeanUint8MultipleDimsTest(
7665 armnn::IWorkloadFactory& workloadFactory,
7666 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007667{
7668 const unsigned int inputShape[] = { 2, 3, 1, 2 };
7669 const unsigned int outputShape[] = { 1, 3, 1, 1 };
7670
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007671 std::vector<uint8_t> input({ 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6 });
narpra011e4c31d2018-09-28 11:07:51 +01007672 std::vector<uint8_t> output({ 1, 3, 5 });
7673
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007674 return MeanTestHelper<uint8_t, 4, 4>(
7675 workloadFactory, memoryManager, inputShape, input, { 0, 3 }, true, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007676}
7677
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007678LayerTestResult<uint8_t, 1> MeanVtsUint8Test(
7679 armnn::IWorkloadFactory& workloadFactory,
7680 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007681{
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007682 const unsigned int inputShape[] = { 4, 3, 2 };
narpra011e4c31d2018-09-28 11:07:51 +01007683 const unsigned int outputShape[] = { 2 };
7684
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007685 std::vector<uint8_t> input({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
7686 24 });
7687 std::vector<uint8_t> output({ 12, 13 });
narpra011e4c31d2018-09-28 11:07:51 +01007688
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007689 return MeanTestHelper<uint8_t, 3, 1>(workloadFactory, memoryManager,
7690 inputShape, input, { 0, 1 }, false, outputShape,
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007691 output, 0.8f, 5);
narpra011e4c31d2018-09-28 11:07:51 +01007692}
7693
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007694LayerTestResult<float, 1> MeanFloatSimpleTest(
7695 armnn::IWorkloadFactory& workloadFactory,
7696 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007697{
7698 const unsigned int inputShape[] = { 3, 2 };
7699 const unsigned int outputShape[] = { 1 };
7700
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007701 std::vector<float> input({ 1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 3.0f });
7702 std::vector<float> output({ 2.0f });
narpra011e4c31d2018-09-28 11:07:51 +01007703
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007704 return MeanTestHelper<float, 2, 1>(
7705 workloadFactory, memoryManager, inputShape, input, {}, false, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007706}
7707
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007708LayerTestResult<float, 3> MeanFloatSimpleAxisTest(
7709 armnn::IWorkloadFactory& workloadFactory,
7710 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007711{
7712 const unsigned int inputShape[] = { 2, 3, 1, 2 };
7713 const unsigned int outputShape[] = { 3, 1, 2 };
7714
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007715 std::vector<float> input({ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f });
7716 std::vector<float> output({ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f });
narpra011e4c31d2018-09-28 11:07:51 +01007717
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007718 return MeanTestHelper<float, 4, 3>(
7719 workloadFactory, memoryManager, inputShape, input, { 0 }, false, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007720}
7721
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007722LayerTestResult<float, 4> MeanFloatKeepDimsTest(
7723 armnn::IWorkloadFactory& workloadFactory,
7724 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007725{
7726 const unsigned int inputShape[] = { 1, 1, 3, 2 };
7727 const unsigned int outputShape[] = { 1, 1, 1, 2 };
7728
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007729 std::vector<float> input({ 1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 3.0f });
7730 std::vector<float> output({ 2.0f, 2.0f });
narpra011e4c31d2018-09-28 11:07:51 +01007731
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007732 return MeanTestHelper<float, 4, 4>(
7733 workloadFactory, memoryManager, inputShape, input, { 2 }, true, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007734}
7735
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007736LayerTestResult<float, 4> MeanFloatMultipleDimsTest(
7737 armnn::IWorkloadFactory& workloadFactory,
7738 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007739{
7740 const unsigned int inputShape[] = { 2, 3, 1, 2 };
7741 const unsigned int outputShape[] = { 1, 3, 1, 1 };
7742
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007743 std::vector<float> input({ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f });
7744 std::vector<float> output({ 1.5f, 3.5f, 5.5f });
narpra011e4c31d2018-09-28 11:07:51 +01007745
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007746 return MeanTestHelper<float, 4, 4>(
7747 workloadFactory, memoryManager, inputShape, input, { 0, 3 }, true, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007748}
7749
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007750LayerTestResult<float, 1> MeanVtsFloat1Test(
7751 armnn::IWorkloadFactory& workloadFactory,
7752 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007753{
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007754 const unsigned int inputShape[] = { 4, 3, 2 };
narpra011e4c31d2018-09-28 11:07:51 +01007755 const unsigned int outputShape[] = { 2 };
7756
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007757 std::vector<float> input({ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f,
7758 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f });
7759 std::vector<float> output({ 12.0f, 13.0f });
narpra011e4c31d2018-09-28 11:07:51 +01007760
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007761 return MeanTestHelper<float, 3, 1>(
7762 workloadFactory, memoryManager, inputShape, input, { 0, 1 }, false, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007763}
7764
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007765LayerTestResult<float, 3> MeanVtsFloat2Test(
7766 armnn::IWorkloadFactory& workloadFactory,
7767 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007768{
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007769 const unsigned int inputShape[] = { 4, 3, 2 };
7770 const unsigned int outputShape[] = { 1, 3, 1 };
narpra011e4c31d2018-09-28 11:07:51 +01007771
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007772 std::vector<float> input({ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f,
7773 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f });
7774 std::vector<float> output({ 10.5f, 12.5f, 14.5f });
narpra011e4c31d2018-09-28 11:07:51 +01007775
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007776 return MeanTestHelper<float, 3, 3>(
7777 workloadFactory, memoryManager, inputShape, input, { 0, 2 }, true, outputShape, output);
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007778}
7779
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007780LayerTestResult<float, 3> MeanVtsFloat3Test(
7781 armnn::IWorkloadFactory& workloadFactory,
7782 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007783{
7784 const unsigned int inputShape[] = { 1, 2, 2, 1 };
7785 const unsigned int outputShape[] = { 1, 2, 1 };
7786
7787 std::vector<float> input({ 1.0f, 2.0f, 3.0f, 4.0f });
7788 std::vector<float> output({ 1.5f, 3.5f });
7789
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007790 return MeanTestHelper<float, 4, 3>(
7791 workloadFactory, memoryManager, inputShape, input, { 2 }, false, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007792}
Éanna Ó Catháin47c1ddb2018-10-12 14:24:13 +01007793
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007794LayerTestResult<float, 4> AdditionAfterMaxPoolTest(
7795 armnn::IWorkloadFactory& workloadFactory,
7796 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Éanna Ó Catháin47c1ddb2018-10-12 14:24:13 +01007797{
7798 // Create Initial Tensor
7799 // 1, 2, 3
7800 // 4, 5, 6
7801 // 7, 8, 9
7802
7803 armnn::TensorInfo poolingInputTensorInfo({ 1, 1, 3, 3}, armnn::GetDataType<float>());
7804 armnn::TensorInfo poolingOutputTensorInfo({ 1, 1, 2, 2}, armnn::GetDataType<float>());
7805
7806 boost::multi_array<float, 4> poolingInput = MakeTensor<float,4>(poolingInputTensorInfo,
7807 {1, 2, 3,
7808 4, 5, 6,
7809 7, 8, 9
7810 });
7811
7812 std::unique_ptr<armnn::ITensorHandle> poolingInputHandle =
7813 workloadFactory.CreateTensorHandle(poolingInputTensorInfo);
7814 std::unique_ptr<armnn::ITensorHandle> poolingOutputHandle =
7815 workloadFactory.CreateTensorHandle(poolingOutputTensorInfo);
7816
7817 // Apply MaxPool poolSize = 1x1, stride=2x2
7818 // Result =
7819 // 1, 3
7820 // 7, 9
7821 armnn::Pooling2dDescriptor descriptor;
7822 descriptor.m_PoolHeight = 1;
7823 descriptor.m_PoolWidth = 1;
7824 descriptor.m_StrideX = 2;
7825 descriptor.m_StrideY = 2;
7826 descriptor.m_PoolType = armnn::PoolingAlgorithm::Max;
7827
7828 armnn::Pooling2dQueueDescriptor queueDescriptor;
7829 queueDescriptor.m_Parameters = descriptor;
7830 armnn::WorkloadInfo workloadInfo;
7831 AddInputToWorkload(queueDescriptor, workloadInfo, poolingInputTensorInfo, poolingInputHandle.get());
7832 AddOutputToWorkload(queueDescriptor, workloadInfo, poolingOutputTensorInfo, poolingOutputHandle.get());
7833
7834 // Create the MaxPool
7835 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreatePooling2d(queueDescriptor, workloadInfo);
7836
7837 //LayerTestResult<float, 4> result(poolingOutputTensorInfo);
7838 auto shape( GetTensorShapeAsArray<4>(poolingOutputTensorInfo));
7839 boost::multi_array<float, 4> resultMaxPool;
7840 resultMaxPool.resize(shape);
7841
7842
7843 // Create addition with another tensor the same size
7844 // This would be the result to apply a Conv2d with kernel ones(2) and stride 1x1
7845 // with the initial tensor.
7846 // 12, 16
7847 // 24, 28
7848
7849 armnn::TensorInfo addInputTensorInfo({ 1,1,2,2}, armnn::GetDataType<float>());
7850 armnn::TensorInfo addOutputTensorInfo({ 1,1,2,2}, armnn::GetDataType<float>());
7851
7852 boost::multi_array<float, 4> addInput = MakeTensor<float,4>(addInputTensorInfo,
7853 {12, 16,
7854 24, 28,
7855 });
7856
7857 // Expected output tensor after MaxPool and Addition.
7858 LayerTestResult<float,4> addRet(addOutputTensorInfo);
7859 addRet.outputExpected = MakeTensor<float, 4>(addOutputTensorInfo, std::vector<float>(
7860 {
7861 13, 19,
7862 31, 37
7863 }));
7864
7865 std::unique_ptr<armnn::ITensorHandle> addInputHandle = workloadFactory.CreateTensorHandle(addInputTensorInfo);
7866 std::unique_ptr<armnn::ITensorHandle> addOutputHandle = workloadFactory.CreateTensorHandle(addOutputTensorInfo);
7867
7868 armnn::AdditionQueueDescriptor data;
7869 armnn::WorkloadInfo info;
7870
7871 // Add the output of the MaxPool and the new tensor
7872 AddInputToWorkload(data, info, poolingOutputTensorInfo, poolingOutputHandle.get());
7873 AddInputToWorkload(data, info, addInputTensorInfo, addInputHandle.get());
7874 AddOutputToWorkload(data, info, addOutputTensorInfo, addOutputHandle.get());
7875
7876 std::unique_ptr<armnn::IWorkload> addWorkload = workloadFactory.CreateAddition(data, info);
7877
7878 poolingInputHandle->Allocate();
7879 poolingOutputHandle->Allocate();
7880 addInputHandle->Allocate();
7881 addOutputHandle->Allocate();
7882
7883 CopyDataToITensorHandle(poolingInputHandle.get(), &poolingInput[0][0][0][0]);
7884 CopyDataFromITensorHandle(&resultMaxPool[0][0][0][0], poolingOutputHandle.get());
7885
7886 CopyDataToITensorHandle(poolingOutputHandle.get(), &resultMaxPool[0][0][0][0]);
7887 CopyDataToITensorHandle(addInputHandle.get(), &addInput[0][0][0][0]);
7888
7889 workload->Execute();
7890 addWorkload->Execute();
7891
7892 CopyDataFromITensorHandle(&addRet.output[0][0][0][0], addOutputHandle.get());
7893
Éanna Ó Catháin47c1ddb2018-10-12 14:24:13 +01007894 return addRet;
7895}
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007896
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007897LayerTestResult<float, 4> SpaceToBatchNdSimpleFloat32Test(
7898 armnn::IWorkloadFactory& workloadFactory,
7899 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007900{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007901 return SpaceToBatchNdSimpleTest<float>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007902}
7903
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007904LayerTestResult<float, 4> SpaceToBatchNdMultiChannelsFloat32Test(
7905 armnn::IWorkloadFactory& workloadFactory,
7906 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007907{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007908 return SpaceToBatchNdMultiChannelsTest<float>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007909}
7910
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007911LayerTestResult<float, 4> SpaceToBatchNdMultiBlockFloat32Test(
7912 armnn::IWorkloadFactory& workloadFactory,
7913 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007914{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007915 return SpaceToBatchNdMultiBlockTest<float>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007916}
7917
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007918LayerTestResult<float, 4> SpaceToBatchNdPaddingFloat32Test(
7919 armnn::IWorkloadFactory& workloadFactory,
7920 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007921{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007922 return SpaceToBatchNdPaddingTest<float>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007923}
7924
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007925LayerTestResult<uint8_t, 4> SpaceToBatchNdSimpleUint8Test(
7926 armnn::IWorkloadFactory& workloadFactory,
7927 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007928{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007929 return SpaceToBatchNdSimpleTest<uint8_t>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007930}
7931
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007932LayerTestResult<uint8_t, 4> SpaceToBatchNdMultiChannelsUint8Test(
7933 armnn::IWorkloadFactory& workloadFactory,
7934 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007935{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007936 return SpaceToBatchNdMultiChannelsTest<uint8_t>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007937}
7938
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007939LayerTestResult<uint8_t, 4> SpaceToBatchNdMultiBlockUint8Test(
7940 armnn::IWorkloadFactory& workloadFactory,
7941 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007942{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007943 return SpaceToBatchNdMultiBlockTest<uint8_t>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007944}
7945
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007946LayerTestResult<uint8_t, 4> SpaceToBatchNdPaddingUint8Test(
7947 armnn::IWorkloadFactory& workloadFactory,
7948 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007949{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007950 return SpaceToBatchNdPaddingTest<uint8_t>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007951}
7952
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007953LayerTestResult<float, 4> SpaceToBatchNdSimpleNHWCFloat32Test(
7954 armnn::IWorkloadFactory& workloadFactory,
7955 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007956{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007957 return SpaceToBatchNdSimpleNHWCTest<float>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007958}
7959
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007960LayerTestResult<float, 4> SpaceToBatchNdMultiChannelsNHWCFloat32Test(
7961 armnn::IWorkloadFactory& workloadFactory,
7962 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007963{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007964 return SpaceToBatchNdMultiChannelsNHWCTest<float>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007965}
7966
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007967LayerTestResult<float, 4> SpaceToBatchNdMultiBlockNHWCFloat32Test(
7968 armnn::IWorkloadFactory& workloadFactory,
7969 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007970{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007971 return SpaceToBatchNdMultiBlockNHWCTest<float>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007972}
7973
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007974LayerTestResult<float, 4> SpaceToBatchNdPaddingNHWCFloat32Test(
7975 armnn::IWorkloadFactory& workloadFactory,
7976 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007977{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007978 return SpaceToBatchNdPaddingNHWCTest<float>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007979}
7980
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007981LayerTestResult<uint8_t, 4> SpaceToBatchNdSimpleNHWCUint8Test(
7982 armnn::IWorkloadFactory& workloadFactory,
7983 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007984{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007985 return SpaceToBatchNdSimpleNHWCTest<uint8_t>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007986}
7987
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007988LayerTestResult<uint8_t, 4> SpaceToBatchNdMultiChannelsNHWCUint8Test(
7989 armnn::IWorkloadFactory& workloadFactory,
7990 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007991{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007992 return SpaceToBatchNdMultiChannelsNHWCTest<uint8_t>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007993}
7994
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007995LayerTestResult<uint8_t, 4> SpaceToBatchNdMultiBlockNHWCUint8Test(
7996 armnn::IWorkloadFactory& workloadFactory,
7997 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007998{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007999 return SpaceToBatchNdMultiBlockNHWCTest<uint8_t>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00008000}
8001
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00008002LayerTestResult<uint8_t, 4> SpaceToBatchNdPaddingNHWCUint8Test(
8003 armnn::IWorkloadFactory& workloadFactory,
8004 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00008005{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00008006 return SpaceToBatchNdPaddingNHWCTest<uint8_t>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00008007}
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00008008
8009namespace {
8010
8011template<typename T, std::size_t InputDim, std::size_t OutputDim>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00008012LayerTestResult<T, OutputDim> BatchToSpaceNdHelper(
8013 armnn::IWorkloadFactory &workloadFactory,
8014 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
8015 const armnn::DataLayout& dataLayout,
8016 const unsigned int *inputShape,
8017 const std::vector<T> &inputData,
8018 const std::vector<unsigned int> &blockShape,
8019 const std::vector<std::pair<unsigned int, unsigned int>> &crops,
8020 const unsigned int *outputShape,
8021 const std::vector<T> &outputData,
8022 float scale = 1.0f,
8023 int32_t offset = 0)
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00008024 {
8025 auto dataType = (std::is_same<T, uint8_t>::value ? armnn::DataType::QuantisedAsymm8 : armnn::DataType::Float32);
8026
8027 armnn::TensorInfo inputTensorInfo(InputDim, inputShape, dataType);
8028 armnn::TensorInfo outputTensorInfo(OutputDim, outputShape, dataType);
8029
8030 inputTensorInfo.SetQuantizationScale(scale);
8031 inputTensorInfo.SetQuantizationOffset(offset);
8032
8033 outputTensorInfo.SetQuantizationScale(scale);
8034 outputTensorInfo.SetQuantizationOffset(offset);
8035
8036 auto input = MakeTensor<T, InputDim>(inputTensorInfo, inputData);
8037
8038 LayerTestResult<T, OutputDim> result(outputTensorInfo);
8039 result.outputExpected = MakeTensor<T, OutputDim>(outputTensorInfo, outputData);
8040
8041 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
8042 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
8043
8044 armnn::BatchToSpaceNdQueueDescriptor data;
8045 data.m_Parameters.m_DataLayout = dataLayout;
8046 data.m_Parameters.m_BlockShape = blockShape;
8047 data.m_Parameters.m_Crops = crops;
8048 armnn::WorkloadInfo info;
8049 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
8050 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
8051
8052 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateBatchToSpaceNd(data, info);
8053
8054 inputHandle->Allocate();
8055 outputHandle->Allocate();
8056
8057 CopyDataToITensorHandle(inputHandle.get(), input.origin());
8058
8059 workload->Execute();
8060
8061 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
8062
8063 return result;
8064}
8065
8066} // anonymous namespace
8067
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00008068LayerTestResult<float, 4> BatchToSpaceNdNhwcFloat32Test1(
8069 armnn::IWorkloadFactory& workloadFactory,
8070 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00008071{
8072 const unsigned int inputShape[] = {4, 2, 2, 1};
8073 const unsigned int outputShape[] = {1, 4, 4, 1 };
8074
8075 std::vector<float> input
8076 ({
8077 // Batch 0, Height 0, Width (2) x Channel (1)
8078 1.0f, 3.0f,
8079 // Batch 0, Height 1, Width (2) x Channel (1)
8080 9.0f, 11.0f,
8081
8082
8083 // Batch 1, Height 0, Width (2) x Channel (1)
8084 2.0f, 4.0f,
8085 // Batch 1, Height 1, Width (2) x Channel (1)
8086 10.0f, 12.0f,
8087
8088
8089 // Batch 2, Height 0, Width (2) x Channel (1)
8090 5.0f, 7.0f,
8091 // Batch 2, Height 1, Width (2) x Channel (1)
8092 13.0f, 15.0f,
8093
8094 // Batch 3, Height 0, Width (2) x Channel (3)
8095 6.0f, 8.0f,
8096 // Batch 3, Height 1, Width (2) x Channel (1)
8097 14.0f, 16.0f
8098 });
8099
8100 std::vector<float> expectedOutput
8101 ({
8102 1.0f, 2.0f, 3.0f, 4.0f,
8103 5.0f, 6.0f, 7.0f, 8.0f,
8104 9.0f, 10.0f, 11.0f, 12.0f,
8105 13.0f, 14.0f, 15.0f, 16.0f
8106 });
8107
8108 std::vector<unsigned int> blockShape {2, 2};
Éanna Ó Catháin95807ce2018-11-12 17:14:43 +00008109 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00008110
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00008111 return BatchToSpaceNdHelper<float, 4, 4>(workloadFactory, memoryManager,
8112 armnn::DataLayout::NHWC, inputShape, input, blockShape,
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00008113 crops, outputShape, expectedOutput);
8114}
8115
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00008116LayerTestResult<float, 4> BatchToSpaceNdNhwcFloat32Test2(
8117 armnn::IWorkloadFactory& workloadFactory,
8118 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00008119{
8120 const unsigned int inputShape[] = {4, 1, 1, 1};
8121 const unsigned int outputShape[] = {1, 2, 2, 1};
8122
8123 std::vector<float> input
8124 ({
8125 // Batch 0, Height 0, Width (2) x Channel (1)
8126 1.0f, 2.0f, 3.0f, 4.0f
8127 });
8128
8129 std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f});
8130
8131 std::vector<unsigned int> blockShape({2, 2});
Éanna Ó Catháin95807ce2018-11-12 17:14:43 +00008132 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00008133
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00008134 return BatchToSpaceNdHelper<float, 4, 4>(workloadFactory, memoryManager,
8135 armnn::DataLayout::NHWC, inputShape, input, blockShape,
8136 crops, outputShape, expectedOutput);
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00008137}
8138
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00008139LayerTestResult<float, 4> BatchToSpaceNdNhwcFloat32Test3(
8140 armnn::IWorkloadFactory& workloadFactory,
8141 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00008142{
8143 const unsigned int inputShape[] = {4, 1, 1, 3};
8144 const unsigned int outputShape[] = {1, 2, 2, 3};
8145
8146 std::vector<float> input({ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f });
8147
8148 std::vector<float> expectedOutput({ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f });
8149
8150 std::vector<unsigned int> blockShape({2, 2});
Éanna Ó Catháin95807ce2018-11-12 17:14:43 +00008151 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00008152
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00008153 return BatchToSpaceNdHelper<float, 4, 4>(workloadFactory, memoryManager,
8154 armnn::DataLayout::NHWC, inputShape, input, blockShape,
8155 crops, outputShape, expectedOutput);
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00008156}
8157
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00008158LayerTestResult<float, 4> BatchToSpaceNdNchwFloat32Test1(
8159 armnn::IWorkloadFactory &workloadFactory,
8160 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00008161{
8162 const unsigned int inputShape[] = {4, 3, 1, 1};
8163 const unsigned int outputShape[] = {1, 3, 2, 2};
8164
8165 std::vector<float> input({ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f });
8166
8167 std::vector<float> expectedOutput
8168 ({
8169 // Batch 0, Channel 0, Height (2) x Width (2)
8170 1.0f, 4.0f,
8171 7.0f, 10.0f,
8172
8173 // Batch 0, Channel 1, Height (2) x Width (2)
8174 2.0f, 5.0f,
8175 8.0f, 11.0f,
8176
8177 // Batch 0, Channel 2, Height (2) x Width (2)
8178 3.0f, 6.0f,
8179 9.0f, 12.0f,
8180 });
8181
8182 std::vector<unsigned int> blockShape({2, 2});
Éanna Ó Catháin95807ce2018-11-12 17:14:43 +00008183 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00008184
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00008185 return BatchToSpaceNdHelper<float, 4, 4>(workloadFactory, memoryManager,
8186 armnn::DataLayout::NCHW, inputShape, input, blockShape,
8187 crops, outputShape, expectedOutput);
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00008188}
Éanna Ó Catháin262553e2018-11-14 11:26:23 +00008189
Mike Kelly831faed2018-11-28 11:52:08 +00008190LayerTestResult<float, 4> BatchToSpaceNdNchwFloat32Test2(
8191 armnn::IWorkloadFactory& workloadFactory,
8192 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8193{
8194 const unsigned int inputShape[] = {4, 1, 1, 1};
8195 const unsigned int outputShape[] = {1, 1, 2, 2};
8196
8197 std::vector<float> input
8198 ({
8199 // Batch 0, Height 0, Width (2) x Channel (1)
8200 1.0f, 2.0f, 3.0f, 4.0f
8201 });
8202
8203 std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f});
8204
8205 std::vector<unsigned int> blockShape({2, 2});
8206 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
8207
8208 return BatchToSpaceNdHelper<float, 4, 4>(workloadFactory, memoryManager,
8209 armnn::DataLayout::NCHW, inputShape, input, blockShape,
8210 crops, outputShape, expectedOutput);
8211}
8212
8213LayerTestResult<float, 4> BatchToSpaceNdNchwFloat32Test3(
8214 armnn::IWorkloadFactory& workloadFactory,
8215 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8216{
8217 const unsigned int inputShape[] = {4, 3, 1, 1};
8218 const unsigned int outputShape[] = {1, 3, 2, 2};
8219
8220 std::vector<float> input({ 1.0f, 3.0f, 5.0f, 7.0f, 9.0f, 11.0f, 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f });
8221
8222 std::vector<float> expectedOutput
8223 ({
8224 // Batch 0, Channel 0, Height (2) x Width (2)
8225 1.0f, 7.0f,
8226 2.0f, 8.0f,
8227
8228 // Batch 0, Channel 1, Height (2) x Width (2)
8229 3.0f, 9.0f,
8230 4.0f, 10.0f,
8231
8232 // Batch 0, Channel 2, Height (2) x Width (2)
8233 5.0f, 11.0f,
8234 6.0f, 12.0f,
8235 });
8236
8237 std::vector<unsigned int> blockShape({2, 2});
8238 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
8239
8240 return BatchToSpaceNdHelper<float, 4, 4>(workloadFactory, memoryManager,
8241 armnn::DataLayout::NCHW, inputShape, input, blockShape,
8242 crops, outputShape, expectedOutput);
8243}
Éanna Ó Catháin262553e2018-11-14 11:26:23 +00008244
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00008245LayerTestResult<uint8_t, 4> BatchToSpaceNdNhwcUintTest1(
8246 armnn::IWorkloadFactory& workloadFactory,
8247 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Éanna Ó Catháin262553e2018-11-14 11:26:23 +00008248{
8249 const unsigned int inputShape[] = {4, 2, 2, 1};
8250 const unsigned int outputShape[] = {1, 4, 4, 1};
8251
8252 std::vector<uint8_t> input({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 });
8253 std::vector<uint8_t> expectedOutput({ 1, 5, 2, 6, 9, 13, 10, 14, 3, 7, 4, 8, 11, 15, 12, 16});
8254
8255 std::vector<unsigned int> blockShape({2, 2});
8256 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
8257
Matteo Martincigha65b7ae2018-11-14 12:39:55 +00008258 return BatchToSpaceNdHelper<uint8_t, 4, 4>(workloadFactory, memoryManager, armnn::DataLayout::NHWC, inputShape,
8259 input, blockShape, crops, outputShape, expectedOutput);
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00008260}
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00008261
8262LayerTestResult<float, 4> StridedSlice4DFloat32Test(
8263 armnn::IWorkloadFactory& workloadFactory,
8264 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8265{
8266 return StridedSlice4DTest<float>(workloadFactory, memoryManager);
8267}
8268
8269LayerTestResult<float, 4> StridedSlice4DReverseFloat32Test(
8270 armnn::IWorkloadFactory& workloadFactory,
8271 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8272{
8273 return StridedSlice4DReverseTest<float>(workloadFactory, memoryManager);
8274}
8275
8276LayerTestResult<float, 4> StridedSliceSimpleStrideFloat32Test(
8277 armnn::IWorkloadFactory& workloadFactory,
8278 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8279{
8280 return StridedSliceSimpleStrideTest<float>(workloadFactory, memoryManager);
8281}
8282
8283LayerTestResult<float, 4> StridedSliceSimpleRangeMaskFloat32Test(
8284 armnn::IWorkloadFactory& workloadFactory,
8285 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8286{
8287 return StridedSliceSimpleRangeMaskTest<float>(workloadFactory, memoryManager);
8288}
8289
8290LayerTestResult<float, 2> StridedSliceShrinkAxisMaskFloat32Test(
8291 armnn::IWorkloadFactory& workloadFactory,
8292 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8293{
8294 return StridedSliceShrinkAxisMaskTest<float>(workloadFactory, memoryManager);
8295}
8296
8297LayerTestResult<float, 3> StridedSlice3DFloat32Test(
8298 armnn::IWorkloadFactory& workloadFactory,
8299 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8300{
8301 return StridedSlice3DTest<float>(workloadFactory, memoryManager);
8302}
8303
8304LayerTestResult<float, 3> StridedSlice3DReverseFloat32Test(
8305 armnn::IWorkloadFactory& workloadFactory,
8306 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8307{
8308 return StridedSlice3DReverseTest<float>(workloadFactory, memoryManager);
8309}
8310
8311LayerTestResult<float, 2> StridedSlice2DFloat32Test(
8312 armnn::IWorkloadFactory& workloadFactory,
8313 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8314{
8315 return StridedSlice2DTest<float>(workloadFactory, memoryManager);
8316}
8317
8318LayerTestResult<float, 2> StridedSlice2DReverseFloat32Test(
8319 armnn::IWorkloadFactory& workloadFactory,
8320 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8321{
8322 return StridedSlice2DReverseTest<float>(workloadFactory, memoryManager);
8323}
8324
8325LayerTestResult<uint8_t, 4> StridedSlice4DUint8Test(
8326 armnn::IWorkloadFactory& workloadFactory,
8327 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8328{
8329 return StridedSlice4DTest<uint8_t>(workloadFactory, memoryManager);
8330}
8331
8332LayerTestResult<uint8_t, 4> StridedSlice4DReverseUint8Test(
8333 armnn::IWorkloadFactory& workloadFactory,
8334 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8335{
8336 return StridedSlice4DReverseTest<uint8_t>(workloadFactory, memoryManager);
8337}
8338
8339LayerTestResult<uint8_t, 4> StridedSliceSimpleStrideUint8Test(
8340 armnn::IWorkloadFactory& workloadFactory,
8341 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8342{
8343 return StridedSliceSimpleStrideTest<uint8_t>(workloadFactory, memoryManager);
8344}
8345
8346LayerTestResult<uint8_t, 4> StridedSliceSimpleRangeMaskUint8Test(
8347 armnn::IWorkloadFactory& workloadFactory,
8348 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8349{
8350 return StridedSliceSimpleRangeMaskTest<uint8_t>(workloadFactory, memoryManager);
8351}
8352
8353LayerTestResult<uint8_t, 2> StridedSliceShrinkAxisMaskUint8Test(
8354 armnn::IWorkloadFactory& workloadFactory,
8355 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8356{
8357 return StridedSliceShrinkAxisMaskTest<uint8_t>(workloadFactory, memoryManager);
8358}
8359
8360LayerTestResult<uint8_t, 3> StridedSlice3DUint8Test(
8361 armnn::IWorkloadFactory& workloadFactory,
8362 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8363{
8364 return StridedSlice3DTest<uint8_t>(workloadFactory, memoryManager);
8365}
8366
8367LayerTestResult<uint8_t, 3> StridedSlice3DReverseUint8Test(
8368 armnn::IWorkloadFactory& workloadFactory,
8369 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8370{
8371 return StridedSlice3DReverseTest<uint8_t>(workloadFactory, memoryManager);
8372}
8373
8374LayerTestResult<uint8_t, 2> StridedSlice2DUint8Test(
8375 armnn::IWorkloadFactory& workloadFactory,
8376 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8377{
8378 return StridedSlice2DTest<uint8_t>(workloadFactory, memoryManager);
8379}
8380
8381LayerTestResult<uint8_t, 2> StridedSlice2DReverseUint8Test(
8382 armnn::IWorkloadFactory& workloadFactory,
8383 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8384{
8385 return StridedSlice2DReverseTest<uint8_t>(workloadFactory, memoryManager);
8386}
Mike Kelly831faed2018-11-28 11:52:08 +00008387LayerTestResult<uint8_t, 4> BatchToSpaceNdNhwcUintTest2(
8388 armnn::IWorkloadFactory& workloadFactory,
8389 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8390{
8391 const unsigned int inputShape[] = {4, 1, 1, 1};
8392 const unsigned int outputShape[] = {1, 2, 2, 1};
8393
8394 std::vector<uint8_t> input
8395 ({
8396 // Batch 0, Height 0, Width (2) x Channel (1)
8397 1, 2, 3, 4
8398 });
8399
8400 std::vector<uint8_t> expectedOutput({1, 2, 3, 4});
8401
8402 std::vector<unsigned int> blockShape({2, 2});
8403 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
8404
8405 return BatchToSpaceNdHelper<uint8_t, 4, 4>(workloadFactory, memoryManager,
8406 armnn::DataLayout::NHWC, inputShape, input, blockShape,
8407 crops, outputShape, expectedOutput);
8408}
8409
8410LayerTestResult<uint8_t, 4> BatchToSpaceNdNhwcUintTest3(
8411 armnn::IWorkloadFactory& workloadFactory,
8412 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8413{
8414 const unsigned int inputShape[] = {4, 1, 1, 3};
8415 const unsigned int outputShape[] = {1, 2, 2, 3};
8416
8417 std::vector<uint8_t> input({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
8418
8419 std::vector<uint8_t> expectedOutput({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
8420
8421 std::vector<unsigned int> blockShape({2, 2});
8422 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
8423
8424 return BatchToSpaceNdHelper<uint8_t, 4, 4>(workloadFactory, memoryManager,
8425 armnn::DataLayout::NHWC, inputShape, input, blockShape,
8426 crops, outputShape, expectedOutput);
8427}
8428
8429
8430LayerTestResult<uint8_t, 4> BatchToSpaceNdNchwUintTest1(
8431 armnn::IWorkloadFactory &workloadFactory,
8432 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8433{
8434 const unsigned int inputShape[] = {4, 3, 1, 1};
8435 const unsigned int outputShape[] = {1, 3, 2, 2};
8436
8437 std::vector<uint8_t> input({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
8438
8439 std::vector<uint8_t> expectedOutput
8440 ({
8441 // Batch 0, Channel 0, Height (2) x Width (2)
8442 1, 4,
8443 7, 10,
8444
8445 // Batch 0, Channel 1, Height (2) x Width (2)
8446 2, 5,
8447 8, 11,
8448
8449 // Batch 0, Channel 2, Height (2) x Width (2)
8450 3, 6,
8451 9, 12,
8452 });
8453
8454 std::vector<unsigned int> blockShape({2, 2});
8455 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
8456
8457 return BatchToSpaceNdHelper<uint8_t, 4, 4>(workloadFactory, memoryManager,
8458 armnn::DataLayout::NCHW, inputShape, input, blockShape,
8459 crops, outputShape, expectedOutput);
8460}
8461
8462LayerTestResult<uint8_t, 4> BatchToSpaceNdNchwUintTest2(
8463 armnn::IWorkloadFactory& workloadFactory,
8464 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8465{
8466 const unsigned int inputShape[] = {4, 1, 1, 1};
8467 const unsigned int outputShape[] = {1, 1, 2, 2};
8468
8469 std::vector<uint8_t> input
8470 ({
8471 // Batch 0, Height 0, Width (2) x Channel (1)
8472 1, 2, 3, 4
8473 });
8474
8475 std::vector<uint8_t> expectedOutput({1, 2, 3, 4});
8476
8477 std::vector<unsigned int> blockShape({2, 2});
8478 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
8479
8480 return BatchToSpaceNdHelper<uint8_t, 4, 4>(workloadFactory, memoryManager,
8481 armnn::DataLayout::NCHW, inputShape, input, blockShape,
8482 crops, outputShape, expectedOutput);
8483}
8484
8485LayerTestResult<uint8_t, 4> BatchToSpaceNdNchwUintTest3(
8486 armnn::IWorkloadFactory& workloadFactory,
8487 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8488{
8489 const unsigned int inputShape[] = {4, 3, 1, 1};
8490 const unsigned int outputShape[] = {1, 3, 2, 2};
8491
8492 std::vector<uint8_t> input({ 1, 3, 5, 7, 9, 11, 2, 4, 6, 8, 10, 12 });
8493
8494 std::vector<uint8_t> expectedOutput
8495 ({
8496 // Batch 0, Channel 0, Height (2) x Width (2)
8497 1, 7,
8498 2, 8,
8499
8500 // Batch 0, Channel 1, Height (2) x Width (2)
8501 3, 9,
8502 4, 10,
8503
8504 // Batch 0, Channel 2, Height (2) x Width (2)
8505 5, 11,
8506 6, 12,
8507 });
8508 std::vector<unsigned int> blockShape({2, 2});
8509 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
8510
8511 return BatchToSpaceNdHelper<uint8_t, 4, 4>(workloadFactory, memoryManager,
8512 armnn::DataLayout::NCHW, inputShape, input, blockShape,
8513 crops, outputShape, expectedOutput);
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +00008514}
8515
8516LayerTestResult<float, 4> Debug4DFloat32Test(
8517 armnn::IWorkloadFactory& workloadFactory,
8518 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8519{
8520 return Debug4DTest<float>(workloadFactory, memoryManager);
8521}
8522
8523LayerTestResult<float, 3> Debug3DFloat32Test(
8524 armnn::IWorkloadFactory& workloadFactory,
8525 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8526{
8527 return Debug3DTest<float>(workloadFactory, memoryManager);
8528}
8529
8530LayerTestResult<float, 2> Debug2DFloat32Test(
8531 armnn::IWorkloadFactory& workloadFactory,
8532 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8533{
8534 return Debug2DTest<float>(workloadFactory, memoryManager);
8535}
8536
8537LayerTestResult<float, 1> Debug1DFloat32Test(
8538 armnn::IWorkloadFactory& workloadFactory,
8539 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8540{
8541 return Debug1DTest<float>(workloadFactory, memoryManager);
8542}
8543
8544LayerTestResult<uint8_t, 4> Debug4DUint8Test(
8545 armnn::IWorkloadFactory& workloadFactory,
8546 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8547{
8548 return Debug4DTest<uint8_t>(workloadFactory, memoryManager);
8549}
8550
8551LayerTestResult<uint8_t, 3> Debug3DUint8Test(
8552 armnn::IWorkloadFactory& workloadFactory,
8553 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8554{
8555 return Debug3DTest<uint8_t>(workloadFactory, memoryManager);
8556}
8557
8558LayerTestResult<uint8_t, 2> Debug2DUint8Test(
8559 armnn::IWorkloadFactory& workloadFactory,
8560 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8561{
8562 return Debug2DTest<uint8_t>(workloadFactory, memoryManager);
8563}
8564
8565LayerTestResult<uint8_t, 1> Debug1DUint8Test(
8566 armnn::IWorkloadFactory& workloadFactory,
8567 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8568{
8569 return Debug1DTest<uint8_t>(workloadFactory, memoryManager);
8570}
Matteo Martincigh49124022019-01-11 13:25:59 +00008571
8572LayerTestResult<uint8_t, 4> PreCompiledConvolution2dTest(
8573 armnn::IWorkloadFactory& workloadFactory,
8574 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8575{
8576 return PreCompiledConvolution2dTestImpl(workloadFactory, memoryManager);
8577}
8578
8579LayerTestResult<uint8_t, 4> PreCompiledConvolution2dStride2x2Test(
8580 armnn::IWorkloadFactory& workloadFactory,
8581 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8582{
8583 return PreCompiledConvolution2dStride2x2TestImpl(workloadFactory, memoryManager);
8584}
8585
8586LayerTestResult<uint8_t, 4> PreCompiledDepthwiseConvolution2dTest(
8587 armnn::IWorkloadFactory & workloadFactory,
8588 const armnn::IBackendInternal::IMemoryManagerSharedPtr & memoryManager)
8589{
8590 return PreCompiledDepthwiseConvolution2dTestImpl(workloadFactory, memoryManager);
8591}
8592
8593LayerTestResult<uint8_t, 4> PreCompiledDepthwiseConvolution2dStride2x2Test(
8594 armnn::IWorkloadFactory & workloadFactory,
8595 const armnn::IBackendInternal::IMemoryManagerSharedPtr & memoryManager)
8596{
8597 return PreCompiledDepthwiseConvolution2dStride2x2TestImpl(workloadFactory, memoryManager);
8598}
8599
8600LayerTestResult<uint8_t, 4> PreCompiledMaxPooling2dTest(
8601 armnn::IWorkloadFactory& workloadFactory,
8602 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
8603{
8604 return PreCompiledMaxPooling2dTestImpl(workloadFactory, memoryManager);
8605}