xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/CL/ArgMinMax.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2018-2021 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/core/utils/misc/ShapeCalculator.h"
26 #include "arm_compute/runtime/CL/CLTensor.h"
27 #include "arm_compute/runtime/CL/CLTensorAllocator.h"
28 #include "arm_compute/runtime/CL/functions/CLArgMinMaxLayer.h"
29 #include "arm_compute/runtime/CL/functions/CLReductionOperation.h"
30 #include "tests/CL/CLAccessor.h"
31 #include "tests/datasets/ShapeDatasets.h"
32 #include "tests/datasets/SplitDataset.h"
33 #include "tests/framework/Asserts.h"
34 #include "tests/framework/Macros.h"
35 #include "tests/validation/Validation.h"
36 #include "tests/validation/fixtures/ArgMinMaxFixture.h"
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 namespace
45 {
46 const auto ArgMinMaxSmallDataset = framework::dataset::make("Shape",
47 {
48     TensorShape{ 1U, 7U, 1U, 3U },
49     TensorShape{ 149U, 5U, 1U, 2U },
50     TensorShape{ 166U, 5U, 1U, 2U },
51     TensorShape{ 322U, 5U, 1U, 2U },
52     TensorShape{ 128U, 5U, 21U, 3U },
53     TensorShape{ 2560, 2U, 2U, 2U },
54 });
55 
56 const auto ArgMinMaxLargeDataset = framework::dataset::make("Shape",
57 { TensorShape{ 517U, 123U, 13U, 2U } });
58 } // namespace
59 TEST_SUITE(CL)
TEST_SUITE(ArgMinMax)60 TEST_SUITE(ArgMinMax)
61 
62 // *INDENT-OFF*
63 // clang-format off
64 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
65         framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid axis
66                                                 TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid output shape
67                                                 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32),
68                                                 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32), // Invalid operation
69                                                 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32) // Not allowed keeping the dimension
70         }),
71         framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32),
72                                                  TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32),
73                                                  TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::S32),
74                                                  TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32),
75                                                  TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::U32)
76         })),
77         framework::dataset::make("Axis", { 4, 0, 2, 0, 2 })),
78         framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::MEAN_SUM, ReductionOperation::ARG_IDX_MAX })),
79         framework::dataset::make("Expected", { false, false, true, false, false })),
80         input_info, output_info, axis, operation, expected)
81 {
82     const Status status = CLArgMinMaxLayer::validate(&input_info.clone()->set_is_resizable(false), axis, &output_info.clone()->set_is_resizable(false), operation);
83     ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
84 }
85 // clang-format on
86 // *INDENT-ON*
87 
88 template <typename T>
89 using CLArgMinMaxValidationFixture = ArgMinMaxValidationFixture<CLTensor, CLAccessor, CLArgMinMaxLayer, T>;
90 
91 TEST_SUITE(S32)
92 FIXTURE_DATA_TEST_CASE(RunSmall,
93                        CLArgMinMaxValidationFixture<int32_t>,
94                        framework::DatasetMode::PRECOMMIT,
95                        combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
96                                framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
97 {
98     // Validate output
99     validate(CLAccessor(_target), _reference);
100 }
101 FIXTURE_DATA_TEST_CASE(RunLarge,
102                        CLArgMinMaxValidationFixture<int32_t>,
103                        framework::DatasetMode::NIGHTLY,
104                        combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
105                                framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
106 {
107     // Validate output
108     validate(CLAccessor(_target), _reference);
109 }
110 TEST_SUITE_END() // S32
111 
TEST_SUITE(Float)112 TEST_SUITE(Float)
113 TEST_SUITE(FP16)
114 FIXTURE_DATA_TEST_CASE(RunSmall,
115                        CLArgMinMaxValidationFixture<half>,
116                        framework::DatasetMode::PRECOMMIT,
117                        combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
118                                framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
119 {
120     // Validate output
121     validate(CLAccessor(_target), _reference);
122 }
123 
124 FIXTURE_DATA_TEST_CASE(RunLarge,
125                        CLArgMinMaxValidationFixture<half>,
126                        framework::DatasetMode::NIGHTLY,
127                        combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
128                                framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
129 {
130     // Validate output
131     validate(CLAccessor(_target), _reference);
132 }
133 TEST_SUITE_END() // FP16
134 
TEST_SUITE(FP32)135 TEST_SUITE(FP32)
136 FIXTURE_DATA_TEST_CASE(RunSmall,
137                        CLArgMinMaxValidationFixture<float>,
138                        framework::DatasetMode::PRECOMMIT,
139                        combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
140                                framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
141 {
142     // Validate output
143     validate(CLAccessor(_target), _reference);
144 }
145 
146 FIXTURE_DATA_TEST_CASE(RunLarge,
147                        CLArgMinMaxValidationFixture<float>,
148                        framework::DatasetMode::NIGHTLY,
149                        combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
150                                framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
151 {
152     // Validate output
153     validate(CLAccessor(_target), _reference);
154 }
155 TEST_SUITE_END() // FP32
156 TEST_SUITE_END() // Float
157 
158 template <typename T>
159 using CLArgMinMaxQuantizedValidationFixture = ArgMinMaxValidationQuantizedFixture<CLTensor, CLAccessor, CLArgMinMaxLayer, T>;
160 
161 TEST_SUITE(Quantized)
TEST_SUITE(QASYMM8)162 TEST_SUITE(QASYMM8)
163 FIXTURE_DATA_TEST_CASE(RunSmall,
164                        CLArgMinMaxQuantizedValidationFixture<uint8_t>,
165                        framework::DatasetMode::PRECOMMIT,
166                        combine(combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
167                                        framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
168                                framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
169 {
170     // Validate output
171     validate(CLAccessor(_target), _reference);
172 }
173 
174 FIXTURE_DATA_TEST_CASE(RunLarge,
175                        CLArgMinMaxQuantizedValidationFixture<uint8_t>,
176                        framework::DatasetMode::NIGHTLY,
177                        combine(combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
178                                        framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
179                                framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
180 {
181     // Validate output
182     validate(CLAccessor(_target), _reference);
183 }
184 TEST_SUITE_END() // QASYMM8
185 
TEST_SUITE(QASYMM8_SIGNED)186 TEST_SUITE(QASYMM8_SIGNED)
187 FIXTURE_DATA_TEST_CASE(RunSmall,
188                        CLArgMinMaxQuantizedValidationFixture<int8_t>,
189                        framework::DatasetMode::PRECOMMIT,
190                        combine(combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
191                                        framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
192                                framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
193 {
194     // Validate output
195     validate(CLAccessor(_target), _reference);
196 }
197 
198 FIXTURE_DATA_TEST_CASE(RunLarge,
199                        CLArgMinMaxQuantizedValidationFixture<int8_t>,
200                        framework::DatasetMode::NIGHTLY,
201                        combine(combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
202                                        framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
203                                framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
204 {
205     // Validate output
206     validate(CLAccessor(_target), _reference);
207 }
208 TEST_SUITE_END() // QASYMM8_SIGNED
209 
210 TEST_SUITE_END() // Quantized
211 TEST_SUITE_END() // ArgMinMax
212 TEST_SUITE_END() // CL
213 } // namespace validation
214 } // namespace test
215 } // namespace arm_compute
216