blob: 089911272a0866bccf45e93b96fd9c390429a671 [file] [log] [blame]
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +00001/*
2 * Copyright (c) 2018 ARM Limited.
3 *
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)
120TEST_SUITE(Shapes1D)
121
122DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(shapes_1d_small,
123 data_types),
124 n_values),
125shape_in, axis, data_type, num_tensors)
126{
127 validate_configuration(shape_in, axis, data_type, num_tensors);
128}
129
130TEST_SUITE(S32)
131FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
132 combine(combine(shapes_1d_small,
133 framework::dataset::make("DataType", { DataType::S32 })),
134 n_values))
135{
136 // Validate output
137 validate(CLAccessor(_target), _reference);
138}
139
140FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
141 combine(combine(shapes_1d_large,
142 framework::dataset::make("DataType", { DataType::S32 })),
143 n_values))
144{
145 // Validate output
146 validate(CLAccessor(_target), _reference);
147}
148TEST_SUITE_END() // S32
149
150TEST_SUITE(S16)
151FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL,
152 combine(combine(shapes_1d_small,
153 framework::dataset::make("DataType", { DataType::S16 })),
154 n_values))
155{
156 // Validate output
157 validate(CLAccessor(_target), _reference);
158}
159
160FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
161 combine(combine(shapes_1d_large,
162 framework::dataset::make("DataType", { DataType::S16 })),
163 n_values))
164{
165 // Validate output
166 validate(CLAccessor(_target), _reference);
167}
168TEST_SUITE_END() // S16
169
170TEST_SUITE(S8)
171FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL,
172 combine(combine(shapes_1d_small,
173 framework::dataset::make("DataType", { DataType::S8 })),
174 n_values))
175{
176 // Validate output
177 validate(CLAccessor(_target), _reference);
178}
179
180FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
181 combine(combine(shapes_1d_large,
182 framework::dataset::make("DataType", { DataType::S8 })),
183 n_values))
184{
185 // Validate output
186 validate(CLAccessor(_target), _reference);
187}
188TEST_SUITE_END() // S8
189TEST_SUITE_END() // Shapes1D
190
191TEST_SUITE(Shapes2D)
192
193DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(shapes_2d_small,
194 data_types),
195 n_values),
196shape_in, axis, data_type, num_tensors)
197{
198 validate_configuration(shape_in, axis, data_type, num_tensors);
199}
200
201TEST_SUITE(S32)
202FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
203 combine(combine(shapes_2d_small,
204 framework::dataset::make("DataType", { DataType::S32 })),
205 n_values))
206{
207 // Validate output
208 validate(CLAccessor(_target), _reference);
209}
210
211FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
212 combine(combine(shapes_2d_large,
213 framework::dataset::make("DataType", { DataType::S32 })),
214 n_values))
215{
216 // Validate output
217 validate(CLAccessor(_target), _reference);
218}
219TEST_SUITE_END() // S32
220
221TEST_SUITE(S16)
222FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL,
223 combine(combine(shapes_2d_small,
224 framework::dataset::make("DataType", { DataType::S16 })),
225 n_values))
226{
227 // Validate output
228 validate(CLAccessor(_target), _reference);
229}
230
231FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
232 combine(combine(shapes_2d_large,
233 framework::dataset::make("DataType", { DataType::S16 })),
234 n_values))
235{
236 // Validate output
237 validate(CLAccessor(_target), _reference);
238}
239TEST_SUITE_END() // S16
240
241TEST_SUITE(S8)
242FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL,
243 combine(combine(shapes_2d_small,
244 framework::dataset::make("DataType", { DataType::S8 })),
245 n_values))
246{
247 // Validate output
248 validate(CLAccessor(_target), _reference);
249}
250
251FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
252 combine(combine(shapes_2d_large,
253 framework::dataset::make("DataType", { DataType::S8 })),
254 n_values))
255{
256 // Validate output
257 validate(CLAccessor(_target), _reference);
258}
259TEST_SUITE_END() // S8
260TEST_SUITE_END() // Shapes2D
261
262TEST_SUITE(Shapes3D)
263DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(shapes_3d_small,
264 data_types),
265 n_values),
266shape_in, axis, data_type, num_tensors)
267{
268 validate_configuration(shape_in, axis, data_type, num_tensors);
269}
270
271TEST_SUITE(S32)
272FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
273 combine(combine(shapes_3d_small,
274 framework::dataset::make("DataType", { DataType::S32 })),
275 n_values))
276{
277 // Validate output
278 validate(CLAccessor(_target), _reference);
279}
280
281FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
282 combine(combine(shapes_3d_large,
283 framework::dataset::make("DataType", { DataType::S32 })),
284 n_values))
285{
286 // Validate output
287 validate(CLAccessor(_target), _reference);
288}
289TEST_SUITE_END() // S32
290
291TEST_SUITE(S16)
292FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL,
293 combine(combine(shapes_3d_small,
294 framework::dataset::make("DataType", { DataType::S16 })),
295 n_values))
296{
297 // Validate output
298 validate(CLAccessor(_target), _reference);
299}
300
301FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
302 combine(combine(shapes_3d_large,
303 framework::dataset::make("DataType", { DataType::S16 })),
304 n_values))
305{
306 // Validate output
307 validate(CLAccessor(_target), _reference);
308}
309TEST_SUITE_END() // S16
310
311TEST_SUITE(S8)
312FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL,
313 combine(combine(shapes_3d_small,
314 framework::dataset::make("DataType", { DataType::S8 })),
315 n_values))
316{
317 // Validate output
318 validate(CLAccessor(_target), _reference);
319}
320
321FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
322 combine(combine(shapes_3d_large,
323 framework::dataset::make("DataType", { DataType::S8 })),
324 n_values))
325{
326 // Validate output
327 validate(CLAccessor(_target), _reference);
328}
329TEST_SUITE_END() // S8
330TEST_SUITE_END() // Shapes3D
331
332TEST_SUITE(Shapes4D)
333DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(shapes_4d_small,
334 data_types),
335 n_values),
336shape_in, axis, data_type, num_tensors)
337{
338 validate_configuration(shape_in, axis, data_type, num_tensors);
339}
340
341TEST_SUITE(S32)
342FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
343 combine(combine(shapes_4d_small,
344 framework::dataset::make("DataType", { DataType::S32 })),
345 n_values))
346{
347 // Validate output
348 validate(CLAccessor(_target), _reference);
349}
350
351FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
352 combine(combine(shapes_4d_large,
353 framework::dataset::make("DataType", { DataType::S32 })),
354 n_values))
355{
356 // Validate output
357 validate(CLAccessor(_target), _reference);
358}
359TEST_SUITE_END() // S32
360
361TEST_SUITE(S16)
362FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<short>, framework::DatasetMode::ALL,
363 combine(combine(shapes_4d_small,
364 framework::dataset::make("DataType", { DataType::S16 })),
365 n_values))
366{
367 // Validate output
368 validate(CLAccessor(_target), _reference);
369}
370
371FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
372 combine(combine(shapes_4d_large,
373 framework::dataset::make("DataType", { DataType::S16 })),
374 n_values))
375{
376 // Validate output
377 validate(CLAccessor(_target), _reference);
378}
379TEST_SUITE_END() // S16
380
381TEST_SUITE(S8)
382FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<char>, framework::DatasetMode::ALL,
383 combine(combine(shapes_4d_small,
384 framework::dataset::make("DataType", { DataType::S8 })),
385 n_values))
386{
387 // Validate output
388 validate(CLAccessor(_target), _reference);
389}
390
391FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
392 combine(combine(shapes_4d_large,
393 framework::dataset::make("DataType", { DataType::S8 })),
394 n_values))
395{
396 // Validate output
397 validate(CLAccessor(_target), _reference);
398}
399TEST_SUITE_END() // S8
400TEST_SUITE_END() // Shapes4D
401TEST_SUITE_END() // StackLayer
402TEST_SUITE_END() // CL
403} // namespace validation
404} // namespace test
405} // namespace arm_compute