blob: f080c834e520d0aacebac347917265038f65c1fb [file] [log] [blame]
George Wortd88590f2018-12-12 17:39:58 +00001/*
morgolock74a16962020-01-15 11:40:49 +00002 * 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{
46const auto configure_dataset = combine(datasets::SmallShapes(),
47 framework::dataset::make("DataType", { DataType::QASYMM8,
morgolock74a16962020-01-15 11:40:49 +000048 DataType::QASYMM8_SIGNED,
George Wortd88590f2018-12-12 17:39:58 +000049#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
50 DataType::F16,
51#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
52 DataType::F32
53 }));
54
Michele Di Giorgio81870c02020-04-30 12:02:20 +010055const auto run_small_dataset = combine(datasets::ComparisonOperations(), datasets::SmallShapes());
56const auto run_small_broadcast_dataset = combine(datasets::ComparisonOperations(), datasets::SmallShapesBroadcast());
57const auto run_large_dataset = combine(datasets::ComparisonOperations(), datasets::LargeShapes());
George Wortd88590f2018-12-12 17:39:58 +000058
59} // namespace
60
61TEST_SUITE(NEON)
62TEST_SUITE(Comparison)
63
64// *INDENT-OFF*
65// clang-format off
66DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
67 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Invalid output type
68 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching input types
69 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
70 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
71 }),
72 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
73 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
74 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
75 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
76 })),
77 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
78 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
79 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::U8),
80 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
81 })),
82 framework::dataset::make("Expected", { false, false, false, true})),
83 input1_info, input2_info, output_info, expected)
84{
85 Status s = NEElementwiseComparison::validate(&input1_info.clone()->set_is_resizable(false),
86 &input2_info.clone()->set_is_resizable(false),
87 &output_info.clone()->set_is_resizable(false),
88 ComparisonOperation::Equal);
89 ARM_COMPUTE_EXPECT(bool(s) == expected, framework::LogLevel::ERRORS);
90}
91// clang-format on
92// *INDENT-ON*
93
George Wortd88590f2018-12-12 17:39:58 +000094template <typename T>
95using NEComparisonFixture = ComparisonValidationFixture<Tensor, Accessor, NEElementwiseComparison, T>;
96
97TEST_SUITE(Float)
98#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
99TEST_SUITE(FP16)
100FIXTURE_DATA_TEST_CASE(RunSmall,
101 NEComparisonFixture<half>,
102 framework::DatasetMode::PRECOMMIT,
103 combine(run_small_dataset, framework::dataset::make("DataType", DataType::F16)))
104{
105 // Validate output
106 validate(Accessor(_target), _reference);
107}
108FIXTURE_DATA_TEST_CASE(RunLarge,
109 NEComparisonFixture<half>,
110 framework::DatasetMode::NIGHTLY,
111 combine(run_large_dataset, framework::dataset::make("DataType", DataType::F16)))
112{
113 // Validate output
114 validate(Accessor(_target), _reference);
115}
116TEST_SUITE_END() // FP16
117#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
118
119TEST_SUITE(FP32)
120FIXTURE_DATA_TEST_CASE(RunSmall,
121 NEComparisonFixture<float>,
122 framework::DatasetMode::PRECOMMIT,
123 combine(run_small_dataset, framework::dataset::make("DataType", DataType::F32)))
124{
125 // Validate output
126 validate(Accessor(_target), _reference);
127}
128FIXTURE_DATA_TEST_CASE(RunLarge,
129 NEComparisonFixture<float>,
130 framework::DatasetMode::NIGHTLY,
131 combine(run_large_dataset, framework::dataset::make("DataType", DataType::F32)))
132{
133 // Validate output
134 validate(Accessor(_target), _reference);
135}
136TEST_SUITE_END() // FP32
137TEST_SUITE_END() // Float
138
139template <typename T>
140using NEComparisonQuantizedFixture = ComparisonValidationQuantizedFixture<Tensor, Accessor, NEElementwiseComparison, T>;
Michele Di Giorgio81870c02020-04-30 12:02:20 +0100141template <typename T>
142using NEComparisonQuantizedBroadcastFixture = ComparisonQuantizedBroadcastValidationFixture<Tensor, Accessor, NEElementwiseComparison, T>;
George Wortd88590f2018-12-12 17:39:58 +0000143
144TEST_SUITE(Quantized)
145TEST_SUITE(QASYMM8)
146FIXTURE_DATA_TEST_CASE(RunSmall,
147 NEComparisonQuantizedFixture<uint8_t>,
148 framework::DatasetMode::PRECOMMIT,
149 combine(combine(combine(run_small_dataset, framework::dataset::make("DataType", DataType::QASYMM8)),
150 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
151 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })))
152{
153 // Validate output
154 validate(Accessor(_target), _reference);
155}
156TEST_SUITE_END()
morgolock74a16962020-01-15 11:40:49 +0000157TEST_SUITE(QASYMM8_SIGNED)
Michele Di Giorgio81870c02020-04-30 12:02:20 +0100158FIXTURE_DATA_TEST_CASE(RunSmallBroadcast,
159 NEComparisonQuantizedBroadcastFixture<int8_t>,
160 framework::DatasetMode::ALL,
161 combine(combine(combine(run_small_broadcast_dataset, framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
162 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.1, -30) })),
163 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.3f, 2) })))
164{
165 // Validate output
166 validate(Accessor(_target), _reference);
167}
168
morgolock74a16962020-01-15 11:40:49 +0000169FIXTURE_DATA_TEST_CASE(RunSmall,
170 NEComparisonQuantizedFixture<int8_t>,
171 framework::DatasetMode::PRECOMMIT,
172 combine(combine(combine(run_small_dataset, framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
Michele Di Giorgio81870c02020-04-30 12:02:20 +0100173 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.1, -30) })),
morgolock74a16962020-01-15 11:40:49 +0000174 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.3f, 2) })))
175{
176 // Validate output
177 validate(Accessor(_target), _reference);
178}
179TEST_SUITE_END()
George Wortd88590f2018-12-12 17:39:58 +0000180TEST_SUITE_END()
181
182TEST_SUITE_END() // Comparison
183TEST_SUITE_END() // CL
184} // namespace validation
185} // namespace test
186} // namespace arm_compute