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