blob: 3f17aa1aced36625d8f2ce41ef03d1f1d83b762d [file] [log] [blame]
Jenkins514be652019-02-28 12:25:18 +00001/*
Jenkins36ccc902020-02-21 11:10:48 +00002 * Copyright (c) 2018-2020 ARM Limited.
Jenkins514be652019-02-28 12:25:18 +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
Jenkins514be652019-02-28 12:25:18 +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 */
Jenkins4ba87db2019-05-23 17:11:51 +010071const auto shapes_2d_large = combine(datasets::Medium2DShapes(), framework::dataset::make("Axis", -2, 3));
Jenkins514be652019-02-28 12:25:18 +000072
73/** Shapes 3D to test */
Jenkins4ba87db2019-05-23 17:11:51 +010074const auto shapes_3d_large = combine(datasets::Medium3DShapes(), framework::dataset::make("Axis", -3, 4));
Jenkins514be652019-02-28 12:25:18 +000075
76/** Shapes 4D to test */
Jenkins4ba87db2019-05-23 17:11:51 +010077const auto shapes_4d_large = combine(datasets::Medium4DShapes(), framework::dataset::make("Axis", -4, 5));
Jenkins514be652019-02-28 12:25:18 +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)
88
89// *INDENT-OFF*
90// clang-format off
91DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
92 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)
107{
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}
116// clang-format on
117// *INDENT-ON*
118
119TEST_SUITE(Shapes1D)
120TEST_SUITE(S32)
121FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
122 combine(combine(shapes_1d_small,
123 framework::dataset::make("DataType", { DataType::S32 })),
124 n_values))
125{
126 // Validate output
127 validate(CLAccessor(_target), _reference);
128}
129
130FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
131 combine(combine(shapes_1d_large,
132 framework::dataset::make("DataType", { DataType::S32 })),
133 n_values))
134{
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,
142 combine(combine(shapes_1d_small,
143 framework::dataset::make("DataType", { DataType::S16 })),
144 n_values))
145{
146 // Validate output
147 validate(CLAccessor(_target), _reference);
148}
149
150FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
151 combine(combine(shapes_1d_large,
152 framework::dataset::make("DataType", { DataType::S16 })),
153 n_values))
154{
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,
162 combine(combine(shapes_1d_small,
163 framework::dataset::make("DataType", { DataType::S8 })),
164 n_values))
165{
166 // Validate output
167 validate(CLAccessor(_target), _reference);
168}
169
170FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
171 combine(combine(shapes_1d_large,
172 framework::dataset::make("DataType", { DataType::S8 })),
173 n_values))
174{
175 // Validate output
176 validate(CLAccessor(_target), _reference);
177}
178TEST_SUITE_END() // S8
179TEST_SUITE_END() // Shapes1D
180
181TEST_SUITE(Shapes2D)
182TEST_SUITE(S32)
183FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
184 combine(combine(shapes_2d_small,
185 framework::dataset::make("DataType", { DataType::S32 })),
186 n_values))
187{
188 // Validate output
189 validate(CLAccessor(_target), _reference);
190}
191
192FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
193 combine(combine(shapes_2d_large,
194 framework::dataset::make("DataType", { DataType::S32 })),
195 n_values))
196{
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,
204 combine(combine(shapes_2d_small,
205 framework::dataset::make("DataType", { DataType::S16 })),
206 n_values))
207{
208 // Validate output
209 validate(CLAccessor(_target), _reference);
210}
211
212FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
213 combine(combine(shapes_2d_large,
214 framework::dataset::make("DataType", { DataType::S16 })),
215 n_values))
216{
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,
224 combine(combine(shapes_2d_small,
225 framework::dataset::make("DataType", { DataType::S8 })),
226 n_values))
227{
228 // Validate output
229 validate(CLAccessor(_target), _reference);
230}
231
232FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
233 combine(combine(shapes_2d_large,
234 framework::dataset::make("DataType", { DataType::S8 })),
235 n_values))
236{
237 // Validate output
238 validate(CLAccessor(_target), _reference);
239}
240TEST_SUITE_END() // S8
241TEST_SUITE_END() // Shapes2D
242
243TEST_SUITE(Shapes3D)
244TEST_SUITE(S32)
245FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
246 combine(combine(shapes_3d_small,
247 framework::dataset::make("DataType", { DataType::S32 })),
248 n_values))
249{
250 // Validate output
251 validate(CLAccessor(_target), _reference);
252}
253
254FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
255 combine(combine(shapes_3d_large,
256 framework::dataset::make("DataType", { DataType::S32 })),
257 n_values))
258{
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,
266 combine(combine(shapes_3d_small,
267 framework::dataset::make("DataType", { DataType::S16 })),
268 n_values))
269{
270 // Validate output
271 validate(CLAccessor(_target), _reference);
272}
273
274FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
275 combine(combine(shapes_3d_large,
276 framework::dataset::make("DataType", { DataType::S16 })),
277 n_values))
278{
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,
286 combine(combine(shapes_3d_small,
287 framework::dataset::make("DataType", { DataType::S8 })),
288 n_values))
289{
290 // Validate output
291 validate(CLAccessor(_target), _reference);
292}
293
294FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
295 combine(combine(shapes_3d_large,
296 framework::dataset::make("DataType", { DataType::S8 })),
297 n_values))
298{
299 // Validate output
300 validate(CLAccessor(_target), _reference);
301}
302TEST_SUITE_END() // S8
303TEST_SUITE_END() // Shapes3D
304
305TEST_SUITE(Shapes4D)
306TEST_SUITE(S32)
307FIXTURE_DATA_TEST_CASE(RunSmall, CLStackLayerFixture<int>, framework::DatasetMode::ALL,
308 combine(combine(shapes_4d_small,
309 framework::dataset::make("DataType", { DataType::S32 })),
310 n_values))
311{
312 // Validate output
313 validate(CLAccessor(_target), _reference);
314}
315
316FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<int>, framework::DatasetMode::NIGHTLY,
317 combine(combine(shapes_4d_large,
318 framework::dataset::make("DataType", { DataType::S32 })),
319 n_values))
320{
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,
328 combine(combine(shapes_4d_small,
329 framework::dataset::make("DataType", { DataType::S16 })),
330 n_values))
331{
332 // Validate output
333 validate(CLAccessor(_target), _reference);
334}
335
336FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<short>, framework::DatasetMode::NIGHTLY,
337 combine(combine(shapes_4d_large,
338 framework::dataset::make("DataType", { DataType::S16 })),
339 n_values))
340{
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,
348 combine(combine(shapes_4d_small,
349 framework::dataset::make("DataType", { DataType::S8 })),
350 n_values))
351{
352 // Validate output
353 validate(CLAccessor(_target), _reference);
354}
355
356FIXTURE_DATA_TEST_CASE(RunLarge, CLStackLayerFixture<char>, framework::DatasetMode::NIGHTLY,
357 combine(combine(shapes_4d_large,
358 framework::dataset::make("DataType", { DataType::S8 })),
359 n_values))
360{
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