blob: 6f38c55e4872d7c2d0ad7ea2b3841232f40a9e0d [file] [log] [blame]
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +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/CL/CLTensor.h"
28#include "arm_compute/runtime/CL/CLTensorAllocator.h"
29#include "arm_compute/runtime/CL/functions/CLStackLayer.h"
30#include "tests/CL/CLAccessor.h"
31#include "tests/CL/Helper.h"
32#include "tests/PaddingCalculator.h"
33#include "tests/datasets/ShapeDatasets.h"
34#include "tests/framework/Asserts.h"
35#include "tests/framework/Macros.h"
36#include "tests/framework/datasets/Datasets.h"
37#include "tests/validation/Validation.h"
38#include "tests/validation/fixtures/StackLayerFixture.h"
39
40#include <vector>
41
42namespace arm_compute
43{
44namespace test
45{
46namespace validation
47{
48namespace
49{
50// *INDENT-OFF*
51// clang-format off
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +000052/** Num tensors values to test */
53const auto n_values = framework::dataset::make("NumTensors", { 3, 4 });
54
55/** Shapes 1D to test */
56const auto shapes_1d_small = combine(datasets::Small1DShapes(), framework::dataset::make("Axis", -1, 2));
57
58/** Shapes 2D to test */
59const auto shapes_2d_small = combine(datasets::Small2DShapes(), framework::dataset::make("Axis", -2, 3));
60
61/** Shapes 3D to test */
62const auto shapes_3d_small = combine(datasets::Small3DShapes(), framework::dataset::make("Axis", -3, 4));
63
64/** Shapes 4D to test */
65const auto shapes_4d_small = combine(datasets::Small4DShapes(), framework::dataset::make("Axis", -4, 5));
66
67/** Shapes 1D to test */
68const auto shapes_1d_large = combine(datasets::Large1DShapes(), framework::dataset::make("Axis", -1, 2));
69
70/** Shapes 2D to test */
Michalis Spyrou5ed7b5b2019-03-19 12:17:26 +000071const auto shapes_2d_large = combine(datasets::Medium2DShapes(), framework::dataset::make("Axis", -2, 3));
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +000072
73/** Shapes 3D to test */
Michalis Spyrou5ed7b5b2019-03-19 12:17:26 +000074const auto shapes_3d_large = combine(datasets::Medium3DShapes(), framework::dataset::make("Axis", -3, 4));
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +000075
76/** Shapes 4D to test */
Michalis Spyrou5ed7b5b2019-03-19 12:17:26 +000077const auto shapes_4d_large = combine(datasets::Medium4DShapes(), framework::dataset::make("Axis", -4, 5));
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +000078} // namespace
79
80/** Fixture to use */
81template<typename T>
82using CLStackLayerFixture = StackLayerValidationFixture<CLTensor, ICLTensor, CLAccessor, CLStackLayer, T>;
83
84using namespace arm_compute::misc::shape_calculator;
85
86TEST_SUITE(CL)
87TEST_SUITE(StackLayer)
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000088
Michalis Spyrou80943252019-01-10 17:19:50 +000089// *INDENT-OFF*
90// clang-format off
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000091DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Michalis Spyrou80943252019-01-10 17:19:50 +000092 framework::dataset::make("InputInfo", { std::vector<TensorInfo>{ TensorInfo(TensorShape(9U, 8U), 1, DataType::U8) },
93 std::vector<TensorInfo>{ TensorInfo(TensorShape(1U, 2U), 1, DataType::U8) , TensorInfo(TensorShape(1U, 2U), 1, DataType::U8), TensorInfo(TensorShape(1U, 2U), 1, DataType::U8)},
94 std::vector<TensorInfo>{ TensorInfo(TensorShape(2U, 3U), 1, DataType::S32) },
95 std::vector<TensorInfo>{ TensorInfo(TensorShape(7U, 5U, 3U, 8U, 2U), 1, DataType::S32), TensorInfo(TensorShape(7U, 5U, 3U, 8U, 2U), 1, DataType::S32)},
96 std::vector<TensorInfo>{ TensorInfo(TensorShape(9U, 8U), 1, DataType::S32) },
97 }),
98 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(1U, 9U, 8U), 1, DataType::U8), // Passes, stack 1 tensor on x axis
99 TensorInfo(TensorShape(1U, 3U, 2U), 1, DataType::U8), // Passes, stack 3 tensors on y axis
100 TensorInfo(TensorShape(1U, 2U, 3U), 1, DataType::S32), // fails axis < (- input's rank)
101 TensorInfo(TensorShape(3U, 7U, 5U), 1, DataType::S32), // fails, input dimensions > 4
102 TensorInfo(TensorShape(1U, 2U, 3U), 1, DataType::U8), // fails mismatching data types
103 })),
104 framework::dataset::make("Axis", { -3, 1, -4, -3, 1 })),
105 framework::dataset::make("Expected", { true, true, false, false, false })),
106 input_info, output_info, axis, expected)
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000107{
108 std::vector<TensorInfo> ti(input_info);
109 std::vector<ITensorInfo *> vec(input_info.size());
110 for(size_t j = 0; j < vec.size(); ++j)
111 {
112 vec[j] = &ti[j];
113 }
114 ARM_COMPUTE_EXPECT(bool(CLStackLayer::validate(vec, axis, &output_info)) == expected, framework::LogLevel::ERRORS);
115}
Michalis Spyrou80943252019-01-10 17:19:50 +0000116// clang-format on
117// *INDENT-ON*
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000118
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000119TEST_SUITE(Shapes1D)
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000120TEST_SUITE(S32)
121FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000122 combine(combine(shapes_1d_small,
123 framework::dataset::make("DataType", { DataType::S32 })),
124 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000125{
126 // Validate output
127 validate(CLAccessor(_target), _reference);
128}
129
130FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000131 combine(combine(shapes_1d_large,
132 framework::dataset::make("DataType", { DataType::S32 })),
133 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000134{
135 // Validate output
136 validate(CLAccessor(_target), _reference);
137}
138TEST_SUITE_END() // S32
139
140TEST_SUITE(S16)
141FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000142 combine(combine(shapes_1d_small,
143 framework::dataset::make("DataType", { DataType::S16 })),
144 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000145{
146 // Validate output
147 validate(CLAccessor(_target), _reference);
148}
149
150FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000151 combine(combine(shapes_1d_large,
152 framework::dataset::make("DataType", { DataType::S16 })),
153 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000154{
155 // Validate output
156 validate(CLAccessor(_target), _reference);
157}
158TEST_SUITE_END() // S16
159
160TEST_SUITE(S8)
161FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000162 combine(combine(shapes_1d_small,
163 framework::dataset::make("DataType", { DataType::S8 })),
164 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000165{
166 // Validate output
167 validate(CLAccessor(_target), _reference);
168}
169
170FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000171 combine(combine(shapes_1d_large,
172 framework::dataset::make("DataType", { DataType::S8 })),
173 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000174{
175 // Validate output
176 validate(CLAccessor(_target), _reference);
177}
178TEST_SUITE_END() // S8
179TEST_SUITE_END() // Shapes1D
180
181TEST_SUITE(Shapes2D)
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000182TEST_SUITE(S32)
183FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000184 combine(combine(shapes_2d_small,
185 framework::dataset::make("DataType", { DataType::S32 })),
186 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000187{
188 // Validate output
189 validate(CLAccessor(_target), _reference);
190}
191
192FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000193 combine(combine(shapes_2d_large,
194 framework::dataset::make("DataType", { DataType::S32 })),
195 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000196{
197 // Validate output
198 validate(CLAccessor(_target), _reference);
199}
200TEST_SUITE_END() // S32
201
202TEST_SUITE(S16)
203FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000204 combine(combine(shapes_2d_small,
205 framework::dataset::make("DataType", { DataType::S16 })),
206 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000207{
208 // Validate output
209 validate(CLAccessor(_target), _reference);
210}
211
212FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000213 combine(combine(shapes_2d_large,
214 framework::dataset::make("DataType", { DataType::S16 })),
215 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000216{
217 // Validate output
218 validate(CLAccessor(_target), _reference);
219}
220TEST_SUITE_END() // S16
221
222TEST_SUITE(S8)
223FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000224 combine(combine(shapes_2d_small,
225 framework::dataset::make("DataType", { DataType::S8 })),
226 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000227{
228 // Validate output
229 validate(CLAccessor(_target), _reference);
230}
231
232FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000233 combine(combine(shapes_2d_large,
234 framework::dataset::make("DataType", { DataType::S8 })),
235 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000236{
237 // Validate output
238 validate(CLAccessor(_target), _reference);
239}
240TEST_SUITE_END() // S8
241TEST_SUITE_END() // Shapes2D
242
243TEST_SUITE(Shapes3D)
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000244TEST_SUITE(S32)
245FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000246 combine(combine(shapes_3d_small,
247 framework::dataset::make("DataType", { DataType::S32 })),
248 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000249{
250 // Validate output
251 validate(CLAccessor(_target), _reference);
252}
253
254FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000255 combine(combine(shapes_3d_large,
256 framework::dataset::make("DataType", { DataType::S32 })),
257 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000258{
259 // Validate output
260 validate(CLAccessor(_target), _reference);
261}
262TEST_SUITE_END() // S32
263
264TEST_SUITE(S16)
265FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000266 combine(combine(shapes_3d_small,
267 framework::dataset::make("DataType", { DataType::S16 })),
268 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000269{
270 // Validate output
271 validate(CLAccessor(_target), _reference);
272}
273
274FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000275 combine(combine(shapes_3d_large,
276 framework::dataset::make("DataType", { DataType::S16 })),
277 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000278{
279 // Validate output
280 validate(CLAccessor(_target), _reference);
281}
282TEST_SUITE_END() // S16
283
284TEST_SUITE(S8)
285FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000286 combine(combine(shapes_3d_small,
287 framework::dataset::make("DataType", { DataType::S8 })),
288 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000289{
290 // Validate output
291 validate(CLAccessor(_target), _reference);
292}
293
294FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000295 combine(combine(shapes_3d_large,
296 framework::dataset::make("DataType", { DataType::S8 })),
297 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000298{
299 // Validate output
300 validate(CLAccessor(_target), _reference);
301}
302TEST_SUITE_END() // S8
303TEST_SUITE_END() // Shapes3D
304
305TEST_SUITE(Shapes4D)
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000306TEST_SUITE(S32)
307FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000308 combine(combine(shapes_4d_small,
309 framework::dataset::make("DataType", { DataType::S32 })),
310 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000311{
312 // Validate output
313 validate(CLAccessor(_target), _reference);
314}
315
316FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000317 combine(combine(shapes_4d_large,
318 framework::dataset::make("DataType", { DataType::S32 })),
319 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000320{
321 // Validate output
322 validate(CLAccessor(_target), _reference);
323}
324TEST_SUITE_END() // S32
325
326TEST_SUITE(S16)
327FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000328 combine(combine(shapes_4d_small,
329 framework::dataset::make("DataType", { DataType::S16 })),
330 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000331{
332 // Validate output
333 validate(CLAccessor(_target), _reference);
334}
335
336FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000337 combine(combine(shapes_4d_large,
338 framework::dataset::make("DataType", { DataType::S16 })),
339 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000340{
341 // Validate output
342 validate(CLAccessor(_target), _reference);
343}
344TEST_SUITE_END() // S16
345
346TEST_SUITE(S8)
347FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000348 combine(combine(shapes_4d_small,
349 framework::dataset::make("DataType", { DataType::S8 })),
350 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000351{
352 // Validate output
353 validate(CLAccessor(_target), _reference);
354}
355
356FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000357 combine(combine(shapes_4d_large,
358 framework::dataset::make("DataType", { DataType::S8 })),
359 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000360{
361 // Validate output
362 validate(CLAccessor(_target), _reference);
363}
364TEST_SUITE_END() // S8
365TEST_SUITE_END() // Shapes4D
366TEST_SUITE_END() // StackLayer
367TEST_SUITE_END() // CL
368} // namespace validation
369} // namespace test
370} // namespace arm_compute