xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/CL/ReorgLayer.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/Types.h"
25 #include "arm_compute/runtime/CL/functions/CLReorgLayer.h"
26 #include "tests/CL/CLAccessor.h"
27 #include "tests/CL/Helper.h"
28 #include "tests/PaddingCalculator.h"
29 #include "tests/datasets/ReorgLayerDataset.h"
30 #include "tests/framework/Asserts.h"
31 #include "tests/framework/Macros.h"
32 #include "tests/framework/datasets/Datasets.h"
33 #include "tests/validation/Validation.h"
34 #include "tests/validation/fixtures/ReorgLayerFixture.h"
35 
36 namespace arm_compute
37 {
38 namespace test
39 {
40 namespace validation
41 {
42 TEST_SUITE(CL)
TEST_SUITE(ReorgLayer)43 TEST_SUITE(ReorgLayer)
44 
45 // *INDENT-OFF*
46 // clang-format off
47 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
48                framework::dataset::make("InputInfo", { TensorInfo(TensorShape(10U, 12U, 1U, 2U), 1, DataType::S64),    // Wrong output tensor
49                                                        TensorInfo(TensorShape(10U, 12U, 1U, 2U), 1, DataType::F32),
50                                                        TensorInfo(TensorShape(10U, 12U, 1U, 2U), 1, DataType::F32),    // Wrong output tensor
51                                                        TensorInfo(TensorShape(3U, 12U, 4U, 2U), 1, DataType::F32),
52                                                        TensorInfo(TensorShape(3U, 12U, 4U, 2U), 1, DataType::F32),     // Wrong data type
53                                                      }),
54                framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(3U, 4U, 10U, 2U), 1, DataType::S64),
55                                                        TensorInfo(TensorShape(5U, 6U, 4U, 2U), 1, DataType::F32),
56                                                        TensorInfo(TensorShape(5U, 6U, 2, 2U), 1, DataType::F32),
57                                                        TensorInfo(TensorShape(1U, 4U, 36U, 2U), 1, DataType::F32),
58                                                        TensorInfo(TensorShape(1U, 4U, 36U, 2U), 1, DataType::F16),
59                                                      })),
60                framework::dataset::make("Stride", { 2, 2, 4, 3 })),
61                framework::dataset::make("Expected", { false, true, false, true, false })),
62                input_info, output_info, stride, expected)
63 {
64     bool status = bool(CLReorgLayer::validate(&input_info, &output_info, stride));
65     ARM_COMPUTE_EXPECT(status == expected, framework::LogLevel::ERRORS);
66 }
67 // clang-format on
68 // *INDENT-ON*
69 
70 template <typename T>
71 using CLReorgLayerFixture = ReorgLayerValidationFixture<CLTensor, CLAccessor, CLReorgLayer, T>;
72 
73 TEST_SUITE(S32)
74 FIXTURE_DATA_TEST_CASE(RunSmall, CLReorgLayerFixture<int32_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallReorgLayerDataset(), framework::dataset::make("DataType",
75                                                                                                                   DataType::S32)),
76                                                                                                           framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
77 {
78     // Validate output
79     validate(CLAccessor(_target), _reference);
80 }
81 
82 FIXTURE_DATA_TEST_CASE(RunLarge, CLReorgLayerFixture<int32_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeReorgLayerDataset(), framework::dataset::make("DataType",
83                                                                                                                 DataType::S32)),
84                                                                                                         framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
85 {
86     // Validate output
87     validate(CLAccessor(_target), _reference);
88 }
89 TEST_SUITE_END() // S32
90 
TEST_SUITE(S16)91 TEST_SUITE(S16)
92 FIXTURE_DATA_TEST_CASE(RunSmall, CLReorgLayerFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallReorgLayerDataset(), framework::dataset::make("DataType",
93                                                                                                                   DataType::S16)),
94                                                                                                           framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
95 {
96     // Validate output
97     validate(CLAccessor(_target), _reference);
98 }
99 
100 FIXTURE_DATA_TEST_CASE(RunLarge, CLReorgLayerFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeReorgLayerDataset(), framework::dataset::make("DataType",
101                                                                                                                 DataType::S16)),
102                                                                                                         framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
103 {
104     // Validate output
105     validate(CLAccessor(_target), _reference);
106 }
107 TEST_SUITE_END() // S16
108 
TEST_SUITE(S8)109 TEST_SUITE(S8)
110 FIXTURE_DATA_TEST_CASE(RunSmall, CLReorgLayerFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallReorgLayerDataset(), framework::dataset::make("DataType",
111                                                                                                                  DataType::S8)),
112                                                                                                          framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
113 {
114     // Validate output
115     validate(CLAccessor(_target), _reference);
116 }
117 
118 FIXTURE_DATA_TEST_CASE(RunLarge, CLReorgLayerFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeReorgLayerDataset(), framework::dataset::make("DataType", DataType::S8)),
119                                                                                                        framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
120 {
121     // Validate output
122     validate(CLAccessor(_target), _reference);
123 }
124 TEST_SUITE_END() // S8
125 
126 TEST_SUITE_END() // ReorgLayer
127 TEST_SUITE_END() // CL
128 } // namespace validation
129 } // namespace test
130 } // namespace arm_compute
131