xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/NEON/Comparisons.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2019-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/NEON/functions/NEElementwiseOperations.h"
26 #include "arm_compute/runtime/Tensor.h"
27 #include "arm_compute/runtime/TensorAllocator.h"
28 #include "tests/NEON/Accessor.h"
29 #include "tests/PaddingCalculator.h"
30 #include "tests/datasets/ComparisonOperationsDataset.h"
31 #include "tests/datasets/ShapeDatasets.h"
32 #include "tests/framework/Asserts.h"
33 #include "tests/framework/Macros.h"
34 #include "tests/framework/datasets/Datasets.h"
35 #include "tests/validation/Validation.h"
36 #include "tests/validation/fixtures/ComparisonFixture.h"
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 namespace
45 {
46 const auto run_small_dataset           = combine(datasets::ComparisonOperations(), datasets::SmallShapes());
47 const auto run_small_broadcast_dataset = combine(datasets::ComparisonOperations(), datasets::SmallShapesBroadcast());
48 const auto run_large_dataset           = combine(datasets::ComparisonOperations(), datasets::LargeShapes());
49 
50 } // namespace
51 
52 TEST_SUITE(NEON)
TEST_SUITE(Comparison)53 TEST_SUITE(Comparison)
54 
55 // *INDENT-OFF*
56 // clang-format off
57 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
58         framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Invalid output type
59                                                  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching input types
60                                                  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
61                                                  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
62         }),
63         framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
64                                                 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
65                                                 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
66                                                 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
67         })),
68         framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
69                                                 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
70                                                 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::U8),
71                                                 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
72         })),
73         framework::dataset::make("Expected", { false, false, false, true})),
74         input1_info, input2_info, output_info, expected)
75 {
76     Status s = NEElementwiseComparison::validate(&input1_info.clone()->set_is_resizable(false),
77                                       &input2_info.clone()->set_is_resizable(false),
78                                       &output_info.clone()->set_is_resizable(false),
79                                       ComparisonOperation::Equal);
80     ARM_COMPUTE_EXPECT(bool(s) == expected, framework::LogLevel::ERRORS);
81 }
82 // clang-format on
83 // *INDENT-ON*
84 
85 template <typename T>
86 using NEComparisonFixture = ComparisonValidationFixture<Tensor, Accessor, NEElementwiseComparison, T>;
87 
88 TEST_SUITE(Bool)
89 FIXTURE_DATA_TEST_CASE(RunSmall,
90                        NEComparisonFixture<uint8_t>,
91                        framework::DatasetMode::PRECOMMIT,
92                        combine(run_small_dataset, framework::dataset::make("DataType", DataType::U8)))
93 {
94     // Validate output
95     validate(Accessor(_target), _reference);
96 }
97 TEST_SUITE_END()
98 
TEST_SUITE(Float)99 TEST_SUITE(Float)
100 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
101 TEST_SUITE(FP16)
102 FIXTURE_DATA_TEST_CASE(RunSmall,
103                        NEComparisonFixture<half>,
104                        framework::DatasetMode::PRECOMMIT,
105                        combine(run_small_dataset, framework::dataset::make("DataType", DataType::F16)))
106 {
107     // Validate output
108     validate(Accessor(_target), _reference);
109 }
110 FIXTURE_DATA_TEST_CASE(RunLarge,
111                        NEComparisonFixture<half>,
112                        framework::DatasetMode::NIGHTLY,
113                        combine(run_large_dataset, framework::dataset::make("DataType", DataType::F16)))
114 {
115     // Validate output
116     validate(Accessor(_target), _reference);
117 }
118 TEST_SUITE_END() // FP16
119 #endif           /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
120 
TEST_SUITE(FP32)121 TEST_SUITE(FP32)
122 FIXTURE_DATA_TEST_CASE(RunSmall,
123                        NEComparisonFixture<float>,
124                        framework::DatasetMode::PRECOMMIT,
125                        combine(run_small_dataset, framework::dataset::make("DataType", DataType::F32)))
126 {
127     // Validate output
128     validate(Accessor(_target), _reference);
129 }
130 FIXTURE_DATA_TEST_CASE(RunLarge,
131                        NEComparisonFixture<float>,
132                        framework::DatasetMode::NIGHTLY,
133                        combine(run_large_dataset, framework::dataset::make("DataType", DataType::F32)))
134 {
135     // Validate output
136     validate(Accessor(_target), _reference);
137 }
138 TEST_SUITE_END() // FP32
139 TEST_SUITE_END() // Float
140 
141 template <typename T>
142 using NEComparisonQuantizedFixture = ComparisonValidationQuantizedFixture<Tensor, Accessor, NEElementwiseComparison, T>;
143 template <typename T>
144 using NEComparisonQuantizedBroadcastFixture = ComparisonQuantizedBroadcastValidationFixture<Tensor, Accessor, NEElementwiseComparison, T>;
145 
146 TEST_SUITE(Quantized)
TEST_SUITE(QASYMM8)147 TEST_SUITE(QASYMM8)
148 FIXTURE_DATA_TEST_CASE(RunSmall,
149                        NEComparisonQuantizedFixture<uint8_t>,
150                        framework::DatasetMode::PRECOMMIT,
151                        combine(combine(combine(run_small_dataset, framework::dataset::make("DataType", DataType::QASYMM8)),
152                                        framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
153                                framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })))
154 {
155     // Validate output
156     validate(Accessor(_target), _reference);
157 }
158 TEST_SUITE_END()
TEST_SUITE(QASYMM8_SIGNED)159 TEST_SUITE(QASYMM8_SIGNED)
160 FIXTURE_DATA_TEST_CASE(RunSmallBroadcast,
161                        NEComparisonQuantizedBroadcastFixture<int8_t>,
162                        framework::DatasetMode::ALL,
163                        combine(combine(combine(run_small_broadcast_dataset, framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
164                                        framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.1, -30) })),
165                                framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.3f, 2) })))
166 {
167     // Validate output
168     validate(Accessor(_target), _reference);
169 }
170 
171 FIXTURE_DATA_TEST_CASE(RunSmall,
172                        NEComparisonQuantizedFixture<int8_t>,
173                        framework::DatasetMode::PRECOMMIT,
174                        combine(combine(combine(run_small_dataset, framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
175                                        framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.1, -30) })),
176                                framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.3f, 2) })))
177 {
178     // Validate output
179     validate(Accessor(_target), _reference);
180 }
181 TEST_SUITE_END()
182 TEST_SUITE_END()
183 
184 TEST_SUITE_END() // Comparison
185 TEST_SUITE_END() // CL
186 } // namespace validation
187 } // namespace test
188 } // namespace arm_compute
189