blob: fa2e4acc11f3ab42a21c2e378ecc2e603ab9c2ca [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 */
74const auto shapes_2d_large = combine(datasets::Large2DShapes(), framework::dataset::make("Axis", -2, 3));
75
76/** Shapes 3D to test */
77const auto shapes_3d_large = combine(datasets::Large3DShapes(), framework::dataset::make("Axis", -3, 4));
78
79/** Shapes 4D to test */
80const auto shapes_4d_large = combine(datasets::Large4DShapes(), framework::dataset::make("Axis", -4, 5));
81
82/** Configuration test */
83void validate_configuration(TensorShape shape_in, int axis, DataType data_type, int num_tensors)
84{
85 // Wrap around negative values
86 const unsigned int axis_u = wrap_around(axis, static_cast<int>(shape_in.num_dimensions() + 1));
87
88 const TensorShape shape_dst = compute_stack_shape(TensorInfo(shape_in, 1, data_type), axis_u, num_tensors);
89
90 std::vector<CLTensor> tensors(num_tensors);
91 std::vector<ICLTensor*> src(num_tensors);
92
93 // Create vector of input tensors
94 for(int i = 0; i < num_tensors; ++i)
95 {
96 tensors[i] = create_tensor<CLTensor>(shape_in, data_type);
97 src[i] = &(tensors[i]);
98 ARM_COMPUTE_EXPECT(src[i]->info()->is_resizable(), framework::LogLevel::ERRORS);
99 }
100
101 // Create tensors
102 CLTensor dst = create_tensor<CLTensor>(shape_dst, data_type);
103
104 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
105
106 // Create and configure function
107 CLStackLayer stack;
108 stack.configure(src, axis, &dst);
109}
110} // namespace
111
112/** Fixture to use */
113template<typename T>
114using CLStackLayerFixture = StackLayerValidationFixture<CLTensor, ICLTensor, CLAccessor, CLStackLayer, T>;
115
116using namespace arm_compute::misc::shape_calculator;
117
118TEST_SUITE(CL)
119TEST_SUITE(StackLayer)
Isabella Gottardiee7c15d2018-12-17 16:15:34 +0000120
121DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
122 framework::dataset::make("InputInfo",
123{
124 std::vector<TensorInfo>{ TensorInfo(TensorShape(9U, 8U), 1, DataType::U8) },
125 std::vector<TensorInfo>{ TensorInfo(TensorShape(1U, 2U), 1, DataType::U8) , TensorInfo(TensorShape(1U, 2U), 1, DataType::U8), TensorInfo(TensorShape(1U, 2U), 1, DataType::U8)},
126 std::vector<TensorInfo>{ TensorInfo(TensorShape(2U, 3U), 1, DataType::S32) },
127 std::vector<TensorInfo>{ TensorInfo(TensorShape(7U, 5U, 3U, 8U, 2U), 1, DataType::S32), TensorInfo(TensorShape(7U, 5U, 3U, 8U, 2U), 1, DataType::S32)},
128 std::vector<TensorInfo>{ TensorInfo(TensorShape(9U, 8U), 1, DataType::S32) },
129}),
130framework::dataset::make("OutputInfo",
131{
132 TensorInfo(TensorShape(1U, 9U, 8U), 1, DataType::U8), // Passes, stack 1 tensor on x axis
133 TensorInfo(TensorShape(1U, 3U, 2U), 1, DataType::U8), // Passes, stack 3 tensors on y axis
134 TensorInfo(TensorShape(1U, 2U, 3U), 1, DataType::S32), // fails axis < (- input's rank)
135 TensorInfo(TensorShape(3U, 7U, 5U), 1, DataType::S32), // fails, input dimensions > 4
136 TensorInfo(TensorShape(1U, 2U, 3U), 1, DataType::U8), // fails mismatching data types
137})),
138framework::dataset::make("Axis", { -3, 1, -4, -3, 1 })),
139framework::dataset::make("Expected", { true, true, false, false, false })),
140input_info, output_info, axis, expected)
141{
142 std::vector<TensorInfo> ti(input_info);
143 std::vector<ITensorInfo *> vec(input_info.size());
144 for(size_t j = 0; j < vec.size(); ++j)
145 {
146 vec[j] = &ti[j];
147 }
148 ARM_COMPUTE_EXPECT(bool(CLStackLayer::validate(vec, axis, &output_info)) == expected, framework::LogLevel::ERRORS);
149}
150
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000151TEST_SUITE(Shapes1D)
152
153DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(shapes_1d_small,
154 data_types),
155 n_values),
156shape_in, axis, data_type, num_tensors)
157{
158 validate_configuration(shape_in, axis, data_type, num_tensors);
159}
160
161TEST_SUITE(S32)
162FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
163 combine(combine(shapes_1d_small,
164 framework::dataset::make("DataType", { DataType::S32 })),
165 n_values))
166{
167 // Validate output
168 validate(CLAccessor(_target), _reference);
169}
170
171FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
172 combine(combine(shapes_1d_large,
173 framework::dataset::make("DataType", { DataType::S32 })),
174 n_values))
175{
176 // Validate output
177 validate(CLAccessor(_target), _reference);
178}
179TEST_SUITE_END() // S32
180
181TEST_SUITE(S16)
182FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL,
183 combine(combine(shapes_1d_small,
184 framework::dataset::make("DataType", { DataType::S16 })),
185 n_values))
186{
187 // Validate output
188 validate(CLAccessor(_target), _reference);
189}
190
191FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
192 combine(combine(shapes_1d_large,
193 framework::dataset::make("DataType", { DataType::S16 })),
194 n_values))
195{
196 // Validate output
197 validate(CLAccessor(_target), _reference);
198}
199TEST_SUITE_END() // S16
200
201TEST_SUITE(S8)
202FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL,
203 combine(combine(shapes_1d_small,
204 framework::dataset::make("DataType", { DataType::S8 })),
205 n_values))
206{
207 // Validate output
208 validate(CLAccessor(_target), _reference);
209}
210
211FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
212 combine(combine(shapes_1d_large,
213 framework::dataset::make("DataType", { DataType::S8 })),
214 n_values))
215{
216 // Validate output
217 validate(CLAccessor(_target), _reference);
218}
219TEST_SUITE_END() // S8
220TEST_SUITE_END() // Shapes1D
221
222TEST_SUITE(Shapes2D)
223
224DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(shapes_2d_small,
225 data_types),
226 n_values),
227shape_in, axis, data_type, num_tensors)
228{
229 validate_configuration(shape_in, axis, data_type, num_tensors);
230}
231
232TEST_SUITE(S32)
233FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
234 combine(combine(shapes_2d_small,
235 framework::dataset::make("DataType", { DataType::S32 })),
236 n_values))
237{
238 // Validate output
239 validate(CLAccessor(_target), _reference);
240}
241
242FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
243 combine(combine(shapes_2d_large,
244 framework::dataset::make("DataType", { DataType::S32 })),
245 n_values))
246{
247 // Validate output
248 validate(CLAccessor(_target), _reference);
249}
250TEST_SUITE_END() // S32
251
252TEST_SUITE(S16)
253FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL,
254 combine(combine(shapes_2d_small,
255 framework::dataset::make("DataType", { DataType::S16 })),
256 n_values))
257{
258 // Validate output
259 validate(CLAccessor(_target), _reference);
260}
261
262FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
263 combine(combine(shapes_2d_large,
264 framework::dataset::make("DataType", { DataType::S16 })),
265 n_values))
266{
267 // Validate output
268 validate(CLAccessor(_target), _reference);
269}
270TEST_SUITE_END() // S16
271
272TEST_SUITE(S8)
273FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL,
274 combine(combine(shapes_2d_small,
275 framework::dataset::make("DataType", { DataType::S8 })),
276 n_values))
277{
278 // Validate output
279 validate(CLAccessor(_target), _reference);
280}
281
282FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
283 combine(combine(shapes_2d_large,
284 framework::dataset::make("DataType", { DataType::S8 })),
285 n_values))
286{
287 // Validate output
288 validate(CLAccessor(_target), _reference);
289}
290TEST_SUITE_END() // S8
291TEST_SUITE_END() // Shapes2D
292
293TEST_SUITE(Shapes3D)
294DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(shapes_3d_small,
295 data_types),
296 n_values),
297shape_in, axis, data_type, num_tensors)
298{
299 validate_configuration(shape_in, axis, data_type, num_tensors);
300}
301
302TEST_SUITE(S32)
303FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
304 combine(combine(shapes_3d_small,
305 framework::dataset::make("DataType", { DataType::S32 })),
306 n_values))
307{
308 // Validate output
309 validate(CLAccessor(_target), _reference);
310}
311
312FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
313 combine(combine(shapes_3d_large,
314 framework::dataset::make("DataType", { DataType::S32 })),
315 n_values))
316{
317 // Validate output
318 validate(CLAccessor(_target), _reference);
319}
320TEST_SUITE_END() // S32
321
322TEST_SUITE(S16)
323FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL,
324 combine(combine(shapes_3d_small,
325 framework::dataset::make("DataType", { DataType::S16 })),
326 n_values))
327{
328 // Validate output
329 validate(CLAccessor(_target), _reference);
330}
331
332FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
333 combine(combine(shapes_3d_large,
334 framework::dataset::make("DataType", { DataType::S16 })),
335 n_values))
336{
337 // Validate output
338 validate(CLAccessor(_target), _reference);
339}
340TEST_SUITE_END() // S16
341
342TEST_SUITE(S8)
343FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL,
344 combine(combine(shapes_3d_small,
345 framework::dataset::make("DataType", { DataType::S8 })),
346 n_values))
347{
348 // Validate output
349 validate(CLAccessor(_target), _reference);
350}
351
352FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
353 combine(combine(shapes_3d_large,
354 framework::dataset::make("DataType", { DataType::S8 })),
355 n_values))
356{
357 // Validate output
358 validate(CLAccessor(_target), _reference);
359}
360TEST_SUITE_END() // S8
361TEST_SUITE_END() // Shapes3D
362
363TEST_SUITE(Shapes4D)
364DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(shapes_4d_small,
365 data_types),
366 n_values),
367shape_in, axis, data_type, num_tensors)
368{
369 validate_configuration(shape_in, axis, data_type, num_tensors);
370}
371
372TEST_SUITE(S32)
373FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
374 combine(combine(shapes_4d_small,
375 framework::dataset::make("DataType", { DataType::S32 })),
376 n_values))
377{
378 // Validate output
379 validate(CLAccessor(_target), _reference);
380}
381
382FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
383 combine(combine(shapes_4d_large,
384 framework::dataset::make("DataType", { DataType::S32 })),
385 n_values))
386{
387 // Validate output
388 validate(CLAccessor(_target), _reference);
389}
390TEST_SUITE_END() // S32
391
392TEST_SUITE(S16)
393FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL,
394 combine(combine(shapes_4d_small,
395 framework::dataset::make("DataType", { DataType::S16 })),
396 n_values))
397{
398 // Validate output
399 validate(CLAccessor(_target), _reference);
400}
401
402FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
403 combine(combine(shapes_4d_large,
404 framework::dataset::make("DataType", { DataType::S16 })),
405 n_values))
406{
407 // Validate output
408 validate(CLAccessor(_target), _reference);
409}
410TEST_SUITE_END() // S16
411
412TEST_SUITE(S8)
413FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL,
414 combine(combine(shapes_4d_small,
415 framework::dataset::make("DataType", { DataType::S8 })),
416 n_values))
417{
418 // Validate output
419 validate(CLAccessor(_target), _reference);
420}
421
422FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
423 combine(combine(shapes_4d_large,
424 framework::dataset::make("DataType", { DataType::S8 })),
425 n_values))
426{
427 // Validate output
428 validate(CLAccessor(_target), _reference);
429}
430TEST_SUITE_END() // S8
431TEST_SUITE_END() // Shapes4D
432TEST_SUITE_END() // StackLayer
433TEST_SUITE_END() // CL
434} // namespace validation
435} // namespace test
436} // namespace arm_compute