xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/CL/StackLayer.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2018-2020 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 
42 namespace arm_compute
43 {
44 namespace test
45 {
46 namespace validation
47 {
48 namespace
49 {
50 // *INDENT-OFF*
51 // clang-format off
52 /** Num tensors values to test */
53 const auto n_values = framework::dataset::make("NumTensors", { 3, 4 });
54 
55 /** Shapes 1D to test */
56 const auto shapes_1d_small = combine(datasets::Small1DShapes(), framework::dataset::make("Axis", -1, 2));
57 
58 /** Shapes 2D to test */
59 const auto shapes_2d_small = combine(datasets::Small2DShapes(), framework::dataset::make("Axis", -2, 3));
60 
61 /** Shapes 3D to test */
62 const auto shapes_3d_small = combine(datasets::Small3DShapes(), framework::dataset::make("Axis", -3, 4));
63 
64 /** Shapes 4D to test */
65 const auto shapes_4d_small = combine(datasets::Small4DShapes(), framework::dataset::make("Axis", -4, 5));
66 
67 /** Shapes 1D to test */
68 const auto shapes_1d_large = combine(datasets::Large1DShapes(), framework::dataset::make("Axis", -1, 2));
69 
70 /** Shapes 2D to test */
71 const auto shapes_2d_large = combine(datasets::Medium2DShapes(), framework::dataset::make("Axis", -2, 3));
72 
73 /** Shapes 3D to test */
74 const auto shapes_3d_large = combine(datasets::Medium3DShapes(), framework::dataset::make("Axis", -3, 4));
75 
76 /** Shapes 4D to test */
77 const auto shapes_4d_large = combine(datasets::Medium4DShapes(), framework::dataset::make("Axis", -4, 5));
78 } // namespace
79 
80 /** Fixture to use */
81 template<typename T>
82 using CLStackLayerFixture = StackLayerValidationFixture<CLTensor, ICLTensor, CLAccessor, CLStackLayer, T>;
83 
84 using namespace arm_compute::misc::shape_calculator;
85 
86 TEST_SUITE(CL)
TEST_SUITE(StackLayer)87 TEST_SUITE(StackLayer)
88 
89 // *INDENT-OFF*
90 // clang-format off
91 DATA_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 
119 TEST_SUITE(Shapes1D)
TEST_SUITE(S32)120 TEST_SUITE(S32)
121 FIXTURE_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 
130 FIXTURE_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 }
138 TEST_SUITE_END() // S32
139 
TEST_SUITE(S16)140 TEST_SUITE(S16)
141 FIXTURE_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 
150 FIXTURE_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 }
158 TEST_SUITE_END() // S16
159 
TEST_SUITE(S8)160 TEST_SUITE(S8)
161 FIXTURE_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 
170 FIXTURE_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 }
178 TEST_SUITE_END() // S8
TEST_SUITE_END()179 TEST_SUITE_END() // Shapes1D
180 
181 TEST_SUITE(Shapes2D)
182 TEST_SUITE(S32)
183 FIXTURE_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 
192 FIXTURE_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 }
200 TEST_SUITE_END() // S32
201 
TEST_SUITE(S16)202 TEST_SUITE(S16)
203 FIXTURE_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 
212 FIXTURE_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 }
220 TEST_SUITE_END() // S16
221 
TEST_SUITE(S8)222 TEST_SUITE(S8)
223 FIXTURE_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 
232 FIXTURE_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 }
240 TEST_SUITE_END() // S8
TEST_SUITE_END()241 TEST_SUITE_END() // Shapes2D
242 
243 TEST_SUITE(Shapes3D)
244 TEST_SUITE(S32)
245 FIXTURE_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 
254 FIXTURE_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 }
262 TEST_SUITE_END() // S32
263 
TEST_SUITE(S16)264 TEST_SUITE(S16)
265 FIXTURE_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 
274 FIXTURE_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 }
282 TEST_SUITE_END() // S16
283 
TEST_SUITE(S8)284 TEST_SUITE(S8)
285 FIXTURE_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 
294 FIXTURE_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 }
302 TEST_SUITE_END() // S8
TEST_SUITE_END()303 TEST_SUITE_END() // Shapes3D
304 
305 TEST_SUITE(Shapes4D)
306 TEST_SUITE(S32)
307 FIXTURE_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 
316 FIXTURE_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 }
324 TEST_SUITE_END() // S32
325 
TEST_SUITE(S16)326 TEST_SUITE(S16)
327 FIXTURE_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 
336 FIXTURE_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 }
344 TEST_SUITE_END() // S16
345 
TEST_SUITE(S8)346 TEST_SUITE(S8)
347 FIXTURE_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 
356 FIXTURE_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 }
364 TEST_SUITE_END() // S8
365 TEST_SUITE_END() // Shapes4D
366 TEST_SUITE_END() // StackLayer
367 TEST_SUITE_END() // CL
368 } // namespace validation
369 } // namespace test
370 } // namespace arm_compute
371