blob: 131b84c859a3ee3208aedf1f64807f0d707a9858 [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"
telsoa01c577f2c2018-08-31 09:22:23 +010040#include "LstmTestImpl.hpp"
41#include "ConvertFp16ToFp32TestImpl.hpp"
42#include "ConvertFp32ToFp16TestImpl.hpp"
telsoa014fcda012018-03-09 14:13:49 +000043
telsoa01c577f2c2018-08-31 09:22:23 +010044// 3-channel 16x8 image used as common input data for a number of Conv2d tests.
telsoa014fcda012018-03-09 14:13:49 +000045static std::vector<float> ConvInput3x8x16({
46 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,
47 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,
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.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,
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, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
55 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
63 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
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});
71
telsoa01c577f2c2018-08-31 09:22:23 +010072// 2-channel bias used by a number of Conv2d tests.
telsoa014fcda012018-03-09 14:13:49 +000073static std::vector<float> Bias2({0, 2});
74
telsoa01c577f2c2018-08-31 09:22:23 +010075// Helper function that returns either Bias2 or an empty vector depending on whether bias is enabled.
telsoa014fcda012018-03-09 14:13:49 +000076template<typename T>
77boost::multi_array<T, 1> GetBias2(bool biasEnabled, float qScale, int32_t qOffset)
78{
79 if(biasEnabled)
80 {
81 armnn::TensorInfo biasDesc({static_cast<unsigned int>(Bias2.size())}, armnn::GetDataType<T>());
82 boost::multi_array<T, 1> bias = MakeTensor<T, 1>(biasDesc, QuantizedVector<T>(qScale, qOffset, Bias2));
83 return bias;
84 }
85 else
86 {
87 return boost::multi_array<T, 1>();
88 }
89}
90
91template<typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +000092LayerTestResult<T, 4> SimpleConvolution2d3x5TestCommon(
93 armnn::IWorkloadFactory& workloadFactory,
94 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
95 float qScale,
96 int32_t qOffset,
97 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +000098 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +000099{
telsoa01c577f2c2018-08-31 09:22:23 +0100100 // Use common single-batch 3-channel 16x8 image.
telsoa014fcda012018-03-09 14:13:49 +0000101 armnn::TensorInfo inputDesc({1, 3, 8, 16}, armnn::GetDataType<T>());
102 boost::multi_array<T, 4> input = MakeTensor<T, 4>(inputDesc, QuantizedVector<T>(qScale, qOffset, ConvInput3x8x16));
103
telsoa01c577f2c2018-08-31 09:22:23 +0100104 // Use a 2-element batch with 3-channel 3x5 kernels.
telsoa014fcda012018-03-09 14:13:49 +0000105 armnn::TensorInfo kernelDesc({2, 3, 5, 3}, armnn::GetDataType<T>());
106 boost::multi_array<T, 4> kernel = MakeTensor<T, 4>(kernelDesc, std::vector<T>(
107 QuantizedVector<T>(qScale, qOffset, {
108 1, 1, 1,
109 1, -1, 1,
110 1, 1, 1,
111 1, 1, 1,
112 1, 1, 1,
113
114 0, 0, 0,
115 0, 0, 0,
116 0, 0, 0,
117 0, 0, 0,
118 0, 0, 0,
119
120 2, 2, 2,
121 2, 2, 2,
122 2, 2, 2,
123 2, 2, 2,
124 2, 2, 2,
125
126
127 0, 0, 0,
128 0, 0, 0,
129 0, 0, 0,
130 0, 0, 0,
131 0, 0, 0,
132
133 1, 1, 1,
134 1, 1, 1,
135 1, 1, 1,
136 1, 1, 1,
137 1, 1, 1,
138
139 0, 0, 0,
140 0, 0, 0,
141 0, 0, 0,
142 0, 0, 0,
143 0, 0, 0
144 })));
145
telsoa01c577f2c2018-08-31 09:22:23 +0100146 // Expected output is 2 batch elements of a 1-channel 14x4 image.
telsoa014fcda012018-03-09 14:13:49 +0000147 armnn::TensorInfo outputDesc({1, 2, 4, 14}, armnn::GetDataType<T>());
148 boost::multi_array<T, 4> expectedOutput = MakeTensor<T, 4>(outputDesc, std::vector<T>(
149 QuantizedVector<T>(qScale, qOffset, {
150 -24, -24, -24, -24, -24, -24, -24, -24, -24, -24, -24, -24, -24, -24,
151 -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, -25,
152 -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f, -23.5f,
153 -23.5f, -23.5f, -23.5f,
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
157 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
158 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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 })));
162
163 return SimpleConvolution2dTestImpl<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000164 memoryManager,
telsoa014fcda012018-03-09 14:13:49 +0000165 input,
166 kernel,
167 GetBias2<typename FullyConnectedBiasTypeForInputType<T>::Type>(biasEnabled, qScale, qOffset),
168 expectedOutput,
169 qScale,
jimfly010a088a62018-10-25 17:05:05 +0100170 qOffset,
171 layout);
telsoa014fcda012018-03-09 14:13:49 +0000172}
173
174template<typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000175LayerTestResult<T, 4> SimpleConvolution2d3x3TestCommon(
176 armnn::IWorkloadFactory& workloadFactory,
177 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
178 float qScale,
179 int32_t qOffset,
180 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000181 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000182{
telsoa01c577f2c2018-08-31 09:22:23 +0100183 // Use a 3x3 kernel, which exercises ArmCompute's direct convolution path.
telsoa014fcda012018-03-09 14:13:49 +0000184
telsoa01c577f2c2018-08-31 09:22:23 +0100185 // Use common single-batch 3-channel 16x8 image.
telsoa014fcda012018-03-09 14:13:49 +0000186 armnn::TensorInfo inputDesc({1, 3, 8, 16}, armnn::GetDataType<T>());
187 boost::multi_array<T, 4> input = MakeTensor<T, 4>(inputDesc, QuantizedVector<T>(qScale, qOffset, ConvInput3x8x16));
188
telsoa01c577f2c2018-08-31 09:22:23 +0100189 // Use a 2-element batch of 3-channel 3x3 kernels.
telsoa014fcda012018-03-09 14:13:49 +0000190 armnn::TensorInfo kernelDesc({2, 3, 3, 3}, armnn::GetDataType<T>());
191 boost::multi_array<T, 4> kernel = MakeTensor<T, 4>(kernelDesc, std::vector<T>(
192 QuantizedVector<T>(qScale, qOffset, {
193 1, 1, 1,
194 1, -1, 1,
195 1, 1, 1,
196
197 0, 0, 0,
198 0, 0, 0,
199 0, 0, 0,
200
201 2, 2, 2,
202 2, 2, 2,
203 2, 2, 2,
204
205
206 0, 0, 0,
207 0, 0, 0,
208 0, 0, 0,
209
210 1, 1, 1,
211 1, 1, 1,
212 1, 1, 1,
213
214 0, 0, 0,
215 0, 0, 0,
216 0, 0, 0
217 })));
218
telsoa01c577f2c2018-08-31 09:22:23 +0100219 // Expected output is 1 batch of a 2-channel 14x6 image.
telsoa014fcda012018-03-09 14:13:49 +0000220 armnn::TensorInfo outputDesc({1, 2, 6, 14}, armnn::GetDataType<T>());
221 boost::multi_array<T, 4> expectedOutput = MakeTensor<T, 4>(outputDesc, std::vector<T>(
222 QuantizedVector<T>(qScale, qOffset, {
223 -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15,
224 -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
225 -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,
226 -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,
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
230 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
231 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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 })));
237
238 return SimpleConvolution2dTestImpl<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000239 memoryManager,
telsoa014fcda012018-03-09 14:13:49 +0000240 input,
241 kernel,
242 GetBias2<typename FullyConnectedBiasTypeForInputType<T>::Type>(biasEnabled, qScale, qOffset),
243 expectedOutput,
244 qScale,
narpra015f703182018-10-26 16:24:58 +0100245 qOffset,
246 layout);
telsoa014fcda012018-03-09 14:13:49 +0000247}
248
Francis Murtaghd59116e2018-10-04 16:03:07 +0100249template<typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000250LayerTestResult<T, 4> SimpleConvolution2d3x3NhwcTestCommon(
251 armnn::IWorkloadFactory& workloadFactory,
252 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
253 float qScale,
254 int32_t qOffset,
255 bool biasEnabled,
256 armnn::DataLayout dataLayout)
Francis Murtaghd59116e2018-10-04 16:03:07 +0100257{
258 // Use common single-batch 5x5 image.
259
260 armnn::TensorInfo inputDesc({1, 3, 4, 1}, armnn::GetDataType<T>());
261 boost::multi_array<T, 4> input = MakeTensor<T, 4>(inputDesc,
262 {
263 1, 5, 2, 3,
264 8, 7, 3, 6,
265 3, 3, 9, 1
266 });
267
268
269 // Use a 2-element batch of 3-channel 3x3 kernels.
270 armnn::TensorInfo kernelDesc({1, 3, 3, 1}, armnn::GetDataType<T>());
271 boost::multi_array<T, 4> kernel = MakeTensor<T, 4>(kernelDesc, {
272 4, 5, 6,
273 0, 0, 0,
274 3, 2, 1
275 });
276
277 // Expected output is 1 batch of a 5x5 image.
278 armnn::TensorInfo outputDesc({1, 3, 4, 1}, armnn::GetDataType<T>());
279
280 const std::vector<float> outputData =
281 {
282 23, 41, 33, 21,
283 44, 65, 76, 52,
284 82, 85, 79, 42
285 };
286
287 boost::multi_array<T, 4> expectedOutput = MakeTensor<T, 4>(outputDesc, outputData);
288
289 return SimpleConvolution2dNhwcTestImpl<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000290 memoryManager,
Francis Murtaghd59116e2018-10-04 16:03:07 +0100291 input,
292 kernel,
293 boost::multi_array<T, 1>(),
294 expectedOutput,
295 dataLayout,
296 qScale,
297 qOffset);
298}
299
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000300LayerTestResult<float, 4> SimpleConvolution2d3x5Test(
301 armnn::IWorkloadFactory& workloadFactory,
302 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
303 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000304 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000305{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000306 return SimpleConvolution2d3x5TestCommon<float>(workloadFactory, memoryManager, 0.f, 0, biasEnabled, layout);
telsoa014fcda012018-03-09 14:13:49 +0000307}
308
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000309LayerTestResult<uint8_t, 4> SimpleConvolution2d3x5Uint8Test(
310 armnn::IWorkloadFactory& workloadFactory,
311 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
312 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000313 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000314{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000315 return SimpleConvolution2d3x5TestCommon<uint8_t>(workloadFactory, memoryManager, 0.5f, 50, biasEnabled, layout);
telsoa014fcda012018-03-09 14:13:49 +0000316}
317
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000318LayerTestResult<float, 4> SimpleConvolution2d3x3Test(
319 armnn::IWorkloadFactory& workloadFactory,
320 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
321 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000322 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000323{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000324 return SimpleConvolution2d3x3TestCommon<float>(workloadFactory, memoryManager, 0.f, 0, biasEnabled, layout);
telsoa014fcda012018-03-09 14:13:49 +0000325}
326
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000327LayerTestResult<float, 4> SimpleConvolution2d3x3NhwcTest(
328 armnn::IWorkloadFactory& workloadFactory,
329 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
330 bool biasEnabled)
Francis Murtaghd59116e2018-10-04 16:03:07 +0100331{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000332 return SimpleConvolution2d3x3NhwcTestCommon<float>(workloadFactory,
333 memoryManager,
334 0.f,
335 0,
336 biasEnabled,
337 armnn::DataLayout::NHWC);
Francis Murtaghd59116e2018-10-04 16:03:07 +0100338}
339
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000340LayerTestResult<uint8_t, 4> SimpleConvolution2d3x3Uint8Test(
341 armnn::IWorkloadFactory& workloadFactory,
342 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
343 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000344 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000345{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000346 return SimpleConvolution2d3x3TestCommon<uint8_t>(workloadFactory, memoryManager, 0.5f, 50, biasEnabled, layout);
telsoa014fcda012018-03-09 14:13:49 +0000347}
348
349template<typename T>
350LayerTestResult<T, 4> Convolution2dAsymmetricPaddingLargerThanHalfKernelSizeTestCommon(
351 armnn::IWorkloadFactory& workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000352 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +0000353 const armnn::DataLayout layout,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000354 float qScale,
355 int32_t qOffset)
telsoa014fcda012018-03-09 14:13:49 +0000356{
telsoa01c577f2c2018-08-31 09:22:23 +0100357 // Use a single-batch 1-channel 3x3 image as input.
telsoa014fcda012018-03-09 14:13:49 +0000358 armnn::TensorInfo inputDesc({1, 1, 3, 3}, armnn::GetDataType<T>());
359 boost::multi_array<T, 4> input = MakeTensor<T, 4>(inputDesc, std::vector<T>(
360 QuantizedVector<T>(qScale, qOffset, {
361 11,21,31,
362 12,22,32,
363 13,23,33
364 })));
365
telsoa01c577f2c2018-08-31 09:22:23 +0100366 // Use 1 batch of a 1-channel 2x2 kernel.
telsoa014fcda012018-03-09 14:13:49 +0000367 armnn::TensorInfo kernelDesc({1, 1, 2, 2}, armnn::GetDataType<T>());
368 boost::multi_array<T, 4> kernel = MakeTensor<T, 4>(kernelDesc, std::vector<T>(
369 QuantizedVector<T>(qScale, qOffset, {
370 -11,-21,
371 -12,-22,
372 })));
373
telsoa01c577f2c2018-08-31 09:22:23 +0100374// Expected output is 1 batch of a 1-channel 6x8 image.
telsoa014fcda012018-03-09 14:13:49 +0000375// Manually calculated like this:
376//[-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 ..]
377//[-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 ..]
378//[-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 ..]
379//[-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 ..]
380//[-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 ..]
381//[-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 ..]
382//[..... ..... ..... ..... ; ..... ..... ..... ..... ; ..... ..... ..... ..... ; ..... ..... ..... ..... ..]
383 armnn::TensorInfo outputDesc({1, 1, 8, 6}, armnn::GetDataType<T>());
384 boost::multi_array<T, 4> expectedOutput = MakeTensor<T, 4>(outputDesc, std::vector<T>(
385 QuantizedVector<T>(qScale, qOffset, {
386 0, 0, 0, 0, 0, 0,
387 -242, -594, -934, -372, 0, 0,
388 -495, -1190, -1850, -725, 0, 0,
389 -538, -1256, -1916, -748, 0, 0,
390 -273, -626, -946, -363, 0, 0,
391 0, 0, 0, 0, 0, 0,
392 0, 0, 0, 0, 0, 0,
393 0, 0, 0, 0, 0, 0
394 })));
395
396 return SimpleConvolution2dTestImpl<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000397 memoryManager,
telsoa014fcda012018-03-09 14:13:49 +0000398 input,
399 kernel,
400 GetBias2<typename FullyConnectedBiasTypeForInputType<T>::Type>(false, qScale, qOffset),
401 expectedOutput,
402 qScale,
403 qOffset,
narpra015f703182018-10-26 16:24:58 +0100404 layout,
telsoa01c577f2c2018-08-31 09:22:23 +0100405 1, // Padding left.
406 2, // Padding top.
407 3, // Padding right.
408 4); // Padding bottom.
telsoa014fcda012018-03-09 14:13:49 +0000409}
410
411template<typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000412LayerTestResult<T, 4> SimpleConvolution2dAsymmetricPaddingTestCommon(
413 armnn::IWorkloadFactory& workloadFactory,
414 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +0000415 const armnn::DataLayout layout,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000416 float qScale,
417 int32_t qOffset)
telsoa014fcda012018-03-09 14:13:49 +0000418{
telsoa01c577f2c2018-08-31 09:22:23 +0100419 // Use a single-batch 1-channel 5x5 image as input.
telsoa014fcda012018-03-09 14:13:49 +0000420 armnn::TensorInfo inputDesc({ 1, 1, 5, 5 }, armnn::GetDataType<T>());
421 boost::multi_array<T, 4> input = MakeTensor<T, 4>(inputDesc, std::vector<T>(
422 QuantizedVector<T>(qScale, qOffset, {
423 11,21,31,41,51,
424 12,22,32,42,52,
425 13,23,33,43,53,
426 14,24,34,44,54,
427 15,25,35,45,55,
428 })));
429
telsoa01c577f2c2018-08-31 09:22:23 +0100430 // Use 1 batch of a 1-channel 4x4 kernel.
telsoa014fcda012018-03-09 14:13:49 +0000431 armnn::TensorInfo kernelDesc({ 1, 1, 4, 4 }, armnn::GetDataType<T>());
432 boost::multi_array<T, 4> kernel = MakeTensor<T, 4>(kernelDesc, std::vector<T>(
433 QuantizedVector<T>(qScale, qOffset, {
434 -11,-21,-31,-41,
435 -12,-22,-32,-42,
436 -13,-23,-33,-43,
437 -14,-24,-34,-44,
438 })));
439
telsoa01c577f2c2018-08-31 09:22:23 +0100440 // Expected output is 1 batch of a 1-channel 5x5 image.
telsoa014fcda012018-03-09 14:13:49 +0000441 armnn::TensorInfo outputDesc({ 1, 1, 5, 5 }, armnn::GetDataType<T>());
442 std::vector<T> myVec(outputDesc.GetNumElements(), 0);
443 boost::multi_array<T, 4> expectedOutput = MakeTensor<T, 4>(outputDesc, std::vector<T>(
444 QuantizedVector<T>(qScale, qOffset, {
telsoa014fcda012018-03-09 14:13:49 +0000445 -7140, -10580, -13940, -9300, -5230,
446 -9590, -14120, -18520, -12290, -6860,
447 -9980, -14560, -18960, -12560, -7000,
448 -7518, -10904, -14144, -9318, -5152,
surmeh013537c2c2018-05-18 16:31:43 +0100449 -5032, -7256, -9376, -6142, -3368,
telsoa014fcda012018-03-09 14:13:49 +0000450 })));
451
452 return SimpleConvolution2dTestImpl<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000453 memoryManager,
telsoa014fcda012018-03-09 14:13:49 +0000454 input,
455 kernel,
456 GetBias2<typename FullyConnectedBiasTypeForInputType<T>::Type>(false, qScale, qOffset),
457 expectedOutput,
458 qScale,
459 qOffset,
narpra015f703182018-10-26 16:24:58 +0100460 layout,
telsoa01c577f2c2018-08-31 09:22:23 +0100461 1, // Padding left.
462 1, // Padding top.
463 2, // Padding right.
464 2); // Padding bottom.
surmeh013537c2c2018-05-18 16:31:43 +0100465}
466
467template<typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000468LayerTestResult<T, 4> DepthwiseConvolution2dAsymmetricTestCommon(
469 armnn::IWorkloadFactory& workloadFactory,
470 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
471 float qScale,
472 int32_t qOffset,
473 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000474 const armnn::DataLayout layout)
surmeh013537c2c2018-05-18 16:31:43 +0100475{
telsoa01c577f2c2018-08-31 09:22:23 +0100476 // Use a single-batch 2-channel 5x5 image as input.
surmeh013537c2c2018-05-18 16:31:43 +0100477 armnn::TensorInfo inputTensorInfo({ 1, 2, 5, 5 }, armnn::GetDataType<T>());
478 auto input = MakeTensor<T, 4>(inputTensorInfo, std::vector<T>(
479 QuantizedVector<T>(inputTensorInfo.GetQuantizationScale(), inputTensorInfo.GetQuantizationOffset(), {
480 0, 1, 2, 3, 4,
481 5, 6, 7, 8, 9,
482 10, 11, 12, 13, 14,
483 15, 16, 17, 18, 19,
484 20, 21, 22, 23, 24,
485
486 25, 26, 27, 28, 29,
487 30, 31, 32, 33, 34,
488 35, 36, 37, 38, 39,
489 40, 41, 42, 43, 44,
490 45, 46, 47, 48, 49
491 })));
492
telsoa01c577f2c2018-08-31 09:22:23 +0100493 // Use a depth multiplier of 1 on a 2-channel 4x4 kernel.
surmeh013537c2c2018-05-18 16:31:43 +0100494 armnn::TensorInfo kernelTensorInfo({ 1, 2, 4, 4 }, armnn::GetDataType<T>());
495 auto kernel = MakeTensor<T, 4>(kernelTensorInfo, std::vector<T>(
496 QuantizedVector<T>(kernelTensorInfo.GetQuantizationScale(), kernelTensorInfo.GetQuantizationOffset(), {
497 32, 31, 30, 29,
498 28, 27, 26, 25,
499 24, 23, 22, 21,
500 20, 19, 18, 17,
501
502 16, 15, 14, 13,
503 12, 11, 10, 9,
504 8, 7, 6, 5,
505 4, 3, 2, 1
506 })));
507
telsoa01c577f2c2018-08-31 09:22:23 +0100508 // Expected output is 1 batch of a 2-channel 5x5 image.
509 // Calculated using the python tensorflow library with strideX=1, strideY=1.
surmeh013537c2c2018-05-18 16:31:43 +0100510 armnn::TensorInfo outputTensorInfo({ 1, 2, 5, 5 }, armnn::GetDataType<T>());
511 boost::multi_array<T, 4> expectedOutput = MakeTensor<T, 4>(outputTensorInfo, std::vector<T>(
512 QuantizedVector<T>(outputTensorInfo.GetQuantizationScale(), outputTensorInfo.GetQuantizationOffset(), {
513 1062, 1580, 1850, 1530, 1117,
514 2140, 3108, 3500, 2842, 2042,
515 3580, 5068, 5460, 4342, 3062,
516 3618, 5072, 5390, 4248, 2971,
517 3074, 4282, 4510, 3533, 2457,
518 1550, 2284, 2362, 1955, 1428,
519 2910, 4206, 4342, 3528, 2536,
520 3390, 4886, 5022, 4068, 2916,
521 3566, 5056, 5182, 4133, 2922,
522 3100, 4352, 4452, 3517, 2465
523 })));
524
525 return DepthwiseConvolution2dAsymmetricTestImpl<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000526 memoryManager,
surmeh013537c2c2018-05-18 16:31:43 +0100527 input,
528 kernel,
529 GetBias2<typename FullyConnectedBiasTypeForInputType<T>::Type>(biasEnabled, qScale, qOffset),
530 expectedOutput,
531 qScale,
532 qOffset,
jimfly01382a91d2018-10-26 15:55:50 +0100533 layout,
telsoa01c577f2c2018-08-31 09:22:23 +0100534 1, // Padding left.
535 1, // Padding top.
536 2, // Padding right.
537 2, // Padding bottom.
surmeh013537c2c2018-05-18 16:31:43 +0100538 1, // strideX
539 1); // strideY
telsoa014fcda012018-03-09 14:13:49 +0000540}
541
Nikhil Rajcec6b652018-10-12 13:51:57 +0100542template<typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000543LayerTestResult<T, 4> DepthwiseConvolution2dNhwcTestCommon(
544 armnn::IWorkloadFactory& workloadFactory,
545 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
546 float qScale,
547 int32_t qOffset,
548 bool biasEnabled)
Nikhil Rajcec6b652018-10-12 13:51:57 +0100549{
550 armnn::TensorInfo inputTensorInfo({ 1, 5, 5, 2}, armnn::GetDataType<T>());
551 auto input = MakeTensor<T, 4>(inputTensorInfo, std::vector<T>(
552 QuantizedVector<T>(inputTensorInfo.GetQuantizationScale(), inputTensorInfo.GetQuantizationOffset(), {
553 0, 25,
554 1, 26,
555 2, 27,
556 3, 28,
557 4, 29,
558
559 5, 30,
560 6, 31,
561 7, 32,
562 8, 33,
563 9, 34,
564
565 10, 35,
566 11, 36,
567 12, 37,
568 13, 38,
569 14, 39,
570
571 15, 40,
572 16, 41,
573 17, 42,
574 18, 43,
575 19, 44,
576
577 20, 45,
578 21, 46,
579 22, 47,
580 23, 48,
581 24, 49
582 })));
583
584 armnn::TensorInfo kernelTensorInfo({ 1, 4, 4, 2}, armnn::GetDataType<T>());
585 auto kernel = MakeTensor<T, 4>(kernelTensorInfo, std::vector<T>(
586 QuantizedVector<T>(kernelTensorInfo.GetQuantizationScale(), kernelTensorInfo.GetQuantizationOffset(), {
587 32, 16,
588 31, 15,
589 30, 14,
590 29, 13,
591
592 28, 12,
593 27, 11,
594 26, 10,
595 25, 9,
596
597 24, 8,
598 23, 7,
599 22, 6,
600 21, 5,
601
602 20, 4,
603 19, 3,
604 18, 2,
605 17, 1
606 })));
607
608 armnn::TensorInfo outputTensorInfo({ 1, 5, 5, 2}, armnn::GetDataType<T>());
609 boost::multi_array<T, 4> expectedOutput = MakeTensor<T, 4>(outputTensorInfo, std::vector<T>(
610 QuantizedVector<T>(outputTensorInfo.GetQuantizationScale(), outputTensorInfo.GetQuantizationOffset(), {
611 1062, 1550,
612 1580, 2284,
613 1850, 2362,
614 1530, 1955,
615 1117, 1428,
616
617 2140, 2910,
618 3108, 4206,
619 3500, 4342,
620 2842, 3528,
621 2042, 2536,
622
623 3580, 3390,
624 5068, 4886,
625 5460, 5022,
626 4342, 4068,
627 3062, 2916,
628
629 3618, 3566,
630 5072, 5056,
631 5390, 5182,
632 4248, 4133,
633 2971, 2922,
634
635 3074, 3100,
636 4282, 4352,
637 4510, 4452,
638 3533, 3517,
639 2457, 2465
640 })));
641
642 return DepthwiseConvolution2dNhwcTestImpl<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000643 memoryManager,
Nikhil Rajcec6b652018-10-12 13:51:57 +0100644 input,
645 kernel,
646 GetBias2<typename FullyConnectedBiasTypeForInputType<T>::Type>(biasEnabled, qScale, qOffset),
647 expectedOutput,
648 qScale,
649 qOffset,
650 1, // Padding left.
651 1, // Padding top.
652 2, // Padding right.
653 2, // Padding bottom.
654 1, // strideX
655 1); // strideY
656}
657
telsoa014fcda012018-03-09 14:13:49 +0000658LayerTestResult<float, 4>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000659Convolution2dAsymmetricPaddingLargerThanHalfKernelSizeTest(
660 armnn::IWorkloadFactory& workloadFactory,
661 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +0000662 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000663{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000664 return Convolution2dAsymmetricPaddingLargerThanHalfKernelSizeTestCommon<float>(
665 workloadFactory, memoryManager, layout, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +0000666}
667
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000668LayerTestResult<float, 4> Convolution2dAsymmetricPaddingTest(
669 armnn::IWorkloadFactory& workloadFactory,
670 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +0000671 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000672{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000673 return SimpleConvolution2dAsymmetricPaddingTestCommon<float>(
674 workloadFactory, memoryManager, layout, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +0000675}
676
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000677LayerTestResult<float, 4> DepthwiseConvolution2dTest(
678 armnn::IWorkloadFactory& workloadFactory,
679 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
680 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000681 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000682{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000683 return DepthwiseConvolution2dTestImpl<float, float>(
684 workloadFactory, memoryManager, 0.0f, 0, biasEnabled, layout);
telsoa014fcda012018-03-09 14:13:49 +0000685}
686
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000687LayerTestResult<float, 4> DepthwiseConvolution2dDepthNhwcTest(
688 armnn::IWorkloadFactory& workloadFactory,
689 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
690 bool biasEnabled)
Nikhil Rajcec6b652018-10-12 13:51:57 +0100691{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000692 return DepthwiseConvolution2dNhwcTestCommon<float>(workloadFactory, memoryManager, 0.0f, 0, biasEnabled);
Nikhil Rajcec6b652018-10-12 13:51:57 +0100693}
694
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000695LayerTestResult<float, 4> DepthwiseConvolution2dDepthMul1Test(
696 armnn::IWorkloadFactory& workloadFactory,
697 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
698 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000699 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000700{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000701 return DepthwiseConvolution2dDepthMul1TestImpl<float, float>(
702 workloadFactory, memoryManager, 0.0f, 0, biasEnabled, layout);
telsoa014fcda012018-03-09 14:13:49 +0000703}
704
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000705LayerTestResult<float, 4> DepthwiseConvolution2dAsymmetricTest(
706 armnn::IWorkloadFactory& workloadFactory,
707 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
708 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000709 const armnn::DataLayout layout)
surmeh013537c2c2018-05-18 16:31:43 +0100710{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000711 return DepthwiseConvolution2dAsymmetricTestCommon<float>(
712 workloadFactory, memoryManager, 0.0f, 0, biasEnabled, layout);
surmeh013537c2c2018-05-18 16:31:43 +0100713}
714
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000715LayerTestResult<uint8_t, 4> DepthwiseConvolution2dUint8Test(
716 armnn::IWorkloadFactory& workloadFactory,
717 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
718 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000719 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000720{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000721 return DepthwiseConvolution2dTestImpl<uint8_t, int32_t>(
722 workloadFactory, memoryManager, 0.5f, 50, biasEnabled, layout);
telsoa014fcda012018-03-09 14:13:49 +0000723}
724
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000725LayerTestResult<uint8_t, 4> DepthwiseConvolution2dDepthMul1Uint8Test(
726 armnn::IWorkloadFactory& workloadFactory,
727 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
728 bool biasEnabled,
Matthew Bentham8800c002018-11-19 13:19:28 +0000729 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000730{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000731 return DepthwiseConvolution2dDepthMul1TestImpl<uint8_t, int32_t>(
732 workloadFactory, memoryManager, 0.5f, 50, biasEnabled, layout);
telsoa014fcda012018-03-09 14:13:49 +0000733}
734
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000735LayerTestResult<float, 4> Convolution1dTest(
736 armnn::IWorkloadFactory& workloadFactory,
737 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
738 bool biasEnabled)
telsoa014fcda012018-03-09 14:13:49 +0000739{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000740 return Convolution1dTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0, biasEnabled);
telsoa014fcda012018-03-09 14:13:49 +0000741}
742
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000743LayerTestResult<uint8_t, 4> Convolution1dUint8Test(
744 armnn::IWorkloadFactory& workloadFactory,
745 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
746 bool biasEnabled)
telsoa014fcda012018-03-09 14:13:49 +0000747{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000748 return Convolution1dTestImpl<uint8_t>(workloadFactory, memoryManager, 0.1f, 128, biasEnabled);
telsoa014fcda012018-03-09 14:13:49 +0000749}
750
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000751LayerTestResult<float,4> CompareConvolution2dTest(
752 armnn::IWorkloadFactory& workloadFactory,
753 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
754 armnn::IWorkloadFactory& refWorkloadFactory)
telsoa014fcda012018-03-09 14:13:49 +0000755{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000756 return CompareConvolution2dTestImpl<float>(workloadFactory, memoryManager, refWorkloadFactory);
telsoa014fcda012018-03-09 14:13:49 +0000757}
758
759template<typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000760LayerTestResult<T,4> CompareDepthwiseConvolution2dTest(
761 armnn::IWorkloadFactory& workloadFactory,
762 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
763 armnn::IWorkloadFactory& refWorkloadFactory,
Matthew Bentham8800c002018-11-19 13:19:28 +0000764 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +0000765{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000766 return CompareDepthwiseConvolution2dTestImpl<T>(workloadFactory, memoryManager, refWorkloadFactory, layout);
telsoa014fcda012018-03-09 14:13:49 +0000767}
768
769template LayerTestResult<float, 4> CompareDepthwiseConvolution2dTest<float>(
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000770 armnn::IWorkloadFactory&,
771 const armnn::IBackendInternal::IMemoryManagerSharedPtr&,
772 armnn::IWorkloadFactory&,
Matthew Bentham8800c002018-11-19 13:19:28 +0000773 const armnn::DataLayout);
telsoa014fcda012018-03-09 14:13:49 +0000774
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000775template LayerTestResult<uint8_t, 4> CompareDepthwiseConvolution2dTest<uint8_t>(
776 armnn::IWorkloadFactory&,
777 const armnn::IBackendInternal::IMemoryManagerSharedPtr&,
778 armnn::IWorkloadFactory&,
Matthew Bentham8800c002018-11-19 13:19:28 +0000779 const armnn::DataLayout);
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000780
781LayerTestResult<float,4> SimpleNormalizationAcrossTest(
782 armnn::IWorkloadFactory& workloadFactory,
783 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +0000784{
785 auto normMethod = armnn::NormalizationAlgorithmMethod::LocalBrightness;
786 auto normChannel = armnn::NormalizationAlgorithmChannel::Across;
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000787 return SimpleNormalizationTestImpl(workloadFactory, memoryManager, normChannel, normMethod);
telsoa014fcda012018-03-09 14:13:49 +0000788}
789
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000790LayerTestResult<float,4> SimpleNormalizationWithinTest(
791 armnn::IWorkloadFactory& workloadFactory,
792 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +0000793{
794 auto normMethod = armnn::NormalizationAlgorithmMethod::LocalBrightness;
795 auto normChannel = armnn::NormalizationAlgorithmChannel::Within;
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000796 return SimpleNormalizationTestImpl(workloadFactory, memoryManager, normChannel, normMethod);
telsoa014fcda012018-03-09 14:13:49 +0000797}
798
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000799LayerTestResult<float,4> SimpleNormalizationAcrossNhwcTest(
800 armnn::IWorkloadFactory& workloadFactory,
801 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra0155a97bc2018-10-02 14:35:53 +0100802{
803 auto normMethod = armnn::NormalizationAlgorithmMethod::LocalBrightness;
804 auto normChannel = armnn::NormalizationAlgorithmChannel::Across;
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000805 return SimpleNormalizationNhwcTestImpl(workloadFactory, memoryManager, normChannel, normMethod);
narpra0155a97bc2018-10-02 14:35:53 +0100806}
807
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000808LayerTestResult<float,2> SimpleSoftmaxTest(
809 armnn::IWorkloadFactory& workloadFactory,
810 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
811 float beta)
telsoa014fcda012018-03-09 14:13:49 +0000812{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000813 return SimpleSoftmaxTestImpl<float>(workloadFactory, memoryManager, beta);
telsoa014fcda012018-03-09 14:13:49 +0000814}
815
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000816LayerTestResult<uint8_t,2> SimpleSoftmaxUint8Test(
817 armnn::IWorkloadFactory& workloadFactory,
818 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
819 float beta)
telsoa014fcda012018-03-09 14:13:49 +0000820{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000821 return SimpleSoftmaxTestImpl<uint8_t>(workloadFactory, memoryManager, beta);
telsoa014fcda012018-03-09 14:13:49 +0000822}
823
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000824LayerTestResult<float,4> CompareNormalizationTest(
825 armnn::IWorkloadFactory& workloadFactory,
826 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
827 armnn::IWorkloadFactory& refWorkloadFactory,
828 armnn::NormalizationAlgorithmChannel normChannel,
829 armnn::NormalizationAlgorithmMethod normMethod)
telsoa014fcda012018-03-09 14:13:49 +0000830{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000831 return CompareNormalizationTestImpl(workloadFactory, memoryManager, refWorkloadFactory, normChannel, normMethod);
telsoa014fcda012018-03-09 14:13:49 +0000832}
833
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000834LayerTestResult<float,2> CompareSoftmaxTest(
835 armnn::IWorkloadFactory& workloadFactory,
836 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
telsoa014fcda012018-03-09 14:13:49 +0000837 armnn::IWorkloadFactory& refWorkloadFactory,
838 float beta)
839{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000840 return CompareSoftmaxTestImpl<float>(workloadFactory, memoryManager, refWorkloadFactory, beta);
telsoa014fcda012018-03-09 14:13:49 +0000841}
842
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000843LayerTestResult<uint8_t,2> CompareSoftmaxUint8Test(
844 armnn::IWorkloadFactory& workloadFactory,
845 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
telsoa014fcda012018-03-09 14:13:49 +0000846 armnn::IWorkloadFactory& refWorkloadFactory,
847 float beta)
848{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000849 return CompareSoftmaxTestImpl<uint8_t>(workloadFactory, memoryManager, refWorkloadFactory, beta);
telsoa014fcda012018-03-09 14:13:49 +0000850}
851
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000852std::vector<LayerTestResult<float,3>> SplitterTest(
853 armnn::IWorkloadFactory& workloadFactory,
854 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +0000855{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000856 return SplitterTestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +0000857}
858
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000859std::vector<LayerTestResult<uint8_t,3>> SplitterUint8Test(
860 armnn::IWorkloadFactory& workloadFactory,
861 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +0000862{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000863 return SplitterTestCommon<uint8_t>(workloadFactory, memoryManager, 1.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +0000864}
865
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000866LayerTestResult<float, 3> CopyViaSplitterTest(
867 armnn::IWorkloadFactory& workloadFactory,
868 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +0000869{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000870 return CopyViaSplitterTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +0000871}
872
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000873LayerTestResult<uint8_t, 3> CopyViaSplitterUint8Test(
874 armnn::IWorkloadFactory& workloadFactory,
875 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +0000876{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000877 return CopyViaSplitterTestImpl<uint8_t>(workloadFactory, memoryManager, 1.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +0000878}
879
telsoa01c577f2c2018-08-31 09:22:23 +0100880LayerTestResult<float, 2> LstmLayerFloat32WithCifgWithPeepholeNoProjectionTest(
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000881 armnn::IWorkloadFactory& workloadFactory,
882 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa01c577f2c2018-08-31 09:22:23 +0100883{
884 armnn::TensorInfo inputDesc({ 2, 2 }, armnn::GetDataType<float>());
885 boost::multi_array<float, 2> input = MakeTensor<float, 2>(inputDesc, std::vector<float>(
886 { 2., 3., 3., 4. }));
887
888 armnn::TensorInfo outputDesc({ 2, 4 }, armnn::GetDataType<float>());
889 boost::multi_array<float, 2> expectedOutput = MakeTensor<float, 2>(outputDesc, std::vector<float>(
890 {-0.36444446f, -0.00352185f, 0.12886585f, -0.05163646f,
891 -0.42734814f, -0.00478661f, 0.13455015f, -0.03560682f}));
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000892 return LstmLayerWithCifgWithPeepholeNoProjectionTestImpl(
893 workloadFactory, memoryManager, input, expectedOutput);
telsoa01c577f2c2018-08-31 09:22:23 +0100894}
895
896LayerTestResult<float, 2> LstmLayerFloat32NoCifgWithPeepholeWithProjectionTest(
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000897 armnn::IWorkloadFactory& workloadFactory,
898 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa01c577f2c2018-08-31 09:22:23 +0100899{
900 armnn::TensorInfo inputDesc({ 2, 5 }, armnn::GetDataType<float>());
901 boost::multi_array<float, 2> input = MakeTensor<float, 2>(inputDesc, std::vector<float>(
902 {0.787926f, 0.151646f, 0.071352f, 0.118426f, 0.458058f,
903 0.295743f, 0.544053f, 0.690064f, 0.858138f, 0.497181f}));
904
905 armnn::TensorInfo outputDesc({ 2, 16 }, armnn::GetDataType<float>());
906 boost::multi_array<float, 2> expectedOutput = MakeTensor<float, 2>(outputDesc, std::vector<float>(
907 {-0.00396806f, 0.029352f, -0.00279226f, 0.0159977f, -0.00835576f,
908 -0.0211779f, 0.0283512f, -0.0114597f, 0.00907307f, -0.0244004f,
909 -0.0152191f, -0.0259063f, 0.00914318f, 0.00415118f, 0.017147f,
910 0.0134203f, -0.013869f, 0.0287268f, -0.00334693f, 0.00733398f, -0.0287926f,
911 -0.0186926f, 0.0193662f, -0.0115437f, 0.00422612f, -0.0345232f,
912 0.00223253f, -0.00957321f, 0.0210624f, 0.013331f, 0.0150954f,
913 0.02168f}));
Matteo Martincigha65b7ae2018-11-14 12:39:55 +0000914 return LstmLayerNoCifgWithPeepholeWithProjectionTestImpl(workloadFactory, memoryManager, input, expectedOutput);
telsoa01c577f2c2018-08-31 09:22:23 +0100915}
916
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000917LayerTestResult<float, 2> LstmLayerFloat32NoCifgNoPeepholeNoProjectionTest(
918 armnn::IWorkloadFactory& workloadFactory,
919 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa01c577f2c2018-08-31 09:22:23 +0100920{
921 armnn::TensorInfo inputDesc({2, 2}, armnn::GetDataType<float>());
922 boost::multi_array<float, 2> input = MakeTensor<float, 2>(inputDesc, std::vector<float>(
923 {2., 3., 3., 4.}));
924
925
926 armnn::TensorInfo outputDesc({2, 4}, armnn::GetDataType<float>());
927 boost::multi_array<float, 2> expectedOutput = MakeTensor<float, 2>(outputDesc, std::vector<float>(
928 {{-0.02973187f, 0.1229473f, 0.20885126f, -0.15358765f,
929 -0.0185422f, 0.11281417f, 0.24466537f, -0.1826292f}}));
930
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000931 return LstmNoCifgNoPeepholeNoProjectionTestImpl(
932 workloadFactory, memoryManager, input, expectedOutput);
telsoa01c577f2c2018-08-31 09:22:23 +0100933}
934
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +0000935LayerTestResult<float,3> MergerTest(
936 armnn::IWorkloadFactory& workloadFactory,
937 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +0000938{
surmeh013537c2c2018-05-18 16:31:43 +0100939 unsigned int outputWidth = 3;
telsoa014fcda012018-03-09 14:13:49 +0000940 unsigned int outputHeight = 6;
941 unsigned int outputChannels = 3;
942
surmeh013537c2c2018-05-18 16:31:43 +0100943 unsigned int inputWidth1 = 3;
944 unsigned int inputHeight1 = 6;
945 unsigned int inputChannels1 = 2;
telsoa014fcda012018-03-09 14:13:49 +0000946
surmeh013537c2c2018-05-18 16:31:43 +0100947 unsigned int inputWidth2 = 3;
948 unsigned int inputHeight2 = 6;
949 unsigned int inputChannels2 = 1;
telsoa014fcda012018-03-09 14:13:49 +0000950
telsoa01c577f2c2018-08-31 09:22:23 +0100951 // Define the tensor descriptors.
telsoa014fcda012018-03-09 14:13:49 +0000952 armnn::TensorInfo outputTensorInfo({ outputChannels, outputHeight, outputWidth }, armnn::DataType::Float32);
953 armnn::TensorInfo inputTensorInfo1({ inputChannels1, inputHeight1, inputWidth1 }, armnn::DataType::Float32);
954 armnn::TensorInfo inputTensorInfo2({ inputChannels2, inputHeight2, inputWidth2 }, armnn::DataType::Float32);
telsoa014fcda012018-03-09 14:13:49 +0000955
956 LayerTestResult<float,3> ret(outputTensorInfo);
957
telsoa014fcda012018-03-09 14:13:49 +0000958 ret.outputExpected = MakeTensor<float, 3>(outputTensorInfo, std::vector<float>(
surmeh013537c2c2018-05-18 16:31:43 +0100959 {
960 1.0f, 2.0f, 3.0f,
961 4.0f, 5.0f, 6.0f,
962 7.0f, 8.0f, 9.0f,
963 10.0f, 11.0f, 12.0f,
964 13.0f, 14.0f, 15.0f,
965 16.0f, 17.0f, 18.0f,
telsoa014fcda012018-03-09 14:13:49 +0000966
surmeh013537c2c2018-05-18 16:31:43 +0100967 19.0f, 20.0f, 21.0f,
968 22.0f, 23.0f, 24.0f,
969 25.0f, 26.0f, 27.0f,
970 28.0f, 29.0f, 30.0f,
971 31.0f, 32.0f, 33.0f,
972 34.0f, 35.0f, 36.0f,
telsoa014fcda012018-03-09 14:13:49 +0000973
surmeh013537c2c2018-05-18 16:31:43 +0100974 37.0f, 38.0f, 39.0f,
975 40.0f, 41.0f, 42.0f,
976 43.0f, 44.0f, 45.0f,
977 46.0f, 47.0f, 48.0f,
978 49.0f, 50.0f, 51.0f,
979 52.0f, 53.0f, 54.0f,
telsoa014fcda012018-03-09 14:13:49 +0000980 })
981 );
982
telsoa014fcda012018-03-09 14:13:49 +0000983 auto input1 = MakeTensor<float, 3>(inputTensorInfo1, std::vector<float>(
984 {
surmeh013537c2c2018-05-18 16:31:43 +0100985 1.0f, 2.0f, 3.0f,
986 4.0f, 5.0f, 6.0f,
987 7.0f, 8.0f, 9.0f,
988 10.0f, 11.0f, 12.0f,
989 13.0f, 14.0f, 15.0f,
990 16.0f, 17.0f, 18.0f,
telsoa014fcda012018-03-09 14:13:49 +0000991
surmeh013537c2c2018-05-18 16:31:43 +0100992 19.0f, 20.0f, 21.0f,
993 22.0f, 23.0f, 24.0f,
994 25.0f, 26.0f, 27.0f,
995 28.0f, 29.0f, 30.0f,
996 31.0f, 32.0f, 33.0f,
997 34.0f, 35.0f, 36.0f,
telsoa014fcda012018-03-09 14:13:49 +0000998 })
999 );
1000
1001 auto input2 = MakeTensor<float, 3>(inputTensorInfo2, std::vector<float>(
1002 {
surmeh013537c2c2018-05-18 16:31:43 +01001003 37.0f, 38.0f, 39.0f,
1004 40.0f, 41.0f, 42.0f,
telsoa014fcda012018-03-09 14:13:49 +00001005 43.0f, 44.0f, 45.0f,
surmeh013537c2c2018-05-18 16:31:43 +01001006 46.0f, 47.0f, 48.0f,
1007 49.0f, 50.0f, 51.0f,
1008 52.0f, 53.0f, 54.0f,
telsoa014fcda012018-03-09 14:13:49 +00001009 })
1010 );
1011
telsoa01c577f2c2018-08-31 09:22:23 +01001012 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 +00001013 armnn::MergerQueueDescriptor::ViewOrigin window1(wOrigin1);
1014
telsoa01c577f2c2018-08-31 09:22:23 +01001015 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 +00001016 armnn::MergerQueueDescriptor::ViewOrigin window2(wOrigin2);
1017
telsoa014fcda012018-03-09 14:13:49 +00001018 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
1019
1020 bool subTensorsSupported = workloadFactory.SupportsSubTensors();
1021
1022 std::unique_ptr<armnn::ITensorHandle> inputHandle1 =
1023 subTensorsSupported ?
1024 workloadFactory.CreateSubTensorHandle(*outputHandle, inputTensorInfo1.GetShape(), wOrigin1.data()) :
1025 workloadFactory.CreateTensorHandle(inputTensorInfo1);
1026
1027 std::unique_ptr<armnn::ITensorHandle> inputHandle2 =
1028 subTensorsSupported ?
1029 workloadFactory.CreateSubTensorHandle(*outputHandle, inputTensorInfo2.GetShape(), wOrigin2.data()) :
1030 workloadFactory.CreateTensorHandle(inputTensorInfo2);
1031
telsoa014fcda012018-03-09 14:13:49 +00001032 armnn::MergerQueueDescriptor data;
1033 armnn::WorkloadInfo info;
1034 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
1035 AddInputToWorkload(data, info, inputTensorInfo2, inputHandle2.get());
telsoa014fcda012018-03-09 14:13:49 +00001036 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1037
1038 data.m_ViewOrigins.push_back(window1);
1039 data.m_ViewOrigins.push_back(window2);
telsoa014fcda012018-03-09 14:13:49 +00001040
1041 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateMerger(data, info);
1042
1043 inputHandle1->Allocate();
1044 inputHandle2->Allocate();
telsoa014fcda012018-03-09 14:13:49 +00001045 outputHandle->Allocate();
1046
1047 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0]);
1048 CopyDataToITensorHandle(inputHandle2.get(), &input2[0][0][0]);
telsoa014fcda012018-03-09 14:13:49 +00001049
1050 workload->Execute();
1051
1052 CopyDataFromITensorHandle(&ret.output[0][0][0], outputHandle.get());
1053
1054 return ret;
1055}
1056
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001057LayerTestResult<float,4> AdditionTest(
1058 armnn::IWorkloadFactory& workloadFactory,
1059 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00001060{
1061 unsigned int batchSize = 2;
1062 unsigned int channels = 2;
1063 unsigned int height = 2;
1064 unsigned int width = 3;
1065
1066 armnn::TensorInfo inputTensorInfo1, inputTensorInfo2;
1067 armnn::TensorInfo outputTensorInfo;
1068
1069 unsigned int shape[] = {batchSize, channels, height, width};
1070
1071 inputTensorInfo1 = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
1072 inputTensorInfo2 = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
1073 outputTensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
1074
1075
1076 auto input1 = MakeTensor<float, 4>(inputTensorInfo1, std::vector<float>(
1077 {
1078 0.0f, 2.0f, 1.0f,
1079 0.2f, 1.0f, 2.0f,
1080
1081 1.0f, 2.0f, 1.0f,
1082 0.2f, 1.0f, 2.0f,
1083
1084 0.0f, 2.0f, 1.0f,
1085 4.2f, 1.0f, 2.0f,
1086
1087 0.0f, 0.0f, 1.0f,
1088 0.2f, 1.0f, 2.0f,
1089 }));
1090
1091 auto input2 = MakeTensor<float, 4>(inputTensorInfo2, std::vector<float>(
1092 {
1093 1.0f, 2.0f, 1.0f,
1094 0.0f, 1.0f, 2.0f,
1095
1096 1.0f, 2.0f, -2.0f,
1097 0.2f, 1.0f, 2.0f,
1098
1099 0.0f, 2.0f, 1.0f,
1100 4.2f, 0.0f, -3.0f,
1101
1102 0.0f, 0.0f, 1.0f,
1103 0.7f, 1.0f, 5.0f,
1104 }));
1105
1106 LayerTestResult<float,4> ret(outputTensorInfo);
1107 ret.outputExpected = MakeTensor<float, 4>(outputTensorInfo, std::vector<float>(
1108 {
1109 1.0f, 4.0f, 2.0f,
1110 0.2f, 2.0f, 4.0f,
1111
1112 2.0f, 4.0f, -1.0f,
1113 0.4f, 2.0f, 4.0f,
1114
1115 0.0f, 4.0f, 2.0f,
1116 8.4f, 1.0f, -1.0f,
1117
1118 0.0f, 0.0f, 2.0f,
1119 0.9f, 2.0f, 7.0f,
1120 }));
1121
1122 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
1123 std::unique_ptr<armnn::ITensorHandle> inputHandle2 = workloadFactory.CreateTensorHandle(inputTensorInfo2);
1124 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
1125
1126 armnn::AdditionQueueDescriptor data;
1127 armnn::WorkloadInfo info;
1128 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
1129 AddInputToWorkload(data, info, inputTensorInfo2, inputHandle2.get());
1130 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1131
1132 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateAddition(data, info);
1133
1134 inputHandle1->Allocate();
1135 inputHandle2->Allocate();
1136 outputHandle->Allocate();
1137
1138 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
1139 CopyDataToITensorHandle(inputHandle2.get(), &input2[0][0][0][0]);
1140
1141 workload->Execute();
1142
1143 CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
1144
1145 return ret;
1146}
1147
1148template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001149LayerTestResult<T, 4> AdditionBroadcastTestImpl(
1150 armnn::IWorkloadFactory& workloadFactory,
1151 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
telsoa014fcda012018-03-09 14:13:49 +00001152 float qScale,
1153 int32_t qOffset)
1154{
1155 armnn::TensorInfo inputTensorInfo1 = armnn::TensorInfo({1, 3, 2, 1}, armnn::GetDataType<T>());
1156 armnn::TensorInfo inputTensorInfo2 = armnn::TensorInfo({1, 1, 2, 3}, armnn::GetDataType<T>());
1157 armnn::TensorInfo outputTensorInfo = armnn::TensorInfo({1, 3, 2, 3}, armnn::GetDataType<T>());
1158
1159 if (armnn::IsQuantizedType<T>())
1160 {
1161 inputTensorInfo1.SetQuantizationScale(qScale);
1162 inputTensorInfo1.SetQuantizationOffset(qOffset);
1163 inputTensorInfo2.SetQuantizationScale(qScale);
1164 inputTensorInfo2.SetQuantizationOffset(qOffset);
1165 outputTensorInfo.SetQuantizationScale(qScale);
1166 outputTensorInfo.SetQuantizationOffset(qOffset);
1167 }
1168
1169 auto input1 = MakeTensor<T, 4>(inputTensorInfo1, QuantizedVector<T>(qScale, qOffset,
1170 {
1171 0.0f,
1172 1.0f,
1173
1174 2.0f,
1175 3.0f,
1176
1177 4.0f,
1178 5.0f,
1179 }));
1180
1181 auto input2 = MakeTensor<T, 4>(inputTensorInfo2, QuantizedVector<T>(qScale, qOffset,
1182 {
1183 0.5f, 1.5f, 2.5f,
1184 3.5f, 4.5f, 5.5f,
1185 }));
1186
1187 LayerTestResult<T,4> ret(outputTensorInfo);
1188 ret.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset,
1189 {
1190 0.5f, 1.5f, 2.5f,
1191 4.5f, 5.5f, 6.5f,
1192
1193 2.5f, 3.5f, 4.5f,
1194 6.5f, 7.5f, 8.5f,
1195
1196 4.5f, 5.5f, 6.5f,
1197 8.5f, 9.5f, 10.5f,
1198 }));
1199
1200 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
1201 std::unique_ptr<armnn::ITensorHandle> inputHandle2 = workloadFactory.CreateTensorHandle(inputTensorInfo2);
1202 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
1203
1204 armnn::AdditionQueueDescriptor data;
1205 armnn::WorkloadInfo info;
1206 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
1207 AddInputToWorkload(data, info, inputTensorInfo2, inputHandle2.get());
1208 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1209
1210 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateAddition(data, info);
1211
1212 inputHandle1->Allocate();
1213 inputHandle2->Allocate();
1214 outputHandle->Allocate();
1215
1216 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
1217 CopyDataToITensorHandle(inputHandle2.get(), &input2[0][0][0][0]);
1218
1219 workload->Execute();
1220
1221 CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
1222
1223 return ret;
1224}
1225
1226template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001227LayerTestResult<T, 4> AdditionBroadcast1ElementTestImpl(
1228 armnn::IWorkloadFactory& workloadFactory,
1229 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
telsoa014fcda012018-03-09 14:13:49 +00001230 float qScale,
1231 int32_t qOffset)
1232{
1233 armnn::TensorInfo inputTensorInfo1 = armnn::TensorInfo({1, 3, 2, 3}, armnn::GetDataType<T>());
1234 armnn::TensorInfo inputTensorInfo2 = armnn::TensorInfo({1, 1, 1, 1}, armnn::GetDataType<T>());
1235 armnn::TensorInfo outputTensorInfo = armnn::TensorInfo({1, 3, 2, 3}, armnn::GetDataType<T>());
1236
1237 if (armnn::IsQuantizedType<T>())
1238 {
1239 inputTensorInfo1.SetQuantizationScale(qScale);
1240 inputTensorInfo1.SetQuantizationOffset(qOffset);
1241 inputTensorInfo2.SetQuantizationScale(qScale);
1242 inputTensorInfo2.SetQuantizationOffset(qOffset);
1243 outputTensorInfo.SetQuantizationScale(qScale);
1244 outputTensorInfo.SetQuantizationOffset(qOffset);
1245 }
1246
1247 auto input1 = MakeTensor<T, 4>(inputTensorInfo1, QuantizedVector<T>(qScale, qOffset,
1248 {
1249 0.0f, 1.0f, 2.0f,
1250 3.0f, 4.0f, 5.0f,
1251 6.0f, 7.0f, 8.0f,
1252 9.0f, 10.0f, 11.0f,
1253 12.0f, 13.0f, 14.0f,
1254 15.0f, 16.0f, 17.0f,
1255 }));
1256
1257 auto input2 = MakeTensor<T, 4>(inputTensorInfo2, QuantizedVector<T>(qScale, qOffset,
1258 {
1259 0.5f,
1260 }));
1261
1262 LayerTestResult<T,4> ret(outputTensorInfo);
1263 ret.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset,
1264 {
1265 0.5f, 1.5f, 2.5f,
1266 3.5f, 4.5f, 5.5f,
1267 6.5f, 7.5f, 8.5f,
1268 9.5f, 10.5f, 11.5f,
1269 12.5f, 13.5f, 14.5f,
1270 15.5f, 16.5f, 17.5f,
1271 }));
1272
1273 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
1274 std::unique_ptr<armnn::ITensorHandle> inputHandle2 = workloadFactory.CreateTensorHandle(inputTensorInfo2);
1275 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
1276
1277 armnn::AdditionQueueDescriptor data;
1278 armnn::WorkloadInfo info;
1279 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
1280 AddInputToWorkload(data, info, inputTensorInfo2, inputHandle2.get());
1281 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1282
1283 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateAddition(data, info);
1284
1285 inputHandle1->Allocate();
1286 inputHandle2->Allocate();
1287 outputHandle->Allocate();
1288
1289 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
1290 CopyDataToITensorHandle(inputHandle2.get(), &input2[0][0][0][0]);
1291
1292 workload->Execute();
1293
1294 CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
1295
1296 return ret;
1297}
1298
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001299LayerTestResult<float, 4> AdditionBroadcastTest(
1300 armnn::IWorkloadFactory& workloadFactory,
1301 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00001302{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001303 return AdditionBroadcastTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00001304}
1305
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001306LayerTestResult<uint8_t, 4> AdditionBroadcastUint8Test(
1307 armnn::IWorkloadFactory& workloadFactory,
1308 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00001309{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001310 return AdditionBroadcastTestImpl<uint8_t>(workloadFactory, memoryManager, 2.f, 0);
telsoa014fcda012018-03-09 14:13:49 +00001311}
1312
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001313LayerTestResult<float, 4> AdditionBroadcast1ElementTest(
1314 armnn::IWorkloadFactory& workloadFactory,
1315 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00001316{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001317 return AdditionBroadcast1ElementTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00001318}
1319
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001320LayerTestResult<uint8_t, 4> AdditionBroadcast1ElementUint8Test(
1321 armnn::IWorkloadFactory& workloadFactory,
1322 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00001323{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001324 return AdditionBroadcast1ElementTestImpl<uint8_t>(workloadFactory, memoryManager, 0.1333333f, 128);
telsoa014fcda012018-03-09 14:13:49 +00001325}
1326
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001327LayerTestResult<float,4> CompareAdditionTest(
1328 armnn::IWorkloadFactory& workloadFactory,
1329 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1330 armnn::IWorkloadFactory& refWorkloadFactory)
telsoa014fcda012018-03-09 14:13:49 +00001331{
1332 unsigned int batchSize = 4;
1333 unsigned int channels = 1;
1334 unsigned int height = 2;
1335 unsigned int width = 3;
1336
1337 armnn::TensorInfo inputTensorInfo1, inputTensorInfo2;
1338 armnn::TensorInfo outputTensorInfo;
1339
1340 unsigned int shape[] = {batchSize, channels, height, width};
1341
1342 inputTensorInfo1 = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
1343 inputTensorInfo2 = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
1344 outputTensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
1345
1346 auto input1 = MakeRandomTensor<float, 4>(inputTensorInfo1, 1232);
1347 auto input2 = MakeRandomTensor<float, 4>(inputTensorInfo2, 456);
1348
1349 LayerTestResult<float,4> ret(outputTensorInfo);
1350
1351 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
1352 std::unique_ptr<armnn::ITensorHandle> inputHandle2 = workloadFactory.CreateTensorHandle(inputTensorInfo2);
1353 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
1354
1355 std::unique_ptr<armnn::ITensorHandle> inputHandle1Ref = refWorkloadFactory.CreateTensorHandle(inputTensorInfo1);
1356 std::unique_ptr<armnn::ITensorHandle> inputHandle2Ref = refWorkloadFactory.CreateTensorHandle(inputTensorInfo2);
1357 std::unique_ptr<armnn::ITensorHandle> outputHandleRef = refWorkloadFactory.CreateTensorHandle(outputTensorInfo);
1358
1359 armnn::AdditionQueueDescriptor data;
1360 armnn::WorkloadInfo info;
1361 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
1362 AddInputToWorkload(data, info, inputTensorInfo2, inputHandle2.get());
1363 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1364
1365 armnn::AdditionQueueDescriptor refData = data;
1366 armnn::WorkloadInfo refInfo = info;
1367 SetWorkloadInput(refData, refInfo, 0, inputTensorInfo1, inputHandle1Ref.get());
1368 SetWorkloadInput(refData, refInfo, 1, inputTensorInfo2, inputHandle2Ref.get());
1369 SetWorkloadOutput(refData, refInfo, 0, outputTensorInfo, outputHandleRef.get());
1370
1371 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateAddition(data, info);
1372 std::unique_ptr<armnn::IWorkload> workloadRef = refWorkloadFactory.CreateAddition(refData, refInfo);
1373
1374 inputHandle1->Allocate();
1375 inputHandle2->Allocate();
1376 outputHandle->Allocate();
1377 inputHandle1Ref->Allocate();
1378 inputHandle2Ref->Allocate();
1379 outputHandleRef->Allocate();
1380
1381 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
1382 CopyDataToITensorHandle(inputHandle2.get(), &input2[0][0][0][0]);
1383 CopyDataToITensorHandle(inputHandle1Ref.get(), &input1[0][0][0][0]);
1384 CopyDataToITensorHandle(inputHandle2Ref.get(), &input2[0][0][0][0]);
1385
1386 workload->Execute();
1387 workloadRef->Execute();
1388
1389 CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
1390 CopyDataFromITensorHandle(&ret.outputExpected[0][0][0][0], outputHandleRef.get());
1391
1392 return ret;
1393}
1394
surmeh01bceff2f2018-03-29 16:29:27 +01001395namespace {
David Beck5cd01f32018-09-12 16:00:08 +01001396template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001397LayerTestResult<T, 4> DivisionTestHelper(
1398 armnn::IWorkloadFactory& workloadFactory,
1399 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1400 const unsigned int shape0[4],
1401 const std::vector<T>& values0,
1402 float scale0,
1403 int32_t offset0,
1404 const unsigned int shape1[4],
1405 const std::vector<T> & values1,
1406 float scale1,
1407 int32_t offset1,
1408 const unsigned int outShape[4],
1409 const std::vector<T> & outValues,
1410 float outScale,
1411 int32_t outOffset)
David Beck5cd01f32018-09-12 16:00:08 +01001412{
1413 auto dataType = (std::is_same<T, uint8_t>::value ?
1414 armnn::DataType::QuantisedAsymm8 :
1415 armnn::DataType::Float32);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001416
David Beck5cd01f32018-09-12 16:00:08 +01001417 armnn::TensorInfo inputTensorInfo0(4, shape0, dataType);
1418 armnn::TensorInfo inputTensorInfo1(4, shape1, dataType);
1419 armnn::TensorInfo outputTensorInfo(4, outShape, dataType);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001420
David Beck5cd01f32018-09-12 16:00:08 +01001421 inputTensorInfo0.SetQuantizationScale(scale0);
1422 inputTensorInfo0.SetQuantizationOffset(offset0);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001423
David Beck5cd01f32018-09-12 16:00:08 +01001424 inputTensorInfo1.SetQuantizationScale(scale1);
1425 inputTensorInfo1.SetQuantizationOffset(offset1);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001426
David Beck5cd01f32018-09-12 16:00:08 +01001427 outputTensorInfo.SetQuantizationScale(outScale);
1428 outputTensorInfo.SetQuantizationOffset(outOffset);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001429
David Beck5cd01f32018-09-12 16:00:08 +01001430 auto input0 = MakeTensor<T, 4>(inputTensorInfo0, values0);
1431 auto input1 = MakeTensor<T, 4>(inputTensorInfo1, values1);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001432
David Beck5cd01f32018-09-12 16:00:08 +01001433 LayerTestResult<T, 4> result(outputTensorInfo);
1434 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, outValues);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001435
David Beck5cd01f32018-09-12 16:00:08 +01001436 std::unique_ptr<armnn::ITensorHandle> inputHandle0 = workloadFactory.CreateTensorHandle(inputTensorInfo0);
1437 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
1438 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001439
David Beck5cd01f32018-09-12 16:00:08 +01001440 armnn::DivisionQueueDescriptor data;
1441 armnn::WorkloadInfo info;
1442 AddInputToWorkload(data, info, inputTensorInfo0, inputHandle0.get());
1443 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
1444 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001445
David Beck5cd01f32018-09-12 16:00:08 +01001446 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateDivision(data, info);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001447
David Beck5cd01f32018-09-12 16:00:08 +01001448 inputHandle0->Allocate();
1449 inputHandle1->Allocate();
1450 outputHandle->Allocate();
1451
1452 CopyDataToITensorHandle(inputHandle0.get(), &input0[0][0][0][0]);
1453 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
1454
David Beck5cd01f32018-09-12 16:00:08 +01001455 workload->Execute();
1456
1457 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
1458
1459 return result;
1460}
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001461} // anonymous namespace
1462
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001463LayerTestResult<float,4> DivisionByZeroTest(
1464 armnn::IWorkloadFactory& workloadFactory,
1465 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Francis Murtagh8c5e3dc2018-08-30 17:18:37 +01001466{
1467 const unsigned int width = 2;
1468 const unsigned int height = 2;
1469 const unsigned int channelCount = 2;
1470 const unsigned int batchSize = 2;
1471
1472 unsigned int shape[] = { batchSize, channelCount, height, width };
1473
1474 std::vector<float> input0({
1475 1.f, 1.f, 1.f, 1.f, 0.f, 0.f, 0.f, 0.f,
1476 -1.f, -1.f, -1.f, -1.f, 5.f, 5.f, 5.f, 5.f });
1477
1478 std::vector<float> input1({
1479 0.f, 0.f, -0.f, -0.f, 0.f, 0.f, -0.f, -0.f,
1480 0.f, 0.f, -0.f, -0.f, 5.f, 5.f, 5.f, 5.f });
1481
1482 std::vector<float> output({
1483 INFINITY, INFINITY, -INFINITY, -INFINITY, NAN, NAN, -NAN, -NAN,
1484 -INFINITY, -INFINITY, INFINITY, INFINITY, 1, 1, 1, 1 });
1485
David Beck5cd01f32018-09-12 16:00:08 +01001486 return DivisionTestHelper<float>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001487 memoryManager,
David Beck5cd01f32018-09-12 16:00:08 +01001488 shape, input0, 1.0f, 0,
1489 shape, input1, 1.0f, 0,
1490 shape, output, 1.0f, 0);
Francis Murtagh8c5e3dc2018-08-30 17:18:37 +01001491}
1492
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001493LayerTestResult<float,4> DivisionTest(
1494 armnn::IWorkloadFactory& workloadFactory,
1495 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001496{
1497 const unsigned int width = 2;
1498 const unsigned int height = 2;
1499 const unsigned int channelCount = 2;
1500 const unsigned int batchSize = 2;
1501
1502 unsigned int shape[] = { batchSize, channelCount, height, width };
1503
1504 std::vector<float> input0({
1505 2, 2, 2, 2, 3, 3, 3, 3,
1506 4, 4, 4, 4, 5, 5, 5, 5 });
1507
1508 std::vector<float> input1({
1509 1, 1, 1, 1, 2, 2, 2, 2,
1510 4, 4, 4, 4, 4, 4, 4, 4 });
1511
1512 std::vector<float> output({
1513 2, 2, 2, 2, 1.5, 1.5, 1.5, 1.5,
1514 1, 1, 1, 1, 1.25, 1.25, 1.25, 1.25 });
1515
David Beck5cd01f32018-09-12 16:00:08 +01001516
1517 return DivisionTestHelper<float>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001518 memoryManager,
David Beck5cd01f32018-09-12 16:00:08 +01001519 shape, input0, 1.0f, 0,
1520 shape, input1, 1.0f, 0,
1521 shape, output, 1.0f, 0);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001522}
1523
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001524LayerTestResult<float, 4> DivisionBroadcast1ElementTest(
1525 armnn::IWorkloadFactory& workloadFactory,
1526 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001527{
1528 unsigned int shape0[] = { 1, 2, 2, 2 };
1529 std::vector<float> input0({ 2, 4, 6, 8, 10, 12, 14, 16});
1530
1531 unsigned int shape1[] = { 1, 1, 1, 1 };
1532 std::vector<float> input1({ 2 });
1533
1534 std::vector<float> output({ 1, 2, 3, 4, 5, 6, 7, 8});
1535
David Beck5cd01f32018-09-12 16:00:08 +01001536
1537 return DivisionTestHelper<float>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001538 memoryManager,
David Beck5cd01f32018-09-12 16:00:08 +01001539 shape0, input0, 1.0f, 0,
1540 shape1, input1, 1.0f, 0,
1541 shape0, output, 1.0f, 0);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001542}
1543
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001544LayerTestResult<float, 4> DivisionBroadcast1DVectorTest(
1545 armnn::IWorkloadFactory& workloadFactory,
1546 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001547{
1548 unsigned int shape0[] = { 1, 3, 3, 2 };
1549 std::vector<float> input0({
1550 1, 4, 3, 8, 5, 12,
1551 7, 16, 9, 20, 11, 24,
1552 13, 28, 15, 32, 17, 36});
1553
1554 unsigned int shape1[] = { 1, 1, 1, 2 };
1555 std::vector<float> input1({ 1, 2 });
1556
1557 std::vector<float> output({
1558 1, 2, 3, 4, 5, 6,
1559 7, 8, 9, 10, 11, 12,
1560 13, 14, 15, 16, 17, 18});
1561
David Beck5cd01f32018-09-12 16:00:08 +01001562 return DivisionTestHelper<float>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001563 memoryManager,
David Beck5cd01f32018-09-12 16:00:08 +01001564 shape0, input0, 1.0f, 0,
1565 shape1, input1, 1.0f, 0,
1566 shape0, output, 1.0f, 0);
1567}
1568
1569
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001570LayerTestResult<uint8_t,4> DivisionUint8Test(
1571 armnn::IWorkloadFactory& workloadFactory,
1572 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beck5cd01f32018-09-12 16:00:08 +01001573{
1574 const unsigned int width = 2;
1575 const unsigned int height = 2;
1576 const unsigned int channelCount = 2;
1577 const unsigned int batchSize = 2;
1578
1579 unsigned int shape[] = { batchSize, channelCount, height, width };
1580
1581 std::vector<uint8_t> input0({2, 2, 2, 2, 3, 3, 3, 3,
1582 4, 4, 4, 4, 5, 5, 5, 5 });
1583
1584 std::vector<uint8_t> input1({1, 1, 1, 1, 2, 2, 2, 2,
1585 4, 4, 4, 4, 4, 4, 4, 4 });
1586
1587 std::vector<uint8_t> output({8, 8, 8, 8, 6, 6, 6, 6,
1588 4, 4, 4, 4, 5, 5, 5, 5});
1589
1590
1591 return DivisionTestHelper<uint8_t>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001592 memoryManager,
1593 shape, input0, 1.0f, 0,
1594 shape, input1, 1.0f, 0,
1595 shape, output, 0.25f, 0);
David Beck5cd01f32018-09-12 16:00:08 +01001596}
1597
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001598LayerTestResult<uint8_t, 4> DivisionBroadcast1ElementUint8Test(
1599 armnn::IWorkloadFactory& workloadFactory,
1600 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beck5cd01f32018-09-12 16:00:08 +01001601{
1602 unsigned int shape0[] = { 1, 2, 2, 2 };
1603 std::vector<uint8_t> input0({ 2, 4, 6, 8, 10, 12, 14, 16});
1604
1605 unsigned int shape1[] = { 1, 1, 1, 1 };
1606 std::vector<uint8_t> input1({ 2 });
1607
1608 std::vector<uint8_t> output({ 1, 2, 3, 4, 5, 6, 7, 8});
1609
1610 return DivisionTestHelper<uint8_t>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001611 memoryManager,
1612 shape0, input0, 1.0f, 0,
1613 shape1, input1, 1.0f, 0,
1614 shape0, output, 1.0f, 0);
David Beck5cd01f32018-09-12 16:00:08 +01001615}
1616
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001617LayerTestResult<uint8_t, 4> DivisionBroadcast1DVectorUint8Test(
1618 armnn::IWorkloadFactory& workloadFactory,
1619 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beck5cd01f32018-09-12 16:00:08 +01001620{
1621 unsigned int shape0[] = { 1, 3, 3, 2 };
1622 std::vector<uint8_t> input0({1, 4, 3, 8, 5, 12,
1623 7, 16, 9, 20, 11, 24,
1624 13, 28, 15, 32, 17, 36});
1625
1626 unsigned int shape1[] = { 1, 1, 1, 2 };
1627 std::vector<uint8_t> input1({ 1, 2 });
1628
1629 std::vector<uint8_t> output({1, 2, 3, 4, 5, 6,
1630 7, 8, 9, 10, 11, 12,
1631 13, 14, 15, 16, 17, 18});
1632
1633 return DivisionTestHelper<uint8_t>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001634 memoryManager,
1635 shape0, input0, 1.0f, 0,
1636 shape1, input1, 1.0f, 0,
1637 shape0, output, 1.0f, 0);
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001638}
1639
Éanna Ó Catháinde705582018-12-03 13:04:22 +00001640template<typename DescriptorType>
1641std::unique_ptr<armnn::IWorkload> CreateWorkload(
1642 const armnn::IWorkloadFactory& workloadFactory,
1643 const armnn::WorkloadInfo& info,
1644 const DescriptorType& descriptor)
1645{
1646 return CreateWorkload(workloadFactory, info, descriptor);
1647};
1648
1649template<>
1650std::unique_ptr<armnn::IWorkload> CreateWorkload<armnn::MaximumQueueDescriptor>(
1651 const armnn::IWorkloadFactory& workloadFactory,
1652 const armnn::WorkloadInfo& info,
1653 const armnn::MaximumQueueDescriptor& descriptor)
1654{
1655 return workloadFactory.CreateMaximum(descriptor, info);
1656}
1657
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001658template<>
1659std::unique_ptr<armnn::IWorkload> CreateWorkload<armnn::MinimumQueueDescriptor>(
1660 const armnn::IWorkloadFactory& workloadFactory,
1661 const armnn::WorkloadInfo& info,
1662 const armnn::MinimumQueueDescriptor& descriptor)
1663{
1664 return workloadFactory.CreateMinimum(descriptor, info);
1665}
1666
Éanna Ó Catháinde705582018-12-03 13:04:22 +00001667namespace {
1668 template <typename Descriptor, typename dataType>
1669 LayerTestResult<dataType, 4> ElementwiseTestHelper
1670 (armnn::IWorkloadFactory & workloadFactory,
1671 const armnn::IBackendInternal::IMemoryManagerSharedPtr & memoryManager,
1672 const unsigned int shape0[4], std::vector<dataType> values0,
1673 const unsigned int shape1[4], std::vector<dataType> values1,
1674 const unsigned int outShape[4], std::vector<dataType> outValues,
1675 float qScale = 0.0f, int qOffset = 0)
1676 {
1677 const size_t dimensionCount = 4;
1678 armnn::TensorInfo inputTensorInfo0{dimensionCount, shape0, armnn::GetDataType<dataType>()};
1679 armnn::TensorInfo inputTensorInfo1{dimensionCount, shape1, armnn::GetDataType<dataType>()};
1680 armnn::TensorInfo outputTensorInfo{dimensionCount, outShape, armnn::GetDataType<dataType>()};
1681
1682 auto input0 = MakeTensor<dataType, 4>(inputTensorInfo0, values0);
1683 auto input1 = MakeTensor<dataType, 4>(inputTensorInfo1, values1);
1684
1685 if (armnn::IsQuantizedType<dataType>())
1686 {
1687 inputTensorInfo0.SetQuantizationScale(qScale);
1688 inputTensorInfo0.SetQuantizationOffset(qOffset);
1689
1690 inputTensorInfo1.SetQuantizationScale(qScale);
1691 inputTensorInfo1.SetQuantizationOffset(qOffset);
1692
1693 outputTensorInfo.SetQuantizationScale(qScale);
1694 outputTensorInfo.SetQuantizationOffset(qOffset);
1695 }
1696
1697 LayerTestResult<dataType,4> ret(outputTensorInfo);
1698
1699 std::unique_ptr<armnn::ITensorHandle> inputHandle0 = workloadFactory.CreateTensorHandle(inputTensorInfo0);
1700 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
1701 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
1702
1703 Descriptor data;
1704 armnn::WorkloadInfo info;
1705 AddInputToWorkload(data, info, inputTensorInfo0, inputHandle0.get());
1706 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
1707 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1708 auto workload = CreateWorkload<Descriptor>(workloadFactory, info, data);
1709
1710 inputHandle0->Allocate();
1711 inputHandle1->Allocate();
1712 outputHandle->Allocate();
1713
1714 CopyDataToITensorHandle(inputHandle0.get(), &input0[0][0][0][0]);
1715 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
1716
1717 ExecuteWorkload(*workload, memoryManager);
1718
1719 CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
1720
1721 ret.outputExpected = MakeTensor<dataType, 4>(outputTensorInfo, outValues);
1722 return ret;
1723 }
1724}
1725
1726
1727LayerTestResult<float, 4> MaximumSimpleTest(armnn::IWorkloadFactory& workloadFactory,
1728 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
1729{
1730 const unsigned int width = 2;
1731 const unsigned int height = 2;
1732 const unsigned int channelCount = 2;
1733 const unsigned int batchSize = 2;
1734
1735 unsigned int shape[] = { batchSize, channelCount, height, width };
1736
1737 std::vector<float> input0({ 1, 1, 1, 1, 5, 5, 5, 5,
1738 3, 3, 3, 3, 4, 4, 4, 4 });
1739
1740 std::vector<float> input1({ 2, 2, 2, 2, 3, 3, 3, 3,
1741 4, 4, 4, 4, 5, 5, 5, 5 });
1742
1743 std::vector<float> output({ 2, 2, 2, 2, 5, 5, 5, 5,
1744 4, 4, 4, 4, 5, 5, 5, 5 });
1745
1746 return ElementwiseTestHelper<armnn::MaximumQueueDescriptor, float>
1747 (workloadFactory,
1748 memoryManager,
1749 shape,
1750 input0,
1751 shape,
1752 input1,
1753 shape,
1754 output);
1755}
1756
1757LayerTestResult<float, 4> MaximumBroadcast1ElementTest(
1758 armnn::IWorkloadFactory& workloadFactory,
1759 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
1760{
1761 unsigned int shape0[] = { 1, 2, 2, 2 };
1762 std::vector<float> input0({ 1, 2, 3, 4, 5, 6, 7, 8});
1763
1764 unsigned int shape1[] = { 1, 1, 1, 1 };
1765 std::vector<float> input1({ 2 });
1766
1767 std::vector<float> output({ 2, 2, 3, 4, 5, 6, 7, 8});
1768
1769 return ElementwiseTestHelper<armnn::MaximumQueueDescriptor, float>
1770 (workloadFactory,
1771 memoryManager,
1772 shape0,
1773 input0,
1774 shape1,
1775 input1,
1776 shape0,
1777 output);
1778}
1779
1780LayerTestResult<float, 4> MaximumBroadcast1DVectorTest(
1781 armnn::IWorkloadFactory& workloadFactory,
1782 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
1783{
1784 const unsigned int shape0[] = { 1, 2, 2, 3 };
1785 const unsigned int shape1[] = { 1, 1, 1, 3 };
1786
1787 std::vector<float> input0({ 1, 2, 3, 4, 5, 6,
1788 7, 8, 9, 10, 11, 12 });
1789
1790 std::vector<float> input1({ 1, 2, 3});
1791
1792 std::vector<float> output({ 1, 2, 3, 4, 5, 6,
1793 7, 8, 9, 10, 11, 12 });
1794
1795 return ElementwiseTestHelper<armnn::MaximumQueueDescriptor, float>
1796 (workloadFactory,
1797 memoryManager,
1798 shape0,
1799 input0,
1800 shape1,
1801 input1,
1802 shape0,
1803 output);
1804}
1805
1806LayerTestResult<uint8_t, 4> MaximumUint8Test(
1807 armnn::IWorkloadFactory& workloadFactory,
1808 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
1809{
1810 unsigned int shape[] = { 2, 2, 2, 2 };
1811
1812 // See dequantized values to the right.
1813 std::vector<uint8_t> input0({ 1, 1, 1, 1, 6, 6, 6, 6,
1814 3, 3, 3, 3, 4, 4, 4, 4 });
1815
1816 std::vector<uint8_t> input1({ 2, 2, 2, 2, 3, 3, 3, 3,
1817 4, 4, 4, 4, 5, 5, 5, 5 });
1818
1819 std::vector<uint8_t> output({ 2, 2, 2, 2, 6, 6, 6, 6,
1820 4, 4, 4, 4, 5, 5, 5, 5 });
1821
1822 return ElementwiseTestHelper<armnn::MaximumQueueDescriptor, uint8_t >
1823 (workloadFactory,
1824 memoryManager,
1825 shape,
1826 input0,
1827 shape,
1828 input1,
1829 shape,
1830 output,
1831 1.0f,
1832 0);
1833}
1834
1835LayerTestResult<uint8_t, 4> MaximumBroadcast1ElementUint8Test(
1836 armnn::IWorkloadFactory& workloadFactory,
1837 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
1838{
1839 const unsigned int shape0[] = { 1, 2, 2, 3 };
1840 const unsigned int shape1[] = { 1, 1, 1, 1 };
1841
1842 std::vector<uint8_t> input0({ 1, 2, 3, 4, 5, 6,
1843 7, 8, 9, 10, 11, 12 });
1844
1845 std::vector<uint8_t> input1({2});
1846
1847 std::vector<uint8_t> output({ 2, 2, 3, 4, 5, 6,
1848 7, 8, 9, 10, 11, 12 });
1849
1850 return ElementwiseTestHelper<armnn::MaximumQueueDescriptor, uint8_t >
1851 (workloadFactory,
1852 memoryManager,
1853 shape0,
1854 input0,
1855 shape1,
1856 input1,
1857 shape0,
1858 output,
1859 1.0f,
1860 0);
1861}
1862
1863LayerTestResult<uint8_t, 4> MaximumBroadcast1DVectorUint8Test(
1864 armnn::IWorkloadFactory& workloadFactory,
1865 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
1866{
1867 const unsigned int shape0[] = { 1, 2, 2, 3 };
1868 const unsigned int shape1[] = { 1, 1, 1, 3 };
1869
1870 std::vector<uint8_t> input0({ 1, 2, 3, 4, 5, 6,
1871 7, 8, 9, 10, 11, 12 });
1872
1873 std::vector<uint8_t> input1({ 1, 10, 3});
1874
1875 std::vector<uint8_t> output({ 1, 10, 3, 4, 10, 6,
1876 7, 10, 9, 10, 11, 12 });
1877
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001878 return ElementwiseTestHelper<armnn::MaximumQueueDescriptor, uint8_t>
Éanna Ó Catháinde705582018-12-03 13:04:22 +00001879 (workloadFactory,
1880 memoryManager,
1881 shape0,
1882 input0,
1883 shape1,
1884 input1,
1885 shape0,
1886 output,
1887 1.0f,
1888 0);
1889}
1890
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001891LayerTestResult<float, 4> MinimumBroadcast1ElementTest1(
1892 armnn::IWorkloadFactory& workloadFactory,
1893 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
1894{
1895 unsigned int shape0[] = { 1, 2, 2, 2 };
1896 std::vector<float> input0({ 1, 2, 3, 4, 5, 6, 7, 8});
1897
1898 unsigned int shape1[] = { 1, 1, 1, 1 };
1899 std::vector<float> input1({ 2 });
1900
1901 std::vector<float> output({ 1, 2, 2, 2, 2, 2, 2, 2});
1902
1903 return ElementwiseTestHelper<armnn::MinimumQueueDescriptor, float>(workloadFactory,
1904 memoryManager,
1905 shape0,
1906 input0,
1907 shape1,
1908 input1,
1909 shape0,
1910 output);
1911}
1912
1913
1914LayerTestResult<float, 4> MinimumBroadcast1ElementTest2(
1915 armnn::IWorkloadFactory& workloadFactory,
1916 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
1917{
1918 unsigned int shape0[] = { 1, 2, 2, 2 };
1919 std::vector<float> input0({ 1, 6, 3, 2, 8, 9, 1, 10});
1920
1921 unsigned int shape1[] = { 1, 1, 1, 1 };
1922 std::vector<float> input1({ 5 });
1923
1924 std::vector<float> output({ 1, 5, 3, 2, 5, 5, 1, 5});
1925
1926 return ElementwiseTestHelper<armnn::MinimumQueueDescriptor, float>(workloadFactory,
1927 memoryManager,
1928 shape0,
1929 input0,
1930 shape1,
1931 input1,
1932 shape0,
1933 output);
1934}
1935
1936LayerTestResult<uint8_t, 4> MinimumBroadcast1DVectorUint8Test(
1937 armnn::IWorkloadFactory & workloadFactory,
1938 const armnn::IBackendInternal::IMemoryManagerSharedPtr & memoryManager)
1939{
1940 const unsigned int shape0[] = { 1, 2, 2, 3 };
1941 const unsigned int shape1[] = { 1, 1, 1, 3 };
1942
1943 std::vector<uint8_t> input0({ 1, 2, 3, 3, 2, 1,
1944 7, 1, 2, 3, 4, 5 });
1945
1946 std::vector<uint8_t> input1({ 1, 2, 3});
1947
1948 std::vector<uint8_t> output({ 1, 2, 3, 1, 2, 1,
1949 1, 1, 2, 1, 2, 3 });
1950
1951 return ElementwiseTestHelper<armnn::MinimumQueueDescriptor, uint8_t>(workloadFactory,
1952 memoryManager,
1953 shape0,
1954 input0,
1955 shape1,
1956 input1,
1957 shape0,
1958 output,
1959 1.0f,
1960 0);
1961}
1962
Francis Murtaghe7a86a42018-08-29 12:42:10 +01001963namespace {
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00001964LayerTestResult<float,4> MultiplicationTestHelper(
1965 armnn::IWorkloadFactory& workloadFactory,
1966 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
1967 const unsigned int shape0[4],
1968 const std::vector<float> & values0,
1969 const unsigned int shape1[4],
1970 const std::vector<float> & values1,
1971 const unsigned int outShape[4],
1972 const std::vector<float> & outValues)
telsoa014fcda012018-03-09 14:13:49 +00001973{
surmeh01bceff2f2018-03-29 16:29:27 +01001974 const size_t dimensionCount = 4;
1975 armnn::TensorInfo inputTensorInfo0{dimensionCount, shape0, armnn::DataType::Float32};
1976 armnn::TensorInfo inputTensorInfo1{dimensionCount, shape1, armnn::DataType::Float32};
1977 armnn::TensorInfo outputTensorInfo{dimensionCount, outShape, armnn::DataType::Float32};
telsoa014fcda012018-03-09 14:13:49 +00001978
surmeh01bceff2f2018-03-29 16:29:27 +01001979 auto input0 = MakeTensor<float, 4>(inputTensorInfo0, values0);
1980 auto input1 = MakeTensor<float, 4>(inputTensorInfo1, values1);
telsoa014fcda012018-03-09 14:13:49 +00001981
1982 LayerTestResult<float,4> ret(outputTensorInfo);
1983
1984 std::unique_ptr<armnn::ITensorHandle> inputHandle0 = workloadFactory.CreateTensorHandle(inputTensorInfo0);
1985 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
1986 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
1987
1988 armnn::MultiplicationQueueDescriptor data;
1989 armnn::WorkloadInfo info;
1990 AddInputToWorkload(data, info, inputTensorInfo0, inputHandle0.get());
1991 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
1992 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
1993
1994 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateMultiplication(data, info);
1995
1996 inputHandle0->Allocate();
1997 inputHandle1->Allocate();
1998 outputHandle->Allocate();
1999
2000 CopyDataToITensorHandle(inputHandle0.get(), &input0[0][0][0][0]);
2001 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
2002
2003 workload->Execute();
2004
2005 CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
2006
surmeh01bceff2f2018-03-29 16:29:27 +01002007 ret.outputExpected = MakeTensor<float, 4>(outputTensorInfo, outValues);
telsoa014fcda012018-03-09 14:13:49 +00002008 return ret;
2009}
surmeh01bceff2f2018-03-29 16:29:27 +01002010} // anonymous namespace
2011
2012
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002013LayerTestResult<float,4> MultiplicationTest(
2014 armnn::IWorkloadFactory& workloadFactory,
2015 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01002016{
2017 const unsigned int width = 2;
2018 const unsigned int height = 2;
2019 const unsigned int channelCount = 2;
2020 const unsigned int batchSize = 2;
2021
2022 unsigned int shape[] = { batchSize, channelCount, height, width };
2023
2024 std::vector<float> input0({
2025 1, 1, 1, 1, 2, 2, 2, 2,
2026 3, 3, 3, 3, 4, 4, 4, 4 });
2027
2028 std::vector<float> input1({
2029 2, 2, 2, 2, 3, 3, 3, 3,
2030 4, 4, 4, 4, 5, 5, 5, 5 });
2031
2032 std::vector<float> output({
2033 2, 2, 2, 2, 6, 6, 6, 6,
2034 12, 12, 12, 12, 20, 20, 20, 20 });
2035
2036 return MultiplicationTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002037 memoryManager,
surmeh01bceff2f2018-03-29 16:29:27 +01002038 shape,
2039 input0,
2040 shape,
2041 input1,
2042 shape,
2043 output);
2044}
2045
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002046LayerTestResult<float, 4> MultiplicationBroadcast1ElementTest(
2047 armnn::IWorkloadFactory& workloadFactory,
2048 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01002049{
2050 unsigned int shape0[] = { 1, 2, 2, 2 };
2051 std::vector<float> input0({ 1, 2, 3, 4, 5, 6, 7, 8});
2052
2053 unsigned int shape1[] = { 1, 1, 1, 1 };
2054 std::vector<float> input1({ 2 });
2055
2056 std::vector<float> output({ 2, 4, 6, 8, 10, 12, 14, 16});
2057
2058 return MultiplicationTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002059 memoryManager,
surmeh01bceff2f2018-03-29 16:29:27 +01002060 shape0,
2061 input0,
2062 shape1,
2063 input1,
2064 shape0,
2065 output);
2066}
2067
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002068LayerTestResult<float, 4> MultiplicationBroadcast1DVectorTest(
2069 armnn::IWorkloadFactory& workloadFactory,
2070 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01002071{
2072 unsigned int shape0[] = { 1, 3, 3, 2 };
2073 std::vector<float> input0({
2074 1, 2, 3, 4, 5, 6,
2075 7, 8, 9, 10, 11, 12,
2076 13, 14, 15, 16, 17, 18});
2077
2078 unsigned int shape1[] = { 1, 1, 1, 2 };
2079 std::vector<float> input1({ 1, 2 });
2080
2081 std::vector<float> output({
2082 1, 4, 3, 8, 5, 12,
2083 7, 16, 9, 20, 11, 24,
2084 13, 28, 15, 32, 17, 36});
2085
2086 return MultiplicationTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002087 memoryManager,
surmeh01bceff2f2018-03-29 16:29:27 +01002088 shape0,
2089 input0,
2090 shape1,
2091 input1,
2092 shape0,
2093 output);
2094}
telsoa014fcda012018-03-09 14:13:49 +00002095
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002096LayerTestResult<float,4> CompareMultiplicationTest(
2097 armnn::IWorkloadFactory& workloadFactory,
2098 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
2099 armnn::IWorkloadFactory& refWorkloadFactory)
telsoa014fcda012018-03-09 14:13:49 +00002100{
2101 const unsigned int width = 16;
2102 const unsigned int height = 32;
2103 const unsigned int channelCount = 2;
2104 const unsigned int batchSize = 5;
2105
2106 armnn::TensorInfo inputTensorInfo0;
2107 armnn::TensorInfo inputTensorInfo1;
2108 armnn::TensorInfo outputTensorInfo;
2109
2110 constexpr unsigned int shape[] = { batchSize, channelCount, height, width };
2111
2112 inputTensorInfo0 = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
2113 inputTensorInfo1 = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
2114 outputTensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
2115
2116 LayerTestResult<float,4> comparisonResult(outputTensorInfo);
2117
2118 auto input0 = MakeRandomTensor<float, 4>(inputTensorInfo0, 803506992);
2119 auto input1 = MakeRandomTensor<float, 4>(inputTensorInfo1, 54902257);
2120
2121 std::unique_ptr<armnn::ITensorHandle> inputHandle0 = workloadFactory.CreateTensorHandle(inputTensorInfo0);
2122 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
2123 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
2124
2125 std::unique_ptr<armnn::ITensorHandle> inputHandle0Ref = refWorkloadFactory.CreateTensorHandle(inputTensorInfo0);
2126 std::unique_ptr<armnn::ITensorHandle> inputHandle1Ref = refWorkloadFactory.CreateTensorHandle(inputTensorInfo1);
2127 std::unique_ptr<armnn::ITensorHandle> outputHandleRef = refWorkloadFactory.CreateTensorHandle(outputTensorInfo);
2128
2129 armnn::MultiplicationQueueDescriptor data;
2130 armnn::WorkloadInfo info;
2131 AddInputToWorkload(data, info, inputTensorInfo0, inputHandle0.get());
2132 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
2133 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
2134
2135 armnn::MultiplicationQueueDescriptor refData = data;
2136 armnn::WorkloadInfo refInfo = info;
2137 SetWorkloadInput(refData, refInfo, 0, inputTensorInfo0, inputHandle0Ref.get());
2138 SetWorkloadInput(refData, refInfo, 1, inputTensorInfo1, inputHandle1Ref.get());
2139 SetWorkloadOutput(refData, refInfo, 0, outputTensorInfo, outputHandleRef.get());
2140
2141 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateMultiplication(data, info);
2142 std::unique_ptr<armnn::IWorkload> workloadRef = refWorkloadFactory.CreateMultiplication(refData, refInfo);
2143
2144 inputHandle0->Allocate();
2145 inputHandle1->Allocate();
2146 outputHandle->Allocate();
2147 inputHandle0Ref->Allocate();
2148 inputHandle1Ref->Allocate();
2149 outputHandleRef->Allocate();
2150
2151 CopyDataToITensorHandle(inputHandle0.get(), &input0[0][0][0][0]);
2152 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
2153 CopyDataToITensorHandle(inputHandle0Ref.get(), &input0[0][0][0][0]);
2154 CopyDataToITensorHandle(inputHandle1Ref.get(), &input1[0][0][0][0]);
2155
2156 workload->Execute();
2157 workloadRef->Execute();
2158
2159 CopyDataFromITensorHandle(&comparisonResult.output[0][0][0][0], outputHandle.get());
2160 CopyDataFromITensorHandle(&comparisonResult.outputExpected[0][0][0][0], outputHandleRef.get());
2161
2162 return comparisonResult;
2163}
2164
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002165LayerTestResult<float,4> CompareBatchNormTest(
2166 armnn::IWorkloadFactory& workloadFactory,
2167 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
2168 armnn::IWorkloadFactory& refWorkloadFactory)
telsoa014fcda012018-03-09 14:13:49 +00002169{
2170 const unsigned int width = 2;
2171 const unsigned int height = 3;
2172 const unsigned int channels = 5;
2173 const unsigned int batchSize = 3;
2174
2175 armnn::TensorInfo inputTensorInfo;
2176 armnn::TensorInfo outputTensorInfo;
2177 armnn::TensorInfo tensorInfo;
2178
2179 constexpr unsigned int shape[] = {batchSize, channels, height, width};
2180 constexpr unsigned int tensorShape[] = {channels};
2181
2182 inputTensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
2183 outputTensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
2184 tensorInfo = armnn::TensorInfo(1, tensorShape, armnn::DataType::Float32);
2185
2186 auto input = MakeRandomTensor<float, 4>(inputTensorInfo, 21312);
2187
2188 auto mean = MakeRandomTensor<float, 1>(tensorInfo, 123);
2189 auto variance = MakeRandomTensor<float, 1>(tensorInfo, 234, 0.0f);
2190 auto beta = MakeRandomTensor<float, 1>(tensorInfo, 123);
2191 auto gamma = MakeRandomTensor<float, 1>(tensorInfo, 345);
2192
2193 LayerTestResult<float,4> ret(outputTensorInfo);
2194
2195 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
2196 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
2197
2198 std::unique_ptr<armnn::ITensorHandle> inputHandleRef = refWorkloadFactory.CreateTensorHandle(inputTensorInfo);
2199 std::unique_ptr<armnn::ITensorHandle> outputHandleRef = refWorkloadFactory.CreateTensorHandle(outputTensorInfo);
2200
2201 armnn::BatchNormalizationQueueDescriptor data;
2202 armnn::WorkloadInfo info;
2203 armnn::ScopedCpuTensorHandle meanTensor(tensorInfo);
2204 armnn::ScopedCpuTensorHandle varianceTensor(tensorInfo);
2205 armnn::ScopedCpuTensorHandle betaTensor(tensorInfo);
2206 armnn::ScopedCpuTensorHandle gammaTensor(tensorInfo);
2207
2208 AllocateAndCopyDataToITensorHandle(&meanTensor, &mean[0]);
2209 AllocateAndCopyDataToITensorHandle(&varianceTensor, &variance[0]);
2210 AllocateAndCopyDataToITensorHandle(&betaTensor, &beta[0]);
2211 AllocateAndCopyDataToITensorHandle(&gammaTensor, &gamma[0]);
2212
2213 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
2214 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
2215 data.m_Mean = &meanTensor;
2216 data.m_Variance = &varianceTensor;
2217 data.m_Beta = &betaTensor;
2218 data.m_Gamma = &gammaTensor;
2219 data.m_Parameters.m_Eps = 0.01f;
2220
2221 armnn::BatchNormalizationQueueDescriptor refData = data;
2222 armnn::WorkloadInfo refInfo = info;
2223 SetWorkloadInput(refData, refInfo, 0, inputTensorInfo, inputHandleRef.get());
2224 SetWorkloadOutput(refData, refInfo, 0, outputTensorInfo, outputHandleRef.get());
2225
2226 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateBatchNormalization(data, info);
2227 std::unique_ptr<armnn::IWorkload> workloadRef = refWorkloadFactory.CreateBatchNormalization(refData, refInfo);
2228
2229 inputHandle->Allocate();
2230 outputHandle->Allocate();
2231 inputHandleRef->Allocate();
2232 outputHandleRef->Allocate();
2233
2234 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
2235 CopyDataToITensorHandle(inputHandleRef.get(), &input[0][0][0][0]);
2236
2237 workload->Execute();
2238 workloadRef->Execute();
2239
2240 CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get());
2241 CopyDataFromITensorHandle(&ret.outputExpected[0][0][0][0], outputHandleRef.get());
2242
2243 return ret;
2244}
2245
surmeh013537c2c2018-05-18 16:31:43 +01002246template<typename T>
2247void PermuteTensorData(
2248 armnn::IWorkloadFactory& workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002249 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
surmeh013537c2c2018-05-18 16:31:43 +01002250 const armnn::PermutationVector& mappings,
2251 armnn::TensorInfo & inputTensorInfo,
2252 const T * inputData,
2253 std::vector<T>& outputData)
telsoa014fcda012018-03-09 14:13:49 +00002254{
surmeh013537c2c2018-05-18 16:31:43 +01002255 BOOST_ASSERT_MSG(inputData != nullptr, "inputData must not be null");
2256 if (inputData == nullptr)
2257 {
2258 // Nullptr is an error in the test. By returning without doing the concatenation
2259 // I expect the caller to fail the test. It still makes sense to report this as
2260 // an assert for Debug builds.
2261 return;
2262 }
telsoa014fcda012018-03-09 14:13:49 +00002263
surmeh013537c2c2018-05-18 16:31:43 +01002264 armnn::TensorInfo outputTensorInfo = armnnUtils::Permuted(inputTensorInfo, mappings);
2265
2266 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
2267 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
2268
2269 armnn::PermuteQueueDescriptor queueDescriptor;
2270 queueDescriptor.m_Parameters = armnn::PermuteDescriptor{mappings};
2271 armnn::WorkloadInfo workloadInfo;
2272 AddInputToWorkload(queueDescriptor, workloadInfo, inputTensorInfo, inputHandle.get());
2273 AddOutputToWorkload(queueDescriptor, workloadInfo, outputTensorInfo, outputHandle.get());
2274
2275 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreatePermute(queueDescriptor, workloadInfo);
2276
2277 inputHandle->Allocate();
2278 outputHandle->Allocate();
2279
2280 CopyDataToITensorHandle(inputHandle.get(), inputData);
2281
2282 workload->Execute();
2283
2284 outputData.resize(outputTensorInfo.GetNumElements());
2285 CopyDataFromITensorHandle(&outputData[0], outputHandle.get());
2286 inputTensorInfo = outputTensorInfo;
2287}
2288
2289armnn::OriginsDescriptor CreateMergerDescriptorForConcatenation(
2290 const std::vector<armnn::TensorInfo> & inputTensorInfos,
2291 unsigned int concatDim)
2292{
telsoa014fcda012018-03-09 14:13:49 +00002293 std::vector<armnn::TensorShape> shapes;
2294 shapes.reserve(inputTensorInfos.size());
2295 for (const armnn::TensorInfo& it: inputTensorInfos)
2296 {
2297 shapes.push_back(it.GetShape());
2298 }
surmeh013537c2c2018-05-18 16:31:43 +01002299
2300 return armnn::CreateMergerDescriptorForConcatenation(shapes.begin(),
2301 shapes.end(),
2302 concatDim);
2303}
2304
2305//
narpra015cdda352018-11-19 15:30:27 +00002306// Concatenation is only supported for N and C dimensions for NCHW and the inner most dimension
2307// In case of <4 dimensions we need to make sure that the concat dimensions are at least
2308// the 3rd slowest iterating one or the inner most dimension.
surmeh013537c2c2018-05-18 16:31:43 +01002309//
2310
2311bool NeedPermuteForConcat(
2312 const std::vector<armnn::TensorInfo> & inputTensorInfos,
2313 unsigned int concatDim)
2314{
2315 // See note above. Additionally we expect the input shapes to have the
2316 // same number of dimensions.
2317 unsigned int nDimensions = 0;
2318
telsoa01c577f2c2018-08-31 09:22:23 +01002319 // Determine the number of dimensions as well as sanity check them
2320 // agains test implementation issues.
surmeh013537c2c2018-05-18 16:31:43 +01002321 for (auto && tensorInfo : inputTensorInfos)
2322 {
2323 if (!nDimensions)
2324 {
2325 nDimensions = tensorInfo.GetShape().GetNumDimensions();
2326 }
2327 else
2328 {
2329 BOOST_ASSERT_MSG(nDimensions == tensorInfo.GetShape().GetNumDimensions(),
2330 "Input shapes must have the same number of dimensions");
2331 }
2332 }
2333
narpra015cdda352018-11-19 15:30:27 +00002334 return (nDimensions < 3 || (nDimensions == 3 && (nDimensions-concatDim) < 3 && (nDimensions-concatDim) != 1));
surmeh013537c2c2018-05-18 16:31:43 +01002335}
2336
2337armnn::TensorShape ExpandTensorShapeTo3dForPermute(const armnn::TensorShape & inputShape)
2338{
2339 unsigned int numDims = inputShape.GetNumDimensions();
2340 if (numDims >= 3)
2341 {
2342 // Nothing to do if the inputShape has at least 3 dimensions.
2343 return inputShape;
2344 }
2345
2346 std::vector<unsigned int> newDims(size_t(3), 1u);
2347 unsigned int expandedBy = 3 - numDims;
2348 for (unsigned int i=0; i<numDims; ++i)
2349 {
2350 newDims[expandedBy+i] = inputShape[i];
2351 }
2352 return armnn::TensorShape(3u, &newDims[0]);
2353}
2354
2355void Generate3dPermuteVectorForConcat(
2356 unsigned int numDimensions,
2357 unsigned int & concatDim,
2358 std::pair<armnn::PermutationVector, armnn::PermutationVector> & permutations)
2359{
2360 BOOST_ASSERT_MSG(numDimensions <= 3,
2361 "Only dimensions 1,2 and 3 are supported by this helper");
surmeh013537c2c2018-05-18 16:31:43 +01002362 unsigned int expandedBy = 3 - numDimensions;
2363 unsigned int expandedConcatAxis = concatDim + expandedBy;
2364
2365 if (expandedConcatAxis == 2)
2366 {
2367 concatDim = 0;
2368 armnn::PermutationVector forwardPermutation({1, 2, 0});
2369 armnn::PermutationVector reversePermutation({2, 0, 1});
2370 permutations = std::make_pair(forwardPermutation, reversePermutation);
2371 }
2372 else if (expandedConcatAxis == 1)
2373 {
2374 concatDim = 0;
2375 armnn::PermutationVector forwardPermutation({2, 0, 1});
2376 armnn::PermutationVector reversePermutation({1, 2, 0});
2377 permutations = std::make_pair(forwardPermutation, reversePermutation);
2378 }
2379 else
2380 {
2381 BOOST_ASSERT(expandedConcatAxis == 0);
2382 concatDim = 0;
2383 }
2384}
2385
2386//
2387// Permute the input tensors so we can do a supported concatenation.
2388// Also treat lower than 3d tensors as 3d by adding dummy 1 dimensions
2389// at the front. Finally this function tells what the output shape
2390// of the permuted concatenated tensor is going to be.
2391//
2392template <typename T>
2393void PermuteInputsForConcat(
2394 armnn::IWorkloadFactory& workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002395 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
surmeh013537c2c2018-05-18 16:31:43 +01002396 std::vector<armnn::TensorInfo> & inputTensorInfos,
2397 std::vector<T *> & inputData,
2398 std::vector<std::vector<T>> & inputDataStorage,
2399 armnn::PermutationVector & permuteVector,
2400 unsigned int & concatDim,
2401 armnn::TensorInfo & outputTensorInfo)
2402{
2403 BOOST_ASSERT_MSG(inputTensorInfos.size() > 1,
2404 "Expecting more than one tensor to be concatenated here");
2405
2406 unsigned int numDims = 0;
2407 unsigned int nthInput = 0;
2408 const armnn::PermutationVector identity({0, 1, 2});
2409
2410 std::pair<armnn::PermutationVector, armnn::PermutationVector> permutations =
2411 std::make_pair(identity, identity);
2412
2413 inputDataStorage.resize(inputData.size());
2414
2415 for (auto && tensorInfo : inputTensorInfos)
2416 {
2417 if (numDims == 0)
2418 {
2419 numDims = tensorInfo.GetShape().GetNumDimensions();
2420 Generate3dPermuteVectorForConcat(numDims, concatDim, permutations);
narpra015cdda352018-11-19 15:30:27 +00002421
telsoa01c577f2c2018-08-31 09:22:23 +01002422 // Store the reverese permutation.
surmeh013537c2c2018-05-18 16:31:43 +01002423 permuteVector = permutations.second;
2424 BOOST_ASSERT_MSG(!permuteVector.IsEqual(identity),
2425 "Test logic error, we don't need permutation, so we shouldn't arrive here");
2426 }
2427 else
2428 {
2429 BOOST_ASSERT_MSG(numDims == tensorInfo.GetShape().GetNumDimensions(),
2430 "All inputs must have the same number of dimensions");
2431 }
2432
2433 armnn::TensorInfo newTensorInfo = tensorInfo;
2434 newTensorInfo.SetShape(ExpandTensorShapeTo3dForPermute(tensorInfo.GetShape()));
2435
2436 PermuteTensorData<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002437 memoryManager,
surmeh013537c2c2018-05-18 16:31:43 +01002438 permutations.first,
2439 newTensorInfo,
2440 inputData[nthInput],
2441 inputDataStorage[nthInput]);
2442
2443 inputData[nthInput] = inputDataStorage[nthInput].data();
2444 inputTensorInfos[nthInput] = newTensorInfo;
2445
2446 ++nthInput;
2447 }
2448
2449 outputTensorInfo.SetShape(
2450 armnnUtils::Permuted(
2451 ExpandTensorShapeTo3dForPermute(outputTensorInfo.GetShape()),
2452 permutations.first));
2453}
2454
2455
2456//
2457// This is the pair of PermuteInputsForConcat(...) which permutes back
telsoa01c577f2c2018-08-31 09:22:23 +01002458// the output of the concatenation so we can check it against an expected
surmeh013537c2c2018-05-18 16:31:43 +01002459// output.
2460//
2461template <typename T>
2462void PermuteOutputForConcat(
2463 armnn::IWorkloadFactory& workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002464 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
surmeh013537c2c2018-05-18 16:31:43 +01002465 const armnn::TensorInfo & tensorInfo,
2466 const armnn::PermutationVector & permuteVector,
2467 std::unique_ptr<armnn::ITensorHandle> && inputDataHandle,
2468 T * data)
2469{
2470 BOOST_ASSERT_MSG(data != nullptr, "data must not be null");
2471 if (data == nullptr)
2472 {
2473 // Nullptr is an error in the test. By returning without doing the permutation
2474 // I expect the caller to fail the test. It still makes sense to report this as
2475 // an assert for Debug builds.
2476 return;
2477 }
2478
2479 armnn::TensorInfo resultTensorInfo = tensorInfo;
2480 std::vector<T> inputData(tensorInfo.GetNumElements());
2481 std::vector<T> outputData;
2482
2483 CopyDataFromITensorHandle(&inputData[0], inputDataHandle.get());
2484
2485 PermuteTensorData<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002486 memoryManager,
surmeh013537c2c2018-05-18 16:31:43 +01002487 permuteVector,
2488 resultTensorInfo,
2489 &inputData[0],
2490 outputData);
2491
2492 ::memcpy(data, &outputData[0], sizeof(T)*outputData.size());
2493}
2494
2495template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002496void Concatenate(
2497 armnn::IWorkloadFactory& workloadFactory,
2498 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
2499 std::initializer_list<const armnn::TensorInfo> inputTensorInfosOrig,
2500 std::initializer_list<T *> inputsOrig,
2501 const armnn::TensorInfo& outputTensorInfoOrig,
2502 T * output,
narpra015cdda352018-11-19 15:30:27 +00002503 unsigned int concatDim,
2504 bool useSubtensor)
surmeh013537c2c2018-05-18 16:31:43 +01002505{
2506 BOOST_ASSERT_MSG(output != nullptr, "output must not be null");
2507 if (output == nullptr)
2508 {
2509 // Nullptr is an error in the test. By returning without doing the permutation
2510 // I expect the caller to fail the test. It still makes sense to report this as
2511 // an assert for Debug builds.
2512 return;
2513 }
2514
telsoa01c577f2c2018-08-31 09:22:23 +01002515 // Saves a copy of the parameters which we might need to change.
surmeh013537c2c2018-05-18 16:31:43 +01002516 std::vector<armnn::TensorInfo> inputTensorInfos(inputTensorInfosOrig.begin(), inputTensorInfosOrig.end());
2517 std::vector<T *> inputs = inputsOrig;
2518 armnn::TensorInfo outputTensorInfo = outputTensorInfoOrig;
2519
2520 armnn::PermutationVector permuteVector{0, 1, 2};
2521
telsoa01c577f2c2018-08-31 09:22:23 +01002522 // Holds and automatically releases memory for the reshaped input data.
surmeh013537c2c2018-05-18 16:31:43 +01002523 std::vector<std::vector<T>> tmpInputDataStorage;
2524
2525 const size_t inputCount = inputTensorInfos.size();
2526
2527 bool needPermuteForConcat = NeedPermuteForConcat(inputTensorInfos, concatDim);
2528
2529 if (needPermuteForConcat)
2530 {
2531 //
2532 // We need to permute the inputs, because concatenation along
telsoa01c577f2c2018-08-31 09:22:23 +01002533 // the requested axis is not supported.
surmeh013537c2c2018-05-18 16:31:43 +01002534 //
2535 PermuteInputsForConcat<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002536 memoryManager,
surmeh013537c2c2018-05-18 16:31:43 +01002537 inputTensorInfos,
2538 inputs,
2539 tmpInputDataStorage,
2540 permuteVector,
2541 concatDim,
2542 outputTensorInfo);
2543 }
2544
narpra015cdda352018-11-19 15:30:27 +00002545 armnn::WorkloadInfo workloadInfo;
telsoa014fcda012018-03-09 14:13:49 +00002546
2547 std::vector<std::unique_ptr<armnn::ITensorHandle>> inputHandles;
2548 inputHandles.reserve(inputCount);
2549
narpra015cdda352018-11-19 15:30:27 +00002550 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
2551
2552 armnn::MergerQueueDescriptor queueDescriptor;
2553 armnn::OriginsDescriptor viewsDescriptor = CreateMergerDescriptorForConcatenation(inputTensorInfos, concatDim);
2554 queueDescriptor.m_Parameters = viewsDescriptor;
2555
2556 if (useSubtensor)
telsoa014fcda012018-03-09 14:13:49 +00002557 {
narpra015cdda352018-11-19 15:30:27 +00002558 queueDescriptor.m_ViewOrigins.reserve(viewsDescriptor.GetNumViews());
2559 for (unsigned int i = 0; i < viewsDescriptor.GetNumViews(); ++i)
2560 {
2561 queueDescriptor.m_ViewOrigins.emplace_back(std::vector<unsigned int>(viewsDescriptor.GetViewOrigin(i),
2562 viewsDescriptor.GetViewOrigin(i) + viewsDescriptor.GetNumDimensions()));
2563 }
telsoa014fcda012018-03-09 14:13:49 +00002564
narpra015cdda352018-11-19 15:30:27 +00002565 outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
telsoa014fcda012018-03-09 14:13:49 +00002566
narpra015cdda352018-11-19 15:30:27 +00002567 const bool subTensorsSupported = workloadFactory.SupportsSubTensors();
2568 for (unsigned int i = 0; i < inputCount; ++i)
2569 {
2570 const armnn::TensorInfo& inputTensorInfo = inputTensorInfos[i];
2571 std::unique_ptr<armnn::ITensorHandle> inputHandle =
2572 subTensorsSupported ?
2573 workloadFactory.CreateSubTensorHandle(*outputHandle,
2574 inputTensorInfo.GetShape(),
2575 queueDescriptor.m_ViewOrigins[i].m_Origin.data()) :
2576 workloadFactory.CreateTensorHandle(inputTensorInfo);
2577
2578 inputHandles.emplace_back(std::move(inputHandle));
2579 }
2580
telsoa014fcda012018-03-09 14:13:49 +00002581 }
narpra015cdda352018-11-19 15:30:27 +00002582 else
2583 {
2584 for (unsigned int i = 0; i < inputCount; ++i)
2585 {
2586 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfos[i]);
2587 inputHandles.emplace_back(std::move(inputHandle));
2588 }
2589 }
telsoa014fcda012018-03-09 14:13:49 +00002590
2591 for (unsigned int i = 0; i < inputCount; ++i)
2592 {
surmeh013537c2c2018-05-18 16:31:43 +01002593 AddInputToWorkload(queueDescriptor, workloadInfo, inputTensorInfos[i], inputHandles[i].get());
telsoa014fcda012018-03-09 14:13:49 +00002594 }
2595
2596 AddOutputToWorkload(queueDescriptor, workloadInfo, outputTensorInfo, outputHandle.get());
2597
2598 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateMerger(queueDescriptor, workloadInfo);
2599
2600 for (auto& inputHandle : inputHandles)
2601 {
2602 inputHandle->Allocate();
2603 }
2604
2605 outputHandle->Allocate();
2606
2607 unsigned int nextInputId = 0;
2608 for (auto& inputHandle : inputHandles)
2609 {
surmeh013537c2c2018-05-18 16:31:43 +01002610 CopyDataToITensorHandle(inputHandle.get(), inputs[nextInputId]);
2611 ++nextInputId;
telsoa014fcda012018-03-09 14:13:49 +00002612 }
2613
2614 workload->Execute();
2615
surmeh013537c2c2018-05-18 16:31:43 +01002616 if (needPermuteForConcat)
2617 {
2618 PermuteOutputForConcat<T>(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002619 memoryManager,
surmeh013537c2c2018-05-18 16:31:43 +01002620 outputTensorInfo,
2621 permuteVector,
2622 std::move(outputHandle),
2623 output);
2624 }
2625 else
2626 {
2627 CopyDataFromITensorHandle(output, outputHandle.get());
2628 }
telsoa014fcda012018-03-09 14:13:49 +00002629}
2630
2631template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002632LayerTestResult<T, 1> Concatenation1dTestImpl(
2633 armnn::IWorkloadFactory& workloadFactory,
2634 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
2635 float qScale,
2636 int32_t qOffset)
telsoa014fcda012018-03-09 14:13:49 +00002637{
2638 armnn::TensorInfo inputTensorInfo({ 3 }, armnn::GetDataType<T>());
2639
2640 auto input0 = MakeTensor<T, 1>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, { 1.0f, 2.0f, 3.0f }));
2641 auto input1 = MakeTensor<T, 1>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, { 4.0f, 5.0f, 6.0f }));
2642 auto input2 = MakeTensor<T, 1>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, { 7.0f, 8.0f, 9.0f }));
2643
2644 armnn::TensorInfo outputTensorInfo({ 9 }, armnn::GetDataType<T>());
2645
2646 LayerTestResult<T, 1> result(outputTensorInfo);
2647
2648 std::vector<T> output;
2649 output.resize(outputTensorInfo.GetNumElements());
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002650 Concatenate<T>(workloadFactory, memoryManager,
narpra015cdda352018-11-19 15:30:27 +00002651 { inputTensorInfo, inputTensorInfo, inputTensorInfo },
2652 { input0.data(), input1.data(), input2.data() },
2653 outputTensorInfo,
2654 output.data(),
2655 0,
2656 true);
telsoa014fcda012018-03-09 14:13:49 +00002657
2658 result.output = MakeTensor<T, 1>(outputTensorInfo, output);
2659 result.outputExpected = MakeTensor<T, 1>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
2660 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f
2661 }));
2662
2663 return result;
2664}
2665
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002666LayerTestResult<float, 1> Concatenation1dTest(
2667 armnn::IWorkloadFactory& workloadFactory,
2668 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00002669{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002670 return Concatenation1dTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00002671}
2672
2673template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002674LayerTestResult<T, 2> Concatenation2dTestImpl(
2675 armnn::IWorkloadFactory& workloadFactory,
2676 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
telsoa014fcda012018-03-09 14:13:49 +00002677 const armnn::TensorInfo& outputTensorInfo,
2678 unsigned int dimension,
2679 const float qScale,
2680 const int32_t qOffset)
2681{
2682 armnn::TensorInfo inputTensorInfo({ 2, 3 }, armnn::GetDataType<T>());
2683
2684 auto input0 = MakeTensor<T, 2>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
2685 // Batch 0
2686 1.0f, 2.0f, 3.0f,
2687
2688 // Batch 1
2689 10.0f, 11.0f, 12.0f,
2690 }));
2691
2692 auto input1 = MakeTensor<T, 2>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
2693 // Batch 0
2694 4.0f, 5.0f, 6.0f,
2695
2696 // Batch 1
2697 13.0f, 14.0f, 15.0f,
2698 }));
2699
2700 auto input2 = MakeTensor<T, 2>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
2701 // Batch 0
2702 7.0f, 8.0f, 9.0f,
2703
2704 // Batch 1
2705 16.0f, 17.0f, 18.0f,
2706 }));
2707
2708 LayerTestResult<T, 2> result(outputTensorInfo);
2709
2710 std::vector<T> output;
2711 output.resize(outputTensorInfo.GetNumElements());
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002712 Concatenate<T>(workloadFactory, memoryManager,
narpra015cdda352018-11-19 15:30:27 +00002713 { inputTensorInfo, inputTensorInfo, inputTensorInfo },
2714 { input0.data(), input1.data(), input2.data() },
2715 outputTensorInfo,
2716 output.data(),
2717 dimension,
2718 true);
telsoa014fcda012018-03-09 14:13:49 +00002719
2720 result.output = MakeTensor<T, 2>(outputTensorInfo, output);
2721 return result;
2722}
2723
2724template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002725LayerTestResult<T, 2> Concatenation2dDim0TestImpl(
2726 armnn::IWorkloadFactory& workloadFactory,
2727 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
2728 float qScale,
2729 int32_t qOffset)
telsoa014fcda012018-03-09 14:13:49 +00002730{
2731 armnn::TensorInfo outputTensorInfo({ 6, 3 }, armnn::GetDataType<T>());
2732
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002733 LayerTestResult<T, 2> result =
2734 Concatenation2dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 0, qScale, qOffset);
telsoa014fcda012018-03-09 14:13:49 +00002735 result.outputExpected = MakeTensor<T, 2>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
2736 // Batch 0
2737 1.0f, 2.0f, 3.0f,
2738
2739 // Batch 1
2740 10.0f, 11.0f, 12.0f,
2741
2742 // Batch 2
2743 4.0f, 5.0f, 6.0f,
2744
2745 // Batch 3
2746 13.0f, 14.0f, 15.0f,
2747
2748 // Batch 4
2749 7.0f, 8.0f, 9.0f,
2750
2751 // Batch 5
2752 16.0f, 17.0f, 18.0f,
2753 }));
2754
2755 return result;
2756}
2757
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002758LayerTestResult<float, 2> Concatenation2dDim0Test(
2759 armnn::IWorkloadFactory& workloadFactory,
2760 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00002761{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002762 return Concatenation2dDim0TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00002763}
2764
2765template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002766LayerTestResult<T, 2> Concatenation2dDim1TestImpl(
2767 armnn::IWorkloadFactory& workloadFactory,
2768 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
2769 float qScale,
2770 int32_t qOffset)
telsoa014fcda012018-03-09 14:13:49 +00002771{
2772 armnn::TensorInfo outputTensorInfo({ 2, 9 }, armnn::GetDataType<T>());
2773
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002774 LayerTestResult<T, 2> result =
2775 Concatenation2dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 1, qScale, qOffset);
telsoa014fcda012018-03-09 14:13:49 +00002776 result.outputExpected = MakeTensor<T, 2>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
2777 // Batch 0
2778 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f,
2779
2780 // Batch 1
2781 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f
2782 }));
2783
2784 return result;
2785}
2786
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002787LayerTestResult<float, 2> Concatenation2dDim1Test(
2788 armnn::IWorkloadFactory& workloadFactory,
2789 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00002790{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002791 return Concatenation2dDim1TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00002792}
2793
2794template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002795LayerTestResult<T, 2> Concatenation2dDim0DiffInputDimsTestImpl(
2796 armnn::IWorkloadFactory& workloadFactory,
2797 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
2798 float qScale,
telsoa014fcda012018-03-09 14:13:49 +00002799 int32_t qOffset)
2800{
2801 armnn::TensorInfo input0TensorInfo({ 2, 3 }, armnn::GetDataType<T>());
2802 auto input0 = MakeTensor<T, 2>(input0TensorInfo, QuantizedVector<T>(qScale, qOffset, {
2803 // Batch 0
2804 1.0f, 2.0f, 3.0f,
2805
2806 // Batch 1
2807 10.0f, 11.0f, 12.0f,
2808 }));
2809
2810 armnn::TensorInfo input1TensorInfo({ 3, 3 }, armnn::GetDataType<T>());
2811 auto input1 = MakeTensor<T, 2>(input1TensorInfo, QuantizedVector<T>(qScale, qOffset, {
2812 // Batch 0
2813 4.0f, 5.0f, 6.0f,
2814
2815 // Batch 1
2816 13.0f, 14.0f, 15.0f,
2817
2818 // Batch 0
2819 7.0f, 8.0f, 9.0f,
2820 }));
2821
2822 armnn::TensorInfo input2TensorInfo({ 1, 3 }, armnn::GetDataType<T>());
2823 auto input2 = MakeTensor<T, 2>(input2TensorInfo, QuantizedVector<T>(qScale, qOffset, {
2824 // Batch 1
2825 16.0f, 17.0f, 18.0f,
2826 }));
2827
2828 armnn::TensorInfo outputTensorInfo({ 6, 3 }, armnn::GetDataType<T>());
2829 LayerTestResult<T, 2> result(outputTensorInfo);
2830
2831 std::vector<T> output;
2832 output.resize(outputTensorInfo.GetNumElements());
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002833 Concatenate<T>(workloadFactory, memoryManager,
narpra015cdda352018-11-19 15:30:27 +00002834 { input0TensorInfo, input1TensorInfo, input2TensorInfo },
2835 { input0.data(), input1.data(), input2.data() },
2836 outputTensorInfo,
2837 output.data(),
2838 0,
2839 true);
telsoa014fcda012018-03-09 14:13:49 +00002840
2841 result.output = MakeTensor<T, 2>(outputTensorInfo, output);
2842 result.outputExpected = MakeTensor<T, 2>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
2843 // Batch 0
2844 1.0f, 2.0f, 3.0f,
2845
2846 // Batch 1
2847 10.0f, 11.0f, 12.0f,
2848
2849 // Batch 2
2850 4.0f, 5.0f, 6.0f,
2851
2852 // Batch 3
2853 13.0f, 14.0f, 15.0f,
2854
2855 // Batch 4
2856 7.0f, 8.0f, 9.0f,
2857
2858 // Batch 5
2859 16.0f, 17.0f, 18.0f,
2860 }));
2861
2862 return result;
2863}
2864
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002865LayerTestResult<float, 2> Concatenation2dDim0DiffInputDimsTest(
2866 armnn::IWorkloadFactory& workloadFactory,
2867 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00002868{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002869 return Concatenation2dDim0DiffInputDimsTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00002870}
2871
2872template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002873LayerTestResult<T, 2> Concatenation2dDim1DiffInputDimsTestImpl(
2874 armnn::IWorkloadFactory& workloadFactory,
2875 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
2876 float qScale,
telsoa014fcda012018-03-09 14:13:49 +00002877 int32_t qOffset)
2878{
2879 armnn::TensorInfo input0TensorInfo({ 2, 3 }, armnn::GetDataType<T>());
2880 auto input0 = MakeTensor<T, 2>(input0TensorInfo, QuantizedVector<T>(qScale, qOffset, {
2881 // Batch 0
2882 1.0f, 2.0f, 3.0f,
2883
2884 // Batch 1
2885 10.0f, 11.0f, 12.0f,
2886 }));
2887
2888 armnn::TensorInfo input1TensorInfo({ 2, 5 }, armnn::GetDataType<T>());
2889 auto input1 = MakeTensor<T, 2>(input1TensorInfo, QuantizedVector<T>(qScale, qOffset, {
2890 // Batch 0
2891 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
2892
2893 // Batch 1
2894 13.0f, 14.0f, 15.0f, 16.0f, 17.0f,
2895 }));
2896
2897 armnn::TensorInfo input2TensorInfo({ 2, 1 }, armnn::GetDataType<T>());
2898 auto input2 = MakeTensor<T, 2>(input2TensorInfo, QuantizedVector<T>(qScale, qOffset, {
2899 // Batch 0
2900 9.0f,
2901
2902 // Batch 1
2903 18.0f
2904 }));
2905
2906 armnn::TensorInfo outputTensorInfo({ 2, 9 }, armnn::GetDataType<T>());
2907 LayerTestResult<T, 2> result(outputTensorInfo);
2908
2909 std::vector<T> output;
2910 output.resize(outputTensorInfo.GetNumElements());
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002911 Concatenate<T>(workloadFactory, memoryManager,
narpra015cdda352018-11-19 15:30:27 +00002912 { input0TensorInfo, input1TensorInfo, input2TensorInfo },
2913 { input0.data(), input1.data(), input2.data() },
2914 outputTensorInfo,
2915 output.data(),
2916 1,
2917 true);
telsoa014fcda012018-03-09 14:13:49 +00002918
2919 result.output = MakeTensor<T, 2>(outputTensorInfo, output);
2920 result.outputExpected = MakeTensor<T, 2>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
2921 // Batch 0
2922 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f,
2923
2924 // Batch 1
2925 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f,
2926 }));
2927
2928 return result;
2929}
2930
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002931LayerTestResult<float, 2> Concatenation2dDim1DiffInputDimsTest(
2932 armnn::IWorkloadFactory& workloadFactory,
2933 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00002934{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002935 return Concatenation2dDim1DiffInputDimsTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00002936}
2937
2938template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00002939LayerTestResult<T, 3> Concatenation3dTestImpl(
2940 armnn::IWorkloadFactory& workloadFactory,
2941 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
telsoa014fcda012018-03-09 14:13:49 +00002942 const armnn::TensorInfo& outputTensorInfo,
2943 unsigned int dimension,
narpra015cdda352018-11-19 15:30:27 +00002944 bool useSubtensor,
telsoa014fcda012018-03-09 14:13:49 +00002945 float qScale,
2946 int32_t qOffset)
2947{
2948 armnn::TensorInfo inputTensorInfo({ 2, 3, 2 }, armnn::GetDataType<T>());
2949
2950 auto input0 = MakeTensor<T, 3>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
2951 // Batch 0, Channel 0
2952 1.0f, 2.0f,
2953
2954 // Batch 0, Channel 1
2955 3.0f, 4.0f,
2956
2957 // Batch 0, Channel 2
2958 5.0f, 6.0f,
2959
2960 // Batch 1, Channel 0
2961 19.0f, 20.0f,
2962
2963 // Batch 1, Channel 1
2964 21.0f, 22.0f,
2965
2966 // Batch 1, Channel 2
2967 23.0f, 24.0f
2968 }));
2969
2970 auto input1 = MakeTensor<T, 3>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
2971 // Batch 0, Channel 0
2972 7.0f, 8.0f,
2973
2974 // Batch 0, Channel 1
2975 9.0f, 10.0f,
2976
2977 // Batch 0, Channel 2
2978 11.0f, 12.0f,
2979
2980 // Batch 1, Channel 0
2981 25.0f, 26.0f,
2982
2983 // Batch 1, Channel 1
2984 27.0f, 28.0f,
2985
2986 // Batch 1, Channel 2
2987 29.0f, 30.0f
2988 }));
2989
2990 auto input2 = MakeTensor<T, 3>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
2991 // Batch 0, Channel 0
2992 13.0f, 14.0f,
2993
2994 // Batch 0, Channel 1
2995 15.0f, 16.0f,
2996
2997 // Batch 0, Channel 2
2998 17.0f, 18.0f,
2999
3000 // Batch 1, Channel 0
3001 31.0f, 32.0f,
3002
3003 // Batch 1, Channel 1
3004 33.0f, 34.0f,
3005
3006 // Batch 1, Channel 2
3007 35.0f, 36.0f
3008 }));
3009
3010 LayerTestResult<T, 3> result(outputTensorInfo);
3011
3012 std::vector<T> output;
3013 output.resize(outputTensorInfo.GetNumElements());
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003014 Concatenate<T>(workloadFactory, memoryManager,
narpra015cdda352018-11-19 15:30:27 +00003015 { inputTensorInfo, inputTensorInfo, inputTensorInfo },
3016 { input0.data(), input1.data(), input2.data() },
3017 outputTensorInfo,
3018 output.data(),
3019 dimension,
3020 useSubtensor);
telsoa014fcda012018-03-09 14:13:49 +00003021
3022 result.output = MakeTensor<T, 3>(outputTensorInfo, output);
3023 return result;
3024}
3025
3026template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003027LayerTestResult<T, 3> Concatenation3dDim0TestImpl(
3028 armnn::IWorkloadFactory& workloadFactory,
3029 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3030 float qScale,
telsoa014fcda012018-03-09 14:13:49 +00003031 int32_t qOffset)
3032{
3033 armnn::TensorInfo outputTensorInfo({ 6, 3, 2 }, armnn::GetDataType<T>());
3034
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003035 LayerTestResult<T, 3> result =
narpra015cdda352018-11-19 15:30:27 +00003036 Concatenation3dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 0, true, qScale, qOffset);
telsoa014fcda012018-03-09 14:13:49 +00003037 result.outputExpected = MakeTensor<T, 3>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3038 // Batch 0, Channel 0
3039 1.0f, 2.0f,
3040
3041 // Batch 0, Channel 1
3042 3.0f, 4.0f,
3043
3044 // Batch 0, Channel 2
3045 5.0f, 6.0f,
3046
3047 // Batch 1, Channel 0
3048 19.0f, 20.0f,
3049
3050 // Batch 1, Channel 1
3051 21.0f, 22.0f,
3052
3053 // Batch 1, Channel 2
3054 23.0f, 24.0f,
3055
3056 // Batch 2, Channel 0
3057 7.0f, 8.0f,
3058
3059 // Batch 2, Channel 1
3060 9.0f, 10.0f,
3061
3062 // Batch 2, Channel 2
3063 11.0f, 12.0f,
3064
3065 // Batch 3, Channel 0
3066 25.0f, 26.0f,
3067
3068 // Batch 3, Channel 1
3069 27.0f, 28.0f,
3070
3071 // Batch 3, Channel 2
3072 29.0f, 30.0f,
3073
3074 // Batch 4, Channel 0
3075 13.0f, 14.0f,
3076
3077 // Batch 4, Channel 1
3078 15.0f, 16.0f,
3079
3080 // Batch 4, Channel 2
3081 17.0f, 18.0f,
3082
3083 // Batch 5, Channel 0
3084 31.0f, 32.0f,
3085
3086 // Batch 5, Channel 1
3087 33.0f, 34.0f,
3088
3089 // Batch 5, Channel 2
3090 35.0f, 36.0f
3091 }));
narpra015cdda352018-11-19 15:30:27 +00003092
telsoa014fcda012018-03-09 14:13:49 +00003093 return result;
3094}
3095
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003096LayerTestResult<float, 3> Concatenation3dDim0Test(
3097 armnn::IWorkloadFactory& workloadFactory,
3098 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00003099{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003100 return Concatenation3dDim0TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00003101}
3102
3103template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003104LayerTestResult<T, 3> Concatenation3dDim1TestImpl(
3105 armnn::IWorkloadFactory& workloadFactory,
3106 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3107 float qScale,
3108 int32_t qOffset)
telsoa014fcda012018-03-09 14:13:49 +00003109{
3110 armnn::TensorInfo outputTensorInfo({ 2, 9, 2 }, armnn::GetDataType<T>());
3111
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003112 LayerTestResult<T, 3> result =
narpra015cdda352018-11-19 15:30:27 +00003113 Concatenation3dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 1, true, qScale, qOffset);
3114
telsoa014fcda012018-03-09 14:13:49 +00003115 result.outputExpected = MakeTensor<T, 3>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3116 // Batch 0, Channel 0
3117 1.0f, 2.0f,
3118
3119 // Batch 0, Channel 1
3120 3.0f, 4.0f,
3121
3122 // Batch 0, Channel 2
3123 5.0f, 6.0f,
3124
3125 // Batch 0, Channel 3
3126 7.0f, 8.0f,
3127
3128 // Batch 0, Channel 4
3129 9.0f, 10.0f,
3130
3131 // Batch 0, Channel 5
3132 11.0f, 12.0f,
3133
3134 // Batch 0, Channel 6
3135 13.0f, 14.0f,
3136
3137 // Batch 0, Channel 7
3138 15.0f, 16.0f,
3139
3140 // Batch 0, Channel 8
3141 17.0f, 18.0f,
3142
3143 // Batch 1, Channel 0
3144 19.0f, 20.0f,
3145
3146 // Batch 1, Channel 1
3147 21.0f, 22.0f,
3148
3149 // Batch 1, Channel 2
3150 23.0f, 24.0f,
3151
3152 // Batch 1, Channel 3
3153 25.0f, 26.0f,
3154
3155 // Batch 1, Channel 4
3156 27.0f, 28.0f,
3157
3158 // Batch 1, Channel 5
3159 29.0f, 30.0f,
3160
3161 // Batch 1, Channel 6
3162 31.0f, 32.0f,
3163
3164 // Batch 1, Channel 7
3165 33.0f, 34.0f,
3166
3167 // Batch 1, Channel 8
3168 35.0f, 36.0f
3169 }));
3170
3171 return result;
3172}
3173
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003174LayerTestResult<float, 3> Concatenation3dDim1Test(
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 Concatenation3dDim1TestImpl<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, 3> Concatenation3dDim2TestImpl(
3183 armnn::IWorkloadFactory& workloadFactory,
3184 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
narpra015cdda352018-11-19 15:30:27 +00003185 bool useSubtensor,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003186 float qScale,
3187 int32_t qOffset)
telsoa014fcda012018-03-09 14:13:49 +00003188{
3189 armnn::TensorInfo outputTensorInfo({ 2, 3, 6 }, armnn::GetDataType<T>());
3190
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003191 LayerTestResult<T, 3> result =
narpra015cdda352018-11-19 15:30:27 +00003192 Concatenation3dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 2, useSubtensor, qScale, qOffset);
3193
telsoa014fcda012018-03-09 14:13:49 +00003194 result.outputExpected = MakeTensor<T, 3>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3195 // Batch 0, Channel 0
3196 1.0f, 2.0f, 7.0f, 8.0f, 13.0f, 14.0f,
3197
3198 // Batch 0, Channel 1
3199 3.0f, 4.0f, 9.0f, 10.0f, 15.0f, 16.0f,
3200
3201 // Batch 0, Channel 2
3202 5.0f, 6.0f, 11.0f, 12.0f, 17.0f, 18.0f,
3203
3204 // Batch 1, Channel 0
3205 19.0f, 20.0f, 25.0f, 26.0f, 31.0f, 32.0f,
3206
3207 // Batch 1, Channel 1
3208 21.0f, 22.0f, 27.0f, 28.0f, 33.0f, 34.0f,
3209
3210 // Batch 1, Channel 2
3211 23.0f, 24.0f, 29.0f, 30.0f, 35.0f, 36.0f,
3212 }));
3213
3214 return result;
3215}
3216
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003217LayerTestResult<float, 3> Concatenation3dDim2Test(
3218 armnn::IWorkloadFactory& workloadFactory,
narpra015cdda352018-11-19 15:30:27 +00003219 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3220 bool useSubtensor)
telsoa014fcda012018-03-09 14:13:49 +00003221{
narpra015cdda352018-11-19 15:30:27 +00003222 return Concatenation3dDim2TestImpl<float>(workloadFactory, memoryManager, useSubtensor, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00003223}
3224
3225template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003226LayerTestResult<T, 3> Concatenation3dDim0DiffInputDimsTestImpl(
3227 armnn::IWorkloadFactory& workloadFactory,
3228 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3229 float qScale,
telsoa014fcda012018-03-09 14:13:49 +00003230 int32_t qOffset)
3231{
3232 armnn::TensorInfo input0TensorInfo({ 2, 3, 2 }, armnn::GetDataType<T>());
3233 auto input0 = MakeTensor<T, 3>(input0TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3234 // Batch 0, Channel 0
3235 1.0f, 2.0f,
3236
3237 // Batch 0, Channel 1
3238 3.0f, 4.0f,
3239
3240 // Batch 0, Channel 2
3241 5.0f, 6.0f,
3242
3243 // Batch 1, Channel 0
3244 19.0f, 20.0f,
3245
3246 // Batch 1, Channel 1
3247 21.0f, 22.0f,
3248
3249 // Batch 1, Channel 2
3250 23.0f, 24.0f
3251 }));
3252
3253 armnn::TensorInfo input1TensorInfo({ 1, 3, 2 }, armnn::GetDataType<T>());
3254 auto input1 = MakeTensor<T, 3>(input1TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3255 // Batch 0, Channel 0
3256 7.0f, 8.0f,
3257
3258 // Batch 0, Channel 1
3259 9.0f, 10.0f,
3260
3261 // Batch 0, Channel 2
3262 11.0f, 12.0f,
3263 }));
3264
3265 armnn::TensorInfo input2TensorInfo({ 3, 3, 2 }, armnn::GetDataType<T>());
3266 auto input2 = MakeTensor<T, 3>(input2TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3267 // Batch 0, Channel 0
3268 25.0f, 26.0f,
3269
3270 // Batch 0, Channel 1
3271 27.0f, 28.0f,
3272
3273 // Batch 0, Channel 2
3274 29.0f, 30.0f,
3275
3276 // Batch 1, Channel 0
3277 13.0f, 14.0f,
3278
3279 // Batch 1, Channel 1
3280 15.0f, 16.0f,
3281
3282 // Batch 1, Channel 2
3283 17.0f, 18.0f,
3284
3285 // Batch 2, Channel 0
3286 31.0f, 32.0f,
3287
3288 // Batch 2, Channel 1
3289 33.0f, 34.0f,
3290
3291 // Batch 2, Channel 2
3292 35.0f, 36.0f
3293 }));
3294
3295 armnn::TensorInfo outputTensorInfo({ 6, 3, 2 }, armnn::GetDataType<T>());
3296 LayerTestResult<T, 3> result(outputTensorInfo);
3297
3298 std::vector<T> output;
3299 output.resize(outputTensorInfo.GetNumElements());
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003300 Concatenate<T>(workloadFactory, memoryManager,
narpra015cdda352018-11-19 15:30:27 +00003301 { input0TensorInfo, input1TensorInfo, input2TensorInfo },
3302 { input0.data(), input1.data(), input2.data() },
3303 outputTensorInfo,
3304 output.data(),
3305 0,
3306 true);
telsoa014fcda012018-03-09 14:13:49 +00003307
3308 result.output = MakeTensor<T, 3>(outputTensorInfo, output);
3309 result.outputExpected = MakeTensor<T, 3>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3310 // Batch 0, Channel 0
3311 1.0f, 2.0f,
3312
3313 // Batch 0, Channel 1
3314 3.0f, 4.0f,
3315
3316 // Batch 0, Channel 2
3317 5.0f, 6.0f,
3318
3319 // Batch 1, Channel 0
3320 19.0f, 20.0f,
3321
3322 // Batch 1, Channel 1
3323 21.0f, 22.0f,
3324
3325 // Batch 1, Channel 2
3326 23.0f, 24.0f,
3327
3328 // Batch 2, Channel 0
3329 7.0f, 8.0f,
3330
3331 // Batch 2, Channel 1
3332 9.0f, 10.0f,
3333
3334 // Batch 2, Channel 2
3335 11.0f, 12.0f,
3336
3337 // Batch 3, Channel 0
3338 25.0f, 26.0f,
3339
3340 // Batch 3, Channel 1
3341 27.0f, 28.0f,
3342
3343 // Batch 3, Channel 2
3344 29.0f, 30.0f,
3345
3346 // Batch 4, Channel 0
3347 13.0f, 14.0f,
3348
3349 // Batch 4, Channel 1
3350 15.0f, 16.0f,
3351
3352 // Batch 4, Channel 2
3353 17.0f, 18.0f,
3354
3355 // Batch 5, Channel 0
3356 31.0f, 32.0f,
3357
3358 // Batch 5, Channel 1
3359 33.0f, 34.0f,
3360
3361 // Batch 5, Channel 2
3362 35.0f, 36.0f
3363 }));
3364
3365 return result;
3366}
3367
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003368LayerTestResult<float, 3> Concatenation3dDim0DiffInputDimsTest(
3369 armnn::IWorkloadFactory& workloadFactory,
3370 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00003371{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003372 return Concatenation3dDim0DiffInputDimsTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00003373}
3374
3375template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003376LayerTestResult<T, 3> Concatenation3dDim1DiffInputDimsTestImpl(
3377 armnn::IWorkloadFactory& workloadFactory,
3378 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3379 float qScale,
telsoa014fcda012018-03-09 14:13:49 +00003380 int32_t qOffset)
3381{
3382 armnn::TensorInfo input0TensorInfo({ 2, 3, 2 }, armnn::GetDataType<T>());
3383 auto input0 = MakeTensor<T, 3>(input0TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3384 // Batch 0, Channel 0
3385 1.0f, 2.0f,
3386
3387 // Batch 0, Channel 1
3388 3.0f, 4.0f,
3389
3390 // Batch 0, Channel 2
3391 5.0f, 6.0f,
3392
3393 // Batch 1, Channel 0
3394 19.0f, 20.0f,
3395
3396 // Batch 1, Channel 1
3397 21.0f, 22.0f,
3398
3399 // Batch 1, Channel 2
3400 23.0f, 24.0f
3401 }));
3402
3403 armnn::TensorInfo input1TensorInfo({ 2, 4, 2 }, armnn::GetDataType<T>());
3404 auto input1 = MakeTensor<T, 3>(input1TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3405 // Batch 0, Channel 0
3406 7.0f, 8.0f,
3407
3408 // Batch 0, Channel 1
3409 9.0f, 10.0f,
3410
3411 // Batch 0, Channel 2
3412 11.0f, 12.0f,
3413
3414 // Batch 0, Channel 3
3415 25.0f, 26.0f,
3416
3417 // Batch 1, Channel 0
3418 27.0f, 28.0f,
3419
3420 // Batch 1, Channel 1
3421 29.0f, 30.0f,
3422
3423 // Batch 1, Channel 2
3424 13.0f, 14.0f,
3425
3426 // Batch 1, Channel 3
3427 15.0f, 16.0f,
3428 }));
3429
3430 armnn::TensorInfo input2TensorInfo({ 2, 1, 2 }, armnn::GetDataType<T>());
3431 auto input2 = MakeTensor<T, 3>(input2TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3432 // Batch 0, Channel 0
3433 17.0f, 18.0f,
3434
3435 // Batch 1, Channel 0
3436 31.0f, 32.0f,
3437 }));
3438
3439 armnn::TensorInfo outputTensorInfo({ 2, 8, 2 }, armnn::GetDataType<T>());
3440 LayerTestResult<T, 3> result(outputTensorInfo);
3441
3442 std::vector<T> output;
3443 output.resize(outputTensorInfo.GetNumElements());
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003444 Concatenate<T>(workloadFactory, memoryManager,
narpra015cdda352018-11-19 15:30:27 +00003445 { input0TensorInfo, input1TensorInfo, input2TensorInfo },
3446 { input0.data(), input1.data(), input2.data() },
3447 outputTensorInfo,
3448 output.data(),
3449 1,
3450 true);
telsoa014fcda012018-03-09 14:13:49 +00003451
3452 result.output = MakeTensor<T, 3>(outputTensorInfo, output);
3453 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 0, Channel 3
3464 7.0f, 8.0f,
3465
3466 // Batch 0, Channel 4
3467 9.0f, 10.0f,
3468
3469 // Batch 0, Channel 5
3470 11.0f, 12.0f,
3471
3472 // Batch 0, Channel 6
3473 25.0f, 26.0f,
3474
3475 // Batch 0, Channel 7
3476 17.0f, 18.0f,
3477
3478 // Batch 1, Channel 0
3479 19.0f, 20.0f,
3480
3481 // Batch 1, Channel 1
3482 21.0f, 22.0f,
3483
3484 // Batch 1, Channel 2
3485 23.0f, 24.0f,
3486
3487 // Batch 1, Channel 3
3488 27.0f, 28.0f,
3489
3490 // Batch 1, Channel 4
3491 29.0f, 30.0f,
3492
3493 // Batch 1, Channel 5
3494 13.0f, 14.0f,
3495
3496 // Batch 1, Channel 6
3497 15.0f, 16.0f,
3498
3499 // Batch 1, Channel 7
3500 31.0f, 32.0f,
3501 }));
3502
3503 return result;
3504}
3505
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003506LayerTestResult<float, 3> Concatenation3dDim1DiffInputDimsTest(
3507 armnn::IWorkloadFactory& workloadFactory,
3508 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00003509{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003510 return Concatenation3dDim1DiffInputDimsTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00003511}
3512
3513template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003514LayerTestResult<T, 3> Concatenation3dDim2DiffInputDimsTestImpl(
3515 armnn::IWorkloadFactory& workloadFactory,
3516 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
narpra015cdda352018-11-19 15:30:27 +00003517 bool useSubtensor,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003518 float qScale,
telsoa014fcda012018-03-09 14:13:49 +00003519 int32_t qOffset)
3520{
3521 armnn::TensorInfo input0TensorInfo({ 2, 3, 2 }, armnn::GetDataType<T>());
3522 auto input0 = MakeTensor<T, 3>(input0TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3523 // Batch 0, Channel 0
3524 1.0f, 2.0f,
3525
3526 // Batch 0, Channel 1
3527 3.0f, 4.0f,
3528
3529 // Batch 0, Channel 2
3530 5.0f, 6.0f,
3531
3532 // Batch 1, Channel 0
3533 19.0f, 20.0f,
3534
3535 // Batch 1, Channel 1
3536 21.0f, 22.0f,
3537
3538 // Batch 1, Channel 2
3539 23.0f, 24.0f
3540 }));
3541
3542 armnn::TensorInfo input1TensorInfo({ 2, 3, 1 }, armnn::GetDataType<T>());
3543 auto input1 = MakeTensor<T, 3>(input1TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3544 // Batch 0, Channel 0
3545 7.0f,
3546
3547 // Batch 0, Channel 1
3548 9.0f,
3549
3550 // Batch 0, Channel 2
3551 11.0f,
3552
3553 // Batch 1, Channel 0
3554 25.0f,
3555
3556 // Batch 1, Channel 1
3557 27.0f,
3558
3559 // Batch 1, Channel 2
3560 29.0f
3561 }));
3562
3563 armnn::TensorInfo input2TensorInfo({ 2, 3, 3 }, armnn::GetDataType<T>());
3564 auto input2 = MakeTensor<T, 3>(input2TensorInfo, QuantizedVector<T>(qScale, qOffset, {
3565 // Batch 0, Channel 0
3566 13.0f, 14.0f, 50.0f,
3567
3568 // Batch 0, Channel 1
3569 15.0f, 16.0f, 51.0f,
3570
3571 // Batch 0, Channel 2
3572 17.0f, 18.0f, 52.0f,
3573
3574 // Batch 1, Channel 0
3575 31.0f, 32.0f, 53.0f,
3576
3577 // Batch 1, Channel 1
3578 33.0f, 34.0f, 54.0f,
3579
3580 // Batch 1, Channel 2
3581 35.0f, 36.0f, 55.0f,
3582 }));
3583
3584 armnn::TensorInfo outputTensorInfo({ 2, 3, 6 }, armnn::GetDataType<T>());
3585 LayerTestResult<T, 3> result(outputTensorInfo);
3586
3587 std::vector<T> output;
3588 output.resize(outputTensorInfo.GetNumElements());
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003589 Concatenate<T>(workloadFactory, memoryManager,
narpra015cdda352018-11-19 15:30:27 +00003590 { input0TensorInfo, input1TensorInfo, input2TensorInfo },
3591 { input0.data(), input1.data(), input2.data() },
3592 outputTensorInfo,
3593 output.data(),
3594 2,
3595 useSubtensor);
telsoa014fcda012018-03-09 14:13:49 +00003596
3597 result.output = MakeTensor<T, 3>(outputTensorInfo, output);
3598 result.outputExpected = MakeTensor<T, 3>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3599 // Batch 0, Channel 0
3600 1.0f, 2.0f, 7.0f, 13.0f, 14.0f, 50.0f,
3601
3602 // Batch 0, Channel 1
3603 3.0f, 4.0f, 9.0f, 15.0f, 16.0f, 51.0f,
3604
3605 // Batch 0, Channel 2
3606 5.0f, 6.0f, 11.0f, 17.0f, 18.0f, 52.0f,
3607
3608 // Batch 1, Channel 0
3609 19.0f, 20.0f, 25.0f, 31.0f, 32.0f, 53.0f,
3610
3611 // Batch 1, Channel 1
3612 21.0f, 22.0f, 27.0f, 33.0f, 34.0f, 54.0f,
3613
3614 // Batch 1, Channel 2
3615 23.0f, 24.0f, 29.0f, 35.0f, 36.0f, 55.0f,
3616 }));
3617
3618 return result;
3619}
3620
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003621LayerTestResult<float, 3> Concatenation3dDim2DiffInputDimsTest(
3622 armnn::IWorkloadFactory& workloadFactory,
narpra015cdda352018-11-19 15:30:27 +00003623 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3624 bool useSubtensor)
3625{
3626 return Concatenation3dDim2DiffInputDimsTestImpl<float>(workloadFactory, memoryManager, useSubtensor, 0.0f, 0);
3627}
3628
3629template <typename T>
3630LayerTestResult<T, 4> Concatenation4dTestImpl(
3631 armnn::IWorkloadFactory& workloadFactory,
3632 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3633 const armnn::TensorInfo& outputTensorInfo,
3634 unsigned int dimension,
3635 bool useSubtensor,
3636 float qScale,
3637 int32_t qOffset)
3638{
3639 armnn::TensorInfo inputTensorInfo({ 1, 3, 2, 2 }, armnn::GetDataType<T>());
3640
3641 auto input0 = MakeTensor<T, 4>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3642 1.0f, 2.0f,
3643 3.0f, 4.0f,
3644 5.0f, 6.0f,
3645 7.0f, 8.0f,
3646 9.0f, 10.0f,
3647 11.0f, 12.0f
3648 }));
3649
3650 auto input1 = MakeTensor<T, 4>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3651 11.0f, 12.0f,
3652 13.0f, 14.0f,
3653 15.0f, 16.0f,
3654 17.0f, 18.0f,
3655 19.0f, 20.0f,
3656 21.0f, 22.0f
3657 }));
3658
3659 auto input2 = MakeTensor<T, 4>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3660 21.0f, 22.0f,
3661 23.0f, 24.0f,
3662 25.0f, 26.0f,
3663 27.0f, 28.0f,
3664 29.0f, 30.0f,
3665 31.0f, 32.0f
3666 }));
3667
3668 LayerTestResult<T, 4> result(outputTensorInfo);
3669
3670 std::vector<T> output;
3671 output.resize(outputTensorInfo.GetNumElements());
3672
3673 Concatenate<T>(workloadFactory,
3674 memoryManager,
3675 {inputTensorInfo, inputTensorInfo, inputTensorInfo},
3676 {input0.data(), input1.data(), input2.data()},
3677 outputTensorInfo,
3678 output.data(),
3679 dimension,
3680 useSubtensor);
3681
3682 result.output = MakeTensor<T, 4>(outputTensorInfo, output);
3683 return result;
3684}
3685
3686template <typename T>
3687LayerTestResult<T, 4> Concatenation4dDim0TestImpl(
3688 armnn::IWorkloadFactory& workloadFactory,
3689 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3690 float qScale,
3691 int32_t qOffset)
3692{
3693 armnn::TensorInfo outputTensorInfo({ 3, 3, 2, 2 }, armnn::GetDataType<T>());
3694
3695 LayerTestResult<T, 4> result = Concatenation4dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 0,
3696 true, qScale, qOffset);
3697 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3698 1.0f, 2.0f,
3699 3.0f, 4.0f,
3700 5.0f, 6.0f,
3701 7.0f, 8.0f,
3702 9.0f, 10.0f,
3703 11.0f, 12.0f,
3704
3705 11.0f, 12.0f,
3706 13.0f, 14.0f,
3707 15.0f, 16.0f,
3708 17.0f, 18.0f,
3709 19.0f, 20.0f,
3710 21.0f, 22.0f,
3711
3712 21.0f, 22.0f,
3713 23.0f, 24.0f,
3714 25.0f, 26.0f,
3715 27.0f, 28.0f,
3716 29.0f, 30.0f,
3717 31.0f, 32.0f
3718 }));
3719 return result;
3720}
3721
3722LayerTestResult<float, 4> Concatenation4dDim0Test(
3723 armnn::IWorkloadFactory& workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00003724 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00003725{
narpra015cdda352018-11-19 15:30:27 +00003726 return Concatenation4dDim0TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
3727}
3728
3729template <typename T>
3730LayerTestResult<T, 4> Concatenation4dDim1TestImpl(
3731 armnn::IWorkloadFactory& workloadFactory,
3732 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3733 float qScale,
3734 int32_t qOffset)
3735{
3736 armnn::TensorInfo outputTensorInfo({ 1, 9, 2, 2 }, armnn::GetDataType<T>());
3737
3738 LayerTestResult<T, 4> result = Concatenation4dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 1,
3739 true, qScale, qOffset);
3740 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3741 1.0f, 2.0f,
3742 3.0f, 4.0f,
3743 5.0f, 6.0f,
3744 7.0f, 8.0f,
3745 9.0f, 10.0f,
3746 11.0f, 12.0f,
3747
3748 11.0f, 12.0f,
3749 13.0f, 14.0f,
3750 15.0f, 16.0f,
3751 17.0f, 18.0f,
3752 19.0f, 20.0f,
3753 21.0f, 22.0f,
3754
3755 21.0f, 22.0f,
3756 23.0f, 24.0f,
3757 25.0f, 26.0f,
3758 27.0f, 28.0f,
3759 29.0f, 30.0f,
3760 31.0f, 32.0f
3761 }));
3762
3763 return result;
3764}
3765
3766LayerTestResult<float, 4> Concatenation4dDim1Test(
3767 armnn::IWorkloadFactory& workloadFactory,
3768 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
3769{
3770 return Concatenation4dDim1TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
3771}
3772
3773template <typename T>
3774LayerTestResult<T, 4> Concatenation4dDim2TestImpl(
3775 armnn::IWorkloadFactory& workloadFactory,
3776 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3777 float qScale,
3778 int32_t qOffset)
3779{
3780 armnn::TensorInfo outputTensorInfo({ 1, 3, 6, 2 }, armnn::GetDataType<T>());
3781
3782 LayerTestResult<T, 4> result = Concatenation4dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 2,
3783 true, qScale, qOffset);
3784 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3785 1.0f, 2.0f,
3786 3.0f, 4.0f,
3787 11.0f, 12.0f,
3788 13.0f, 14.0f,
3789 21.0f, 22.0f,
3790 23.0f, 24.0f,
3791
3792 5.0f, 6.0f,
3793 7.0f, 8.0f,
3794 15.0f, 16.0f,
3795 17.0f, 18.0f,
3796 25.0f, 26.0f,
3797 27.0f, 28.0f,
3798
3799 9.0f, 10.0f,
3800 11.0f, 12.0f,
3801 19.0f, 20.0f,
3802 21.0f, 22.0f,
3803 29.0f, 30.0f,
3804 31.0f, 32.0f
3805 }));
3806
3807 return result;
3808}
3809
3810LayerTestResult<float, 4> Concatenation4dDim2Test(
3811 armnn::IWorkloadFactory& workloadFactory,
3812 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
3813{
3814 return Concatenation4dDim2TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
3815}
3816
3817template <typename T>
3818LayerTestResult<T, 4> Concatenation4dDim3TestImpl(
3819 armnn::IWorkloadFactory& workloadFactory,
3820 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3821 float qScale,
3822 int32_t qOffset,
3823 bool useSubtensor)
3824{
3825 armnn::TensorInfo outputTensorInfo({ 1, 3, 2, 6 }, armnn::GetDataType<T>());
3826
3827 LayerTestResult<T, 4> result = Concatenation4dTestImpl<T>(workloadFactory, memoryManager, outputTensorInfo, 3,
3828 useSubtensor, qScale, qOffset);
3829 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3830 1.0f, 2.0f,
3831 11.0f, 12.0f,
3832 21.0f, 22.0f,
3833 3.0f, 4.0f,
3834 13.0f, 14.0f,
3835 23.0f, 24.0f,
3836
3837 5.0f, 6.0f,
3838 15.0f, 16.0f,
3839 25.0f, 26.0f,
3840 7.0f, 8.0f,
3841 17.0f, 18.0f,
3842 27.0f, 28.0f,
3843
3844 9.0f, 10.0f,
3845 19.0f, 20.0f,
3846 29.0f, 30.0f,
3847 11.0f, 12.0f,
3848 21.0f, 22.0f,
3849 31.0f, 32.0f
3850 }));
3851
3852 return result;
3853}
3854
3855LayerTestResult<float, 4> Concatenation4dDim3Test(
3856 armnn::IWorkloadFactory& workloadFactory,
3857 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3858 bool useSubtensor)
3859{
3860 return Concatenation4dDim3TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0, useSubtensor);
3861}
3862
3863template <typename T>
3864LayerTestResult<T, 4> Concatenation4dDiffShapeDim0TestImpl(
3865 armnn::IWorkloadFactory& workloadFactory,
3866 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3867 float qScale,
3868 int32_t qOffset)
3869{
3870 unsigned int dimension = 0;
3871 armnn::TensorInfo inputTensorInfo0({ 1, 3, 2, 2 }, armnn::GetDataType<T>());
3872
3873 auto input0 = MakeTensor<T, 4>(inputTensorInfo0, QuantizedVector<T>(qScale, qOffset, {
3874 1.0f, 2.0f,
3875 3.0f, 4.0f,
3876 5.0f, 6.0f,
3877 7.0f, 8.0f,
3878 9.0f, 10.0f,
3879 11.0f, 12.0f
3880 }));
3881
3882 armnn::TensorInfo inputTensorInfo1({ 2, 3, 2, 2 }, armnn::GetDataType<T>());
3883
3884 auto input1 = MakeTensor<T, 4>(inputTensorInfo1, QuantizedVector<T>(qScale, qOffset, {
3885 11.0f, 12.0f,
3886 13.0f, 14.0f,
3887 15.0f, 16.0f,
3888 17.0f, 18.0f,
3889 19.0f, 20.0f,
3890 21.0f, 22.0f,
3891
3892 21.0f, 22.0f,
3893 23.0f, 24.0f,
3894 25.0f, 26.0f,
3895 27.0f, 28.0f,
3896 29.0f, 30.0f,
3897 31.0f, 32.0f
3898
3899 }));
3900
3901 armnn::TensorInfo outputTensorInfo({ 3, 3, 2, 2 }, armnn::GetDataType<T>());
3902
3903 LayerTestResult<T, 4> result(outputTensorInfo);
3904
3905 std::vector<T> output;
3906 output.resize(outputTensorInfo.GetNumElements());
3907 Concatenate<T>(workloadFactory,
3908 memoryManager,
3909 {inputTensorInfo0, inputTensorInfo1},
3910 {input0.data(), input1.data()},
3911 outputTensorInfo,
3912 output.data(),
3913 dimension,
3914 true);
3915
3916 result.output = MakeTensor<T, 4>(outputTensorInfo, output);
3917 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3918 1.0f, 2.0f,
3919 3.0f, 4.0f,
3920 5.0f, 6.0f,
3921 7.0f, 8.0f,
3922 9.0f, 10.0f,
3923 11.0f, 12.0f,
3924
3925 11.0f, 12.0f,
3926 13.0f, 14.0f,
3927 15.0f, 16.0f,
3928 17.0f, 18.0f,
3929 19.0f, 20.0f,
3930 21.0f, 22.0f,
3931
3932 21.0f, 22.0f,
3933 23.0f, 24.0f,
3934 25.0f, 26.0f,
3935 27.0f, 28.0f,
3936 29.0f, 30.0f,
3937 31.0f, 32.0f
3938 }));
3939
3940 return result;
3941}
3942
3943LayerTestResult<float, 4> Concatenation4dDiffShapeDim0Test(
3944 armnn::IWorkloadFactory& workloadFactory,
3945 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
3946{
3947 return Concatenation4dDiffShapeDim0TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
3948}
3949
3950template <typename T>
3951LayerTestResult<T, 4> Concatenation4dDiffShapeDim1TestImpl(
3952 armnn::IWorkloadFactory& workloadFactory,
3953 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
3954 float qScale,
3955 int32_t qOffset)
3956{
3957 unsigned int dimension = 1;
3958 armnn::TensorInfo inputTensorInfo0({ 1, 3, 2, 2 }, armnn::GetDataType<T>());
3959
3960 auto input0 = MakeTensor<T, 4>(inputTensorInfo0, QuantizedVector<T>(qScale, qOffset, {
3961 1.0f, 2.0f,
3962 3.0f, 4.0f,
3963 5.0f, 6.0f,
3964 7.0f, 8.0f,
3965 9.0f, 10.0f,
3966 11.0f, 12.0f
3967 }));
3968
3969 armnn::TensorInfo inputTensorInfo1({ 1, 2, 2, 2 }, armnn::GetDataType<T>());
3970
3971 auto input1 = MakeTensor<T, 4>(inputTensorInfo1, QuantizedVector<T>(qScale, qOffset, {
3972 11.0f, 12.0f,
3973 13.0f, 14.0f,
3974 15.0f, 16.0f,
3975 17.0f, 18.0f,
3976
3977 }));
3978
3979 armnn::TensorInfo outputTensorInfo({ 1, 5, 2, 2 }, armnn::GetDataType<T>());
3980
3981 LayerTestResult<T, 4> result(outputTensorInfo);
3982
3983 std::vector<T> output;
3984 output.resize(outputTensorInfo.GetNumElements());
3985 Concatenate<T>(workloadFactory,
3986 memoryManager,
3987 {inputTensorInfo0, inputTensorInfo1},
3988 {input0.data(), input1.data()},
3989 outputTensorInfo,
3990 output.data(),
3991 dimension,
3992 true);
3993
3994 result.output = MakeTensor<T, 4>(outputTensorInfo, output);
3995 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
3996 1.0f, 2.0f,
3997 3.0f, 4.0f,
3998 5.0f, 6.0f,
3999 7.0f, 8.0f,
4000 9.0f, 10.0f,
4001 11.0f, 12.0f,
4002 11.0f, 12.0f,
4003 13.0f, 14.0f,
4004 15.0f, 16.0f,
4005 17.0f, 18.0f
4006 }));
4007
4008 return result;
4009}
4010
4011LayerTestResult<float, 4> Concatenation4dDiffShapeDim1Test(
4012 armnn::IWorkloadFactory& workloadFactory,
4013 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
4014{
4015 return Concatenation4dDiffShapeDim1TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
4016}
4017
4018template <typename T>
4019LayerTestResult<T, 4> Concatenation4dDiffShapeDim2TestImpl(
4020 armnn::IWorkloadFactory& workloadFactory,
4021 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4022 float qScale,
4023 int32_t qOffset)
4024{
4025 unsigned int dimension = 2;
4026 armnn::TensorInfo inputTensorInfo0({ 1, 3, 2, 2 }, armnn::GetDataType<T>());
4027
4028 auto input0 = MakeTensor<T, 4>(inputTensorInfo0, QuantizedVector<T>(qScale, qOffset, {
4029 1.0f, 2.0f,
4030 3.0f, 4.0f,
4031 5.0f, 6.0f,
4032 7.0f, 8.0f,
4033 9.0f, 10.0f,
4034 11.0f, 12.0f
4035 }));
4036
4037 armnn::TensorInfo inputTensorInfo1({ 1, 3, 3, 2 }, armnn::GetDataType<T>());
4038
4039 auto input1 = MakeTensor<T, 4>(inputTensorInfo1, QuantizedVector<T>(qScale, qOffset, {
4040 11.0f, 12.0f,
4041 13.0f, 14.0f,
4042 15.0f, 16.0f,
4043 17.0f, 18.0f,
4044 19.0f, 20.0f,
4045 21.0f, 22.0f,
4046 23.0f, 24.0f,
4047 25.0f, 26.0f,
4048 27.0f, 28.0f
4049 }));
4050
4051 armnn::TensorInfo outputTensorInfo({ 1, 3, 5, 2 }, armnn::GetDataType<T>());
4052
4053 LayerTestResult<T, 4> result(outputTensorInfo);
4054
4055 std::vector<T> output;
4056 output.resize(outputTensorInfo.GetNumElements());
4057 Concatenate<T>(workloadFactory,
4058 memoryManager,
4059 {inputTensorInfo0, inputTensorInfo1},
4060 {input0.data(), input1.data()},
4061 outputTensorInfo,
4062 output.data(),
4063 dimension,
4064 true);
4065
4066 result.output = MakeTensor<T, 4>(outputTensorInfo, output);
4067 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
4068 1.0f, 2.0f,
4069 3.0f, 4.0f,
4070 11.0f, 12.0f,
4071 13.0f, 14.0f,
4072 15.0f, 16.0f,
4073
4074 5.0f, 6.0f,
4075 7.0f, 8.0f,
4076 17.0f, 18.0f,
4077 19.0f, 20.0f,
4078 21.0f, 22.0f,
4079
4080 9.0f, 10.0f,
4081 11.0f, 12.0f,
4082 23.0f, 24.0f,
4083 25.0f, 26.0f,
4084 27.0f, 28.0f
4085 }));
4086
4087 return result;
4088}
4089
4090LayerTestResult<float, 4> Concatenation4dDiffShapeDim2Test(
4091 armnn::IWorkloadFactory& workloadFactory,
4092 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
4093{
4094 return Concatenation4dDiffShapeDim2TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
4095}
4096
4097template <typename T>
4098LayerTestResult<T, 4> Concatenation4dDiffShapeDim3TestImpl(
4099 armnn::IWorkloadFactory& workloadFactory,
4100 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4101 float qScale,
4102 int32_t qOffset,
4103 bool useSubtensor)
4104{
4105 unsigned int dimension = 3;
4106 armnn::TensorInfo inputTensorInfo0({ 1, 3, 2, 2 }, armnn::GetDataType<T>());
4107
4108 auto input0 = MakeTensor<T, 4>(inputTensorInfo0, QuantizedVector<T>(qScale, qOffset, {
4109 1.0f, 2.0f,
4110 3.0f, 4.0f,
4111 5.0f, 6.0f,
4112 7.0f, 8.0f,
4113 9.0f, 10.0f,
4114 11.0f, 12.0f
4115 }));
4116
4117 armnn::TensorInfo inputTensorInfo1({ 1, 3, 2, 3 }, armnn::GetDataType<T>());
4118
4119 auto input1 = MakeTensor<T, 4>(inputTensorInfo1, QuantizedVector<T>(qScale, qOffset, {
4120 11.0f, 12.0f, 13.0f,
4121 14.0f, 15.0f, 16.0f,
4122
4123 17.0f, 18.0f, 19.0f,
4124 20.0f, 21.0f, 22.0f,
4125
4126 23.0f, 24.0f, 25.0f,
4127 26.0f, 27.0f, 28.0f
4128 }));
4129
4130 armnn::TensorInfo outputTensorInfo({ 1, 3, 2, 5 }, armnn::GetDataType<T>());
4131
4132 LayerTestResult<T, 4> result(outputTensorInfo);
4133
4134 std::vector<T> output;
4135 output.resize(outputTensorInfo.GetNumElements());
4136 Concatenate<T>(workloadFactory,
4137 memoryManager,
4138 {inputTensorInfo0, inputTensorInfo1},
4139 {input0.data(), input1.data()},
4140 outputTensorInfo,
4141 output.data(),
4142 dimension,
4143 useSubtensor);
4144
4145 result.output = MakeTensor<T, 4>(outputTensorInfo, output);
4146 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, {
4147 1.0f, 2.0f, 11.0f, 12.0f, 13.0f,
4148 3.0f, 4.0f, 14.0f, 15.0f, 16.0f,
4149 5.0f, 6.0f, 17.0f, 18.0f, 19.0f,
4150 7.0f, 8.0f, 20.0f, 21.0f, 22.0f,
4151 9.0f, 10.0f, 23.0f, 24.0f, 25.0f,
4152 11.0f, 12.0f, 26.0f, 27.0f, 28.0f
4153 }));
4154
4155 return result;
4156}
4157
4158LayerTestResult<float, 4> Concatenation4dDiffShapeDim3Test(
4159 armnn::IWorkloadFactory& workloadFactory,
4160 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4161 bool useSubtensor)
4162{
4163 return Concatenation4dDiffShapeDim3TestImpl<float>(workloadFactory, memoryManager, 0.0f, 0, useSubtensor);
telsoa014fcda012018-03-09 14:13:49 +00004164}
4165
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004166LayerTestResult<float, 4> ResizeBilinearNopTest(
4167 armnn::IWorkloadFactory& workloadFactory,
4168 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00004169 const armnn::DataLayout dataLayout)
telsoa014fcda012018-03-09 14:13:49 +00004170{
Nina Drozdd41b2592018-11-19 13:03:36 +00004171 const armnn::TensorInfo inputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 4, 4, dataLayout);
4172 const armnn::TensorInfo outputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 4, 4, dataLayout);
telsoa014fcda012018-03-09 14:13:49 +00004173
James Conroy6b965822018-11-01 11:33:09 +00004174 std::vector<float> inputData({
4175 1.0f, 2.0f, 3.0f, 4.0f,
4176 2.0f, 3.0f, 4.0f, 5.0f,
4177 3.0f, 4.0f, 5.0f, 6.0f,
4178 4.0f, 5.0f, 6.0f, 7.0f,
4179
telsoa014fcda012018-03-09 14:13:49 +00004180 1.0f, 2.0f, 3.0f, 4.0f,
4181 2.0f, 3.0f, 4.0f, 5.0f,
4182 3.0f, 4.0f, 5.0f, 6.0f,
4183 4.0f, 5.0f, 6.0f, 7.0f
James Conroy6b965822018-11-01 11:33:09 +00004184 });
4185
4186 const armnn::PermutationVector NCHWToNHWC = { 0, 3, 1, 2 };
Matthew Bentham8800c002018-11-19 13:19:28 +00004187 if (dataLayout == armnn::DataLayout::NHWC)
James Conroy6b965822018-11-01 11:33:09 +00004188 {
4189 std::vector<float> tmp(inputData.size());
4190 armnnUtils::Permute(inputTensorInfo.GetShape(), NCHWToNHWC, inputData.data(), tmp.data());
4191 inputData = tmp;
4192 }
4193
4194 auto input = MakeTensor<float, 4>(inputTensorInfo, inputData);
telsoa014fcda012018-03-09 14:13:49 +00004195
4196 LayerTestResult<float, 4> result(outputTensorInfo);
4197 result.outputExpected = input;
4198
4199 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
4200 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
4201
4202 armnn::ResizeBilinearQueueDescriptor descriptor;
James Conroy074f3712018-10-03 09:32:03 +01004203 descriptor.m_Parameters.m_DataLayout = dataLayout;
4204 armnn::WorkloadInfo info;
4205 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
4206 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
4207
4208 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
4209
4210 inputHandle->Allocate();
4211 outputHandle->Allocate();
4212 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
4213
James Conroy074f3712018-10-03 09:32:03 +01004214 workload->Execute();
4215
4216 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
4217 return result;
4218}
4219
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004220LayerTestResult<float, 4> SimpleResizeBilinearTest(
4221 armnn::IWorkloadFactory& workloadFactory,
4222 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00004223 const armnn::DataLayout dataLayout)
James Conroy074f3712018-10-03 09:32:03 +01004224{
Nina Drozdd41b2592018-11-19 13:03:36 +00004225 const armnn::TensorInfo inputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 2, 2, dataLayout);
4226 const armnn::TensorInfo outputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 1, 1, dataLayout);
James Conroy074f3712018-10-03 09:32:03 +01004227
James Conroy6b965822018-11-01 11:33:09 +00004228 std::vector<float> inputData({
James Conroy074f3712018-10-03 09:32:03 +01004229 1.0f, 255.0f,
James Conroy6b965822018-11-01 11:33:09 +00004230 200.0f, 250.0f,
4231
4232 250.0f, 200.0f,
4233 250.0f, 1.0f
4234 });
James Conroy074f3712018-10-03 09:32:03 +01004235
4236 // The 'resize bilinear' operation projects the top-left corner of output texels into the input image,
4237 // then figures out the interpolants and weights. Note this is different to projecting the centre of the
James Conroy6b965822018-11-01 11:33:09 +00004238 // output texel. Thus, for a input matrix of 2x2, we'll expect the output 1x1 matrix to contain, as
4239 // its single element, the value that was at position (0,0) of the input matrix (rather than an average,
4240 // which we would expect if projecting the centre).
4241
4242 std::vector<float> outputData({
4243 1.0f,
4244
4245 250.0f
4246 });
4247
4248 const armnn::PermutationVector NCHWToNHWC = { 0, 3, 1, 2 };
Matthew Bentham8800c002018-11-19 13:19:28 +00004249 if (dataLayout == armnn::DataLayout::NHWC)
James Conroy6b965822018-11-01 11:33:09 +00004250 {
4251 std::vector<float> tmp(inputData.size());
4252 armnnUtils::Permute(inputTensorInfo.GetShape(), NCHWToNHWC, inputData.data(), tmp.data());
4253 inputData = tmp;
4254
4255 std::vector<float> tmp1(outputData.size());
4256 armnnUtils::Permute(outputTensorInfo.GetShape(), NCHWToNHWC, outputData.data(), tmp1.data());
4257 outputData = tmp1;
4258 }
4259
4260 auto input = MakeTensor<float, 4>(inputTensorInfo, inputData);
4261
James Conroy074f3712018-10-03 09:32:03 +01004262 LayerTestResult<float, 4> result(outputTensorInfo);
James Conroy6b965822018-11-01 11:33:09 +00004263 result.outputExpected = MakeTensor<float, 4>(outputTensorInfo, outputData);
James Conroy074f3712018-10-03 09:32:03 +01004264
4265 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
4266 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
4267
4268 armnn::ResizeBilinearQueueDescriptor descriptor;
4269 descriptor.m_Parameters.m_DataLayout = dataLayout;
telsoa014fcda012018-03-09 14:13:49 +00004270 armnn::WorkloadInfo info;
4271 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
4272 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
4273
4274 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
4275
4276 inputHandle->Allocate();
4277 outputHandle->Allocate();
4278 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
4279
4280 workload->Execute();
4281
4282 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
4283 return result;
4284}
4285
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004286LayerTestResult<float, 4> ResizeBilinearSqMinTest(
4287 armnn::IWorkloadFactory& workloadFactory,
4288 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00004289 const armnn::DataLayout dataLayout)
telsoa014fcda012018-03-09 14:13:49 +00004290{
Nina Drozdd41b2592018-11-19 13:03:36 +00004291 const armnn::TensorInfo inputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 4, 4, dataLayout);
4292 const armnn::TensorInfo outputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 2, 2, dataLayout);
telsoa014fcda012018-03-09 14:13:49 +00004293
James Conroy6b965822018-11-01 11:33:09 +00004294 std::vector<float> inputData({
James Conroy074f3712018-10-03 09:32:03 +01004295 1.0f, 2.0f, 3.0f, 4.0f,
4296 2.0f, 3.0f, 4.0f, 5.0f,
4297 3.0f, 4.0f, 5.0f, 6.0f,
James Conroy6b965822018-11-01 11:33:09 +00004298 4.0f, 5.0f, 6.0f, 7.0f,
4299
4300 7.0f, 6.0f, 5.0f, 4.0f,
4301 6.0f, 5.0f, 4.0f, 3.0f,
4302 5.0f, 4.0f, 3.0f, 2.0f,
4303 4.0f, 3.0f, 2.0f, 1.0f
4304 });
4305
4306 std::vector<float> outputData({
4307 1.0f, 3.0f,
4308 3.0f, 5.0f,
4309
4310 7.0f, 5.0f,
4311 5.0f, 3.0f
4312 });
4313
4314 const armnn::PermutationVector NCHWToNHWC = { 0, 3, 1, 2 };
Matthew Bentham8800c002018-11-19 13:19:28 +00004315 if (dataLayout == armnn::DataLayout::NHWC)
James Conroy6b965822018-11-01 11:33:09 +00004316 {
4317 std::vector<float> tmp(inputData.size());
4318 armnnUtils::Permute(inputTensorInfo.GetShape(), NCHWToNHWC, inputData.data(), tmp.data());
4319 inputData = tmp;
4320
4321 std::vector<float> tmp1(outputData.size());
4322 armnnUtils::Permute(outputTensorInfo.GetShape(), NCHWToNHWC, outputData.data(), tmp1.data());
4323 outputData = tmp1;
4324 }
4325
4326 auto input = MakeTensor<float, 4>(inputTensorInfo, inputData);
telsoa014fcda012018-03-09 14:13:49 +00004327
telsoa014fcda012018-03-09 14:13:49 +00004328 LayerTestResult<float, 4> result(outputTensorInfo);
James Conroy6b965822018-11-01 11:33:09 +00004329 result.outputExpected = MakeTensor<float, 4>(outputTensorInfo, outputData);
telsoa014fcda012018-03-09 14:13:49 +00004330
4331 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
4332 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
4333
4334 armnn::ResizeBilinearQueueDescriptor descriptor;
James Conroy074f3712018-10-03 09:32:03 +01004335 descriptor.m_Parameters.m_DataLayout = dataLayout;
telsoa014fcda012018-03-09 14:13:49 +00004336 armnn::WorkloadInfo info;
4337 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
4338 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
4339
4340 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
4341
4342 inputHandle->Allocate();
4343 outputHandle->Allocate();
4344 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
4345
4346 workload->Execute();
4347
4348 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
4349 return result;
4350}
4351
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004352LayerTestResult<float, 4> ResizeBilinearMinTest(
4353 armnn::IWorkloadFactory& workloadFactory,
4354 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00004355 const armnn::DataLayout dataLayout)
telsoa014fcda012018-03-09 14:13:49 +00004356{
Nina Drozdd41b2592018-11-19 13:03:36 +00004357 const armnn::TensorInfo inputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 3, 5, dataLayout);
4358 const armnn::TensorInfo outputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 2, 3, dataLayout);
telsoa014fcda012018-03-09 14:13:49 +00004359
James Conroy6b965822018-11-01 11:33:09 +00004360 std::vector<float> inputData({
James Conroy074f3712018-10-03 09:32:03 +01004361 1.0f, 2.0f, 3.0f, 5.0f, 8.0f,
4362 13.0f, 21.0f, 34.0f, 55.0f, 89.0f,
James Conroy6b965822018-11-01 11:33:09 +00004363 144.0f, 233.0f, 377.0f, 610.0f, 987.0f,
4364
4365 987.0f, 610.0f, 377.0f, 233.0f, 144.0f,
4366 89.0f, 55.0f, 34.0f, 21.0f, 13.0f,
4367 8.0f, 5.0f, 3.0f, 2.0f, 1.0f
4368 });
4369
4370 std::vector<float> outputData({
4371 1.0f, 2.6666f, 6.00f,
4372 78.5f, 179.3333f, 401.00f,
4373
4374 987.0f, 454.6670f, 203.33f,
4375 48.5f, 22.3333f, 10.00f
4376 });
4377
4378 const armnn::PermutationVector NCHWToNHWC = { 0, 3, 1, 2 };
Matthew Bentham8800c002018-11-19 13:19:28 +00004379 if (dataLayout == armnn::DataLayout::NHWC)
James Conroy6b965822018-11-01 11:33:09 +00004380 {
4381 std::vector<float> tmp(inputData.size());
4382 armnnUtils::Permute(inputTensorInfo.GetShape(), NCHWToNHWC, inputData.data(), tmp.data());
4383 inputData = tmp;
4384
4385 std::vector<float> tmp1(outputData.size());
4386 armnnUtils::Permute(outputTensorInfo.GetShape(), NCHWToNHWC, outputData.data(), tmp1.data());
4387 outputData = tmp1;
4388 }
4389
4390 auto input = MakeTensor<float, 4>(inputTensorInfo, inputData);
telsoa014fcda012018-03-09 14:13:49 +00004391
4392 LayerTestResult<float, 4> result(outputTensorInfo);
James Conroy6b965822018-11-01 11:33:09 +00004393 result.outputExpected = MakeTensor<float, 4>(outputTensorInfo, outputData);
telsoa014fcda012018-03-09 14:13:49 +00004394
4395 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
4396 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
4397
4398 armnn::ResizeBilinearQueueDescriptor descriptor;
James Conroy074f3712018-10-03 09:32:03 +01004399 descriptor.m_Parameters.m_DataLayout = dataLayout;
telsoa014fcda012018-03-09 14:13:49 +00004400 armnn::WorkloadInfo info;
4401 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
4402 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
4403
4404 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
4405
4406 inputHandle->Allocate();
4407 outputHandle->Allocate();
4408 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
4409
4410 workload->Execute();
4411
4412 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
4413 return result;
4414}
4415
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004416LayerTestResult<float, 4> ResizeBilinearMagTest(
4417 armnn::IWorkloadFactory& workloadFactory,
4418 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00004419 const armnn::DataLayout dataLayout)
telsoa014fcda012018-03-09 14:13:49 +00004420{
Nina Drozdd41b2592018-11-19 13:03:36 +00004421 const armnn::TensorInfo inputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 3, 2, dataLayout);
4422 const armnn::TensorInfo outputTensorInfo = armnnUtils::GetTensorInfo<float>(1, 2, 3, 5, dataLayout);
telsoa014fcda012018-03-09 14:13:49 +00004423
James Conroy6b965822018-11-01 11:33:09 +00004424 std::vector<float> inputData({
James Conroy074f3712018-10-03 09:32:03 +01004425 1.0f, 2.0f,
4426 13.0f, 21.0f,
James Conroy6b965822018-11-01 11:33:09 +00004427 144.0f, 233.0f,
telsoa014fcda012018-03-09 14:13:49 +00004428
James Conroy6b965822018-11-01 11:33:09 +00004429 233.0f, 144.0f,
4430 21.0f, 13.0f,
4431 2.0f, 1.0f
4432 });
4433
4434 std::vector<float> outputData({
James Conroy074f3712018-10-03 09:32:03 +01004435 1.0f, 1.4f, 1.8f, 2.0f, 2.0f,
4436 13.0f, 16.2f, 19.4f, 21.0f, 21.0f,
James Conroy6b965822018-11-01 11:33:09 +00004437 144.0f, 179.6f, 215.2f, 233.0f, 233.0f,
4438
4439 233.0f, 197.4f, 161.8f, 144.0f, 144.0f,
4440 21.0f, 17.8f, 14.6f, 13.0f, 13.0f,
4441 2.0f, 1.6f, 1.2f, 1.0f, 1.0f
4442 });
4443
4444 const armnn::PermutationVector NCHWToNHWC = { 0, 3, 1, 2 };
Matthew Bentham8800c002018-11-19 13:19:28 +00004445 if (dataLayout == armnn::DataLayout::NHWC)
James Conroy6b965822018-11-01 11:33:09 +00004446 {
4447 std::vector<float> tmp(inputData.size());
4448 armnnUtils::Permute(inputTensorInfo.GetShape(), NCHWToNHWC, inputData.data(), tmp.data());
4449 inputData = tmp;
4450
4451 std::vector<float> tmp1(outputData.size());
4452 armnnUtils::Permute(outputTensorInfo.GetShape(), NCHWToNHWC, outputData.data(), tmp1.data());
4453 outputData = tmp1;
4454 }
4455
4456 auto input = MakeTensor<float, 4>(inputTensorInfo, inputData);
4457
4458 LayerTestResult<float, 4> result(outputTensorInfo);
4459 result.outputExpected = MakeTensor<float, 4>(outputTensorInfo, outputData);
telsoa014fcda012018-03-09 14:13:49 +00004460
4461 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
4462 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
4463
4464 armnn::ResizeBilinearQueueDescriptor descriptor;
James Conroy074f3712018-10-03 09:32:03 +01004465 descriptor.m_Parameters.m_DataLayout = dataLayout;
telsoa014fcda012018-03-09 14:13:49 +00004466 armnn::WorkloadInfo info;
4467 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
4468 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
4469
4470 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
4471
4472 inputHandle->Allocate();
4473 outputHandle->Allocate();
4474 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
4475
4476 workload->Execute();
4477
4478 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
4479 return result;
4480}
4481
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004482LayerTestResult<float, 2> FakeQuantizationTest(
4483 armnn::IWorkloadFactory& workloadFactory,
4484 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00004485{
4486 constexpr unsigned int width = 2;
4487 constexpr unsigned int height = 3;
4488
4489 const armnn::TensorInfo tensorInfo({height, width },
4490 armnn::DataType::Float32);
4491 auto input = MakeTensor<float, 2>(tensorInfo, std::vector<float>({
4492 -10.0f, -5.0f,
4493 0.0f, 5.0f,
4494 10.0f, 10.0f
4495 }));
4496
4497 LayerTestResult<float, 2> ret(tensorInfo);
4498
4499 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(tensorInfo);
4500
4501 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(tensorInfo);
4502
4503 armnn::FakeQuantizationQueueDescriptor data;
4504 armnn::WorkloadInfo info;
4505
4506 AddInputToWorkload(data, info, tensorInfo, inputHandle.get());
4507 AddOutputToWorkload(data, info, tensorInfo, outputHandle.get());
4508 float min = -10.f;
4509 float max = 10.f;
4510
4511 data.m_Parameters.m_Min = min;
4512 data.m_Parameters.m_Max = max;
4513
4514 armnn::PassthroughCpuTensorHandle refHandle(tensorInfo, &ret.outputExpected[0][0]);
4515 armnn::FakeQuantizationQueueDescriptor refData = data;
4516 armnn::WorkloadInfo refInfo = info;
4517 SetWorkloadOutput(refData, refInfo, 0, tensorInfo, &refHandle);
4518
4519 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateFakeQuantization(data, info);
4520
4521 inputHandle->Allocate();
4522 outputHandle->Allocate();
4523
4524 CopyDataToITensorHandle(inputHandle.get(), &input[0][0]);
4525
4526 workload->Execute();
4527
4528 CopyDataFromITensorHandle(&ret.output[0][0], outputHandle.get());
4529
4530 ret.outputExpected = MakeTensor<float, 2>(tensorInfo, std::vector<float>({
4531 0.0f, 63.0f,
4532 128.0f, 191.0f,
4533 255.0f, 255.0f
4534 }));
4535 return ret;
4536}
4537
Matteo Martincigh539b44d2018-10-01 09:26:39 +01004538namespace
4539{
4540
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004541LayerTestResult<float, 4> L2NormalizationTestImpl(
4542 armnn::IWorkloadFactory& workloadFactory,
4543 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4544 const armnn::TensorShape& inputOutputTensorShape,
4545 const std::vector<float>& inputValues,
4546 const std::vector<float>& expectedOutputValues,
Matthew Bentham8800c002018-11-19 13:19:28 +00004547 const armnn::DataLayout layout)
Matteo Martincigh539b44d2018-10-01 09:26:39 +01004548{
4549 const armnn::TensorInfo inputTensorInfo(inputOutputTensorShape, armnn::DataType::Float32);
4550 const armnn::TensorInfo outputTensorInfo(inputOutputTensorShape, armnn::DataType::Float32);
4551
jimfly013aab7c32018-11-12 13:32:08 +00004552 // at this point if we require it permute the input data
4553 const armnn::PermutationVector NCHWToNHWC = { 0, 3, 1, 2 };
4554 std::vector<float> inputData = inputValues;
Matthew Bentham8800c002018-11-19 13:19:28 +00004555 if (layout == armnn::DataLayout::NHWC)
jimfly013aab7c32018-11-12 13:32:08 +00004556 {
4557 std::vector<float> tmp(inputData.size());
4558 armnnUtils::Permute(inputTensorInfo.GetShape(), NCHWToNHWC, inputData.data(), tmp.data());
4559 inputData = tmp;
4560 }
4561
4562 auto inputTensor = MakeTensor<float, 4>(inputTensorInfo, std::vector<float>(inputData));
Matteo Martincigh539b44d2018-10-01 09:26:39 +01004563
4564 LayerTestResult<float, 4> result(outputTensorInfo);
jimfly013aab7c32018-11-12 13:32:08 +00004565 std::vector<float> expectedOutputData = expectedOutputValues;
Matthew Bentham8800c002018-11-19 13:19:28 +00004566 if (layout == armnn::DataLayout::NHWC)
jimfly013aab7c32018-11-12 13:32:08 +00004567 {
4568 std::vector<float> tmp(expectedOutputData.size());
4569 armnnUtils::Permute(inputTensorInfo.GetShape(), NCHWToNHWC, expectedOutputData.data(), tmp.data());
4570 expectedOutputData = tmp;
4571 }
4572 result.outputExpected = MakeTensor<float, 4>(inputTensorInfo, std::vector<float>(expectedOutputData));
Matteo Martincigh539b44d2018-10-01 09:26:39 +01004573
4574 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
4575 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
4576
4577 armnn::L2NormalizationQueueDescriptor descriptor;
Matthew Bentham8800c002018-11-19 13:19:28 +00004578 descriptor.m_Parameters.m_DataLayout = layout;
Matteo Martincigh539b44d2018-10-01 09:26:39 +01004579 armnn::WorkloadInfo info;
4580
4581 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
4582 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
4583
4584 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateL2Normalization(descriptor, info);
4585
4586 inputHandle->Allocate();
4587 outputHandle->Allocate();
4588
4589 CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0][0][0]);
4590
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004591 ExecuteWorkload(*workload, memoryManager);
Matteo Martincigh539b44d2018-10-01 09:26:39 +01004592
4593 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
4594
4595 return result;
4596}
4597
4598float CalcInvL2Norm(std::initializer_list<float> elements)
4599{
4600 const float reduction = std::accumulate(elements.begin(), elements.end(), 0.0f,
4601 [](float acc, float element) { return acc + element * element; });
4602 return 1.0f / sqrtf(reduction);
4603}
4604
4605} // anonymous namespace
4606
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004607template<typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004608LayerTestResult<T, 2> Pad2dTestCommon(
4609 armnn::IWorkloadFactory& workloadFactory,
4610 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4611 float qScale,
4612 int32_t qOffset)
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004613{
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004614 const armnn::TensorShape inputShape{ 3, 3 };
4615 const armnn::TensorShape outputShape{ 7, 7 };
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004616
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004617 const armnn::TensorInfo inputTensorInfo(inputShape, armnn::GetDataType<T>());
4618 const armnn::TensorInfo outputTensorInfo(outputShape, armnn::GetDataType<T>());
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004619
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004620 std::vector<T> inputValues(
4621 QuantizedVector<T>(qScale, qOffset,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004622 {
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004623 // Height (3) x Width (3)
4624 4, 8, 6,
4625 7, 4, 4,
4626 3, 2, 4
4627 }));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004628
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004629 std::vector<T> expectedOutputValues(
4630 QuantizedVector<T>(qScale, qOffset,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004631 {
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004632 0, 0, 0, 0, 0, 0, 0,
4633 0, 0, 0, 0, 0, 0, 0,
4634 0, 0, 4, 8, 6, 0, 0,
4635 0, 0, 7, 4, 4, 0, 0,
4636 0, 0, 3, 2, 4, 0, 0,
4637 0, 0, 0, 0, 0, 0, 0,
4638 0, 0, 0, 0, 0, 0, 0
4639 }));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004640
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004641 auto inputTensor = MakeTensor<T, 2>(inputTensorInfo, std::vector<T>(inputValues));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004642
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004643 LayerTestResult<T, 2> result(outputTensorInfo);
4644 result.outputExpected = MakeTensor<T, 2>(outputTensorInfo, std::vector<T>(expectedOutputValues));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004645
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004646 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
4647 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004648
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004649 armnn::PadQueueDescriptor descriptor;
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004650
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004651 std::vector<std::pair<unsigned int, unsigned int>> PadList;
4652 PadList.push_back(std::pair<unsigned int, unsigned int>(2,2));
4653 PadList.push_back(std::pair<unsigned int, unsigned int>(2,2));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004654
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004655 descriptor.m_Parameters.m_PadList = PadList;
4656 armnn::WorkloadInfo info;
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004657
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004658 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
4659 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004660
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004661 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreatePad(descriptor, info);
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004662
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004663 inputHandle->Allocate();
4664 outputHandle->Allocate();
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004665
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004666 CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0]);
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004667
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004668 workload->Execute();
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004669
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004670 CopyDataFromITensorHandle(&result.output[0][0], outputHandle.get());
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004671
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004672 return result;
4673}
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004674
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004675template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004676LayerTestResult<T, 3> Pad3dTestCommon(
4677 armnn::IWorkloadFactory& workloadFactory,
4678 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4679 float qScale,
4680 int32_t qOffset)
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004681{
4682 const armnn::TensorShape inputShape{ 2, 2, 2 };
4683 const armnn::TensorShape outputShape{ 3, 5, 6 };
4684
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004685 const armnn::TensorInfo inputTensorInfo(inputShape, armnn::GetDataType<T>());
4686 const armnn::TensorInfo outputTensorInfo(outputShape, armnn::GetDataType<T>());
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004687
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004688 std::vector<T> inputValues(
4689 QuantizedVector<T>(qScale,qOffset,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004690 {
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004691 // Channel 0, Height (2) x Width (2)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004692 0, 4,
4693 2, 5,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004694
4695 // Channel 1, Height (2) x Width (2)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004696 6, 1,
4697 5, 2
4698 }));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004699
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004700 std::vector<T> expectedOutputValues(
4701 QuantizedVector<T>(qScale,qOffset,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004702 {
4703
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004704 0, 0, 0, 0, 0, 0,
4705 0, 0, 0, 0, 0, 0,
4706 0, 0, 0, 4, 0, 0,
4707 0, 0, 2, 5, 0, 0,
4708 0, 0, 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004709
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004710 0, 0, 0, 0, 0, 0,
4711 0, 0, 0, 0, 0, 0,
4712 0, 0, 6, 1, 0, 0,
4713 0, 0, 5, 2, 0, 0,
4714 0, 0, 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004715
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004716 0, 0, 0, 0, 0, 0,
4717 0, 0, 0, 0, 0, 0,
4718 0, 0, 0, 0, 0, 0,
4719 0, 0, 0, 0, 0, 0,
4720 0, 0, 0, 0, 0, 0
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004721
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004722 }));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004723
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004724 auto inputTensor = MakeTensor<T, 3>(inputTensorInfo, std::vector<T>(inputValues));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004725
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004726 LayerTestResult<T, 3> result(outputTensorInfo);
4727 result.outputExpected = MakeTensor<T, 3>(outputTensorInfo, std::vector<T>(expectedOutputValues));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004728
4729 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
4730 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
4731
4732 armnn::PadQueueDescriptor descriptor;
4733
4734 std::vector<std::pair<unsigned int, unsigned int>> PadList;
4735 PadList.push_back(std::pair<unsigned int, unsigned int>(0,1));
4736 PadList.push_back(std::pair<unsigned int, unsigned int>(2,1));
4737 PadList.push_back(std::pair<unsigned int, unsigned int>(2,2));
4738
4739 descriptor.m_Parameters.m_PadList = PadList;
4740 armnn::WorkloadInfo info;
4741
4742 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
4743 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
4744
4745 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreatePad(descriptor, info);
4746
4747 inputHandle->Allocate();
4748 outputHandle->Allocate();
4749
4750 CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0][0]);
4751
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004752 workload->Execute();
4753
4754 CopyDataFromITensorHandle(&result.output[0][0][0], outputHandle.get());
4755
4756 return result;
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004757}
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004758
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004759template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004760LayerTestResult<T, 4> Pad4dTestCommon(
4761 armnn::IWorkloadFactory& workloadFactory,
4762 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
4763 float qScale,
4764 int32_t qOffset)
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004765{
4766 const armnn::TensorShape inputShape{ 2, 2, 3, 2 };
4767 const armnn::TensorShape outputShape{ 4, 5, 7, 4 };
4768
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004769 const armnn::TensorInfo inputTensorInfo(inputShape, armnn::GetDataType<T>());
4770 const armnn::TensorInfo outputTensorInfo(outputShape, armnn::GetDataType<T>());
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004771
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004772 std::vector<T> inputValues(
4773 QuantizedVector<T>(qScale,qOffset,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004774 {
4775 // Batch 0, Channel 0, Height (3) x Width (2)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004776 0, 1,
4777 2, 3,
4778 4, 5,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004779
4780 // Batch 0, Channel 1, Height (3) x Width (2)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004781 6, 7,
4782 8, 9,
4783 10, 11,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004784
4785 // Batch 1, Channel 0, Height (3) x Width (2)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004786 12, 13,
4787 14, 15,
4788 16, 17,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004789
4790 // Batch 1, Channel 1, Height (3) x Width (2)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004791 18, 19,
4792 20, 21,
4793 22, 23
4794 }));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004795
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004796 std::vector<T> expectedOutputValues(
4797 QuantizedVector<T>(qScale,qOffset,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004798 {
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004799 0, 0, 0, 0,
4800 0, 0, 0, 0,
4801 0, 0, 0, 0,
4802 0, 0, 0, 0,
4803 0, 0, 0, 0,
4804 0, 0, 0, 0,
4805 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004806
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004807 0, 0, 0, 0,
4808 0, 0, 0, 0,
4809 0, 0, 0, 0,
4810 0, 0, 0, 0,
4811 0, 0, 0, 0,
4812 0, 0, 0, 0,
4813 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004814
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004815 0, 0, 0, 0,
4816 0, 0, 0, 0,
4817 0, 0, 0, 0,
4818 0, 0, 0, 0,
4819 0, 0, 0, 0,
4820 0, 0, 0, 0,
4821 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004822
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004823 0, 0, 0, 0,
4824 0, 0, 0, 0,
4825 0, 0, 0, 0,
4826 0, 0, 0, 0,
4827 0, 0, 0, 0,
4828 0, 0, 0, 0,
4829 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004830
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004831 0, 0, 0, 0,
4832 0, 0, 0, 0,
4833 0, 0, 0, 0,
4834 0, 0, 0, 0,
4835 0, 0, 0, 0,
4836 0, 0, 0, 0,
4837 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004838
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004839 0, 0, 0, 0,
4840 0, 0, 0, 0,
4841 0, 0, 0, 0,
4842 0, 0, 0, 0,
4843 0, 0, 0, 0,
4844 0, 0, 0, 0,
4845 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004846
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004847 0, 0, 0, 0,
4848 0, 0, 0, 0,
4849 0, 0, 0, 0,
4850 0, 0, 0, 0,
4851 0, 0, 0, 0,
4852 0, 0, 0, 0,
4853 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004854
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004855 0, 0, 0, 0,
4856 0, 0, 0, 0,
4857 0, 0, 0, 0,
4858 0, 0, 1, 0,
4859 0, 2, 3, 0,
4860 0, 4, 5, 0,
4861 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004862
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004863 0, 0, 0, 0,
4864 0, 0, 0, 0,
4865 0, 0, 0, 0,
4866 0, 6, 7, 0,
4867 0, 8, 9, 0,
4868 0, 10, 11, 0,
4869 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004870
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004871 0, 0, 0, 0,
4872 0, 0, 0, 0,
4873 0, 0, 0, 0,
4874 0, 0, 0, 0,
4875 0, 0, 0, 0,
4876 0, 0, 0, 0,
4877 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004878
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004879 0, 0, 0, 0,
4880 0, 0, 0, 0,
4881 0, 0, 0, 0,
4882 0, 0, 0, 0,
4883 0, 0, 0, 0,
4884 0, 0, 0, 0,
4885 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004886
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004887 0, 0, 0, 0,
4888 0, 0, 0, 0,
4889 0, 0, 0, 0,
4890 0, 0, 0, 0,
4891 0, 0, 0, 0,
4892 0, 0, 0, 0,
4893 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004894
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004895 0, 0, 0, 0,
4896 0, 0, 0, 0,
4897 0, 0, 0, 0,
4898 0, 12, 13, 0,
4899 0, 14, 15, 0,
4900 0, 16, 17, 0,
4901 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004902
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004903 0, 0, 0, 0,
4904 0, 0, 0, 0,
4905 0, 0, 0, 0,
4906 0, 18, 19, 0,
4907 0, 20, 21, 0,
4908 0, 22, 23, 0,
4909 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004910
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004911 0, 0, 0, 0,
4912 0, 0, 0, 0,
4913 0, 0, 0, 0,
4914 0, 0, 0, 0,
4915 0, 0, 0, 0,
4916 0, 0, 0, 0,
4917 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004918
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004919 0, 0, 0, 0,
4920 0, 0, 0, 0,
4921 0, 0, 0, 0,
4922 0, 0, 0, 0,
4923 0, 0, 0, 0,
4924 0, 0, 0, 0,
4925 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004926
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004927 0, 0, 0, 0,
4928 0, 0, 0, 0,
4929 0, 0, 0, 0,
4930 0, 0, 0, 0,
4931 0, 0, 0, 0,
4932 0, 0, 0, 0,
4933 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004934
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004935 0, 0, 0, 0,
4936 0, 0, 0, 0,
4937 0, 0, 0, 0,
4938 0, 0, 0, 0,
4939 0, 0, 0, 0,
4940 0, 0, 0, 0,
4941 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004942
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004943 0, 0, 0, 0,
4944 0, 0, 0, 0,
4945 0, 0, 0, 0,
4946 0, 0, 0, 0,
4947 0, 0, 0, 0,
4948 0, 0, 0, 0,
4949 0, 0, 0, 0,
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004950
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004951 0, 0, 0, 0,
4952 0, 0, 0, 0,
4953 0, 0, 0, 0,
4954 0, 0, 0, 0,
4955 0, 0, 0, 0,
4956 0, 0, 0, 0,
4957 0, 0, 0, 0
4958 }));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004959
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004960 auto inputTensor = MakeTensor<T, 4>(inputTensorInfo, std::vector<T>(inputValues));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004961
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004962 LayerTestResult<T, 4> result(outputTensorInfo);
4963 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, std::vector<T>(expectedOutputValues));
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004964
4965 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
4966 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
4967
4968 armnn::PadQueueDescriptor descriptor;
4969
4970 std::vector<std::pair<unsigned int, unsigned int>> PadList;
4971 PadList.push_back(std::pair<unsigned int, unsigned int>(1,1));
4972 PadList.push_back(std::pair<unsigned int, unsigned int>(2,1));
4973 PadList.push_back(std::pair<unsigned int, unsigned int>(3,1));
4974 PadList.push_back(std::pair<unsigned int, unsigned int>(1,1));
4975
4976 descriptor.m_Parameters.m_PadList = PadList;
4977 armnn::WorkloadInfo info;
4978
4979 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
4980 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
4981
4982 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreatePad(descriptor, info);
4983
4984 inputHandle->Allocate();
4985 outputHandle->Allocate();
4986
4987 CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0][0][0]);
4988
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01004989 workload->Execute();
4990
4991 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
4992
4993 return result;
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004994}
4995
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00004996LayerTestResult<uint8_t, 2> PadUint82dTest(
4997 armnn::IWorkloadFactory& workloadFactory,
4998 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01004999{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005000 return Pad2dTestCommon<uint8_t>(workloadFactory, memoryManager, 1.0f, 0);
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005001}
5002
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005003LayerTestResult<uint8_t, 3> PadUint83dTest(
5004 armnn::IWorkloadFactory& workloadFactory,
5005 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005006{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005007 return Pad3dTestCommon<uint8_t>(workloadFactory, memoryManager, 1.0f, 0);
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005008}
5009
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005010LayerTestResult<uint8_t, 4> PadUint84dTest(
5011 armnn::IWorkloadFactory& workloadFactory,
5012 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005013{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005014 return Pad4dTestCommon<uint8_t>(workloadFactory, memoryManager, 1.0f, 0);
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005015}
5016
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005017LayerTestResult<float, 2> PadFloat322dTest(
5018 armnn::IWorkloadFactory& workloadFactory,
5019 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005020{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005021 return Pad2dTestCommon<float>(workloadFactory, memoryManager, 0.0f, 0);
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005022}
5023
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005024LayerTestResult<float, 3> PadFloat323dTest(
5025 armnn::IWorkloadFactory& workloadFactory,
5026 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005027{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005028 return Pad3dTestCommon<float>(workloadFactory, memoryManager, 0.0f, 0);
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005029}
5030
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005031LayerTestResult<float, 4> PadFloat324dTest(
5032 armnn::IWorkloadFactory& workloadFactory,
5033 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005034{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005035 return Pad4dTestCommon<float>(workloadFactory, memoryManager, 0.0f, 0);
Mohamed Nour Abouelseouddd6acea2018-10-18 12:26:19 +01005036}
Mohamed Nour Abouelseoud7420e552018-10-12 12:26:24 +01005037
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005038LayerTestResult<float, 4> L2Normalization1dTest(
5039 armnn::IWorkloadFactory& workloadFactory,
5040 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00005041 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +00005042{
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005043 // Width: 1
5044 // Height: 1
5045 // Channels: 10
5046 // BatchSize: 1
jimfly013aab7c32018-11-12 13:32:08 +00005047 unsigned int numberOfBatches = 1;
5048 unsigned int numberOfChannels = 10;
5049 unsigned int height = 1;
5050 unsigned int width = 1;
telsoa014fcda012018-03-09 14:13:49 +00005051
jimfly013aab7c32018-11-12 13:32:08 +00005052
Nina Drozdd41b2592018-11-19 13:03:36 +00005053 const armnn::TensorShape inputOutputShape = armnnUtils::GetTensorShape(
jimfly013aab7c32018-11-12 13:32:08 +00005054 numberOfBatches, numberOfChannels, height, width, layout);
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005055 std::vector<float> inputValues
5056 {
5057 // Batch 0, Channel 0, Height (1) x Width (1)
5058 1.0f,
telsoa014fcda012018-03-09 14:13:49 +00005059
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005060 // Batch 0, Channel 1, Height (1) x Width (1)
5061 2.0f,
telsoa014fcda012018-03-09 14:13:49 +00005062
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005063 // Batch 0, Channel 2, Height (1) x Width (1)
5064 3.0f,
telsoa014fcda012018-03-09 14:13:49 +00005065
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005066 // Batch 0, Channel 3, Height (1) x Width (1)
5067 4.0f,
5068
5069 // Batch 0, Channel 4, Height (1) x Width (1)
5070 5.0f,
5071
5072 // Batch 0, Channel 5, Height (1) x Width (1)
5073 6.0f,
5074
5075 // Batch 0, Channel 6, Height (1) x Width (1)
5076 7.0f,
5077
5078 // Batch 0, Channel 7, Height (1) x Width (1)
5079 8.0f,
5080
5081 // Batch 0, Channel 8, Height (1) x Width (1)
5082 9.0f,
5083
5084 // Batch 0, Channel 9, Height (1) x Width (1)
5085 10.0f
5086 };
telsoa014fcda012018-03-09 14:13:49 +00005087 const float approxInvL2Norm = 0.050964719f;
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005088 std::vector<float> expectedOutputValues
5089 {
5090 // Batch 0, Channel 0, Height (1) x Width (1)
telsoa014fcda012018-03-09 14:13:49 +00005091 1.0f * approxInvL2Norm,
5092 2.0f * approxInvL2Norm,
5093 3.0f * approxInvL2Norm,
5094 4.0f * approxInvL2Norm,
5095 5.0f * approxInvL2Norm,
5096 6.0f * approxInvL2Norm,
5097 7.0f * approxInvL2Norm,
5098 8.0f * approxInvL2Norm,
5099 9.0f * approxInvL2Norm,
5100 10.0f * approxInvL2Norm
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005101 };
telsoa014fcda012018-03-09 14:13:49 +00005102
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005103
5104 return L2NormalizationTestImpl(workloadFactory, memoryManager, inputOutputShape,
jimfly013aab7c32018-11-12 13:32:08 +00005105 inputValues, expectedOutputValues, layout);
telsoa014fcda012018-03-09 14:13:49 +00005106}
5107
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005108LayerTestResult<float, 4> L2Normalization2dTest(
5109 armnn::IWorkloadFactory& workloadFactory,
5110 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00005111 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +00005112{
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005113 // Width: 5
5114 // Height: 1
5115 // Channels: 2
5116 // BatchSize: 1
jimfly013aab7c32018-11-12 13:32:08 +00005117 unsigned int numberOfBatches = 1;
5118 unsigned int numberOfChannels = 2;
5119 unsigned int height = 1;
5120 unsigned int width = 5;
telsoa014fcda012018-03-09 14:13:49 +00005121
Nina Drozdd41b2592018-11-19 13:03:36 +00005122 const armnn::TensorShape inputOutputShape = armnnUtils::GetTensorShape(
jimfly013aab7c32018-11-12 13:32:08 +00005123 numberOfBatches, numberOfChannels, height, width, layout);
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005124 std::vector<float> inputValues
5125 {
5126 // Batch 0, Channel 0, Height (1) x Width (5)
telsoa014fcda012018-03-09 14:13:49 +00005127 1.0f, 3.0f, 5.0f, 7.0f, 9.0f,
telsoa014fcda012018-03-09 14:13:49 +00005128
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005129 // Batch 0, Channel 1, Height (1) x Width (5)
5130 2.0f, 4.0f, 6.0f, 8.0f, 10.0f
5131 };
5132 std::vector<float> expectedOutputValues
5133 {
5134 // Batch 0, Channel 0, Height (1) x Width (5)
5135 1.0f * CalcInvL2Norm({ 1.0f, 2.0f }),
5136 3.0f * CalcInvL2Norm({ 3.0f, 4.0f }),
5137 5.0f * CalcInvL2Norm({ 5.0f, 6.0f }),
5138 7.0f * CalcInvL2Norm({ 7.0f, 8.0f }),
telsoa014fcda012018-03-09 14:13:49 +00005139 9.0f * CalcInvL2Norm({ 9.0f, 10.0f }),
5140
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005141 // Batch 0, Channel 1, Height (1) x Width (5)
5142 2.0f * CalcInvL2Norm({ 1.0f, 2.0f }),
5143 4.0f * CalcInvL2Norm({ 3.0f, 4.0f }),
5144 6.0f * CalcInvL2Norm({ 5.0f, 6.0f }),
5145 8.0f * CalcInvL2Norm({ 7.0f, 8.0f }),
telsoa014fcda012018-03-09 14:13:49 +00005146 10.0f * CalcInvL2Norm({ 9.0f, 10.0f })
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005147 };
telsoa014fcda012018-03-09 14:13:49 +00005148
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005149 return L2NormalizationTestImpl(workloadFactory, memoryManager, inputOutputShape,
jimfly013aab7c32018-11-12 13:32:08 +00005150 inputValues, expectedOutputValues, layout);
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005151}
telsoa014fcda012018-03-09 14:13:49 +00005152
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005153LayerTestResult<float, 4> L2Normalization3dTest(
5154 armnn::IWorkloadFactory& workloadFactory,
5155 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00005156 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +00005157{
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005158 // Width: 3
5159 // Height: 4
5160 // Channels: 2
5161 // BatchSize: 1
jimfly013aab7c32018-11-12 13:32:08 +00005162 unsigned int numberOfBatches = 1;
5163 unsigned int numberOfChannels = 2;
5164 unsigned int height = 4;
5165 unsigned int width = 3;
telsoa014fcda012018-03-09 14:13:49 +00005166
Nina Drozdd41b2592018-11-19 13:03:36 +00005167 const armnn::TensorShape inputOutputShape = armnnUtils::GetTensorShape(
jimfly013aab7c32018-11-12 13:32:08 +00005168 numberOfBatches, numberOfChannels, height, width, layout);
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005169 std::vector<float> inputValues
5170 {
5171 // Batch 0, Channel 0, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005172 119.0f, 21.0f, 150.0f,
5173 149.0f, 32.0f, 179.0f,
5174 15.0f, 227.0f, 141.0f,
5175 147.0f, 199.0f, 220.0f,
5176
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005177 // Batch 0, Channel 1, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005178 110.0f, 140.0f, 73.0f,
5179 211.0f, 212.0f, 89.0f,
5180 24.0f, 138.0f, 188.0f,
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005181 162.0f, 12.0f, 161.0f
5182 };
5183 std::vector<float> expectedOutputValues
5184 {
5185 // Batch 0, Channel 0, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005186 119.0f * CalcInvL2Norm({ 119.0f, 110.0f }),
5187 21.0f * CalcInvL2Norm({ 21.0f, 140.0f }),
5188 150.0f * CalcInvL2Norm({ 150.0f, 73.0f }),
5189 149.0f * CalcInvL2Norm({ 149.0f, 211.0f }),
5190 32.0f * CalcInvL2Norm({ 32.0f, 212.0f }),
5191 179.0f * CalcInvL2Norm({ 179.0f, 89.0f }),
5192 15.0f * CalcInvL2Norm({ 15.0f, 24.0f }),
5193 227.0f * CalcInvL2Norm({ 227.0f, 138.0f }),
5194 141.0f * CalcInvL2Norm({ 141.0f, 188.0f }),
5195 147.0f * CalcInvL2Norm({ 147.0f, 162.0f }),
5196 199.0f * CalcInvL2Norm({ 199.0f, 12.0f }),
5197 220.0f * CalcInvL2Norm({ 220.0f, 161.0f }),
5198
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005199 // Batch 0, Channel 1, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005200 110.0f * CalcInvL2Norm({ 119.0f, 110.0f }),
5201 140.0f * CalcInvL2Norm({ 21.0f, 140.0f }),
5202 73.0f * CalcInvL2Norm({ 150.0f, 73.0f }),
5203 211.0f * CalcInvL2Norm({ 149.0f, 211.0f }),
5204 212.0f * CalcInvL2Norm({ 32.0f, 212.0f }),
5205 89.0f * CalcInvL2Norm({ 179.0f, 89.0f }),
5206 24.0f * CalcInvL2Norm({ 15.0f, 24.0f }),
5207 138.0f * CalcInvL2Norm({ 227.0f, 138.0f }),
5208 188.0f * CalcInvL2Norm({ 141.0f, 188.0f }),
5209 162.0f * CalcInvL2Norm({ 147.0f, 162.0f }),
5210 12.0f * CalcInvL2Norm({ 199.0f, 12.0f }),
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005211 161.0f * CalcInvL2Norm({ 220.0f, 161.0f })
5212 };
telsoa014fcda012018-03-09 14:13:49 +00005213
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005214 return L2NormalizationTestImpl(workloadFactory, memoryManager, inputOutputShape,
jimfly013aab7c32018-11-12 13:32:08 +00005215 inputValues, expectedOutputValues, layout);
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005216}
telsoa014fcda012018-03-09 14:13:49 +00005217
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005218LayerTestResult<float, 4> L2Normalization4dTest(
5219 armnn::IWorkloadFactory& workloadFactory,
5220 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00005221 const armnn::DataLayout layout)
telsoa014fcda012018-03-09 14:13:49 +00005222{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005223 // Width: 3
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005224 // Height: 4
5225 // Channels: 3
5226 // BatchSize: 2
jimfly013aab7c32018-11-12 13:32:08 +00005227 unsigned int numberOfBatches = 2;
5228 unsigned int numberOfChannels = 3;
5229 unsigned int height = 4;
5230 unsigned int width = 3;
telsoa014fcda012018-03-09 14:13:49 +00005231
Nina Drozdd41b2592018-11-19 13:03:36 +00005232 const armnn::TensorShape inputOutputShape = armnnUtils::GetTensorShape(
jimfly013aab7c32018-11-12 13:32:08 +00005233 numberOfBatches, numberOfChannels, height, width, layout);
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005234 std::vector<float> inputValues
5235 {
5236 // Batch 0, Channel 0, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005237 235.0f, 46.0f, 178.0f,
5238 100.0f, 123.0f, 19.0f,
5239 172.0f, 74.0f, 250.0f,
5240 6.0f, 195.0f, 80.0f,
5241
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005242 // Batch 0, Channel 1, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005243 113.0f, 95.0f, 202.0f,
5244 77.0f, 114.0f, 71.0f,
5245 122.0f, 246.0f, 166.0f,
5246 82.0f, 28.0f, 37.0f,
5247
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005248 // Batch 0, Channel 2, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005249 56.0f, 170.0f, 162.0f,
5250 194.0f, 89.0f, 254.0f,
5251 12.0f, 209.0f, 200.0f,
5252 1.0f, 64.0f, 54.0f,
5253
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005254 // Batch 1, Channel 0, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005255 67.0f, 90.0f, 49.0f,
5256 7.0f, 163.0f, 18.0f,
5257 25.0f, 117.0f, 103.0f,
5258 247.0f, 59.0f, 189.0f,
5259
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005260 // Batch 1, Channel 1, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005261 239.0f, 104.0f, 199.0f,
5262 17.0f, 124.0f, 153.0f,
5263 222.0f, 217.0f, 75.0f,
5264 32.0f, 126.0f, 21.0f,
5265
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005266 // Batch 1, Channel 2, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005267 97.0f, 145.0f, 215.0f,
5268 115.0f, 116.0f, 238.0f,
5269 226.0f, 16.0f, 132.0f,
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005270 92.0f, 125.0f, 88.0f
5271 };
5272 std::vector<float> expectedOutputValues
5273 {
5274 // Batch 0, Channel 0, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005275 235.0f * CalcInvL2Norm({ 235.0f, 113.0f, 56.0f }),
5276 46.0f * CalcInvL2Norm({ 46.0f, 95.0f, 170.0f }),
5277 178.0f * CalcInvL2Norm({ 178.0f, 202.0F, 162.0f }),
5278 100.0f * CalcInvL2Norm({ 100.0f, 77.0f, 194.0f }),
5279 123.0f * CalcInvL2Norm({ 123.0f, 114.0f, 89.0f }),
5280 19.0f * CalcInvL2Norm({ 19.0f, 71.0f, 254.0f }),
5281 172.0f * CalcInvL2Norm({ 172.0f, 122.0f, 12.0f }),
5282 74.0f * CalcInvL2Norm({ 74.0f, 246.0f, 209.0f }),
5283 250.0f * CalcInvL2Norm({ 250.0f, 166.0f, 200.0f }),
5284 6.0f * CalcInvL2Norm({ 6.0f, 82.0f, 1.0f }),
5285 195.0f * CalcInvL2Norm({ 195.0f, 28.0f, 64.0f }),
5286 80.0f * CalcInvL2Norm({ 80.0f, 37.0f, 54.0f }),
5287
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005288 // Batch 0, Channel 1, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005289 113.0f * CalcInvL2Norm({ 235.0f, 113.0f, 56.0f }),
5290 95.0f * CalcInvL2Norm({ 46.0f, 95.0f, 170.0f }),
5291 202.0f * CalcInvL2Norm({ 178.0f, 202.0F, 162.0f }),
5292 77.0f * CalcInvL2Norm({ 100.0f, 77.0f, 194.0f }),
5293 114.0f * CalcInvL2Norm({ 123.0f, 114.0f, 89.0f }),
5294 71.0f * CalcInvL2Norm({ 19.0f, 71.0f, 254.0f }),
5295 122.0f * CalcInvL2Norm({ 172.0f, 122.0f, 12.0f }),
5296 246.0f * CalcInvL2Norm({ 74.0f, 246.0f, 209.0f }),
5297 166.0f * CalcInvL2Norm({ 250.0f, 166.0f, 200.0f }),
5298 82.0f * CalcInvL2Norm({ 6.0f, 82.0f, 1.0f }),
5299 28.0f * CalcInvL2Norm({ 195.0f, 28.0f, 64.0f }),
5300 37.0f * CalcInvL2Norm({ 80.0f, 37.0f, 54.0f }),
5301
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005302 // Batch 0, Channel 2, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005303 56.0f * CalcInvL2Norm({ 235.0f, 113.0f, 56.0f }),
5304 170.0f * CalcInvL2Norm({ 46.0f, 95.0f, 170.0f }),
5305 162.0f * CalcInvL2Norm({ 178.0f, 202.0F, 162.0f }),
5306 194.0f * CalcInvL2Norm({ 100.0f, 77.0f, 194.0f }),
5307 89.0f * CalcInvL2Norm({ 123.0f, 114.0f, 89.0f }),
5308 254.0f * CalcInvL2Norm({ 19.0f, 71.0f, 254.0f }),
5309 12.0f * CalcInvL2Norm({ 172.0f, 122.0f, 12.0f }),
5310 209.0f * CalcInvL2Norm({ 74.0f, 246.0f, 209.0f }),
5311 200.0f * CalcInvL2Norm({ 250.0f, 166.0f, 200.0f }),
5312 1.0f * CalcInvL2Norm({ 6.0f, 82.0f, 1.0f }),
5313 64.0f * CalcInvL2Norm({ 195.0f, 28.0f, 64.0f }),
5314 54.0f * CalcInvL2Norm({ 80.0f, 37.0f, 54.0f }),
5315
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005316 // Batch 1, Channel 0, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005317 67.0f * CalcInvL2Norm({ 67.0f, 239.0f, 97.0f }),
5318 90.0f * CalcInvL2Norm({ 90.0f, 104.0f, 145.0f }),
5319 49.0f * CalcInvL2Norm({ 49.0f, 199.0f, 215.0f }),
5320 7.0f * CalcInvL2Norm({ 7.0f, 17.0f, 115.0f }),
5321 163.0f * CalcInvL2Norm({ 163.0f, 124.0f, 116.0f }),
5322 18.0f * CalcInvL2Norm({ 18.0f, 153.0f, 238.0f }),
5323 25.0f * CalcInvL2Norm({ 25.0f, 222.0f, 226.0f }),
5324 117.0f * CalcInvL2Norm({ 117.0f, 217.0f, 16.0f }),
5325 103.0f * CalcInvL2Norm({ 103.0f, 75.0f, 132.0f }),
5326 247.0f * CalcInvL2Norm({ 247.0f, 32.0f, 92.0f }),
5327 59.0f * CalcInvL2Norm({ 59.0f, 126.0f, 125.0f }),
5328 189.0f * CalcInvL2Norm({ 189.0f, 21.0f, 88.0f }),
5329
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005330 // Batch 1, Channel 1, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005331 239.0f * CalcInvL2Norm({ 67.0f, 239.0f, 97.0f }),
5332 104.0f * CalcInvL2Norm({ 90.0f, 104.0f, 145.0f }),
5333 199.0f * CalcInvL2Norm({ 49.0f, 199.0f, 215.0f }),
5334 17.0f * CalcInvL2Norm({ 7.0f, 17.0f, 115.0f }),
5335 124.0f * CalcInvL2Norm({ 163.0f, 124.0f, 116.0f }),
5336 153.0f * CalcInvL2Norm({ 18.0f, 153.0f, 238.0f }),
5337 222.0f * CalcInvL2Norm({ 25.0f, 222.0f, 226.0f }),
5338 217.0f * CalcInvL2Norm({ 117.0f, 217.0f, 16.0f }),
5339 75.0f * CalcInvL2Norm({ 103.0f, 75.0f, 132.0f }),
5340 32.0f * CalcInvL2Norm({ 247.0f, 32.0f, 92.0f }),
5341 126.0f * CalcInvL2Norm({ 59.0f, 126.0f, 125.0f }),
5342 21.0f * CalcInvL2Norm({ 189.0f, 21.0f, 88.0f }),
5343
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005344 // Batch 1, Channel 2, Height (4) x Width (3)
telsoa014fcda012018-03-09 14:13:49 +00005345 97.0f * CalcInvL2Norm({ 67.0f, 239.0f, 97.0f }),
5346 145.0f * CalcInvL2Norm({ 90.0f, 104.0f, 145.0f }),
5347 215.0f * CalcInvL2Norm({ 49.0f, 199.0f, 215.0f }),
5348 115.0f * CalcInvL2Norm({ 7.0f, 17.0f, 115.0f }),
5349 116.0f * CalcInvL2Norm({ 163.0f, 124.0f, 116.0f }),
5350 238.0f * CalcInvL2Norm({ 18.0f, 153.0f, 238.0f }),
5351 226.0f * CalcInvL2Norm({ 25.0f, 222.0f, 226.0f }),
5352 16.0f * CalcInvL2Norm({ 117.0f, 217.0f, 16.0f }),
5353 132.0f * CalcInvL2Norm({ 103.0f, 75.0f, 132.0f }),
5354 92.0f * CalcInvL2Norm({ 247.0f, 32.0f, 92.0f }),
5355 125.0f * CalcInvL2Norm({ 59.0f, 126.0f, 125.0f }),
Matteo Martincigh539b44d2018-10-01 09:26:39 +01005356 88.0f * CalcInvL2Norm({ 189.0f, 21.0f, 88.0f })
5357 };
telsoa014fcda012018-03-09 14:13:49 +00005358
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005359 return L2NormalizationTestImpl(workloadFactory, memoryManager, inputOutputShape,
jimfly013aab7c32018-11-12 13:32:08 +00005360 inputValues, expectedOutputValues, layout);
telsoa014fcda012018-03-09 14:13:49 +00005361}
5362
5363template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005364LayerTestResult<T, 4> ConstantTestImpl(
5365 armnn::IWorkloadFactory& workloadFactory,
5366 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
telsoa014fcda012018-03-09 14:13:49 +00005367 float qScale,
5368 int32_t qOffset)
5369{
5370 constexpr unsigned int inputWidth = 3;
5371 constexpr unsigned int inputHeight = 4;
5372 constexpr unsigned int inputChannels = 3;
5373 constexpr unsigned int inputBatchSize = 2;
5374
5375 constexpr unsigned int outputWidth = inputWidth;
5376 constexpr unsigned int outputHeight = inputHeight;
5377 constexpr unsigned int outputChannels = inputChannels;
5378 constexpr unsigned int outputBatchSize = inputBatchSize;
5379
5380 armnn::TensorInfo inputTensorInfo({ inputBatchSize, inputChannels, inputHeight, inputWidth },
5381 armnn::GetDataType<T>());
5382
5383 armnn::TensorInfo outputTensorInfo({ outputBatchSize, outputChannels, outputHeight, outputWidth },
5384 armnn::GetDataType<T>());
5385
5386 // Set quantization parameters if the requested type is a quantized type.
5387 if(armnn::IsQuantizedType<T>())
5388 {
5389 inputTensorInfo.SetQuantizationScale(qScale);
5390 inputTensorInfo.SetQuantizationOffset(qOffset);
5391 outputTensorInfo.SetQuantizationScale(qScale);
5392 outputTensorInfo.SetQuantizationOffset(qOffset);
5393 }
5394
5395 auto input = MakeTensor<T, 4>(inputTensorInfo, std::vector<T>(
5396 QuantizedVector<T>(qScale, qOffset, {
5397 // Batch 0, Channel 0
5398 235.0f, 46.0f, 178.0f,
5399 100.0f, 123.0f, 19.0f,
5400 172.0f, 74.0f, 250.0f,
5401 6.0f, 195.0f, 80.0f,
5402
5403 // Batch 0, Channel 1
5404 113.0f, 95.0f, 202.0f,
5405 77.0f, 114.0f, 71.0f,
5406 122.0f, 246.0f, 166.0f,
5407 82.0f, 28.0f, 37.0f,
5408
5409 // Batch 0, Channel 2
5410 56.0f, 170.0f, 162.0f,
5411 194.0f, 89.0f, 254.0f,
5412 12.0f, 209.0f, 200.0f,
5413 1.0f, 64.0f, 54.0f,
5414
5415 // Batch 1, Channel 0
5416 67.0f, 90.0f, 49.0f,
5417 7.0f, 163.0f, 18.0f,
5418 25.0f, 117.0f, 103.0f,
5419 247.0f, 59.0f, 189.0f,
5420
5421 // Batch 1, Channel 1
5422 239.0f, 104.0f, 199.0f,
5423 17.0f, 124.0f, 153.0f,
5424 222.0f, 217.0f, 75.0f,
5425 32.0f, 126.0f, 21.0f,
5426
5427 // Batch 1, Channel 2
5428 97.0f, 145.0f, 215.0f,
5429 115.0f, 116.0f, 238.0f,
5430 226.0f, 16.0f, 132.0f,
5431 92.0f, 125.0f, 88.0f,
5432 })));
5433
5434 LayerTestResult<T, 4> result(outputTensorInfo);
5435 result.outputExpected = input;
5436
5437 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
5438
5439 armnn::ScopedCpuTensorHandle constantTensor(inputTensorInfo);
5440 AllocateAndCopyDataToITensorHandle(&constantTensor, &input[0][0][0][0]);
5441
5442 armnn::ConstantQueueDescriptor descriptor;
5443 descriptor.m_LayerOutput = &constantTensor;
5444
5445 armnn::WorkloadInfo info;
5446 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
5447
5448 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateConstant(descriptor, info);
5449
5450 outputHandle->Allocate();
5451
5452 workload->Execute();
5453
5454 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
5455 return result;
5456}
5457
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005458LayerTestResult<float, 4> ConstantTest(
5459 armnn::IWorkloadFactory& workloadFactory,
5460 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00005461{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005462 return ConstantTestImpl<float>(workloadFactory, memoryManager, 0.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00005463}
5464
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005465LayerTestResult<uint8_t, 4> ConstantTestUint8(
5466 armnn::IWorkloadFactory& workloadFactory,
5467 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00005468{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005469 return ConstantTestImpl<uint8_t>(workloadFactory, memoryManager, 1.0f, 0);
telsoa014fcda012018-03-09 14:13:49 +00005470}
5471
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005472LayerTestResult<uint8_t, 3> MergerUint8Test(
5473 armnn::IWorkloadFactory& workloadFactory,
5474 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00005475{
surmeh013537c2c2018-05-18 16:31:43 +01005476 unsigned int outputWidth = 3;
telsoa014fcda012018-03-09 14:13:49 +00005477 unsigned int outputHeight = 6;
5478 unsigned int outputChannels = 3;
5479
surmeh013537c2c2018-05-18 16:31:43 +01005480 unsigned int inputWidth1 = 3;
5481 unsigned int inputHeight1 = 6;
5482 unsigned int inputChannels1 = 2;
telsoa014fcda012018-03-09 14:13:49 +00005483
surmeh013537c2c2018-05-18 16:31:43 +01005484 unsigned int inputWidth2 = 3;
5485 unsigned int inputHeight2 = 6;
5486 unsigned int inputChannels2 = 1;
telsoa014fcda012018-03-09 14:13:49 +00005487
telsoa01c577f2c2018-08-31 09:22:23 +01005488 // Defines the tensor descriptors.
telsoa014fcda012018-03-09 14:13:49 +00005489 armnn::TensorInfo outputTensorInfo({ outputChannels, outputHeight, outputWidth }, armnn::DataType::QuantisedAsymm8);
5490 armnn::TensorInfo inputTensorInfo1({ inputChannels1, inputHeight1, inputWidth1 }, armnn::DataType::QuantisedAsymm8);
5491 armnn::TensorInfo inputTensorInfo2({ inputChannels2, inputHeight2, inputWidth2 }, armnn::DataType::QuantisedAsymm8);
telsoa014fcda012018-03-09 14:13:49 +00005492
telsoa01c577f2c2018-08-31 09:22:23 +01005493 // Arbitrary scale and offsets. They don't really matter as the merger operator doesn't dequantize/quantize them.
telsoa014fcda012018-03-09 14:13:49 +00005494 const float scale = 0.13497836f;
5495 const int32_t offset = -7;
5496
5497 outputTensorInfo.SetQuantizationScale(scale);
5498 outputTensorInfo.SetQuantizationOffset(offset);
5499 inputTensorInfo1.SetQuantizationScale(scale);
5500 inputTensorInfo1.SetQuantizationOffset(offset);
5501 inputTensorInfo2.SetQuantizationScale(scale);
5502 inputTensorInfo2.SetQuantizationOffset(offset);
telsoa014fcda012018-03-09 14:13:49 +00005503
5504 LayerTestResult<uint8_t, 3> ret(outputTensorInfo);
5505
5506 ret.outputExpected = MakeTensor<uint8_t, 3>(outputTensorInfo, std::vector<uint8_t>(
surmeh013537c2c2018-05-18 16:31:43 +01005507 {
5508 1, 2, 3,
5509 4, 5, 6,
5510 7, 8, 9,
5511 10, 11, 12,
5512 13, 14, 15,
5513 16, 17, 18,
telsoa014fcda012018-03-09 14:13:49 +00005514
surmeh013537c2c2018-05-18 16:31:43 +01005515 19, 20, 21,
5516 22, 23, 24,
5517 25, 26, 27,
5518 28, 29, 30,
5519 31, 32, 33,
5520 34, 35, 36,
telsoa014fcda012018-03-09 14:13:49 +00005521
surmeh013537c2c2018-05-18 16:31:43 +01005522 37, 38, 39,
5523 40, 41, 42,
5524 43, 44, 45,
5525 46, 47, 48,
5526 49, 50, 51,
5527 52, 53, 54,
5528 })
telsoa014fcda012018-03-09 14:13:49 +00005529 );
5530
telsoa014fcda012018-03-09 14:13:49 +00005531 auto input1 = MakeTensor<uint8_t, 3>(inputTensorInfo1, std::vector<uint8_t>(
5532 {
surmeh013537c2c2018-05-18 16:31:43 +01005533 1, 2, 3,
5534 4, 5, 6,
5535 7, 8, 9,
5536 10, 11, 12,
5537 13, 14, 15,
5538 16, 17, 18,
telsoa014fcda012018-03-09 14:13:49 +00005539
surmeh013537c2c2018-05-18 16:31:43 +01005540 19, 20, 21,
5541 22, 23, 24,
5542 25, 26, 27,
5543 28, 29, 30,
5544 31, 32, 33,
5545 34, 35, 36,
telsoa014fcda012018-03-09 14:13:49 +00005546 })
5547 );
5548
5549 auto input2 = MakeTensor<uint8_t, 3>(inputTensorInfo2, std::vector<uint8_t>(
5550 {
surmeh013537c2c2018-05-18 16:31:43 +01005551 37, 38, 39,
5552 40, 41, 42,
telsoa014fcda012018-03-09 14:13:49 +00005553 43, 44, 45,
surmeh013537c2c2018-05-18 16:31:43 +01005554 46, 47, 48,
5555 49, 50, 51,
5556 52, 53, 54,
telsoa014fcda012018-03-09 14:13:49 +00005557 })
5558 );
5559
telsoa01c577f2c2018-08-31 09:22:23 +01005560 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 +00005561 armnn::MergerQueueDescriptor::ViewOrigin window1(wOrigin1);
5562
telsoa01c577f2c2018-08-31 09:22:23 +01005563 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 +00005564 armnn::MergerQueueDescriptor::ViewOrigin window2(wOrigin2);
5565
telsoa014fcda012018-03-09 14:13:49 +00005566
5567 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
5568
5569 bool subTensorsSupported = workloadFactory.SupportsSubTensors();
5570
5571 std::unique_ptr<armnn::ITensorHandle> inputHandle1 =
5572 subTensorsSupported ?
5573 workloadFactory.CreateSubTensorHandle(*outputHandle, inputTensorInfo1.GetShape(), wOrigin1.data()) :
5574 workloadFactory.CreateTensorHandle(inputTensorInfo1);
5575
5576 std::unique_ptr<armnn::ITensorHandle> inputHandle2 =
5577 subTensorsSupported ?
5578 workloadFactory.CreateSubTensorHandle(*outputHandle, inputTensorInfo2.GetShape(), wOrigin2.data()) :
5579 workloadFactory.CreateTensorHandle(inputTensorInfo2);
5580
telsoa014fcda012018-03-09 14:13:49 +00005581
5582 armnn::MergerQueueDescriptor data;
5583 armnn::WorkloadInfo info;
5584 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
5585 AddInputToWorkload(data, info, inputTensorInfo2, inputHandle2.get());
telsoa014fcda012018-03-09 14:13:49 +00005586 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
5587
5588 data.m_ViewOrigins.push_back(window1);
5589 data.m_ViewOrigins.push_back(window2);
telsoa014fcda012018-03-09 14:13:49 +00005590
5591 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateMerger(data, info);
5592
5593 inputHandle1->Allocate();
5594 inputHandle2->Allocate();
telsoa014fcda012018-03-09 14:13:49 +00005595 outputHandle->Allocate();
5596
5597 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0]);
5598 CopyDataToITensorHandle(inputHandle2.get(), &input2[0][0][0]);
telsoa014fcda012018-03-09 14:13:49 +00005599
5600 workload->Execute();
5601
5602 CopyDataFromITensorHandle(&ret.output[0][0][0], outputHandle.get());
5603
5604 return ret;
5605}
5606
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005607LayerTestResult<uint8_t, 4> AdditionUint8Test(
5608 armnn::IWorkloadFactory& workloadFactory,
5609 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00005610{
5611 unsigned int batchSize = 1;
5612 unsigned int channels = 2;
5613 unsigned int height = 2;
5614 unsigned int width = 3;
5615
5616 const float scale = 7.0f;
5617 const int32_t offset = 3;
5618
5619 armnn::TensorInfo inputTensorInfo1, inputTensorInfo2;
5620 armnn::TensorInfo outputTensorInfo;
5621
5622 const unsigned int shape[] = { batchSize, channels, height, width };
5623 inputTensorInfo1 = armnn::TensorInfo(4, shape, armnn::DataType::QuantisedAsymm8);
5624 inputTensorInfo1.SetQuantizationScale(scale);
5625 inputTensorInfo1.SetQuantizationOffset(offset);
5626
5627 inputTensorInfo2 = armnn::TensorInfo(4, shape, armnn::DataType::QuantisedAsymm8);
5628 inputTensorInfo2.SetQuantizationScale(scale);
5629 inputTensorInfo2.SetQuantizationOffset(offset);
5630
5631 outputTensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::QuantisedAsymm8);
5632 outputTensorInfo.SetQuantizationScale(scale);
5633 outputTensorInfo.SetQuantizationOffset(offset);
5634
telsoa01c577f2c2018-08-31 09:22:23 +01005635 // See dequantized values to the right.
telsoa014fcda012018-03-09 14:13:49 +00005636 auto input1 = MakeTensor<uint8_t, 4>(inputTensorInfo1, std::vector<uint8_t>(
5637 {
5638 63, 35, 77, 70, 56, 112, // 420, 224, 518, 469, 371, 763
5639 203, 28, 252, 168, 245, 91 // 1400, 175, 1743, 1155, 1694, 616
5640 }));
5641
telsoa01c577f2c2018-08-31 09:22:23 +01005642 // See dequantized values to the right.
telsoa014fcda012018-03-09 14:13:49 +00005643 auto input2 = MakeTensor<uint8_t, 4>(inputTensorInfo1, std::vector<uint8_t>(
5644 {
5645 21, 7, 175, 231, 175, 210, // 126, 28, 1204, 1596, 1204, 1449
5646 126, 161, 63, 21, 105, 126 // 861, 1106, 420, 126, 714, 861
5647 }));
5648
telsoa01c577f2c2018-08-31 09:22:23 +01005649 // See dequantized values to the right.
telsoa014fcda012018-03-09 14:13:49 +00005650 LayerTestResult<uint8_t, 4> result(outputTensorInfo);
5651 result.outputExpected = MakeTensor<uint8_t, 4>(outputTensorInfo, std::vector<uint8_t>(
5652 {
5653 81, 39, 249, 255, 228, 255, // 546, 252, 1722, 2065(clamped), 1575, 2212(clamped)
5654 255, 186, 255, 186, 255, 214, // 2261(clamped), 1281, 2163(clamped), 1281, 2408(clamped), 1477
5655 }));
5656
5657 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
5658 std::unique_ptr<armnn::ITensorHandle> inputHandle2 = workloadFactory.CreateTensorHandle(inputTensorInfo2);
5659 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
5660
5661 armnn::AdditionQueueDescriptor data;
5662 armnn::WorkloadInfo info;
5663 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
5664 AddInputToWorkload(data, info, inputTensorInfo2, inputHandle2.get());
5665 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
5666
5667 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateAddition(data, info);
5668
5669 inputHandle1->Allocate();
5670 inputHandle2->Allocate();
5671 outputHandle->Allocate();
5672
5673 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
5674 CopyDataToITensorHandle(inputHandle2.get(), &input2[0][0][0][0]);
5675
5676 workload->Execute();
5677
5678 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
5679
5680 return result;
5681}
5682
surmeh01bceff2f2018-03-29 16:29:27 +01005683namespace
telsoa014fcda012018-03-09 14:13:49 +00005684{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005685LayerTestResult<uint8_t, 4> MultiplicationUint8TestHelper(
5686 armnn::IWorkloadFactory& workloadFactory,
5687 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
5688 const unsigned int shape0[4],
5689 const std::vector<uint8_t> & values0,
5690 float scale0,
5691 int32_t offset0,
5692 const unsigned int shape1[4],
5693 const std::vector<uint8_t> & values1,
5694 float scale1,
5695 int32_t offset1,
5696 const unsigned int outShape[4],
5697 const std::vector<uint8_t> & outValues,
5698 float outScale,
5699 int32_t outOffset)
surmeh01bceff2f2018-03-29 16:29:27 +01005700{
5701 armnn::TensorInfo inputTensorInfo0(4, shape0, armnn::DataType::QuantisedAsymm8);
5702 armnn::TensorInfo inputTensorInfo1(4, shape1, armnn::DataType::QuantisedAsymm8);
5703 armnn::TensorInfo outputTensorInfo(4, outShape, armnn::DataType::QuantisedAsymm8);
telsoa014fcda012018-03-09 14:13:49 +00005704
surmeh01bceff2f2018-03-29 16:29:27 +01005705 inputTensorInfo0.SetQuantizationScale(scale0);
5706 inputTensorInfo0.SetQuantizationOffset(offset0);
telsoa014fcda012018-03-09 14:13:49 +00005707
surmeh01bceff2f2018-03-29 16:29:27 +01005708 inputTensorInfo1.SetQuantizationScale(scale1);
5709 inputTensorInfo1.SetQuantizationOffset(offset1);
telsoa014fcda012018-03-09 14:13:49 +00005710
surmeh01bceff2f2018-03-29 16:29:27 +01005711 outputTensorInfo.SetQuantizationScale(outScale);
5712 outputTensorInfo.SetQuantizationOffset(outOffset);
telsoa014fcda012018-03-09 14:13:49 +00005713
surmeh01bceff2f2018-03-29 16:29:27 +01005714 auto input0 = MakeTensor<uint8_t, 4>(inputTensorInfo0, values0);
5715 auto input1 = MakeTensor<uint8_t, 4>(inputTensorInfo1, values1);
telsoa014fcda012018-03-09 14:13:49 +00005716
telsoa014fcda012018-03-09 14:13:49 +00005717 LayerTestResult<uint8_t, 4> result(outputTensorInfo);
surmeh01bceff2f2018-03-29 16:29:27 +01005718 result.outputExpected = MakeTensor<uint8_t, 4>(outputTensorInfo, outValues);
telsoa014fcda012018-03-09 14:13:49 +00005719
surmeh01bceff2f2018-03-29 16:29:27 +01005720 std::unique_ptr<armnn::ITensorHandle> inputHandle0 = workloadFactory.CreateTensorHandle(inputTensorInfo0);
telsoa014fcda012018-03-09 14:13:49 +00005721 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
telsoa014fcda012018-03-09 14:13:49 +00005722 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
5723
5724 armnn::MultiplicationQueueDescriptor data;
5725 armnn::WorkloadInfo info;
surmeh01bceff2f2018-03-29 16:29:27 +01005726 AddInputToWorkload(data, info, inputTensorInfo0, inputHandle0.get());
5727 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
telsoa014fcda012018-03-09 14:13:49 +00005728 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
5729
5730 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateMultiplication(data, info);
5731
surmeh01bceff2f2018-03-29 16:29:27 +01005732 inputHandle0->Allocate();
telsoa014fcda012018-03-09 14:13:49 +00005733 inputHandle1->Allocate();
telsoa014fcda012018-03-09 14:13:49 +00005734 outputHandle->Allocate();
5735
surmeh01bceff2f2018-03-29 16:29:27 +01005736 CopyDataToITensorHandle(inputHandle0.get(), &input0[0][0][0][0]);
telsoa014fcda012018-03-09 14:13:49 +00005737 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
telsoa014fcda012018-03-09 14:13:49 +00005738
5739 workload->Execute();
5740
5741 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
5742
5743 return result;
5744}
surmeh01bceff2f2018-03-29 16:29:27 +01005745} // anonymous namespace
5746
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005747LayerTestResult<uint8_t, 4> MultiplicationUint8Test(
5748 armnn::IWorkloadFactory& workloadFactory,
5749 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01005750{
5751 unsigned int batchSize = 1;
5752 unsigned int channels = 2;
5753 unsigned int height = 2;
5754 unsigned int width = 3;
5755 const unsigned int shape[] = { batchSize, channels, height, width };
5756
telsoa01c577f2c2018-08-31 09:22:23 +01005757 // See dequantized values to the right.
surmeh01bceff2f2018-03-29 16:29:27 +01005758 std::vector<uint8_t> input0({
5759 62, 37, 3, 172, 13, 111, // 244, 144, 8, 684, 48, 440,
5760 188, 20, 73, 31, 23, 31 // 748, 76, 288, 120, 88, 120
5761 });
5762
telsoa01c577f2c2018-08-31 09:22:23 +01005763 // See dequantized values to the right.
surmeh01bceff2f2018-03-29 16:29:27 +01005764 std::vector<uint8_t> input1({
5765 126, 240, 252, 183, 121, 247, // 384, 726, 762, 555, 369, 747,
5766 48, 115, 151, 79, 78, 97 // 150, 351, 459, 243, 240, 297
5767 });
5768
telsoa01c577f2c2018-08-31 09:22:23 +01005769 // See dequantized values to the right.
surmeh01bceff2f2018-03-29 16:29:27 +01005770 std::vector<uint8_t> output(
5771 {
5772 64, 72, 0, 255, 8, 236, // 93696, 104544, 6096(clamped), 379620(clamped), 17712, 328680,
5773 77, 15, 92, 16, 10, 21, // 112200, 26676, 132192, 29160, 21120, 35640
5774 });
5775
5776 return MultiplicationUint8TestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005777 memoryManager,
surmeh01bceff2f2018-03-29 16:29:27 +01005778 shape,
5779 input0,
5780 4.0f,
5781 1,
5782 shape,
5783 input1,
5784 3.0f,
5785 -2,
5786 shape,
5787 output,
telsoa01c577f2c2018-08-31 09:22:23 +01005788 1366.255f, // Scale/offset chosen to have output values out of range.
surmeh01bceff2f2018-03-29 16:29:27 +01005789 -5);
5790}
5791
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005792LayerTestResult<uint8_t, 4> MultiplicationBroadcast1ElementUint8Test(
5793 armnn::IWorkloadFactory& workloadFactory,
5794 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01005795{
5796 const unsigned int shape0[] = { 1, 2, 2, 3 };
5797 const unsigned int shape1[] = { 1, 1, 1, 1 };
5798
5799 std::vector<uint8_t> input0({
5800 1, 2, 3, 4, 5, 6,
5801 7, 8, 9, 10, 11, 12
5802 });
5803
5804 std::vector<uint8_t> input1({2});
5805
5806 std::vector<uint8_t> output({
5807 2, 4, 6, 8, 10, 12,
5808 14, 16, 18, 20, 22, 24
5809 });
5810
5811 return MultiplicationUint8TestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005812 memoryManager,
surmeh01bceff2f2018-03-29 16:29:27 +01005813 shape0,
5814 input0,
5815 1.0f,
5816 0,
5817 shape1,
5818 input1,
5819 1.0f,
5820 0,
5821 shape0,
5822 output,
5823 1.0f,
5824 0);
5825}
5826
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005827LayerTestResult<uint8_t, 4> MultiplicationBroadcast1DVectorUint8Test(
5828 armnn::IWorkloadFactory& workloadFactory,
5829 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01005830{
5831 const unsigned int shape0[] = { 1, 2, 2, 3 };
5832 const unsigned int shape1[] = { 1, 1, 1, 3 };
5833
5834 std::vector<uint8_t> input0({
5835 1, 2, 3, 4, 5, 6,
5836 7, 8, 9, 10, 11, 12
5837 });
5838
5839 std::vector<uint8_t> input1({1, 2, 3});
5840
5841 std::vector<uint8_t> output({
5842 1, 4, 9, 4, 10, 18,
5843 7, 16, 27, 10, 22, 36
5844 });
5845
5846 return MultiplicationUint8TestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005847 memoryManager,
surmeh01bceff2f2018-03-29 16:29:27 +01005848 shape0,
5849 input0,
5850 1.0f,
5851 0,
5852 shape1,
5853 input1,
5854 1.0f,
5855 0,
5856 shape0,
5857 output,
5858 1.0f,
5859 0);
5860}
telsoa014fcda012018-03-09 14:13:49 +00005861
David Beckf195f032018-09-06 16:46:34 +01005862namespace
5863{
5864template <typename T>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005865LayerTestResult<T, 4> SubtractionTestHelper(
5866 armnn::IWorkloadFactory& workloadFactory,
5867 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
5868 const unsigned int shape0[4],
5869 const std::vector<T>& values0,
5870 float scale0,
5871 int32_t offset0,
5872 const unsigned int shape1[4],
5873 const std::vector<T> & values1,
5874 float scale1,
5875 int32_t offset1,
5876 const unsigned int outShape[4],
5877 const std::vector<T> & outValues,
5878 float outScale,
5879 int32_t outOffset)
David Beckf195f032018-09-06 16:46:34 +01005880{
5881 auto dataType = (std::is_same<T, uint8_t>::value ?
5882 armnn::DataType::QuantisedAsymm8 :
5883 armnn::DataType::Float32);
5884
5885 armnn::TensorInfo inputTensorInfo0(4, shape0, dataType);
5886 armnn::TensorInfo inputTensorInfo1(4, shape1, dataType);
5887 armnn::TensorInfo outputTensorInfo(4, outShape, dataType);
5888
5889 inputTensorInfo0.SetQuantizationScale(scale0);
5890 inputTensorInfo0.SetQuantizationOffset(offset0);
5891
5892 inputTensorInfo1.SetQuantizationScale(scale1);
5893 inputTensorInfo1.SetQuantizationOffset(offset1);
5894
5895 outputTensorInfo.SetQuantizationScale(outScale);
5896 outputTensorInfo.SetQuantizationOffset(outOffset);
5897
5898 auto input0 = MakeTensor<T, 4>(inputTensorInfo0, values0);
5899 auto input1 = MakeTensor<T, 4>(inputTensorInfo1, values1);
5900
5901 LayerTestResult<T, 4> result(outputTensorInfo);
5902 result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, outValues);
5903
5904 std::unique_ptr<armnn::ITensorHandle> inputHandle0 = workloadFactory.CreateTensorHandle(inputTensorInfo0);
5905 std::unique_ptr<armnn::ITensorHandle> inputHandle1 = workloadFactory.CreateTensorHandle(inputTensorInfo1);
5906 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
5907
5908 armnn::SubtractionQueueDescriptor data;
5909 armnn::WorkloadInfo info;
5910 AddInputToWorkload(data, info, inputTensorInfo0, inputHandle0.get());
5911 AddInputToWorkload(data, info, inputTensorInfo1, inputHandle1.get());
5912 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
5913
5914 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateSubtraction(data, info);
5915
5916 inputHandle0->Allocate();
5917 inputHandle1->Allocate();
5918 outputHandle->Allocate();
5919
5920 CopyDataToITensorHandle(inputHandle0.get(), &input0[0][0][0][0]);
5921 CopyDataToITensorHandle(inputHandle1.get(), &input1[0][0][0][0]);
5922
David Beckf195f032018-09-06 16:46:34 +01005923 workload->Execute();
5924
5925 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
5926
5927 return result;
5928}
5929} // anonymous namespace
5930
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005931LayerTestResult<uint8_t, 4> SubtractionUint8Test(
5932 armnn::IWorkloadFactory& workloadFactory,
5933 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beckf195f032018-09-06 16:46:34 +01005934{
5935 const unsigned int shape0[] = { 1, 1, 2, 2 };
5936 const unsigned int shape1[] = { 1, 1, 2, 2 };
5937
5938 std::vector<uint8_t> input0({ 10, 12, 14, 16 });
5939 std::vector<uint8_t> input1({ 1, 2, 1, 2 });
5940 std::vector<uint8_t> output({ 3, 3, 5, 5 });
5941
5942 return SubtractionTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005943 memoryManager,
David Beckf195f032018-09-06 16:46:34 +01005944 shape0, input0, 0.5f, 2,
5945 shape1, input1, 1.0f, 0,
5946 shape0, output, 1.0f, 0);
5947}
5948
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005949LayerTestResult<uint8_t, 4> SubtractionBroadcast1ElementUint8Test(
5950 armnn::IWorkloadFactory& workloadFactory,
5951 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beckf195f032018-09-06 16:46:34 +01005952{
5953 const unsigned int shape0[] = { 1, 1, 2, 2 };
5954 const unsigned int shape1[] = { 1, 1, 1, 1 };
5955
5956 std::vector<uint8_t> input0({ 10, 12, 14, 16 });
5957 std::vector<uint8_t> input1({ 2 });
5958 std::vector<uint8_t> output({ 5, 6, 7, 8 });
5959
5960 return SubtractionTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005961 memoryManager,
David Beckf195f032018-09-06 16:46:34 +01005962 shape0, input0, 0.5f, 2,
5963 shape1, input1, 1.0f, 0,
5964 shape0, output, 1.0f, 3);
5965}
5966
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005967LayerTestResult<uint8_t, 4> SubtractionBroadcastUint8Test(
5968 armnn::IWorkloadFactory& workloadFactory,
5969 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beckf195f032018-09-06 16:46:34 +01005970{
5971 const unsigned int shape0[] = { 1, 1, 2, 2 };
5972 const unsigned int shape1[] = { 1, 1, 2, 1 };
5973
5974 std::vector<uint8_t> input0({ 10, 12, 14, 16 });
5975 std::vector<uint8_t> input1({ 2, 1 });
5976 std::vector<uint8_t> output({ 8, 11, 12, 15 });
5977
5978 return SubtractionTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005979 memoryManager,
David Beckf195f032018-09-06 16:46:34 +01005980 shape0, input0, 1.0f, 0,
5981 shape1, input1, 1.0f, 0,
5982 shape0, output, 1.0f, 0);
5983}
5984
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005985LayerTestResult<float, 4> SubtractionTest(
5986 armnn::IWorkloadFactory& workloadFactory,
5987 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beckf195f032018-09-06 16:46:34 +01005988{
5989 const unsigned int shape0[] = { 1, 1, 2, 2 };
5990 const unsigned int shape1[] = { 1, 1, 2, 2 };
5991
5992 std::vector<float> input0({ 1, 2, 3, 4 });
5993 std::vector<float> input1({ 1, -1, 0, 2 });
5994 std::vector<float> output({ 0, 3, 3, 2 });
5995
5996 return SubtractionTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00005997 memoryManager,
David Beckf195f032018-09-06 16:46:34 +01005998 shape0, input0, 1.0f, 0,
5999 shape1, input1, 1.0f, 0,
6000 shape0, output, 1.0f, 0);
6001}
6002
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006003LayerTestResult<float, 4> SubtractionBroadcast1ElementTest(
6004 armnn::IWorkloadFactory& workloadFactory,
6005 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beckf195f032018-09-06 16:46:34 +01006006{
6007 const unsigned int shape0[] = { 1, 1, 2, 2 };
6008 const unsigned int shape1[] = { 1, 1, 1, 1 };
6009
6010 std::vector<float> input0({ 1, 2, 3, 4 });
6011 std::vector<float> input1({ 10 });
6012 std::vector<float> output({ -9, -8, -7, -6 });
6013
6014 return SubtractionTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006015 memoryManager,
David Beckf195f032018-09-06 16:46:34 +01006016 shape0, input0, 1.0f, 0,
6017 shape1, input1, 1.0f, 0,
6018 shape0, output, 1.0f, 0);
6019}
6020
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006021LayerTestResult<float, 4> SubtractionBroadcastTest(
6022 armnn::IWorkloadFactory& workloadFactory,
6023 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
David Beckf195f032018-09-06 16:46:34 +01006024{
6025 const unsigned int shape0[] = { 1, 1, 2, 2 };
6026 const unsigned int shape1[] = { 1, 1, 1, 2 };
6027
6028 std::vector<float> input0({ 1, 2, 3, 4 });
6029 std::vector<float> input1({ 10, -5 });
6030 std::vector<float> output({ -9, 7, -7, 9 });
6031
6032 return SubtractionTestHelper(workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006033 memoryManager,
David Beckf195f032018-09-06 16:46:34 +01006034 shape0, input0, 1.0f, 0,
6035 shape1, input1, 1.0f, 0,
6036 shape0, output, 1.0f, 0);
6037}
6038
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006039LayerTestResult<uint8_t, 4> ResizeBilinearNopUint8Test(
6040 armnn::IWorkloadFactory& workloadFactory,
6041 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006042{
6043 constexpr unsigned int inputWidth = 4;
6044 constexpr unsigned int inputHeight = 4;
6045 constexpr unsigned int inputChannels = 1;
6046 constexpr unsigned int inputBatchSize = 1;
6047
6048 constexpr unsigned int outputWidth = inputWidth;
6049 constexpr unsigned int outputHeight = inputHeight;
6050 constexpr unsigned int outputChannels = inputChannels;
6051 constexpr unsigned int outputBatchSize = inputBatchSize;
6052
6053 armnn::TensorInfo inputTensorInfo({ inputBatchSize, inputChannels, inputHeight, inputWidth },
6054 armnn::DataType::QuantisedAsymm8);
6055 inputTensorInfo.SetQuantizationScale(1.5f);
6056 inputTensorInfo.SetQuantizationOffset(-3);
6057
6058 armnn::TensorInfo outputTensorInfo({ outputBatchSize, outputChannels, outputHeight, outputWidth },
6059 armnn::DataType::QuantisedAsymm8);
6060 outputTensorInfo.SetQuantizationScale(1.5f);
6061 outputTensorInfo.SetQuantizationOffset(-3);
6062
6063 auto input = MakeTensor<uint8_t, 4>(inputTensorInfo, std::vector<uint8_t>({
6064 1, 2, 3, 4,
6065 2, 3, 4, 5,
6066 3, 4, 5, 6,
6067 4, 5, 6, 7
6068 }));
6069
6070 LayerTestResult<uint8_t, 4> result(outputTensorInfo);
6071 result.outputExpected = input;
6072
6073 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
6074 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
6075
6076 armnn::ResizeBilinearQueueDescriptor descriptor;
6077 armnn::WorkloadInfo info;
6078 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
6079 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
6080
6081 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
6082
6083 inputHandle->Allocate();
6084 outputHandle->Allocate();
6085 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
6086
6087 workload->Execute();
6088
6089 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
6090 return result;
6091}
6092
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006093LayerTestResult<uint8_t, 4> SimpleResizeBilinearUint8Test(
6094 armnn::IWorkloadFactory& workloadFactory,
6095 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006096{
6097 constexpr unsigned int inputWidth = 2;
6098 constexpr unsigned int inputHeight = 2;
6099 constexpr unsigned int inputChannels = 1;
6100 constexpr unsigned int inputBatchSize = 1;
6101
6102 constexpr unsigned int outputWidth = inputWidth / 2;
6103 constexpr unsigned int outputHeight = inputHeight / 2;
6104 constexpr unsigned int outputChannels = inputChannels;
6105 constexpr unsigned int outputBatchSize = inputBatchSize;
6106
6107 armnn::TensorInfo inputTensorInfo({ inputBatchSize, inputChannels, inputHeight, inputWidth },
6108 armnn::DataType::QuantisedAsymm8);
6109 inputTensorInfo.SetQuantizationScale(0.1567f);
6110 inputTensorInfo.SetQuantizationOffset(1);
6111
6112 armnn::TensorInfo outputTensorInfo({ outputBatchSize, outputChannels, outputHeight, outputWidth },
6113 armnn::DataType::QuantisedAsymm8);
6114 outputTensorInfo.SetQuantizationScale(0.1567f);
6115 outputTensorInfo.SetQuantizationOffset(1);
6116
6117 auto input = MakeTensor<uint8_t, 4>(inputTensorInfo, std::vector<uint8_t>({
6118 1, 255,
6119 200, 250
6120 }));
6121
6122 // The 'resize bilinear' operation projects the top-left corner of output texels into the input image,
6123 // then figures out the interpolants and weights. Note this is different to projecting the centre of the
telsoa01c577f2c2018-08-31 09:22:23 +01006124 // 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 +00006125 // that was at position (0,0) of the input matrix (rather than an average, which we would expect if projecting
6126 // the centre).
6127 LayerTestResult<uint8_t, 4> result(outputTensorInfo);
6128 result.outputExpected = MakeTensor<uint8_t, 4>(outputTensorInfo, std::vector<uint8_t>({
6129 1
6130 }));
6131
6132 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
6133 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
6134
6135 armnn::ResizeBilinearQueueDescriptor descriptor;
6136 armnn::WorkloadInfo info;
6137 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
6138 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
6139
6140 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
6141
6142 inputHandle->Allocate();
6143 outputHandle->Allocate();
6144 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
6145
6146 workload->Execute();
6147
6148 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
6149 return result;
6150}
6151
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006152LayerTestResult<uint8_t, 4> ResizeBilinearSqMinUint8Test(
6153 armnn::IWorkloadFactory& workloadFactory,
6154 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006155{
6156 constexpr unsigned int inputWidth = 4;
6157 constexpr unsigned int inputHeight = 4;
6158 constexpr unsigned int inputChannels = 1;
6159 constexpr unsigned int inputBatchSize = 1;
6160
6161 constexpr unsigned int outputWidth = inputWidth / 2;
6162 constexpr unsigned int outputHeight = inputHeight / 2;
6163 constexpr unsigned int outputChannels = inputChannels;
6164 constexpr unsigned int outputBatchSize = inputBatchSize;
6165
6166 armnn::TensorInfo inputTensorInfo({ inputBatchSize, inputChannels, inputHeight, inputWidth },
6167 armnn::DataType::QuantisedAsymm8);
6168 inputTensorInfo.SetQuantizationScale(3.141592f);
6169 inputTensorInfo.SetQuantizationOffset(3);
6170
6171 armnn::TensorInfo outputTensorInfo({ outputBatchSize, outputChannels, outputHeight, outputWidth },
6172 armnn::DataType::QuantisedAsymm8);
6173 outputTensorInfo.SetQuantizationScale(3.141592f);
6174 outputTensorInfo.SetQuantizationOffset(3);
6175
6176 auto input = MakeTensor<uint8_t, 4>(inputTensorInfo, std::vector<uint8_t>({
6177 1, 2, 3, 4,
6178 2, 3, 4, 5,
6179 3, 4, 5, 6,
6180 4, 5, 6, 7
6181 }));
6182
6183 LayerTestResult<uint8_t, 4> result(outputTensorInfo);
6184 result.outputExpected = MakeTensor<uint8_t, 4>(outputTensorInfo, std::vector<uint8_t>({
6185 1, 3,
6186 3, 5
6187 }));
6188
6189 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
6190 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
6191
6192 armnn::ResizeBilinearQueueDescriptor descriptor;
6193 armnn::WorkloadInfo info;
6194 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
6195 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
6196
6197 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
6198
6199 inputHandle->Allocate();
6200 outputHandle->Allocate();
6201 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
6202
6203 workload->Execute();
6204
6205 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
6206 return result;
6207}
6208
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006209LayerTestResult<uint8_t, 4> ResizeBilinearMinUint8Test(
6210 armnn::IWorkloadFactory& workloadFactory,
6211 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006212{
6213 constexpr unsigned int inputWidth = 3;
6214 constexpr unsigned int inputHeight = 2;
6215 constexpr unsigned int inputChannels = 1;
6216 constexpr unsigned int inputBatchSize = 1;
6217
6218 constexpr unsigned int outputWidth = 2;
6219 constexpr unsigned int outputHeight = 1;
6220 constexpr unsigned int outputChannels = inputChannels;
6221 constexpr unsigned int outputBatchSize = inputBatchSize;
6222
6223 armnn::TensorInfo inputTensorInfo({ inputBatchSize, inputChannels, inputHeight, inputWidth },
6224 armnn::DataType::QuantisedAsymm8);
6225 inputTensorInfo.SetQuantizationScale(1.5f);
6226 inputTensorInfo.SetQuantizationOffset(-1);
6227
6228 armnn::TensorInfo outputTensorInfo({ outputBatchSize, outputChannels, outputHeight, outputWidth },
6229 armnn::DataType::QuantisedAsymm8);
6230 outputTensorInfo.SetQuantizationScale(1.5f);
6231 outputTensorInfo.SetQuantizationOffset(-1);
6232
6233 auto input = MakeTensor<uint8_t, 4>(inputTensorInfo, std::vector<uint8_t>({
6234 1, 2, 3, // 3.0, 4.5, 6.0
6235 5, 8, 13 // 9.0, 13.5, 21.0
6236 }));
6237
6238 LayerTestResult<uint8_t, 4> result(outputTensorInfo);
6239 result.outputExpected = MakeTensor<uint8_t, 4>(outputTensorInfo, std::vector<uint8_t>({
6240 1, 3 // 3.0, 5.25
6241 }));
6242
6243 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
6244 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
6245
6246 armnn::ResizeBilinearQueueDescriptor descriptor;
6247 armnn::WorkloadInfo info;
6248 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
6249 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
6250
6251 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
6252
6253 inputHandle->Allocate();
6254 outputHandle->Allocate();
6255
6256 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
6257
6258 workload->Execute();
6259
6260 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
6261 return result;
6262}
6263
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006264LayerTestResult<uint8_t, 4> ResizeBilinearMagUint8Test(
6265 armnn::IWorkloadFactory& workloadFactory,
6266 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006267{
6268 constexpr unsigned int inputWidth = 2;
6269 constexpr unsigned int inputHeight = 3;
6270 constexpr unsigned int inputChannels = 1;
6271 constexpr unsigned int inputBatchSize = 1;
6272
6273 constexpr unsigned int outputWidth = 5;
6274 constexpr unsigned int outputHeight = 3;
6275 constexpr unsigned int outputChannels = inputChannels;
6276 constexpr unsigned int outputBatchSize = inputBatchSize;
6277
6278 armnn::TensorInfo inputTensorInfo({ inputBatchSize, inputChannels, inputHeight, inputWidth },
6279 armnn::DataType::QuantisedAsymm8);
6280 inputTensorInfo.SetQuantizationScale(0.010765f);
6281 inputTensorInfo.SetQuantizationOffset(7);
6282
6283 armnn::TensorInfo outputTensorInfo({ outputBatchSize, outputChannels, outputHeight, outputWidth },
6284 armnn::DataType::QuantisedAsymm8);
6285 outputTensorInfo.SetQuantizationScale(0.010132f);
6286 outputTensorInfo.SetQuantizationOffset(-18);
6287
6288 auto input = MakeTensor<uint8_t, 4>(inputTensorInfo, std::vector<uint8_t>({
6289 24, 228, // 0.183005, 2.379065,
6290 105, 128, // 1.05497, 1.302565
6291 230, 71 // 2.400595, 0.68896
6292 }));
6293
6294 LayerTestResult<uint8_t, 4> result(outputTensorInfo);
6295 result.outputExpected = MakeTensor<uint8_t, 4>(outputTensorInfo, std::vector<uint8_t>({
6296 0, 87, 173, 217, 217, // 0.18300501, 1.06142902, 1.93985295, 2.37906504, 2.37906504
6297 86, 96, 106, 111, 111, // 1.05497003, 1.15400803, 1.25304604, 1.30256498, 1.30256498
6298 219, 151, 84, 50, 50 // 2.40059495, 1.71594095, 1.03128707, 0.68896002, 0.68896002
6299 }));
6300
6301 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
6302 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
6303
6304 armnn::ResizeBilinearQueueDescriptor descriptor;
6305 armnn::WorkloadInfo info;
6306 AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get());
6307 AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get());
6308
6309 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResizeBilinear(descriptor, info);
6310
6311 inputHandle->Allocate();
6312 outputHandle->Allocate();
6313 CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]);
6314
6315 workload->Execute();
6316
6317 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
6318 return result;
6319}
6320
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006321LayerTestResult<float, 4> BatchNormTest(
6322 armnn::IWorkloadFactory& workloadFactory,
6323 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006324{
Matteo Martincigh8eb675e2018-10-17 14:43:29 +01006325 // BatchSize: 1
6326 // Channels: 2
6327 // Height: 3
6328 // Width: 2
6329
6330 const armnn::TensorShape inputOutputShape{ 1, 2, 3, 2 };
6331 std::vector<float> inputValues
6332 {
6333 // Batch 0, Channel 0, Height (3) x Width (2)
6334 1.f, 4.f,
6335 4.f, 2.f,
6336 1.f, 6.f,
6337
6338 // Batch 0, Channel 1, Height (3) x Width (2)
6339 1.f, 1.f,
6340 4.f, 1.f,
6341 -2.f, 4.f
6342 };
6343 std::vector<float> expectedOutputValues
6344 {
6345 // Batch 0, Channel 0, Height (3) x Width (2)
6346 1.f, 4.f,
6347 4.f, 2.f,
6348 1.f, 6.f,
6349
6350 // Batch 0, Channel 1, Height (3) x Width (2)
6351 3.f, 3.f,
6352 4.f, 3.f,
6353 2.f, 4.f
6354 };
6355
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006356 return BatchNormTestImpl<float>(workloadFactory, memoryManager,
6357 inputOutputShape, inputValues, expectedOutputValues,
Matteo Martincigh8eb675e2018-10-17 14:43:29 +01006358 0.f, 0, armnn::DataLayout::NCHW);
6359}
6360
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006361LayerTestResult<float, 4> BatchNormNhwcTest(
6362 armnn::IWorkloadFactory& workloadFactory,
6363 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Matteo Martincigh8eb675e2018-10-17 14:43:29 +01006364{
6365 // BatchSize: 1
6366 // Height: 3
6367 // Width: 2
6368 // Channels: 2
6369
6370 const armnn::TensorShape inputOutputShape{ 1, 3, 2, 2 };
6371 std::vector<float> inputValues
6372 {
6373 // Batch 0, Height 0, Width (2) x Channel (2)
6374 1.f, 1.f,
6375 4.f, 1.f,
6376
6377 // Batch 0, Height 1, Width (2) x Channel (2)
6378 4.f, 4.f,
6379 2.f, 1.f,
6380
6381 // Batch 0, Height 2, Width (2) x Channel (2)
6382 1.f, -2.f,
6383 6.f, 4.f
6384 };
6385 std::vector<float> expectedOutputValues
6386 {
6387 // Batch 0, Height 0, Width (2) x Channel (2)
6388 1.f, 3.f,
6389 4.f, 3.f,
6390
6391 // Batch 0, Height 1, Width (2) x Channel (2)
6392 4.f, 4.f,
6393 2.f, 3.f,
6394
6395 // Batch 0, Height 2, Width (2) x Channel (2)
6396 1.f, 2.f,
6397 6.f, 4.f
6398 };
6399
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006400 return BatchNormTestImpl<float>(workloadFactory, memoryManager,
6401 inputOutputShape, inputValues, expectedOutputValues,
Matteo Martincigh8eb675e2018-10-17 14:43:29 +01006402 0.f, 0, armnn::DataLayout::NHWC);
telsoa014fcda012018-03-09 14:13:49 +00006403}
6404
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006405LayerTestResult<uint8_t, 4> BatchNormUint8Test(
6406 armnn::IWorkloadFactory& workloadFactory,
6407 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006408{
Matteo Martincigh8eb675e2018-10-17 14:43:29 +01006409 // BatchSize: 1
6410 // Channels: 2
6411 // Height: 3
6412 // Width: 2
6413
6414 const armnn::TensorShape inputOutputShape{ 1, 2, 3, 2 };
6415 std::vector<float> inputValues
6416 {
6417 // Batch 0, Channel 0, Height (3) x Width (2)
6418 1.f, 4.f,
6419 4.f, 2.f,
6420 1.f, 6.f,
6421
6422 // Batch 0, Channel 1, Height (3) x Width (2)
6423 1.f, 1.f,
6424 4.f, 1.f,
6425 -2.f, 4.f
6426 };
6427 std::vector<float> expectedOutputValues
6428 {
6429 // Batch 0, Channel 0, Height (3) x Width (2)
6430 1.f, 4.f,
6431 4.f, 2.f,
6432 1.f, 6.f,
6433
6434 // Batch 0, Channel 1, Height (3) x Width (2)
6435 3.f, 3.f,
6436 4.f, 3.f,
6437 2.f, 4.f
6438 };
6439
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006440 return BatchNormTestImpl<uint8_t>(workloadFactory, memoryManager,
6441 inputOutputShape, inputValues, expectedOutputValues,
Matteo Martincigh8eb675e2018-10-17 14:43:29 +01006442 1.f/20.f, 50, armnn::DataLayout::NCHW);
6443}
6444
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006445LayerTestResult<uint8_t, 4> BatchNormUint8NhwcTest(
6446 armnn::IWorkloadFactory& workloadFactory,
6447 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Matteo Martincigh8eb675e2018-10-17 14:43:29 +01006448{
6449 // BatchSize: 1
6450 // Height: 3
6451 // Width: 2
6452 // Channels: 2
6453
6454 const armnn::TensorShape inputOutputShape{ 1, 3, 2, 2 };
6455 std::vector<float> inputValues
6456 {
6457 // Batch 0, Height 0, Width (2) x Channel (2)
6458 1.f, 1.f,
6459 4.f, 1.f,
6460
6461 // Batch 0, Height 1, Width (2) x Channel (2)
6462 4.f, 4.f,
6463 2.f, 1.f,
6464
6465 // Batch 0, Height 2, Width (2) x Channel (2)
6466 1.f, -2.f,
6467 6.f, 4.f
6468 };
6469 std::vector<float> expectedOutputValues
6470 {
6471 // Batch 0, Height 0, Width (2) x Channel (2)
6472 1.f, 3.f,
6473 4.f, 3.f,
6474
6475 // Batch 0, Height 1, Width (2) x Channel (2)
6476 4.f, 4.f,
6477 2.f, 3.f,
6478
6479 // Batch 0, Height 2, Width (2) x Channel (2)
6480 1.f, 2.f,
6481 6.f, 4.f
6482 };
6483
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006484 return BatchNormTestImpl<uint8_t>(workloadFactory, memoryManager,
6485 inputOutputShape, inputValues, expectedOutputValues,
Matteo Martincigh8eb675e2018-10-17 14:43:29 +01006486 1.f/20.f, 50, armnn::DataLayout::NHWC);
telsoa014fcda012018-03-09 14:13:49 +00006487}
6488
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006489LayerTestResult<uint8_t, 4> ConstantUint8Test(
6490 armnn::IWorkloadFactory& workloadFactory,
6491 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006492{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006493 return ConstantTestImpl<uint8_t>(workloadFactory, memoryManager, 2e-6f, 1);
telsoa014fcda012018-03-09 14:13:49 +00006494}
6495
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006496LayerTestResult<uint8_t, 1> Concatenation1dUint8Test(
6497 armnn::IWorkloadFactory& workloadFactory,
6498 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006499{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006500 return Concatenation1dTestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00006501}
6502
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006503LayerTestResult<uint8_t, 2> Concatenation2dDim0Uint8Test(
6504 armnn::IWorkloadFactory& workloadFactory,
6505 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006506{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006507 return Concatenation2dDim0TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00006508}
6509
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006510LayerTestResult<uint8_t, 2> Concatenation2dDim1Uint8Test(
6511 armnn::IWorkloadFactory& workloadFactory,
6512 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006513{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006514 return Concatenation2dDim1TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00006515}
6516
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006517LayerTestResult<uint8_t, 2> Concatenation2dDim0DiffInputDimsUint8Test(
6518 armnn::IWorkloadFactory& workloadFactory,
6519 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006520{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006521 return Concatenation2dDim0DiffInputDimsTestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00006522}
6523
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006524LayerTestResult<uint8_t, 2> Concatenation2dDim1DiffInputDimsUint8Test(
6525 armnn::IWorkloadFactory& workloadFactory,
6526 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006527{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006528 return Concatenation2dDim1DiffInputDimsTestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00006529}
6530
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006531LayerTestResult<uint8_t, 3> Concatenation3dDim0Uint8Test(
6532 armnn::IWorkloadFactory& workloadFactory,
6533 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006534{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006535 return Concatenation3dDim0TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00006536}
6537
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006538LayerTestResult<uint8_t, 3> Concatenation3dDim1Uint8Test(
6539 armnn::IWorkloadFactory& workloadFactory,
6540 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006541{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006542 return Concatenation3dDim1TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00006543}
6544
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006545LayerTestResult<uint8_t, 3> Concatenation3dDim2Uint8Test(
6546 armnn::IWorkloadFactory& workloadFactory,
narpra015cdda352018-11-19 15:30:27 +00006547 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
6548 bool useSubtensor)
telsoa014fcda012018-03-09 14:13:49 +00006549{
narpra015cdda352018-11-19 15:30:27 +00006550 return Concatenation3dDim2TestImpl<uint8_t>(workloadFactory, memoryManager, useSubtensor, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00006551}
6552
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006553LayerTestResult<uint8_t, 3> Concatenation3dDim0DiffInputDimsUint8Test(
6554 armnn::IWorkloadFactory& workloadFactory,
6555 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006556{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006557 return Concatenation3dDim0TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00006558}
6559
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006560LayerTestResult<uint8_t, 3> Concatenation3dDim1DiffInputDimsUint8Test(
6561 armnn::IWorkloadFactory& workloadFactory,
6562 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006563{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006564 return Concatenation3dDim1DiffInputDimsTestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
telsoa014fcda012018-03-09 14:13:49 +00006565}
6566
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006567LayerTestResult<uint8_t, 3> Concatenation3dDim2DiffInputDimsUint8Test(
6568 armnn::IWorkloadFactory& workloadFactory,
narpra015cdda352018-11-19 15:30:27 +00006569 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
6570 bool useSubtensor)
6571{
6572 return Concatenation3dDim2DiffInputDimsTestImpl<uint8_t>(workloadFactory, memoryManager, useSubtensor, 0.5f, -1);
6573}
6574
6575LayerTestResult<uint8_t, 4> Concatenation4dDim0Uint8Test(
6576 armnn::IWorkloadFactory& workloadFactory,
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006577 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006578{
narpra015cdda352018-11-19 15:30:27 +00006579 return Concatenation4dDim0TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
6580}
6581
6582LayerTestResult<uint8_t, 4> Concatenation4dDim1Uint8Test(
6583 armnn::IWorkloadFactory& workloadFactory,
6584 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
6585{
6586 return Concatenation4dDim1TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
6587}
6588
6589LayerTestResult<uint8_t, 4> Concatenation4dDim2Uint8Test(
6590 armnn::IWorkloadFactory& workloadFactory,
6591 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
6592{
6593 return Concatenation4dDim2TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
6594}
6595
6596LayerTestResult<uint8_t, 4> Concatenation4dDim3Uint8Test(
6597 armnn::IWorkloadFactory& workloadFactory,
6598 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, bool useSubtensor)
6599{
6600 return Concatenation4dDim3TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1, useSubtensor);
6601}
6602
6603LayerTestResult<uint8_t, 4> Concatenation4dDiffShapeDim0Uint8Test(
6604 armnn::IWorkloadFactory& workloadFactory,
6605 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
6606{
6607 return Concatenation4dDiffShapeDim0TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
6608}
6609
6610LayerTestResult<uint8_t, 4> Concatenation4dDiffShapeDim1Uint8Test(
6611 armnn::IWorkloadFactory& workloadFactory,
6612 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
6613{
6614 return Concatenation4dDiffShapeDim1TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
6615}
6616
6617LayerTestResult<uint8_t, 4> Concatenation4dDiffShapeDim2Uint8Test(
6618 armnn::IWorkloadFactory& workloadFactory,
6619 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
6620{
6621 return Concatenation4dDiffShapeDim2TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1);
6622}
6623
6624LayerTestResult<uint8_t, 4> Concatenation4dDiffShapeDim3Uint8Test(
6625 armnn::IWorkloadFactory& workloadFactory,
6626 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
6627 bool useSubtensor)
6628{
6629 return Concatenation4dDiffShapeDim3TestImpl<uint8_t>(workloadFactory, memoryManager, 0.5f, -1, useSubtensor);
telsoa014fcda012018-03-09 14:13:49 +00006630}
6631
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006632LayerTestResult<float, 4> SimpleMaxPooling2dSize2x2Stride2x2Test(
6633 armnn::IWorkloadFactory& workloadFactory,
6634 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
6635 bool forceNoPadding)
telsoa014fcda012018-03-09 14:13:49 +00006636{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006637 return SimpleMaxPooling2dSize2x2Stride2x2TestCommon<float>(workloadFactory, memoryManager, forceNoPadding);
telsoa014fcda012018-03-09 14:13:49 +00006638}
6639
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006640LayerTestResult<uint8_t, 4> SimpleMaxPooling2dSize2x2Stride2x2Uint8Test(
6641 armnn::IWorkloadFactory& workloadFactory,
6642 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
6643 bool forceNoPadding)
telsoa014fcda012018-03-09 14:13:49 +00006644{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006645 return SimpleMaxPooling2dSize2x2Stride2x2TestCommon<uint8_t>(
6646 workloadFactory, memoryManager, forceNoPadding, 3.0f, -5);
telsoa014fcda012018-03-09 14:13:49 +00006647}
6648
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006649LayerTestResult<float, 4> SimpleMaxPooling2dSize3x3Stride2x4Test(
6650 armnn::IWorkloadFactory& workloadFactory,
6651 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
6652 bool forceNoPadding)
telsoa014fcda012018-03-09 14:13:49 +00006653{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006654 return SimpleMaxPooling2dSize3x3Stride2x4TestCommon<float>(workloadFactory, memoryManager, forceNoPadding);
telsoa014fcda012018-03-09 14:13:49 +00006655}
6656
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006657LayerTestResult<uint8_t, 4> SimpleMaxPooling2dSize3x3Stride2x4Uint8Test(
6658 armnn::IWorkloadFactory& workloadFactory,
6659 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
6660 bool forceNoPadding)
telsoa014fcda012018-03-09 14:13:49 +00006661{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006662 return SimpleMaxPooling2dSize3x3Stride2x4TestCommon<uint8_t>(
6663 workloadFactory, memoryManager, forceNoPadding, 0.1f, 128);
telsoa014fcda012018-03-09 14:13:49 +00006664}
6665
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006666LayerTestResult<float, 4> SimpleMaxPooling2dTest(
6667 armnn::IWorkloadFactory& workloadFactory,
6668 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00006669 const armnn::DataLayout dataLayout)
telsoa014fcda012018-03-09 14:13:49 +00006670{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006671 return SimpleMaxPooling2dTestCommon<float>(workloadFactory, memoryManager, dataLayout);
telsoa014fcda012018-03-09 14:13:49 +00006672}
6673
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006674LayerTestResult<uint8_t, 4> SimpleMaxPooling2dUint8Test(
6675 armnn::IWorkloadFactory& workloadFactory,
6676 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00006677 const armnn::DataLayout dataLayout)
Francis Murtagh043d0d02018-10-05 14:08:48 +01006678{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006679 return SimpleMaxPooling2dTestCommon<uint8_t>(workloadFactory, memoryManager, dataLayout);
Francis Murtagh043d0d02018-10-05 14:08:48 +01006680}
6681
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006682LayerTestResult<float, 4> SimpleAveragePooling2dTest(
6683 armnn::IWorkloadFactory& workloadFactory,
6684 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00006685 const armnn::DataLayout dataLayout)
telsoa014fcda012018-03-09 14:13:49 +00006686{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006687 return SimpleAveragePooling2dTestCommon<float>(workloadFactory, memoryManager, dataLayout);
James Conroy69482272018-10-19 10:41:35 +01006688}
6689
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006690LayerTestResult<uint8_t, 4> SimpleAveragePooling2dUint8Test(
6691 armnn::IWorkloadFactory& workloadFactory,
6692 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00006693 const armnn::DataLayout dataLayout)
James Conroy69482272018-10-19 10:41:35 +01006694{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006695 return SimpleAveragePooling2dTestCommon<uint8_t>(
6696 workloadFactory, memoryManager, dataLayout, 0.5, -1);
telsoa014fcda012018-03-09 14:13:49 +00006697}
6698
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006699LayerTestResult<float, 4> IgnorePaddingAveragePooling2dSize3x2Stride2x2Test(
6700 armnn::IWorkloadFactory& workloadFactory,
6701 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
6702 bool forceNoPadding)
surmeh01bceff2f2018-03-29 16:29:27 +01006703{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006704 return IgnorePaddingAveragePooling2dSize3x2Stride2x2TestCommon<float>(
6705 workloadFactory, memoryManager, forceNoPadding);
surmeh01bceff2f2018-03-29 16:29:27 +01006706}
6707
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006708LayerTestResult<float, 4> LargeTensorsAveragePooling2dTest(
6709 armnn::IWorkloadFactory& workloadFactory,
6710 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006711{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006712 return LargeTensorsAveragePooling2dTestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006713}
6714
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006715LayerTestResult<uint8_t, 4> LargeTensorsAveragePooling2dUint8Test(
6716 armnn::IWorkloadFactory& workloadFactory,
6717 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006718{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006719 return LargeTensorsAveragePooling2dTestCommon<uint8_t>(workloadFactory, memoryManager, 0.5, -1);
telsoa014fcda012018-03-09 14:13:49 +00006720}
6721
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006722LayerTestResult<float, 4> SimpleL2Pooling2dTest(
6723 armnn::IWorkloadFactory& workloadFactory,
6724 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00006725 const armnn::DataLayout dataLayout)
telsoa014fcda012018-03-09 14:13:49 +00006726{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006727 return SimpleL2Pooling2dTestCommon<float>(workloadFactory, memoryManager, dataLayout);
telsoa014fcda012018-03-09 14:13:49 +00006728}
6729
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006730LayerTestResult<uint8_t, 4> SimpleL2Pooling2dUint8Test(
6731 armnn::IWorkloadFactory& workloadFactory,
6732 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
Matthew Bentham8800c002018-11-19 13:19:28 +00006733 const armnn::DataLayout dataLayout)
telsoa014fcda012018-03-09 14:13:49 +00006734{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006735 return SimpleL2Pooling2dTestCommon<uint8_t>(workloadFactory, memoryManager, dataLayout);
telsoa014fcda012018-03-09 14:13:49 +00006736}
6737
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006738LayerTestResult<float, 4> L2Pooling2dSize3Stride1Test(
6739 armnn::IWorkloadFactory& workloadFactory,
6740 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006741{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006742 return L2Pooling2dSize3Stride1TestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006743}
6744
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006745LayerTestResult<uint8_t, 4> L2Pooling2dSize3Stride1Uint8Test(
6746 armnn::IWorkloadFactory& workloadFactory,
6747 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006748{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006749 return L2Pooling2dSize3Stride1TestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006750}
6751
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006752LayerTestResult<float, 4> L2Pooling2dSize3Stride3Test(
6753 armnn::IWorkloadFactory& workloadFactory,
6754 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006755{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006756 return L2Pooling2dSize3Stride3TestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006757}
6758
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006759LayerTestResult<uint8_t, 4> L2Pooling2dSize3Stride3Uint8Test(
6760 armnn::IWorkloadFactory& workloadFactory,
6761 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006762{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006763 return L2Pooling2dSize3Stride3TestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006764}
6765
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006766LayerTestResult<float, 4> L2Pooling2dSize3Stride4Test(
6767 armnn::IWorkloadFactory& workloadFactory,
6768 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006769{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006770 return L2Pooling2dSize3Stride4TestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006771}
6772
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006773LayerTestResult<uint8_t, 4> L2Pooling2dSize3Stride4Uint8Test(
6774 armnn::IWorkloadFactory& workloadFactory,
6775 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006776{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006777 return L2Pooling2dSize3Stride4TestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006778}
6779
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006780LayerTestResult<float, 4> L2Pooling2dSize7Test(
6781 armnn::IWorkloadFactory& workloadFactory,
6782 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006783{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006784 return L2Pooling2dSize7TestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006785}
6786
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006787LayerTestResult<uint8_t, 4> L2Pooling2dSize7Uint8Test(
6788 armnn::IWorkloadFactory& workloadFactory,
6789 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006790{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006791 return L2Pooling2dSize7TestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006792}
6793
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006794LayerTestResult<float, 4> L2Pooling2dSize9Test(
6795 armnn::IWorkloadFactory& workloadFactory,
6796 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006797{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006798 return L2Pooling2dSize9TestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006799}
6800
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006801LayerTestResult<uint8_t, 4> L2Pooling2dSize9Uint8Test(
6802 armnn::IWorkloadFactory& workloadFactory,
6803 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006804{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006805 return L2Pooling2dSize9TestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006806}
6807
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006808LayerTestResult<float, 4> AsymmetricNonSquarePooling2dTest(
6809 armnn::IWorkloadFactory& workloadFactory,
6810 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006811{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006812 return AsymmetricNonSquarePooling2dTestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006813}
6814
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006815LayerTestResult<uint8_t, 4> AsymmetricNonSquarePooling2dUint8Test(
6816 armnn::IWorkloadFactory& workloadFactory,
6817 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006818{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006819 return AsymmetricNonSquarePooling2dTestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006820}
6821
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006822LayerTestResult<float, 4> ComparePooling2dTest(
6823 armnn::IWorkloadFactory& workloadFactory,
6824 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
6825 armnn::IWorkloadFactory& refWorkloadFactory,
6826 armnn::PoolingAlgorithm poolingType)
telsoa014fcda012018-03-09 14:13:49 +00006827{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006828 return ComparePooling2dTestCommon<float>(
6829 workloadFactory, memoryManager, refWorkloadFactory, poolingType);
telsoa014fcda012018-03-09 14:13:49 +00006830}
6831
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006832LayerTestResult<uint8_t, 4> ComparePooling2dUint8Test(
6833 armnn::IWorkloadFactory& workloadFactory,
6834 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
6835 armnn::IWorkloadFactory& refWorkloadFactory,
6836 armnn::PoolingAlgorithm poolingType)
telsoa014fcda012018-03-09 14:13:49 +00006837{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006838 return ComparePooling2dTestCommon<uint8_t>(
6839 workloadFactory, memoryManager, refWorkloadFactory, poolingType, 0.1f, 128);
telsoa014fcda012018-03-09 14:13:49 +00006840}
6841
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006842LayerTestResult<float, 2> FullyConnectedLargeTest(
6843 armnn::IWorkloadFactory& workloadFactory,
6844 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
6845 bool transposeWeights)
telsoa014fcda012018-03-09 14:13:49 +00006846{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006847 return FullyConnectedLargeTestCommon<float>(workloadFactory, memoryManager, transposeWeights);
telsoa014fcda012018-03-09 14:13:49 +00006848}
6849
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006850LayerTestResult<float, 4> IgnorePaddingSimpleMaxPooling2dTest(
6851 armnn::IWorkloadFactory& workloadFactory,
6852 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006853{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006854 return IgnorePaddingSimpleMaxPooling2dTestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006855}
6856
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006857LayerTestResult<uint8_t, 4> IgnorePaddingSimpleMaxPooling2dUint8Test(
6858 armnn::IWorkloadFactory& workloadFactory,
6859 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006860{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006861 return IgnorePaddingSimpleMaxPooling2dTestCommon<uint8_t>(workloadFactory, memoryManager, 1.0f, -5);
telsoa014fcda012018-03-09 14:13:49 +00006862}
6863
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006864LayerTestResult<float, 4> IgnorePaddingMaxPooling2dSize3Test(
6865 armnn::IWorkloadFactory& workloadFactory,
6866 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006867{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006868 return IgnorePaddingMaxPooling2dSize3TestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006869}
6870
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006871LayerTestResult<uint8_t, 4> IgnorePaddingMaxPooling2dSize3Uint8Test(
6872 armnn::IWorkloadFactory& workloadFactory,
6873 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006874{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006875 return IgnorePaddingMaxPooling2dSize3TestCommon<uint8_t>(workloadFactory, memoryManager, 1.0f, -5);
telsoa014fcda012018-03-09 14:13:49 +00006876}
6877
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006878LayerTestResult<float, 4> IgnorePaddingSimpleAveragePooling2dTest(
6879 armnn::IWorkloadFactory& workloadFactory,
6880 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006881{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006882 return IgnorePaddingSimpleAveragePooling2dTestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006883}
6884
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006885LayerTestResult<uint8_t, 4> IgnorePaddingSimpleAveragePooling2dUint8Test(
6886 armnn::IWorkloadFactory& workloadFactory,
6887 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006888{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006889 return IgnorePaddingSimpleAveragePooling2dTestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006890}
6891
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006892LayerTestResult<float, 4> IgnorePaddingSimpleAveragePooling2dNoPaddingTest(
6893 armnn::IWorkloadFactory& workloadFactory,
6894 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006895{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006896 return IgnorePaddingSimpleAveragePooling2dNoPaddingTestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006897}
6898
6899LayerTestResult<uint8_t, 4> IgnorePaddingSimpleAveragePooling2dNoPaddingUint8Test(
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006900 armnn::IWorkloadFactory& workloadFactory,
6901 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006902{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006903 return IgnorePaddingSimpleAveragePooling2dNoPaddingTestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006904}
6905
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006906LayerTestResult<float, 4> IgnorePaddingAveragePooling2dSize3Test(
6907 armnn::IWorkloadFactory& workloadFactory,
6908 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006909{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006910 return IgnorePaddingAveragePooling2dSize3TestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006911}
6912
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006913LayerTestResult<uint8_t, 4> IgnorePaddingAveragePooling2dSize3Uint8Test(
6914 armnn::IWorkloadFactory& workloadFactory,
6915 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006916{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006917 return IgnorePaddingAveragePooling2dSize3TestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006918}
6919
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006920LayerTestResult<float, 4> IgnorePaddingSimpleL2Pooling2dTest(
6921 armnn::IWorkloadFactory& workloadFactory,
6922 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006923{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006924 return IgnorePaddingSimpleL2Pooling2dTestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006925}
6926
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006927LayerTestResult<uint8_t, 4> IgnorePaddingSimpleL2Pooling2dUint8Test(
6928 armnn::IWorkloadFactory& workloadFactory,
6929 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006930{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006931 return IgnorePaddingSimpleL2Pooling2dTestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006932}
6933
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006934LayerTestResult<float, 4> IgnorePaddingL2Pooling2dSize3Test(
6935 armnn::IWorkloadFactory& workloadFactory,
6936 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006937{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006938 return IgnorePaddingL2Pooling2dSize3TestCommon<float>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006939}
6940
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006941LayerTestResult<uint8_t, 4> IgnorePaddingL2Pooling2dSize3Uint8Test(
6942 armnn::IWorkloadFactory& workloadFactory,
6943 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006944{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006945 return IgnorePaddingL2Pooling2dSize3TestCommon<uint8_t>(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006946}
6947
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006948LayerTestResult<float, 4> SimplePermuteFloat32Test(
6949 armnn::IWorkloadFactory& workloadFactory,
6950 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006951{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006952 return SimplePermuteFloat32TestCommon(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006953};
6954
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006955LayerTestResult<uint8_t, 4> SimplePermuteUint8Test(
6956 armnn::IWorkloadFactory& workloadFactory,
6957 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
telsoa014fcda012018-03-09 14:13:49 +00006958{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006959 return SimplePermuteUint8TestCommon(workloadFactory, memoryManager);
telsoa014fcda012018-03-09 14:13:49 +00006960};
surmeh01bceff2f2018-03-29 16:29:27 +01006961
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006962LayerTestResult<float, 4> PermuteFloat32ValueSet1Test(
6963 armnn::IWorkloadFactory& workloadFactory,
6964 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01006965{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006966 return PermuteFloat32ValueSet1TestCommon(workloadFactory, memoryManager);
surmeh01bceff2f2018-03-29 16:29:27 +01006967};
6968
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006969LayerTestResult<float, 4> PermuteFloat32ValueSet2Test(
6970 armnn::IWorkloadFactory& workloadFactory,
6971 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01006972{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006973 return PermuteFloat32ValueSet2TestCommon(workloadFactory, memoryManager);
surmeh01bceff2f2018-03-29 16:29:27 +01006974};
6975
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006976LayerTestResult<float, 4> PermuteFloat32ValueSet3Test(
6977 armnn::IWorkloadFactory& workloadFactory,
6978 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
surmeh01bceff2f2018-03-29 16:29:27 +01006979{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006980 return PermuteFloat32ValueSet3TestCommon(workloadFactory, memoryManager);
narpra011e4c31d2018-09-28 11:07:51 +01006981};
6982
6983namespace
6984{
Matteo Martincigh28dcab62018-10-19 16:40:03 +01006985
narpra011e4c31d2018-09-28 11:07:51 +01006986template <typename T, std::size_t InputDim, std::size_t OutputDim>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00006987LayerTestResult<T, OutputDim> MeanTestHelper(
6988 armnn::IWorkloadFactory& workloadFactory,
6989 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
6990 const unsigned int* inputShape,
6991 const std::vector<T>& inputData,
6992 const std::vector<unsigned int>& axis,
6993 bool keepDims,
6994 const unsigned int* outputShape,
6995 const std::vector<T>& outputData,
6996 float scale = 1.0f,
6997 int32_t offset = 0)
narpra011e4c31d2018-09-28 11:07:51 +01006998{
Matteo Martincigh28dcab62018-10-19 16:40:03 +01006999 auto dataType = (std::is_same<T, uint8_t>::value ? armnn::DataType::QuantisedAsymm8 : armnn::DataType::Float32);
narpra011e4c31d2018-09-28 11:07:51 +01007000
7001 armnn::TensorInfo inputTensorInfo(InputDim, inputShape, dataType);
7002 armnn::TensorInfo outputTensorInfo(OutputDim, outputShape, dataType);
7003
7004 inputTensorInfo.SetQuantizationScale(scale);
7005 inputTensorInfo.SetQuantizationOffset(offset);
7006
7007 outputTensorInfo.SetQuantizationScale(scale);
7008 outputTensorInfo.SetQuantizationOffset(offset);
7009
7010 auto input = MakeTensor<T, InputDim>(inputTensorInfo, inputData);
7011
7012 LayerTestResult<T, OutputDim> result(outputTensorInfo);
7013 result.outputExpected = MakeTensor<T, OutputDim>(outputTensorInfo, outputData);
7014
7015 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
7016 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
7017
7018 armnn::MeanQueueDescriptor data;
7019 data.m_Parameters.m_Axis = axis;
7020 data.m_Parameters.m_KeepDims = keepDims;
7021 armnn::WorkloadInfo info;
7022 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
7023 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
7024
7025 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateMean(data, info);
7026
7027 inputHandle->Allocate();
7028 outputHandle->Allocate();
7029
7030 CopyDataToITensorHandle(inputHandle.get(), input.origin());
7031
narpra011e4c31d2018-09-28 11:07:51 +01007032 workload->Execute();
7033
7034 CopyDataFromITensorHandle(result.output.origin(), outputHandle.get());
7035
7036 return result;
7037}
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007038
narpra011e4c31d2018-09-28 11:07:51 +01007039} // anonymous namespace
7040
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007041LayerTestResult<uint8_t, 1> MeanUint8SimpleTest(
7042 armnn::IWorkloadFactory& workloadFactory,
7043 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007044{
7045 const unsigned int inputShape[] = { 3, 2 };
7046 const unsigned int outputShape[] = { 1 };
7047
7048 std::vector<uint8_t> input({ 1, 1, 2, 2, 3, 3 });
7049 std::vector<uint8_t> output({ 2 });
7050
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007051 return MeanTestHelper<uint8_t, 2, 1>(
7052 workloadFactory, memoryManager, inputShape, input, {}, false, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007053}
7054
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007055LayerTestResult<uint8_t, 3> MeanUint8SimpleAxisTest(
7056 armnn::IWorkloadFactory& workloadFactory,
7057 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007058{
7059 const unsigned int inputShape[] = { 1, 1, 3, 2 };
7060 const unsigned int outputShape[] = { 1, 1, 2 };
7061
7062 std::vector<uint8_t> input({ 1, 1, 2, 2, 3, 3 });
7063 std::vector<uint8_t> output({ 2, 2 });
7064
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007065 return MeanTestHelper<uint8_t, 4, 3>(
7066 workloadFactory, memoryManager, inputShape, input, { 2 }, false, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007067}
7068
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007069LayerTestResult<uint8_t, 4> MeanUint8KeepDimsTest(
7070 armnn::IWorkloadFactory& workloadFactory,
7071 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007072{
7073 const unsigned int inputShape[] = { 1, 1, 3, 2 };
7074 const unsigned int outputShape[] = { 1, 1, 1, 2 };
7075
7076 std::vector<uint8_t> input({ 1, 1, 2, 2, 3, 3 });
7077 std::vector<uint8_t> output({ 2, 2 });
7078
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007079 return MeanTestHelper<uint8_t, 4, 4>(
7080 workloadFactory, memoryManager, inputShape, input, { 2 }, true, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007081}
7082
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007083LayerTestResult<uint8_t, 4> MeanUint8MultipleDimsTest(
7084 armnn::IWorkloadFactory& workloadFactory,
7085 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007086{
7087 const unsigned int inputShape[] = { 2, 3, 1, 2 };
7088 const unsigned int outputShape[] = { 1, 3, 1, 1 };
7089
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007090 std::vector<uint8_t> input({ 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6 });
narpra011e4c31d2018-09-28 11:07:51 +01007091 std::vector<uint8_t> output({ 1, 3, 5 });
7092
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007093 return MeanTestHelper<uint8_t, 4, 4>(
7094 workloadFactory, memoryManager, inputShape, input, { 0, 3 }, true, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007095}
7096
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007097LayerTestResult<uint8_t, 1> MeanVtsUint8Test(
7098 armnn::IWorkloadFactory& workloadFactory,
7099 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007100{
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007101 const unsigned int inputShape[] = { 4, 3, 2 };
narpra011e4c31d2018-09-28 11:07:51 +01007102 const unsigned int outputShape[] = { 2 };
7103
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007104 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,
7105 24 });
7106 std::vector<uint8_t> output({ 12, 13 });
narpra011e4c31d2018-09-28 11:07:51 +01007107
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007108 return MeanTestHelper<uint8_t, 3, 1>(workloadFactory, memoryManager,
7109 inputShape, input, { 0, 1 }, false, outputShape,
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007110 output, 0.8f, 5);
narpra011e4c31d2018-09-28 11:07:51 +01007111}
7112
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007113LayerTestResult<float, 1> MeanFloatSimpleTest(
7114 armnn::IWorkloadFactory& workloadFactory,
7115 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007116{
7117 const unsigned int inputShape[] = { 3, 2 };
7118 const unsigned int outputShape[] = { 1 };
7119
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007120 std::vector<float> input({ 1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 3.0f });
7121 std::vector<float> output({ 2.0f });
narpra011e4c31d2018-09-28 11:07:51 +01007122
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007123 return MeanTestHelper<float, 2, 1>(
7124 workloadFactory, memoryManager, inputShape, input, {}, false, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007125}
7126
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007127LayerTestResult<float, 3> MeanFloatSimpleAxisTest(
7128 armnn::IWorkloadFactory& workloadFactory,
7129 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007130{
7131 const unsigned int inputShape[] = { 2, 3, 1, 2 };
7132 const unsigned int outputShape[] = { 3, 1, 2 };
7133
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007134 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 });
7135 std::vector<float> output({ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f });
narpra011e4c31d2018-09-28 11:07:51 +01007136
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007137 return MeanTestHelper<float, 4, 3>(
7138 workloadFactory, memoryManager, inputShape, input, { 0 }, false, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007139}
7140
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007141LayerTestResult<float, 4> MeanFloatKeepDimsTest(
7142 armnn::IWorkloadFactory& workloadFactory,
7143 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007144{
7145 const unsigned int inputShape[] = { 1, 1, 3, 2 };
7146 const unsigned int outputShape[] = { 1, 1, 1, 2 };
7147
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007148 std::vector<float> input({ 1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 3.0f });
7149 std::vector<float> output({ 2.0f, 2.0f });
narpra011e4c31d2018-09-28 11:07:51 +01007150
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007151 return MeanTestHelper<float, 4, 4>(
7152 workloadFactory, memoryManager, inputShape, input, { 2 }, true, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007153}
7154
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007155LayerTestResult<float, 4> MeanFloatMultipleDimsTest(
7156 armnn::IWorkloadFactory& workloadFactory,
7157 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007158{
7159 const unsigned int inputShape[] = { 2, 3, 1, 2 };
7160 const unsigned int outputShape[] = { 1, 3, 1, 1 };
7161
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007162 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 });
7163 std::vector<float> output({ 1.5f, 3.5f, 5.5f });
narpra011e4c31d2018-09-28 11:07:51 +01007164
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007165 return MeanTestHelper<float, 4, 4>(
7166 workloadFactory, memoryManager, inputShape, input, { 0, 3 }, true, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007167}
7168
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007169LayerTestResult<float, 1> MeanVtsFloat1Test(
7170 armnn::IWorkloadFactory& workloadFactory,
7171 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007172{
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007173 const unsigned int inputShape[] = { 4, 3, 2 };
narpra011e4c31d2018-09-28 11:07:51 +01007174 const unsigned int outputShape[] = { 2 };
7175
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007176 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,
7177 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f });
7178 std::vector<float> output({ 12.0f, 13.0f });
narpra011e4c31d2018-09-28 11:07:51 +01007179
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007180 return MeanTestHelper<float, 3, 1>(
7181 workloadFactory, memoryManager, inputShape, input, { 0, 1 }, false, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007182}
7183
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007184LayerTestResult<float, 3> MeanVtsFloat2Test(
7185 armnn::IWorkloadFactory& workloadFactory,
7186 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
narpra011e4c31d2018-09-28 11:07:51 +01007187{
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007188 const unsigned int inputShape[] = { 4, 3, 2 };
7189 const unsigned int outputShape[] = { 1, 3, 1 };
narpra011e4c31d2018-09-28 11:07:51 +01007190
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007191 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,
7192 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f });
7193 std::vector<float> output({ 10.5f, 12.5f, 14.5f });
narpra011e4c31d2018-09-28 11:07:51 +01007194
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007195 return MeanTestHelper<float, 3, 3>(
7196 workloadFactory, memoryManager, inputShape, input, { 0, 2 }, true, outputShape, output);
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007197}
7198
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007199LayerTestResult<float, 3> MeanVtsFloat3Test(
7200 armnn::IWorkloadFactory& workloadFactory,
7201 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Matteo Martincigh28dcab62018-10-19 16:40:03 +01007202{
7203 const unsigned int inputShape[] = { 1, 2, 2, 1 };
7204 const unsigned int outputShape[] = { 1, 2, 1 };
7205
7206 std::vector<float> input({ 1.0f, 2.0f, 3.0f, 4.0f });
7207 std::vector<float> output({ 1.5f, 3.5f });
7208
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007209 return MeanTestHelper<float, 4, 3>(
7210 workloadFactory, memoryManager, inputShape, input, { 2 }, false, outputShape, output);
narpra011e4c31d2018-09-28 11:07:51 +01007211}
Éanna Ó Catháin47c1ddb2018-10-12 14:24:13 +01007212
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007213LayerTestResult<float, 4> AdditionAfterMaxPoolTest(
7214 armnn::IWorkloadFactory& workloadFactory,
7215 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Éanna Ó Catháin47c1ddb2018-10-12 14:24:13 +01007216{
7217 // Create Initial Tensor
7218 // 1, 2, 3
7219 // 4, 5, 6
7220 // 7, 8, 9
7221
7222 armnn::TensorInfo poolingInputTensorInfo({ 1, 1, 3, 3}, armnn::GetDataType<float>());
7223 armnn::TensorInfo poolingOutputTensorInfo({ 1, 1, 2, 2}, armnn::GetDataType<float>());
7224
7225 boost::multi_array<float, 4> poolingInput = MakeTensor<float,4>(poolingInputTensorInfo,
7226 {1, 2, 3,
7227 4, 5, 6,
7228 7, 8, 9
7229 });
7230
7231 std::unique_ptr<armnn::ITensorHandle> poolingInputHandle =
7232 workloadFactory.CreateTensorHandle(poolingInputTensorInfo);
7233 std::unique_ptr<armnn::ITensorHandle> poolingOutputHandle =
7234 workloadFactory.CreateTensorHandle(poolingOutputTensorInfo);
7235
7236 // Apply MaxPool poolSize = 1x1, stride=2x2
7237 // Result =
7238 // 1, 3
7239 // 7, 9
7240 armnn::Pooling2dDescriptor descriptor;
7241 descriptor.m_PoolHeight = 1;
7242 descriptor.m_PoolWidth = 1;
7243 descriptor.m_StrideX = 2;
7244 descriptor.m_StrideY = 2;
7245 descriptor.m_PoolType = armnn::PoolingAlgorithm::Max;
7246
7247 armnn::Pooling2dQueueDescriptor queueDescriptor;
7248 queueDescriptor.m_Parameters = descriptor;
7249 armnn::WorkloadInfo workloadInfo;
7250 AddInputToWorkload(queueDescriptor, workloadInfo, poolingInputTensorInfo, poolingInputHandle.get());
7251 AddOutputToWorkload(queueDescriptor, workloadInfo, poolingOutputTensorInfo, poolingOutputHandle.get());
7252
7253 // Create the MaxPool
7254 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreatePooling2d(queueDescriptor, workloadInfo);
7255
7256 //LayerTestResult<float, 4> result(poolingOutputTensorInfo);
7257 auto shape( GetTensorShapeAsArray<4>(poolingOutputTensorInfo));
7258 boost::multi_array<float, 4> resultMaxPool;
7259 resultMaxPool.resize(shape);
7260
7261
7262 // Create addition with another tensor the same size
7263 // This would be the result to apply a Conv2d with kernel ones(2) and stride 1x1
7264 // with the initial tensor.
7265 // 12, 16
7266 // 24, 28
7267
7268 armnn::TensorInfo addInputTensorInfo({ 1,1,2,2}, armnn::GetDataType<float>());
7269 armnn::TensorInfo addOutputTensorInfo({ 1,1,2,2}, armnn::GetDataType<float>());
7270
7271 boost::multi_array<float, 4> addInput = MakeTensor<float,4>(addInputTensorInfo,
7272 {12, 16,
7273 24, 28,
7274 });
7275
7276 // Expected output tensor after MaxPool and Addition.
7277 LayerTestResult<float,4> addRet(addOutputTensorInfo);
7278 addRet.outputExpected = MakeTensor<float, 4>(addOutputTensorInfo, std::vector<float>(
7279 {
7280 13, 19,
7281 31, 37
7282 }));
7283
7284 std::unique_ptr<armnn::ITensorHandle> addInputHandle = workloadFactory.CreateTensorHandle(addInputTensorInfo);
7285 std::unique_ptr<armnn::ITensorHandle> addOutputHandle = workloadFactory.CreateTensorHandle(addOutputTensorInfo);
7286
7287 armnn::AdditionQueueDescriptor data;
7288 armnn::WorkloadInfo info;
7289
7290 // Add the output of the MaxPool and the new tensor
7291 AddInputToWorkload(data, info, poolingOutputTensorInfo, poolingOutputHandle.get());
7292 AddInputToWorkload(data, info, addInputTensorInfo, addInputHandle.get());
7293 AddOutputToWorkload(data, info, addOutputTensorInfo, addOutputHandle.get());
7294
7295 std::unique_ptr<armnn::IWorkload> addWorkload = workloadFactory.CreateAddition(data, info);
7296
7297 poolingInputHandle->Allocate();
7298 poolingOutputHandle->Allocate();
7299 addInputHandle->Allocate();
7300 addOutputHandle->Allocate();
7301
7302 CopyDataToITensorHandle(poolingInputHandle.get(), &poolingInput[0][0][0][0]);
7303 CopyDataFromITensorHandle(&resultMaxPool[0][0][0][0], poolingOutputHandle.get());
7304
7305 CopyDataToITensorHandle(poolingOutputHandle.get(), &resultMaxPool[0][0][0][0]);
7306 CopyDataToITensorHandle(addInputHandle.get(), &addInput[0][0][0][0]);
7307
7308 workload->Execute();
7309 addWorkload->Execute();
7310
7311 CopyDataFromITensorHandle(&addRet.output[0][0][0][0], addOutputHandle.get());
7312
Éanna Ó Catháin47c1ddb2018-10-12 14:24:13 +01007313 return addRet;
7314}
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007315
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007316LayerTestResult<float, 4> SpaceToBatchNdSimpleFloat32Test(
7317 armnn::IWorkloadFactory& workloadFactory,
7318 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007319{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007320 return SpaceToBatchNdSimpleTest<float>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007321}
7322
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007323LayerTestResult<float, 4> SpaceToBatchNdMultiChannelsFloat32Test(
7324 armnn::IWorkloadFactory& workloadFactory,
7325 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007326{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007327 return SpaceToBatchNdMultiChannelsTest<float>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007328}
7329
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007330LayerTestResult<float, 4> SpaceToBatchNdMultiBlockFloat32Test(
7331 armnn::IWorkloadFactory& workloadFactory,
7332 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007333{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007334 return SpaceToBatchNdMultiBlockTest<float>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007335}
7336
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007337LayerTestResult<float, 4> SpaceToBatchNdPaddingFloat32Test(
7338 armnn::IWorkloadFactory& workloadFactory,
7339 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007340{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007341 return SpaceToBatchNdPaddingTest<float>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007342}
7343
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007344LayerTestResult<uint8_t, 4> SpaceToBatchNdSimpleUint8Test(
7345 armnn::IWorkloadFactory& workloadFactory,
7346 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007347{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007348 return SpaceToBatchNdSimpleTest<uint8_t>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007349}
7350
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007351LayerTestResult<uint8_t, 4> SpaceToBatchNdMultiChannelsUint8Test(
7352 armnn::IWorkloadFactory& workloadFactory,
7353 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007354{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007355 return SpaceToBatchNdMultiChannelsTest<uint8_t>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007356}
7357
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007358LayerTestResult<uint8_t, 4> SpaceToBatchNdMultiBlockUint8Test(
7359 armnn::IWorkloadFactory& workloadFactory,
7360 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007361{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007362 return SpaceToBatchNdMultiBlockTest<uint8_t>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007363}
7364
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007365LayerTestResult<uint8_t, 4> SpaceToBatchNdPaddingUint8Test(
7366 armnn::IWorkloadFactory& workloadFactory,
7367 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007368{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007369 return SpaceToBatchNdPaddingTest<uint8_t>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007370}
7371
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007372LayerTestResult<float, 4> SpaceToBatchNdSimpleNHWCFloat32Test(
7373 armnn::IWorkloadFactory& workloadFactory,
7374 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007375{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007376 return SpaceToBatchNdSimpleNHWCTest<float>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007377}
7378
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007379LayerTestResult<float, 4> SpaceToBatchNdMultiChannelsNHWCFloat32Test(
7380 armnn::IWorkloadFactory& workloadFactory,
7381 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007382{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007383 return SpaceToBatchNdMultiChannelsNHWCTest<float>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007384}
7385
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007386LayerTestResult<float, 4> SpaceToBatchNdMultiBlockNHWCFloat32Test(
7387 armnn::IWorkloadFactory& workloadFactory,
7388 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007389{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007390 return SpaceToBatchNdMultiBlockNHWCTest<float>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007391}
7392
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007393LayerTestResult<float, 4> SpaceToBatchNdPaddingNHWCFloat32Test(
7394 armnn::IWorkloadFactory& workloadFactory,
7395 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007396{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007397 return SpaceToBatchNdPaddingNHWCTest<float>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007398}
7399
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007400LayerTestResult<uint8_t, 4> SpaceToBatchNdSimpleNHWCUint8Test(
7401 armnn::IWorkloadFactory& workloadFactory,
7402 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007403{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007404 return SpaceToBatchNdSimpleNHWCTest<uint8_t>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007405}
7406
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007407LayerTestResult<uint8_t, 4> SpaceToBatchNdMultiChannelsNHWCUint8Test(
7408 armnn::IWorkloadFactory& workloadFactory,
7409 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007410{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007411 return SpaceToBatchNdMultiChannelsNHWCTest<uint8_t>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007412}
7413
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007414LayerTestResult<uint8_t, 4> SpaceToBatchNdMultiBlockNHWCUint8Test(
7415 armnn::IWorkloadFactory& workloadFactory,
7416 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007417{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007418 return SpaceToBatchNdMultiBlockNHWCTest<uint8_t>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007419}
7420
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007421LayerTestResult<uint8_t, 4> SpaceToBatchNdPaddingNHWCUint8Test(
7422 armnn::IWorkloadFactory& workloadFactory,
7423 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007424{
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007425 return SpaceToBatchNdPaddingNHWCTest<uint8_t>(workloadFactory, memoryManager);
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00007426}
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00007427
7428namespace {
7429
7430template<typename T, std::size_t InputDim, std::size_t OutputDim>
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007431LayerTestResult<T, OutputDim> BatchToSpaceNdHelper(
7432 armnn::IWorkloadFactory &workloadFactory,
7433 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
7434 const armnn::DataLayout& dataLayout,
7435 const unsigned int *inputShape,
7436 const std::vector<T> &inputData,
7437 const std::vector<unsigned int> &blockShape,
7438 const std::vector<std::pair<unsigned int, unsigned int>> &crops,
7439 const unsigned int *outputShape,
7440 const std::vector<T> &outputData,
7441 float scale = 1.0f,
7442 int32_t offset = 0)
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00007443 {
7444 auto dataType = (std::is_same<T, uint8_t>::value ? armnn::DataType::QuantisedAsymm8 : armnn::DataType::Float32);
7445
7446 armnn::TensorInfo inputTensorInfo(InputDim, inputShape, dataType);
7447 armnn::TensorInfo outputTensorInfo(OutputDim, outputShape, dataType);
7448
7449 inputTensorInfo.SetQuantizationScale(scale);
7450 inputTensorInfo.SetQuantizationOffset(offset);
7451
7452 outputTensorInfo.SetQuantizationScale(scale);
7453 outputTensorInfo.SetQuantizationOffset(offset);
7454
7455 auto input = MakeTensor<T, InputDim>(inputTensorInfo, inputData);
7456
7457 LayerTestResult<T, OutputDim> result(outputTensorInfo);
7458 result.outputExpected = MakeTensor<T, OutputDim>(outputTensorInfo, outputData);
7459
7460 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
7461 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
7462
7463 armnn::BatchToSpaceNdQueueDescriptor data;
7464 data.m_Parameters.m_DataLayout = dataLayout;
7465 data.m_Parameters.m_BlockShape = blockShape;
7466 data.m_Parameters.m_Crops = crops;
7467 armnn::WorkloadInfo info;
7468 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
7469 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
7470
7471 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateBatchToSpaceNd(data, info);
7472
7473 inputHandle->Allocate();
7474 outputHandle->Allocate();
7475
7476 CopyDataToITensorHandle(inputHandle.get(), input.origin());
7477
7478 workload->Execute();
7479
7480 CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get());
7481
7482 return result;
7483}
7484
7485} // anonymous namespace
7486
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007487LayerTestResult<float, 4> BatchToSpaceNdNhwcFloat32Test1(
7488 armnn::IWorkloadFactory& workloadFactory,
7489 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00007490{
7491 const unsigned int inputShape[] = {4, 2, 2, 1};
7492 const unsigned int outputShape[] = {1, 4, 4, 1 };
7493
7494 std::vector<float> input
7495 ({
7496 // Batch 0, Height 0, Width (2) x Channel (1)
7497 1.0f, 3.0f,
7498 // Batch 0, Height 1, Width (2) x Channel (1)
7499 9.0f, 11.0f,
7500
7501
7502 // Batch 1, Height 0, Width (2) x Channel (1)
7503 2.0f, 4.0f,
7504 // Batch 1, Height 1, Width (2) x Channel (1)
7505 10.0f, 12.0f,
7506
7507
7508 // Batch 2, Height 0, Width (2) x Channel (1)
7509 5.0f, 7.0f,
7510 // Batch 2, Height 1, Width (2) x Channel (1)
7511 13.0f, 15.0f,
7512
7513 // Batch 3, Height 0, Width (2) x Channel (3)
7514 6.0f, 8.0f,
7515 // Batch 3, Height 1, Width (2) x Channel (1)
7516 14.0f, 16.0f
7517 });
7518
7519 std::vector<float> expectedOutput
7520 ({
7521 1.0f, 2.0f, 3.0f, 4.0f,
7522 5.0f, 6.0f, 7.0f, 8.0f,
7523 9.0f, 10.0f, 11.0f, 12.0f,
7524 13.0f, 14.0f, 15.0f, 16.0f
7525 });
7526
7527 std::vector<unsigned int> blockShape {2, 2};
Éanna Ó Catháin95807ce2018-11-12 17:14:43 +00007528 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00007529
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007530 return BatchToSpaceNdHelper<float, 4, 4>(workloadFactory, memoryManager,
7531 armnn::DataLayout::NHWC, inputShape, input, blockShape,
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00007532 crops, outputShape, expectedOutput);
7533}
7534
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007535LayerTestResult<float, 4> BatchToSpaceNdNhwcFloat32Test2(
7536 armnn::IWorkloadFactory& workloadFactory,
7537 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00007538{
7539 const unsigned int inputShape[] = {4, 1, 1, 1};
7540 const unsigned int outputShape[] = {1, 2, 2, 1};
7541
7542 std::vector<float> input
7543 ({
7544 // Batch 0, Height 0, Width (2) x Channel (1)
7545 1.0f, 2.0f, 3.0f, 4.0f
7546 });
7547
7548 std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f});
7549
7550 std::vector<unsigned int> blockShape({2, 2});
Éanna Ó Catháin95807ce2018-11-12 17:14:43 +00007551 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00007552
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007553 return BatchToSpaceNdHelper<float, 4, 4>(workloadFactory, memoryManager,
7554 armnn::DataLayout::NHWC, inputShape, input, blockShape,
7555 crops, outputShape, expectedOutput);
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00007556}
7557
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007558LayerTestResult<float, 4> BatchToSpaceNdNhwcFloat32Test3(
7559 armnn::IWorkloadFactory& workloadFactory,
7560 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00007561{
7562 const unsigned int inputShape[] = {4, 1, 1, 3};
7563 const unsigned int outputShape[] = {1, 2, 2, 3};
7564
7565 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 });
7566
7567 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 });
7568
7569 std::vector<unsigned int> blockShape({2, 2});
Éanna Ó Catháin95807ce2018-11-12 17:14:43 +00007570 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00007571
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007572 return BatchToSpaceNdHelper<float, 4, 4>(workloadFactory, memoryManager,
7573 armnn::DataLayout::NHWC, inputShape, input, blockShape,
7574 crops, outputShape, expectedOutput);
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00007575}
7576
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007577LayerTestResult<float, 4> BatchToSpaceNdNchwFloat32Test1(
7578 armnn::IWorkloadFactory &workloadFactory,
7579 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00007580{
7581 const unsigned int inputShape[] = {4, 3, 1, 1};
7582 const unsigned int outputShape[] = {1, 3, 2, 2};
7583
7584 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 });
7585
7586 std::vector<float> expectedOutput
7587 ({
7588 // Batch 0, Channel 0, Height (2) x Width (2)
7589 1.0f, 4.0f,
7590 7.0f, 10.0f,
7591
7592 // Batch 0, Channel 1, Height (2) x Width (2)
7593 2.0f, 5.0f,
7594 8.0f, 11.0f,
7595
7596 // Batch 0, Channel 2, Height (2) x Width (2)
7597 3.0f, 6.0f,
7598 9.0f, 12.0f,
7599 });
7600
7601 std::vector<unsigned int> blockShape({2, 2});
Éanna Ó Catháin95807ce2018-11-12 17:14:43 +00007602 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00007603
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007604 return BatchToSpaceNdHelper<float, 4, 4>(workloadFactory, memoryManager,
7605 armnn::DataLayout::NCHW, inputShape, input, blockShape,
7606 crops, outputShape, expectedOutput);
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +00007607}
Éanna Ó Catháin262553e2018-11-14 11:26:23 +00007608
Mike Kelly831faed2018-11-28 11:52:08 +00007609LayerTestResult<float, 4> BatchToSpaceNdNchwFloat32Test2(
7610 armnn::IWorkloadFactory& workloadFactory,
7611 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7612{
7613 const unsigned int inputShape[] = {4, 1, 1, 1};
7614 const unsigned int outputShape[] = {1, 1, 2, 2};
7615
7616 std::vector<float> input
7617 ({
7618 // Batch 0, Height 0, Width (2) x Channel (1)
7619 1.0f, 2.0f, 3.0f, 4.0f
7620 });
7621
7622 std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f});
7623
7624 std::vector<unsigned int> blockShape({2, 2});
7625 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
7626
7627 return BatchToSpaceNdHelper<float, 4, 4>(workloadFactory, memoryManager,
7628 armnn::DataLayout::NCHW, inputShape, input, blockShape,
7629 crops, outputShape, expectedOutput);
7630}
7631
7632LayerTestResult<float, 4> BatchToSpaceNdNchwFloat32Test3(
7633 armnn::IWorkloadFactory& workloadFactory,
7634 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7635{
7636 const unsigned int inputShape[] = {4, 3, 1, 1};
7637 const unsigned int outputShape[] = {1, 3, 2, 2};
7638
7639 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 });
7640
7641 std::vector<float> expectedOutput
7642 ({
7643 // Batch 0, Channel 0, Height (2) x Width (2)
7644 1.0f, 7.0f,
7645 2.0f, 8.0f,
7646
7647 // Batch 0, Channel 1, Height (2) x Width (2)
7648 3.0f, 9.0f,
7649 4.0f, 10.0f,
7650
7651 // Batch 0, Channel 2, Height (2) x Width (2)
7652 5.0f, 11.0f,
7653 6.0f, 12.0f,
7654 });
7655
7656 std::vector<unsigned int> blockShape({2, 2});
7657 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
7658
7659 return BatchToSpaceNdHelper<float, 4, 4>(workloadFactory, memoryManager,
7660 armnn::DataLayout::NCHW, inputShape, input, blockShape,
7661 crops, outputShape, expectedOutput);
7662}
Éanna Ó Catháin262553e2018-11-14 11:26:23 +00007663
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007664LayerTestResult<uint8_t, 4> BatchToSpaceNdNhwcUintTest1(
7665 armnn::IWorkloadFactory& workloadFactory,
7666 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
Éanna Ó Catháin262553e2018-11-14 11:26:23 +00007667{
7668 const unsigned int inputShape[] = {4, 2, 2, 1};
7669 const unsigned int outputShape[] = {1, 4, 4, 1};
7670
7671 std::vector<uint8_t> input({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 });
7672 std::vector<uint8_t> expectedOutput({ 1, 5, 2, 6, 9, 13, 10, 14, 3, 7, 4, 8, 11, 15, 12, 16});
7673
7674 std::vector<unsigned int> blockShape({2, 2});
7675 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
7676
Matteo Martincigha65b7ae2018-11-14 12:39:55 +00007677 return BatchToSpaceNdHelper<uint8_t, 4, 4>(workloadFactory, memoryManager, armnn::DataLayout::NHWC, inputShape,
7678 input, blockShape, crops, outputShape, expectedOutput);
Aron Virginas-Tar5caf9072018-11-14 18:35:18 +00007679}
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00007680
7681LayerTestResult<float, 4> StridedSlice4DFloat32Test(
7682 armnn::IWorkloadFactory& workloadFactory,
7683 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7684{
7685 return StridedSlice4DTest<float>(workloadFactory, memoryManager);
7686}
7687
7688LayerTestResult<float, 4> StridedSlice4DReverseFloat32Test(
7689 armnn::IWorkloadFactory& workloadFactory,
7690 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7691{
7692 return StridedSlice4DReverseTest<float>(workloadFactory, memoryManager);
7693}
7694
7695LayerTestResult<float, 4> StridedSliceSimpleStrideFloat32Test(
7696 armnn::IWorkloadFactory& workloadFactory,
7697 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7698{
7699 return StridedSliceSimpleStrideTest<float>(workloadFactory, memoryManager);
7700}
7701
7702LayerTestResult<float, 4> StridedSliceSimpleRangeMaskFloat32Test(
7703 armnn::IWorkloadFactory& workloadFactory,
7704 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7705{
7706 return StridedSliceSimpleRangeMaskTest<float>(workloadFactory, memoryManager);
7707}
7708
7709LayerTestResult<float, 2> StridedSliceShrinkAxisMaskFloat32Test(
7710 armnn::IWorkloadFactory& workloadFactory,
7711 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7712{
7713 return StridedSliceShrinkAxisMaskTest<float>(workloadFactory, memoryManager);
7714}
7715
7716LayerTestResult<float, 3> StridedSlice3DFloat32Test(
7717 armnn::IWorkloadFactory& workloadFactory,
7718 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7719{
7720 return StridedSlice3DTest<float>(workloadFactory, memoryManager);
7721}
7722
7723LayerTestResult<float, 3> StridedSlice3DReverseFloat32Test(
7724 armnn::IWorkloadFactory& workloadFactory,
7725 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7726{
7727 return StridedSlice3DReverseTest<float>(workloadFactory, memoryManager);
7728}
7729
7730LayerTestResult<float, 2> StridedSlice2DFloat32Test(
7731 armnn::IWorkloadFactory& workloadFactory,
7732 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7733{
7734 return StridedSlice2DTest<float>(workloadFactory, memoryManager);
7735}
7736
7737LayerTestResult<float, 2> StridedSlice2DReverseFloat32Test(
7738 armnn::IWorkloadFactory& workloadFactory,
7739 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7740{
7741 return StridedSlice2DReverseTest<float>(workloadFactory, memoryManager);
7742}
7743
7744LayerTestResult<uint8_t, 4> StridedSlice4DUint8Test(
7745 armnn::IWorkloadFactory& workloadFactory,
7746 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7747{
7748 return StridedSlice4DTest<uint8_t>(workloadFactory, memoryManager);
7749}
7750
7751LayerTestResult<uint8_t, 4> StridedSlice4DReverseUint8Test(
7752 armnn::IWorkloadFactory& workloadFactory,
7753 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7754{
7755 return StridedSlice4DReverseTest<uint8_t>(workloadFactory, memoryManager);
7756}
7757
7758LayerTestResult<uint8_t, 4> StridedSliceSimpleStrideUint8Test(
7759 armnn::IWorkloadFactory& workloadFactory,
7760 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7761{
7762 return StridedSliceSimpleStrideTest<uint8_t>(workloadFactory, memoryManager);
7763}
7764
7765LayerTestResult<uint8_t, 4> StridedSliceSimpleRangeMaskUint8Test(
7766 armnn::IWorkloadFactory& workloadFactory,
7767 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7768{
7769 return StridedSliceSimpleRangeMaskTest<uint8_t>(workloadFactory, memoryManager);
7770}
7771
7772LayerTestResult<uint8_t, 2> StridedSliceShrinkAxisMaskUint8Test(
7773 armnn::IWorkloadFactory& workloadFactory,
7774 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7775{
7776 return StridedSliceShrinkAxisMaskTest<uint8_t>(workloadFactory, memoryManager);
7777}
7778
7779LayerTestResult<uint8_t, 3> StridedSlice3DUint8Test(
7780 armnn::IWorkloadFactory& workloadFactory,
7781 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7782{
7783 return StridedSlice3DTest<uint8_t>(workloadFactory, memoryManager);
7784}
7785
7786LayerTestResult<uint8_t, 3> StridedSlice3DReverseUint8Test(
7787 armnn::IWorkloadFactory& workloadFactory,
7788 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7789{
7790 return StridedSlice3DReverseTest<uint8_t>(workloadFactory, memoryManager);
7791}
7792
7793LayerTestResult<uint8_t, 2> StridedSlice2DUint8Test(
7794 armnn::IWorkloadFactory& workloadFactory,
7795 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7796{
7797 return StridedSlice2DTest<uint8_t>(workloadFactory, memoryManager);
7798}
7799
7800LayerTestResult<uint8_t, 2> StridedSlice2DReverseUint8Test(
7801 armnn::IWorkloadFactory& workloadFactory,
7802 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7803{
7804 return StridedSlice2DReverseTest<uint8_t>(workloadFactory, memoryManager);
7805}
Mike Kelly831faed2018-11-28 11:52:08 +00007806LayerTestResult<uint8_t, 4> BatchToSpaceNdNhwcUintTest2(
7807 armnn::IWorkloadFactory& workloadFactory,
7808 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7809{
7810 const unsigned int inputShape[] = {4, 1, 1, 1};
7811 const unsigned int outputShape[] = {1, 2, 2, 1};
7812
7813 std::vector<uint8_t> input
7814 ({
7815 // Batch 0, Height 0, Width (2) x Channel (1)
7816 1, 2, 3, 4
7817 });
7818
7819 std::vector<uint8_t> expectedOutput({1, 2, 3, 4});
7820
7821 std::vector<unsigned int> blockShape({2, 2});
7822 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
7823
7824 return BatchToSpaceNdHelper<uint8_t, 4, 4>(workloadFactory, memoryManager,
7825 armnn::DataLayout::NHWC, inputShape, input, blockShape,
7826 crops, outputShape, expectedOutput);
7827}
7828
7829LayerTestResult<uint8_t, 4> BatchToSpaceNdNhwcUintTest3(
7830 armnn::IWorkloadFactory& workloadFactory,
7831 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7832{
7833 const unsigned int inputShape[] = {4, 1, 1, 3};
7834 const unsigned int outputShape[] = {1, 2, 2, 3};
7835
7836 std::vector<uint8_t> input({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
7837
7838 std::vector<uint8_t> expectedOutput({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
7839
7840 std::vector<unsigned int> blockShape({2, 2});
7841 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
7842
7843 return BatchToSpaceNdHelper<uint8_t, 4, 4>(workloadFactory, memoryManager,
7844 armnn::DataLayout::NHWC, inputShape, input, blockShape,
7845 crops, outputShape, expectedOutput);
7846}
7847
7848
7849LayerTestResult<uint8_t, 4> BatchToSpaceNdNchwUintTest1(
7850 armnn::IWorkloadFactory &workloadFactory,
7851 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7852{
7853 const unsigned int inputShape[] = {4, 3, 1, 1};
7854 const unsigned int outputShape[] = {1, 3, 2, 2};
7855
7856 std::vector<uint8_t> input({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
7857
7858 std::vector<uint8_t> expectedOutput
7859 ({
7860 // Batch 0, Channel 0, Height (2) x Width (2)
7861 1, 4,
7862 7, 10,
7863
7864 // Batch 0, Channel 1, Height (2) x Width (2)
7865 2, 5,
7866 8, 11,
7867
7868 // Batch 0, Channel 2, Height (2) x Width (2)
7869 3, 6,
7870 9, 12,
7871 });
7872
7873 std::vector<unsigned int> blockShape({2, 2});
7874 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
7875
7876 return BatchToSpaceNdHelper<uint8_t, 4, 4>(workloadFactory, memoryManager,
7877 armnn::DataLayout::NCHW, inputShape, input, blockShape,
7878 crops, outputShape, expectedOutput);
7879}
7880
7881LayerTestResult<uint8_t, 4> BatchToSpaceNdNchwUintTest2(
7882 armnn::IWorkloadFactory& workloadFactory,
7883 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7884{
7885 const unsigned int inputShape[] = {4, 1, 1, 1};
7886 const unsigned int outputShape[] = {1, 1, 2, 2};
7887
7888 std::vector<uint8_t> input
7889 ({
7890 // Batch 0, Height 0, Width (2) x Channel (1)
7891 1, 2, 3, 4
7892 });
7893
7894 std::vector<uint8_t> expectedOutput({1, 2, 3, 4});
7895
7896 std::vector<unsigned int> blockShape({2, 2});
7897 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
7898
7899 return BatchToSpaceNdHelper<uint8_t, 4, 4>(workloadFactory, memoryManager,
7900 armnn::DataLayout::NCHW, inputShape, input, blockShape,
7901 crops, outputShape, expectedOutput);
7902}
7903
7904LayerTestResult<uint8_t, 4> BatchToSpaceNdNchwUintTest3(
7905 armnn::IWorkloadFactory& workloadFactory,
7906 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
7907{
7908 const unsigned int inputShape[] = {4, 3, 1, 1};
7909 const unsigned int outputShape[] = {1, 3, 2, 2};
7910
7911 std::vector<uint8_t> input({ 1, 3, 5, 7, 9, 11, 2, 4, 6, 8, 10, 12 });
7912
7913 std::vector<uint8_t> expectedOutput
7914 ({
7915 // Batch 0, Channel 0, Height (2) x Width (2)
7916 1, 7,
7917 2, 8,
7918
7919 // Batch 0, Channel 1, Height (2) x Width (2)
7920 3, 9,
7921 4, 10,
7922
7923 // Batch 0, Channel 2, Height (2) x Width (2)
7924 5, 11,
7925 6, 12,
7926 });
7927 std::vector<unsigned int> blockShape({2, 2});
7928 std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}};
7929
7930 return BatchToSpaceNdHelper<uint8_t, 4, 4>(workloadFactory, memoryManager,
7931 armnn::DataLayout::NCHW, inputShape, input, blockShape,
7932 crops, outputShape, expectedOutput);
7933}