blob: 3828010c7b302e615d845f47bf89c2a996aa080f [file] [log] [blame]
Isabella Gottardiee7c15d2018-12-17 16:15:34 +00001/*
Gunes Bayir0b72aa42023-10-07 23:52:48 +01002 * Copyright (c) 2018-2021, 2023 Arm Limited.
Isabella Gottardiee7c15d2018-12-17 16:15:34 +00003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/core/Helpers.h"
25#include "arm_compute/core/Types.h"
26#include "arm_compute/core/utils/misc/ShapeCalculator.h"
27#include "arm_compute/runtime/NEON/functions/NEStackLayer.h"
28#include "arm_compute/runtime/Tensor.h"
29#include "arm_compute/runtime/TensorAllocator.h"
30#include "tests/NEON/Accessor.h"
31#include "tests/PaddingCalculator.h"
32#include "tests/datasets/ShapeDatasets.h"
33#include "tests/framework/Asserts.h"
34#include "tests/framework/Macros.h"
35#include "tests/framework/datasets/Datasets.h"
36#include "tests/validation/Validation.h"
37#include "tests/validation/fixtures/StackLayerFixture.h"
38
39#include <vector>
40
41namespace arm_compute
42{
43namespace test
44{
45namespace validation
46{
Gunes Bayir0b72aa42023-10-07 23:52:48 +010047
48using framework::dataset::make;
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000049namespace
50{
51// *INDENT-OFF*
52// clang-format off
53/** Data types */
Gunes Bayir0b72aa42023-10-07 23:52:48 +010054const auto data_types = make("DataType", { DataType::QASYMM8, DataType::F16, DataType::F32 });
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000055
56/** Num tensors values to test */
Gunes Bayir0b72aa42023-10-07 23:52:48 +010057const auto n_values = make("NumTensors", { 3, 4 });
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000058
59/** Shapes 1D to test */
Gunes Bayir0b72aa42023-10-07 23:52:48 +010060const auto shapes_1d_small = combine(datasets::Small1DShapes(), make("Axis", -1, 2));
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000061
62/** Shapes 2D to test */
Gunes Bayir0b72aa42023-10-07 23:52:48 +010063const auto shapes_2d_small = combine(datasets::Small2DShapes(), make("Axis", -2, 3));
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000064
65/** Shapes 3D to test */
Gunes Bayir0b72aa42023-10-07 23:52:48 +010066const auto shapes_3d_small = combine(datasets::Small3DShapes(), make("Axis", -3, 4));
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000067
68/** Shapes 4D to test */
Gunes Bayir0b72aa42023-10-07 23:52:48 +010069const auto shapes_4d_small = combine(datasets::Small4DShapes(), make("Axis", -4, 5));
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000070
71/** Shapes 1D to test */
Gunes Bayir0b72aa42023-10-07 23:52:48 +010072const auto shapes_1d_large = combine(datasets::Large1DShapes(), make("Axis", -1, 2));
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000073
74/** Shapes 2D to test */
Gunes Bayir0b72aa42023-10-07 23:52:48 +010075const auto shapes_2d_large = combine(datasets::Medium2DShapes(), make("Axis", -2, 3));
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000076
77/** Shapes 3D to test */
Gunes Bayir0b72aa42023-10-07 23:52:48 +010078const auto shapes_3d_large = combine(datasets::Medium3DShapes(), make("Axis", -3, 4));
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000079
80/** Shapes 4D to test */
Gunes Bayir0b72aa42023-10-07 23:52:48 +010081const auto shapes_4d_large = combine(datasets::Medium4DShapes(), make("Axis", -4, 5));
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000082} // namespace
83
84/** Fixture to use */
85template<typename T>
86using NEStackLayerFixture = StackLayerValidationFixture<Tensor, ITensor, Accessor, NEStackLayer, T>;
87
Gunes Bayir0b72aa42023-10-07 23:52:48 +010088template<typename T>
89using NEStackLayerWithPaddingFixture = StackLayerWithPaddingValidationFixture<Tensor, ITensor, Accessor, NEStackLayer, T>;
90
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000091using namespace arm_compute::misc::shape_calculator;
92
93TEST_SUITE(NEON)
94TEST_SUITE(StackLayer)
95
Gunes Bayir0b72aa42023-10-07 23:52:48 +010096DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(
97make("InputInfo",
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000098{
99 std::vector<TensorInfo>{ TensorInfo(TensorShape(9U, 8U), 1, DataType::U8) },
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100100 std::vector<TensorInfo>{ TensorInfo(TensorShape(1U, 2U), 1, DataType::U8) , TensorInfo(TensorShape(1U, 2U), 1, DataType::U8), TensorInfo(TensorShape(1U, 2U), 1, DataType::U8)},
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000101 std::vector<TensorInfo>{ TensorInfo(TensorShape(2U, 3U), 1, DataType::S32) },
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100102 std::vector<TensorInfo>{ TensorInfo(TensorShape(7U, 5U, 3U, 8U, 2U), 1, DataType::S32), TensorInfo(TensorShape(7U, 5U, 3U, 8U, 2U), 1, DataType::S32)},
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000103 std::vector<TensorInfo>{ TensorInfo(TensorShape(9U, 8U), 1, DataType::S32) },
104}),
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100105make("OutputInfo",
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000106{
107 TensorInfo(TensorShape(1U, 9U, 8U), 1, DataType::U8), // Passes, stack 1 tensor on x axis
108 TensorInfo(TensorShape(1U, 3U, 2U), 1, DataType::U8), // Passes, stack 3 tensors on y axis
109 TensorInfo(TensorShape(1U, 2U, 3U), 1, DataType::S32), // fails axis < (- input's rank)
110 TensorInfo(TensorShape(3U, 7U, 5U), 1, DataType::S32), // fails, input dimensions > 4
111 TensorInfo(TensorShape(1U, 2U, 3U), 1, DataType::U8), // fails mismatching data types
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100112}),
113make("Axis", { -3, 1, -4, -3, 1 }),
114make("Expected", { true, true, false, false, false })),
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000115input_info, output_info, axis, expected)
116{
117 std::vector<TensorInfo> ti(input_info);
118 std::vector<ITensorInfo *> vec(input_info.size());
119 for(size_t j = 0; j < vec.size(); ++j)
120 {
121 vec[j] = &ti[j];
122 }
123 ARM_COMPUTE_EXPECT(bool(NEStackLayer::validate(vec, axis, &output_info)) == expected, framework::LogLevel::ERRORS);
124}
125
126TEST_SUITE(Shapes1D)
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000127TEST_SUITE(S32)
128FIXTURE_DATA_TEST_CASE(RunSmall, NEStackLayerFixture<int>, framework::DatasetMode::ALL,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100129 combine(shapes_1d_small,
130 make("DataType", { DataType::S32 }),
131 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000132{
133 // Validate output
134 validate(Accessor(_target), _reference);
135}
136
137FIXTURE_DATA_TEST_CASE(RunLarge, NEStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100138 combine(shapes_1d_large,
139 make("DataType", { DataType::S32 }),
140 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000141{
142 // Validate output
143 validate(Accessor(_target), _reference);
144}
145TEST_SUITE_END() // S32
146
147TEST_SUITE(S16)
148FIXTURE_DATA_TEST_CASE(RunSmall, NEStackLayerFixture<short>, framework::DatasetMode::ALL,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100149 combine(shapes_1d_small,
150 make("DataType", { DataType::S16 }),
151 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000152{
153 // Validate output
154 validate(Accessor(_target), _reference);
155}
156
157FIXTURE_DATA_TEST_CASE(RunLarge, NEStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100158 combine(shapes_1d_large,
159 make("DataType", { DataType::S16 }),
160 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000161{
162 // Validate output
163 validate(Accessor(_target), _reference);
164}
165TEST_SUITE_END() // S16
166
167TEST_SUITE(S8)
168FIXTURE_DATA_TEST_CASE(RunSmall, NEStackLayerFixture<char>, framework::DatasetMode::ALL,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100169 combine(shapes_1d_small,
170 make("DataType", { DataType::S8 }),
171 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000172{
173 // Validate output
174 validate(Accessor(_target), _reference);
175}
176
177FIXTURE_DATA_TEST_CASE(RunLarge, NEStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100178 combine(shapes_1d_large,
179 make("DataType", { DataType::S8 }),
180 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000181{
182 // Validate output
183 validate(Accessor(_target), _reference);
184}
185TEST_SUITE_END() // S8
186TEST_SUITE_END() // Shapes1D
187
188TEST_SUITE(Shapes2D)
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000189TEST_SUITE(S32)
190FIXTURE_DATA_TEST_CASE(RunSmall, NEStackLayerFixture<int>, framework::DatasetMode::ALL,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100191 combine(shapes_2d_small,
192 make("DataType", { DataType::S32 }),
193 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000194{
195 // Validate output
196 validate(Accessor(_target), _reference);
197}
198
199FIXTURE_DATA_TEST_CASE(RunLarge, NEStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100200 combine(shapes_2d_large,
201 make("DataType", { DataType::S32 }),
202 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000203{
204 // Validate output
205 validate(Accessor(_target), _reference);
206}
207TEST_SUITE_END() // S32
208
209TEST_SUITE(S16)
210FIXTURE_DATA_TEST_CASE(RunSmall, NEStackLayerFixture<short>, framework::DatasetMode::ALL,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100211 combine(shapes_2d_small,
212 make("DataType", { DataType::S16 }),
213 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000214{
215 // Validate output
216 validate(Accessor(_target), _reference);
217}
218
219FIXTURE_DATA_TEST_CASE(RunLarge, NEStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100220 combine(shapes_2d_large,
221 make("DataType", { DataType::S16 }),
222 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000223{
224 // Validate output
225 validate(Accessor(_target), _reference);
226}
227TEST_SUITE_END() // S16
228
229TEST_SUITE(S8)
230FIXTURE_DATA_TEST_CASE(RunSmall, NEStackLayerFixture<char>, framework::DatasetMode::ALL,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100231 combine(shapes_2d_small,
232 make("DataType", { DataType::S8 }),
233 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000234{
235 // Validate output
236 validate(Accessor(_target), _reference);
237}
238
239FIXTURE_DATA_TEST_CASE(RunLarge, NEStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100240 combine(shapes_2d_large,
241 make("DataType", { DataType::S8 }),
242 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000243{
244 // Validate output
245 validate(Accessor(_target), _reference);
246}
247TEST_SUITE_END() // S8
248TEST_SUITE_END() // Shapes2D
249
250TEST_SUITE(Shapes3D)
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000251TEST_SUITE(S32)
252FIXTURE_DATA_TEST_CASE(RunSmall, NEStackLayerFixture<int>, framework::DatasetMode::ALL,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100253 combine(shapes_3d_small,
254 make("DataType", { DataType::S32 }),
255 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000256{
257 // Validate output
258 validate(Accessor(_target), _reference);
259}
260
261FIXTURE_DATA_TEST_CASE(RunLarge, NEStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100262 combine(shapes_3d_large,
263 make("DataType", { DataType::S32 }),
264 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000265{
266 // Validate output
267 validate(Accessor(_target), _reference);
268}
269TEST_SUITE_END() // S32
270
271TEST_SUITE(S16)
272FIXTURE_DATA_TEST_CASE(RunSmall, NEStackLayerFixture<short>, framework::DatasetMode::ALL,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100273 combine(shapes_3d_small,
274 make("DataType", { DataType::S16 }),
275 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000276{
277 // Validate output
278 validate(Accessor(_target), _reference);
279}
280
281FIXTURE_DATA_TEST_CASE(RunLarge, NEStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100282 combine(shapes_3d_large,
283 make("DataType", { DataType::S16 }),
284 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000285{
286 // Validate output
287 validate(Accessor(_target), _reference);
288}
289TEST_SUITE_END() // S16
290
291TEST_SUITE(S8)
292FIXTURE_DATA_TEST_CASE(RunSmall, NEStackLayerFixture<char>, framework::DatasetMode::ALL,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100293 combine(shapes_3d_small,
294 make("DataType", { DataType::S8 }),
295 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000296{
297 // Validate output
298 validate(Accessor(_target), _reference);
299}
300
301FIXTURE_DATA_TEST_CASE(RunLarge, NEStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100302 combine(shapes_3d_large,
303 make("DataType", { DataType::S8 }),
304 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000305{
306 // Validate output
307 validate(Accessor(_target), _reference);
308}
309TEST_SUITE_END() // S8
310TEST_SUITE_END() // Shapes3D
311
312TEST_SUITE(Shapes4D)
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000313TEST_SUITE(S32)
314FIXTURE_DATA_TEST_CASE(RunSmall, NEStackLayerFixture<int>, framework::DatasetMode::ALL,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100315 combine(shapes_4d_small,
316 make("DataType", { DataType::S32 }),
317 n_values))
318{
319 // Validate output
320 validate(Accessor(_target), _reference);
321}
322
323// Testing the case with padding for only 4d shapes and for one data type. This is because the underlying code
324// path depends only on the padding, which isn't affected by the shapes or data types.
325FIXTURE_DATA_TEST_CASE(RunSmallWithPadding, NEStackLayerWithPaddingFixture<int>, framework::DatasetMode::ALL,
326 combine(shapes_4d_small,
327 make("DataType", { DataType::S32 }),
328 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000329{
330 // Validate output
331 validate(Accessor(_target), _reference);
332}
333
334FIXTURE_DATA_TEST_CASE(RunLarge, NEStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100335 combine(shapes_4d_large,
336 make("DataType", { DataType::S32 }),
337 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000338{
339 // Validate output
340 validate(Accessor(_target), _reference);
341}
342TEST_SUITE_END() // S32
343
344TEST_SUITE(S16)
345FIXTURE_DATA_TEST_CASE(RunSmall, NEStackLayerFixture<short>, framework::DatasetMode::ALL,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100346 combine(shapes_4d_small,
347 make("DataType", { DataType::S16 }),
348 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000349{
350 // Validate output
351 validate(Accessor(_target), _reference);
352}
353
354FIXTURE_DATA_TEST_CASE(RunLarge, NEStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100355 combine(shapes_4d_large,
356 make("DataType", { DataType::S16 }),
357 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000358{
359 // Validate output
360 validate(Accessor(_target), _reference);
361}
362TEST_SUITE_END() // S16
363
364TEST_SUITE(S8)
365FIXTURE_DATA_TEST_CASE(RunSmall, NEStackLayerFixture<char>, framework::DatasetMode::ALL,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100366 combine(shapes_4d_small,
367 make("DataType", { DataType::S8 }),
368 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000369{
370 // Validate output
371 validate(Accessor(_target), _reference);
372}
373
374FIXTURE_DATA_TEST_CASE(RunLarge, NEStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100375 combine(shapes_4d_large,
376 make("DataType", { DataType::S8 }),
377 n_values))
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000378{
379 // Validate output
380 validate(Accessor(_target), _reference);
381}
382TEST_SUITE_END() // S8
383TEST_SUITE_END() // Shapes4D
Gunes Bayir0b72aa42023-10-07 23:52:48 +0100384
385TEST_SUITE(HighDimensional)
386// The Cpu implementation supports tensors of size 4D+, but reference implementation does not.
387FIXTURE_DATA_TEST_CASE(RunHighDimensional, NEStackLayerFixture<char>, framework::DatasetMode::DISABLED,
388 combine(make("Shape", { TensorShape{2U, 3U, 4U, 5U, 3U} }),
389 make("Axis", { 5, 0, -3, 2 }),
390 make("DataType", { DataType::S8 }),
391 make("NumTensors", { 3 })))
392{
393 // Validate output
394 validate(Accessor(_target), _reference);
395}
396TEST_SUITE_END() // HighDimensional
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000397TEST_SUITE_END() // StackLayer
Sheri Zhangac6499a2021-02-10 15:32:38 +0000398TEST_SUITE_END() // Neon
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000399} // namespace validation
400} // namespace test
401} // namespace arm_compute