blob: 1715a5e8b1122f826abaef58dc0872734d8c61b2 [file] [log] [blame]
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +00001/*
Isabella Gottardiee7c15d2018-12-17 16:15:34 +00002 * Copyright (c) 2018-2019 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
52/** Data types */
53const auto data_types = framework::dataset::make("DataType", { DataType::QASYMM8, DataType::F16, DataType::F32 });
54
55/** Num tensors values to test */
56const auto n_values = framework::dataset::make("NumTensors", { 3, 4 });
57
58/** Shapes 1D to test */
59const auto shapes_1d_small = combine(datasets::Small1DShapes(), framework::dataset::make("Axis", -1, 2));
60
61/** Shapes 2D to test */
62const auto shapes_2d_small = combine(datasets::Small2DShapes(), framework::dataset::make("Axis", -2, 3));
63
64/** Shapes 3D to test */
65const auto shapes_3d_small = combine(datasets::Small3DShapes(), framework::dataset::make("Axis", -3, 4));
66
67/** Shapes 4D to test */
68const auto shapes_4d_small = combine(datasets::Small4DShapes(), framework::dataset::make("Axis", -4, 5));
69
70/** Shapes 1D to test */
71const auto shapes_1d_large = combine(datasets::Large1DShapes(), framework::dataset::make("Axis", -1, 2));
72
73/** Shapes 2D to test */
Michalis Spyrou5ed7b5b2019-03-19 12:17:26 +000074const auto shapes_2d_large = combine(datasets::Medium2DShapes(), framework::dataset::make("Axis", -2, 3));
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +000075
76/** Shapes 3D to test */
Michalis Spyrou5ed7b5b2019-03-19 12:17:26 +000077const auto shapes_3d_large = combine(datasets::Medium3DShapes(), framework::dataset::make("Axis", -3, 4));
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +000078
79/** Shapes 4D to test */
Michalis Spyrou5ed7b5b2019-03-19 12:17:26 +000080const auto shapes_4d_large = combine(datasets::Medium4DShapes(), framework::dataset::make("Axis", -4, 5));
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +000081} // namespace
82
83/** Fixture to use */
84template<typename T>
85using CLStackLayerFixture = StackLayerValidationFixture<CLTensor, ICLTensor, CLAccessor, CLStackLayer, T>;
86
87using namespace arm_compute::misc::shape_calculator;
88
89TEST_SUITE(CL)
90TEST_SUITE(StackLayer)
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000091
Michalis Spyrou80943252019-01-10 17:19:50 +000092// *INDENT-OFF*
93// clang-format off
Isabella Gottardiee7c15d2018-12-17 16:15:34 +000094DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Michalis Spyrou80943252019-01-10 17:19:50 +000095 framework::dataset::make("InputInfo", { std::vector<TensorInfo>{ TensorInfo(TensorShape(9U, 8U), 1, DataType::U8) },
96 std::vector<TensorInfo>{ TensorInfo(TensorShape(1U, 2U), 1, DataType::U8) , TensorInfo(TensorShape(1U, 2U), 1, DataType::U8), TensorInfo(TensorShape(1U, 2U), 1, DataType::U8)},
97 std::vector<TensorInfo>{ TensorInfo(TensorShape(2U, 3U), 1, DataType::S32) },
98 std::vector<TensorInfo>{ TensorInfo(TensorShape(7U, 5U, 3U, 8U, 2U), 1, DataType::S32), TensorInfo(TensorShape(7U, 5U, 3U, 8U, 2U), 1, DataType::S32)},
99 std::vector<TensorInfo>{ TensorInfo(TensorShape(9U, 8U), 1, DataType::S32) },
100 }),
101 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(1U, 9U, 8U), 1, DataType::U8), // Passes, stack 1 tensor on x axis
102 TensorInfo(TensorShape(1U, 3U, 2U), 1, DataType::U8), // Passes, stack 3 tensors on y axis
103 TensorInfo(TensorShape(1U, 2U, 3U), 1, DataType::S32), // fails axis < (- input's rank)
104 TensorInfo(TensorShape(3U, 7U, 5U), 1, DataType::S32), // fails, input dimensions > 4
105 TensorInfo(TensorShape(1U, 2U, 3U), 1, DataType::U8), // fails mismatching data types
106 })),
107 framework::dataset::make("Axis", { -3, 1, -4, -3, 1 })),
108 framework::dataset::make("Expected", { true, true, false, false, false })),
109 input_info, output_info, axis, expected)
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000110{
111 std::vector<TensorInfo> ti(input_info);
112 std::vector<ITensorInfo *> vec(input_info.size());
113 for(size_t j = 0; j < vec.size(); ++j)
114 {
115 vec[j] = &ti[j];
116 }
117 ARM_COMPUTE_EXPECT(bool(CLStackLayer::validate(vec, axis, &output_info)) == expected, framework::LogLevel::ERRORS);
118}
Michalis Spyrou80943252019-01-10 17:19:50 +0000119// clang-format on
120// *INDENT-ON*
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000121
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000122TEST_SUITE(Shapes1D)
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000123TEST_SUITE(S32)
124FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000125 combine(combine(shapes_1d_small,
126 framework::dataset::make("DataType", { DataType::S32 })),
127 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000128{
129 // Validate output
130 validate(CLAccessor(_target), _reference);
131}
132
133FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000134 combine(combine(shapes_1d_large,
135 framework::dataset::make("DataType", { DataType::S32 })),
136 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000137{
138 // Validate output
139 validate(CLAccessor(_target), _reference);
140}
141TEST_SUITE_END() // S32
142
143TEST_SUITE(S16)
144FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000145 combine(combine(shapes_1d_small,
146 framework::dataset::make("DataType", { DataType::S16 })),
147 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000148{
149 // Validate output
150 validate(CLAccessor(_target), _reference);
151}
152
153FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000154 combine(combine(shapes_1d_large,
155 framework::dataset::make("DataType", { DataType::S16 })),
156 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000157{
158 // Validate output
159 validate(CLAccessor(_target), _reference);
160}
161TEST_SUITE_END() // S16
162
163TEST_SUITE(S8)
164FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000165 combine(combine(shapes_1d_small,
166 framework::dataset::make("DataType", { DataType::S8 })),
167 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000168{
169 // Validate output
170 validate(CLAccessor(_target), _reference);
171}
172
173FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000174 combine(combine(shapes_1d_large,
175 framework::dataset::make("DataType", { DataType::S8 })),
176 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000177{
178 // Validate output
179 validate(CLAccessor(_target), _reference);
180}
181TEST_SUITE_END() // S8
182TEST_SUITE_END() // Shapes1D
183
184TEST_SUITE(Shapes2D)
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000185TEST_SUITE(S32)
186FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000187 combine(combine(shapes_2d_small,
188 framework::dataset::make("DataType", { DataType::S32 })),
189 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000190{
191 // Validate output
192 validate(CLAccessor(_target), _reference);
193}
194
195FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000196 combine(combine(shapes_2d_large,
197 framework::dataset::make("DataType", { DataType::S32 })),
198 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000199{
200 // Validate output
201 validate(CLAccessor(_target), _reference);
202}
203TEST_SUITE_END() // S32
204
205TEST_SUITE(S16)
206FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000207 combine(combine(shapes_2d_small,
208 framework::dataset::make("DataType", { DataType::S16 })),
209 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000210{
211 // Validate output
212 validate(CLAccessor(_target), _reference);
213}
214
215FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000216 combine(combine(shapes_2d_large,
217 framework::dataset::make("DataType", { DataType::S16 })),
218 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000219{
220 // Validate output
221 validate(CLAccessor(_target), _reference);
222}
223TEST_SUITE_END() // S16
224
225TEST_SUITE(S8)
226FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000227 combine(combine(shapes_2d_small,
228 framework::dataset::make("DataType", { DataType::S8 })),
229 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000230{
231 // Validate output
232 validate(CLAccessor(_target), _reference);
233}
234
235FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000236 combine(combine(shapes_2d_large,
237 framework::dataset::make("DataType", { DataType::S8 })),
238 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000239{
240 // Validate output
241 validate(CLAccessor(_target), _reference);
242}
243TEST_SUITE_END() // S8
244TEST_SUITE_END() // Shapes2D
245
246TEST_SUITE(Shapes3D)
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000247TEST_SUITE(S32)
248FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000249 combine(combine(shapes_3d_small,
250 framework::dataset::make("DataType", { DataType::S32 })),
251 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000252{
253 // Validate output
254 validate(CLAccessor(_target), _reference);
255}
256
257FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000258 combine(combine(shapes_3d_large,
259 framework::dataset::make("DataType", { DataType::S32 })),
260 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000261{
262 // Validate output
263 validate(CLAccessor(_target), _reference);
264}
265TEST_SUITE_END() // S32
266
267TEST_SUITE(S16)
268FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000269 combine(combine(shapes_3d_small,
270 framework::dataset::make("DataType", { DataType::S16 })),
271 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000272{
273 // Validate output
274 validate(CLAccessor(_target), _reference);
275}
276
277FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000278 combine(combine(shapes_3d_large,
279 framework::dataset::make("DataType", { DataType::S16 })),
280 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000281{
282 // Validate output
283 validate(CLAccessor(_target), _reference);
284}
285TEST_SUITE_END() // S16
286
287TEST_SUITE(S8)
288FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000289 combine(combine(shapes_3d_small,
290 framework::dataset::make("DataType", { DataType::S8 })),
291 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000292{
293 // Validate output
294 validate(CLAccessor(_target), _reference);
295}
296
297FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000298 combine(combine(shapes_3d_large,
299 framework::dataset::make("DataType", { DataType::S8 })),
300 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000301{
302 // Validate output
303 validate(CLAccessor(_target), _reference);
304}
305TEST_SUITE_END() // S8
306TEST_SUITE_END() // Shapes3D
307
308TEST_SUITE(Shapes4D)
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000309TEST_SUITE(S32)
310FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000311 combine(combine(shapes_4d_small,
312 framework::dataset::make("DataType", { DataType::S32 })),
313 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000314{
315 // Validate output
316 validate(CLAccessor(_target), _reference);
317}
318
319FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000320 combine(combine(shapes_4d_large,
321 framework::dataset::make("DataType", { DataType::S32 })),
322 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000323{
324 // Validate output
325 validate(CLAccessor(_target), _reference);
326}
327TEST_SUITE_END() // S32
328
329TEST_SUITE(S16)
330FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000331 combine(combine(shapes_4d_small,
332 framework::dataset::make("DataType", { DataType::S16 })),
333 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000334{
335 // Validate output
336 validate(CLAccessor(_target), _reference);
337}
338
339FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000340 combine(combine(shapes_4d_large,
341 framework::dataset::make("DataType", { DataType::S16 })),
342 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000343{
344 // Validate output
345 validate(CLAccessor(_target), _reference);
346}
347TEST_SUITE_END() // S16
348
349TEST_SUITE(S8)
350FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL,
Michalis Spyrou80943252019-01-10 17:19:50 +0000351 combine(combine(shapes_4d_small,
352 framework::dataset::make("DataType", { DataType::S8 })),
353 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000354{
355 // Validate output
356 validate(CLAccessor(_target), _reference);
357}
358
359FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
Michalis Spyrou80943252019-01-10 17:19:50 +0000360 combine(combine(shapes_4d_large,
361 framework::dataset::make("DataType", { DataType::S8 })),
362 n_values))
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000363{
364 // Validate output
365 validate(CLAccessor(_target), _reference);
366}
367TEST_SUITE_END() // S8
368TEST_SUITE_END() // Shapes4D
369TEST_SUITE_END() // StackLayer
370TEST_SUITE_END() // CL
371} // namespace validation
372} // namespace test
373} // namespace arm_compute