blob: 9b950a06a799838f8668cc062bd91e90c3fd5c17 [file] [log] [blame]
giuros0192fd9432018-12-03 17:30:00 +00001/*
morgolock781d7272020-01-10 10:11:14 +00002 * Copyright (c) 2018-2020 ARM Limited.
giuros0192fd9432018-12-03 17:30:00 +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,
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +000021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
giuros0192fd9432018-12-03 17:30:00 +000022 * 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/datasets/ShapeDatasets.h"
30#include "tests/framework/Asserts.h"
31#include "tests/framework/Macros.h"
32#include "tests/framework/datasets/Datasets.h"
33#include "tests/validation/Validation.h"
34#include "tests/validation/fixtures/ElementwiseOperationsFixture.h"
35
36namespace arm_compute
37{
38namespace test
39{
40namespace validation
41{
42namespace
43{
44RelativeTolerance<float> tolerance_fp32(0.000001f);
45/** Input data sets **/
46const auto ElementwiseMinQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)),
47 framework::dataset::make("DataType",
48 DataType::QASYMM8));
morgolock781d7272020-01-10 10:11:14 +000049
50const auto ElementwiseMaxQASYMM8SignedDataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8_SIGNED), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
51 framework::dataset::make("DataType",
52 DataType::QASYMM8_SIGNED));
53
giuros0192fd9432018-12-03 17:30:00 +000054const auto ElementwiseMinS32Dataset = combine(combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("DataType",
55 DataType::S32));
56const auto ElementwiseMinS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
57 framework::dataset::make("DataType", DataType::S16));
58#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
59const auto ElementwiseMinFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
60 framework::dataset::make("DataType", DataType::F16));
61#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
62const auto ElementwiseMinFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
63 framework::dataset::make("DataType", DataType::F32));
64} // namespace
65
66TEST_SUITE(NEON)
67TEST_SUITE(ElementwiseMin)
68
69template <typename T>
70using NEElementwiseMinFixture = ElementwiseMinValidationFixture<Tensor, Accessor, NEElementwiseMin, T>;
71
72// *INDENT-OFF*
73// clang-format off
74DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
75 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
76 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
77 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32),
morgolock781d7272020-01-10 10:11:14 +000078 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), // Invalid data type combination
79 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
80 TensorInfo(TensorShape(4U, 4U, 2U), 1, DataType::QASYMM8_SIGNED), // Ok
81 TensorInfo(TensorShape(4U, 4U, 2U), 1, DataType::QASYMM8_SIGNED), // Mismatching types, cannot mix QASYMM8_SIGNED with QASYMM8
82 TensorInfo(TensorShape(1U, 2U, 3U), 1, DataType::QASYMM8_SIGNED,QuantizationInfo(0.1f, 2) ), // Mismatching qinfo
giuros0192fd9432018-12-03 17:30:00 +000083 }),
84 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
85 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
86 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32),
87 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
88 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
morgolock781d7272020-01-10 10:11:14 +000089 TensorInfo(TensorShape(4U, 4U, 2U), 1, DataType::QASYMM8_SIGNED),
90 TensorInfo(TensorShape(4U, 4U, 2U), 1, DataType::QASYMM8),
91 TensorInfo(TensorShape(1U, 2U, 3U), 1, DataType::QASYMM8_SIGNED,QuantizationInfo(0.5f, 1) ),
giuros0192fd9432018-12-03 17:30:00 +000092 })),
93 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
94 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
95 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32),
96 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
97 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
morgolock781d7272020-01-10 10:11:14 +000098 TensorInfo(TensorShape(4U, 4U, 2U), 1, DataType::QASYMM8_SIGNED),
99 TensorInfo(TensorShape(4U, 4U, 2U), 1, DataType::QASYMM8_SIGNED),
100 TensorInfo(TensorShape(1U, 2U, 3U), 1, DataType::QASYMM8_SIGNED,QuantizationInfo(0.5f, 1) ),
giuros0192fd9432018-12-03 17:30:00 +0000101 })),
morgolock781d7272020-01-10 10:11:14 +0000102 framework::dataset::make("Expected", { true, true, true, false,
103 false,true,false,false})),
giuros0192fd9432018-12-03 17:30:00 +0000104 input1_info, input2_info, output_info, expected)
105{
morgolock781d7272020-01-10 10:11:14 +0000106 ARM_COMPUTE_EXPECT(bool(NEElementwiseMin::validate(
107 &input1_info.clone()->set_is_resizable(false),
108 &input2_info.clone()->set_is_resizable(false),
109 &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS);
giuros0192fd9432018-12-03 17:30:00 +0000110}
111// clang-format on
112// *INDENT-ON*
113
114TEST_SUITE(S32)
giuros0192fd9432018-12-03 17:30:00 +0000115FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinFixture<int32_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMinS32Dataset))
116{
117 // Validate output
118 validate(Accessor(_target), _reference);
119}
120TEST_SUITE_END() // S32
121
122TEST_SUITE(S16)
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000123FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMinS16Dataset))
giuros0192fd9432018-12-03 17:30:00 +0000124{
125 // Validate output
126 validate(Accessor(_target), _reference);
127}
128TEST_SUITE_END() // S16
129
130template <typename T>
131using NEElementwiseMinQuantizedFixture = ElementwiseMinValidationQuantizedFixture<Tensor, Accessor, NEElementwiseMin, T>;
132
133TEST_SUITE(Quantized)
134TEST_SUITE(QASYMM8)
giuros0192fd9432018-12-03 17:30:00 +0000135template <typename T>
136using NEElementwiseMinQuantizedBroadcastFixture = ElementwiseMinQuantizedBroadcastValidationFixture<Tensor, Accessor, NEElementwiseMin, T>;
137
138FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEElementwiseMinQuantizedBroadcastFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapesBroadcast(),
139 ElementwiseMinQASYMM8Dataset),
140 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
141 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
142 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) })))
143{
144 // Validate output
145 validate(Accessor(_target), _reference);
146}
147
148FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
149 ElementwiseMinQASYMM8Dataset),
150 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
151 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
152 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))
153
154 )
155{
156 // Validate output
157 validate(Accessor(_target), _reference, tolerance_fp32, 0.01);
158}
159TEST_SUITE_END()
morgolock781d7272020-01-10 10:11:14 +0000160
161TEST_SUITE(QASYMM8_SIGNED)
162FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
163 ElementwiseMaxQASYMM8SignedDataset),
164 framework::dataset::make("QuantizationInfo", { QuantizationInfo(10.f, 2) })),
165 framework::dataset::make("QuantizationInfo", { QuantizationInfo(10.f, 2) })),
166 framework::dataset::make("QuantizationInfo", { QuantizationInfo(10.f, 2) })))
167{
168 // Validate output
169 validate(Accessor(_target), _reference);
170}
171
172TEST_SUITE_END()
173
giuros0192fd9432018-12-03 17:30:00 +0000174TEST_SUITE_END()
175
176TEST_SUITE(Float)
177#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
178TEST_SUITE(F16)
179FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMinFP16Dataset))
180{
181 // Validate output
182 validate(Accessor(_target), _reference);
183}
184TEST_SUITE_END() // F16
185#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
186
187TEST_SUITE(F32)
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000188FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMinFP32Dataset))
giuros0192fd9432018-12-03 17:30:00 +0000189{
190 // Validate output
191 validate(Accessor(_target), _reference);
192}
193
194template <typename T>
195using NEElementwiseMinBroadcastFixture = ElementwiseMinBroadcastValidationFixture<Tensor, Accessor, NEElementwiseMin, T>;
196
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000197FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEElementwiseMinBroadcastFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapesBroadcast(),
198 ElementwiseMinFP32Dataset))
giuros0192fd9432018-12-03 17:30:00 +0000199{
200 // Validate output
201 validate(Accessor(_target), _reference);
202}
203TEST_SUITE_END() // F32
204TEST_SUITE_END() // Float
205
206TEST_SUITE_END() // ElementwiseMin
207TEST_SUITE_END() // NEON
208} // namespace validation
209} // namespace test
210} // namespace arm_compute