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