blob: 38e440e64962930aaafbe90b4b7ec62cd599450d [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
55const auto run_small_dataset = combine(datasets::ComparisonOperations(), datasets::SmallShapes());
56const auto run_large_dataset = combine(datasets::ComparisonOperations(), datasets::LargeShapes());
57
58} // namespace
59
60TEST_SUITE(NEON)
61TEST_SUITE(Comparison)
62
63// *INDENT-OFF*
64// clang-format off
65DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
66 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Invalid output type
67 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching input types
68 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
69 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
70 }),
71 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
72 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
73 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
74 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
75 })),
76 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
77 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
78 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::U8),
79 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
80 })),
81 framework::dataset::make("Expected", { false, false, false, true})),
82 input1_info, input2_info, output_info, expected)
83{
84 Status s = NEElementwiseComparison::validate(&input1_info.clone()->set_is_resizable(false),
85 &input2_info.clone()->set_is_resizable(false),
86 &output_info.clone()->set_is_resizable(false),
87 ComparisonOperation::Equal);
88 ARM_COMPUTE_EXPECT(bool(s) == expected, framework::LogLevel::ERRORS);
89}
90// clang-format on
91// *INDENT-ON*
92
93DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, configure_dataset,
94 shape, data_type)
95{
96 // Create tensors
97 Tensor ref_src1 = create_tensor<Tensor>(shape, data_type);
98 Tensor ref_src2 = create_tensor<Tensor>(shape, data_type);
99 Tensor dst = create_tensor<Tensor>(shape, DataType::U8);
100
101 // Create and Configure function
102 NEElementwiseComparison compare;
103 compare.configure(&ref_src1, &ref_src2, &dst, ComparisonOperation::Equal);
104
105 // Validate valid region
106 const ValidRegion valid_region = shape_to_valid_region(shape);
107 validate(dst.info()->valid_region(), valid_region);
108}
109
110template <typename T>
111using NEComparisonFixture = ComparisonValidationFixture<Tensor, Accessor, NEElementwiseComparison, T>;
112
113TEST_SUITE(Float)
114#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
115TEST_SUITE(FP16)
116FIXTURE_DATA_TEST_CASE(RunSmall,
117 NEComparisonFixture<half>,
118 framework::DatasetMode::PRECOMMIT,
119 combine(run_small_dataset, framework::dataset::make("DataType", DataType::F16)))
120{
121 // Validate output
122 validate(Accessor(_target), _reference);
123}
124FIXTURE_DATA_TEST_CASE(RunLarge,
125 NEComparisonFixture<half>,
126 framework::DatasetMode::NIGHTLY,
127 combine(run_large_dataset, framework::dataset::make("DataType", DataType::F16)))
128{
129 // Validate output
130 validate(Accessor(_target), _reference);
131}
132TEST_SUITE_END() // FP16
133#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
134
135TEST_SUITE(FP32)
136FIXTURE_DATA_TEST_CASE(RunSmall,
137 NEComparisonFixture<float>,
138 framework::DatasetMode::PRECOMMIT,
139 combine(run_small_dataset, framework::dataset::make("DataType", DataType::F32)))
140{
141 // Validate output
142 validate(Accessor(_target), _reference);
143}
144FIXTURE_DATA_TEST_CASE(RunLarge,
145 NEComparisonFixture<float>,
146 framework::DatasetMode::NIGHTLY,
147 combine(run_large_dataset, framework::dataset::make("DataType", DataType::F32)))
148{
149 // Validate output
150 validate(Accessor(_target), _reference);
151}
152TEST_SUITE_END() // FP32
153TEST_SUITE_END() // Float
154
155template <typename T>
156using NEComparisonQuantizedFixture = ComparisonValidationQuantizedFixture<Tensor, Accessor, NEElementwiseComparison, T>;
157
158TEST_SUITE(Quantized)
159TEST_SUITE(QASYMM8)
160FIXTURE_DATA_TEST_CASE(RunSmall,
161 NEComparisonQuantizedFixture<uint8_t>,
162 framework::DatasetMode::PRECOMMIT,
163 combine(combine(combine(run_small_dataset, framework::dataset::make("DataType", DataType::QASYMM8)),
164 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
165 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })))
166{
167 // Validate output
168 validate(Accessor(_target), _reference);
169}
170TEST_SUITE_END()
morgolock74a16962020-01-15 11:40:49 +0000171TEST_SUITE(QASYMM8_SIGNED)
172FIXTURE_DATA_TEST_CASE(RunSmall,
173 NEComparisonQuantizedFixture<int8_t>,
174 framework::DatasetMode::PRECOMMIT,
175 combine(combine(combine(run_small_dataset, framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
176 framework::dataset::make("QuantizationInfo", { QuantizationInfo() })),
177 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.3f, 2) })))
178{
179 // Validate output
180 validate(Accessor(_target), _reference);
181}
182TEST_SUITE_END()
George Wortd88590f2018-12-12 17:39:58 +0000183TEST_SUITE_END()
184
185TEST_SUITE_END() // Comparison
186TEST_SUITE_END() // CL
187} // namespace validation
188} // namespace test
189} // namespace arm_compute