blob: b77bcdd4f0e9dd05485de1168d9db75ab6458f17 [file] [log] [blame]
George Wortd88590f2018-12-12 17:39:58 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 Arm Limited.
George Wortd88590f2018-12-12 17:39:58 +00003 *
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
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
Michele Di Giorgio81870c02020-04-30 12:02:20 +010046const auto run_small_dataset = combine(datasets::ComparisonOperations(), datasets::SmallShapes());
47const auto run_small_broadcast_dataset = combine(datasets::ComparisonOperations(), datasets::SmallShapesBroadcast());
48const auto run_large_dataset = combine(datasets::ComparisonOperations(), datasets::LargeShapes());
George Wortd88590f2018-12-12 17:39:58 +000049
50} // namespace
51
52TEST_SUITE(NEON)
53TEST_SUITE(Comparison)
54
55// *INDENT-OFF*
56// clang-format off
57DATA_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
George Wortd88590f2018-12-12 17:39:58 +000085template <typename T>
86using NEComparisonFixture = ComparisonValidationFixture<Tensor, Accessor, NEElementwiseComparison, T>;
87
Michele Di Giorgio1c76c1d2020-08-28 13:25:31 +010088TEST_SUITE(Bool)
89FIXTURE_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}
97TEST_SUITE_END()
98
George Wortd88590f2018-12-12 17:39:58 +000099TEST_SUITE(Float)
100#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
101TEST_SUITE(FP16)
102FIXTURE_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}
110FIXTURE_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}
118TEST_SUITE_END() // FP16
119#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
120
121TEST_SUITE(FP32)
122FIXTURE_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}
130FIXTURE_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}
138TEST_SUITE_END() // FP32
139TEST_SUITE_END() // Float
140
141template <typename T>
142using NEComparisonQuantizedFixture = ComparisonValidationQuantizedFixture<Tensor, Accessor, NEElementwiseComparison, T>;
Michele Di Giorgio81870c02020-04-30 12:02:20 +0100143template <typename T>
144using NEComparisonQuantizedBroadcastFixture = ComparisonQuantizedBroadcastValidationFixture<Tensor, Accessor, NEElementwiseComparison, T>;
George Wortd88590f2018-12-12 17:39:58 +0000145
146TEST_SUITE(Quantized)
147TEST_SUITE(QASYMM8)
148FIXTURE_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}
158TEST_SUITE_END()
morgolock74a16962020-01-15 11:40:49 +0000159TEST_SUITE(QASYMM8_SIGNED)
Michele Di Giorgio81870c02020-04-30 12:02:20 +0100160FIXTURE_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
morgolock74a16962020-01-15 11:40:49 +0000171FIXTURE_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)),
Michele Di Giorgio81870c02020-04-30 12:02:20 +0100175 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.1, -30) })),
morgolock74a16962020-01-15 11:40:49 +0000176 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.3f, 2) })))
177{
178 // Validate output
179 validate(Accessor(_target), _reference);
180}
181TEST_SUITE_END()
George Wortd88590f2018-12-12 17:39:58 +0000182TEST_SUITE_END()
183
184TEST_SUITE_END() // Comparison
185TEST_SUITE_END() // CL
186} // namespace validation
187} // namespace test
188} // namespace arm_compute