blob: 449d5db3fc81ffd91dde2440b7ac549a953a1841 [file] [log] [blame]
giuros0192fd9432018-12-03 17:30:00 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * 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{
Michele Di Giorgiobc0e1c92020-04-29 17:25:20 +010044constexpr RelativeTolerance<float> tolerance_fp32(0.000001f);
45constexpr AbsoluteTolerance<int8_t> tolerance_qasymm8_signed(1);
giuros0192fd9432018-12-03 17:30:00 +000046/** Input data sets **/
47const auto ElementwiseMaxQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)),
48 framework::dataset::make("DataType",
49 DataType::QASYMM8));
morgolocka3598052019-12-31 12:20:47 +000050const 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 +000054/** Input data sets **/
55const auto ElementwiseMaxS32Dataset = combine(combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("DataType",
56 DataType::S32));
57const auto ElementwiseMaxS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
58 framework::dataset::make("DataType", DataType::S16));
59#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
60const auto ElementwiseMaxFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
61 framework::dataset::make("DataType", DataType::F16));
62#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
63const auto ElementwiseMaxFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
64 framework::dataset::make("DataType", DataType::F32));
65} // namespace
66
67TEST_SUITE(NEON)
68TEST_SUITE(ElementwiseMax)
69
70template <typename T>
71using NEElementwiseMaxFixture = ElementwiseMaxValidationFixture<Tensor, Accessor, NEElementwiseMax, T>;
72
73// *INDENT-OFF*
74// clang-format off
75DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
76 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
77 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
78 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32),
morgolocka3598052019-12-31 12:20:47 +000079 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), // Invalid data type combination
80 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
81 TensorInfo(TensorShape(8U, 8U, 3U), 1, DataType::QASYMM8_SIGNED), // OK
82 TensorInfo(TensorShape(8U, 8U, 3U), 1, DataType::QASYMM8_SIGNED), // Mismatching data types
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),
morgolocka3598052019-12-31 12:20:47 +000089 TensorInfo(TensorShape(8U, 8U, 3U), 1, DataType::QASYMM8_SIGNED),
90 TensorInfo(TensorShape(8U, 8U, 3U), 1, DataType::QASYMM8),
giuros0192fd9432018-12-03 17:30:00 +000091 })),
92 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
93 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
94 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32),
95 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
96 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
morgolocka3598052019-12-31 12:20:47 +000097 TensorInfo(TensorShape(8U, 8U, 3U), 1, DataType::QASYMM8_SIGNED),
98 TensorInfo(TensorShape(8U, 8U, 3U), 1, DataType::QASYMM8_SIGNED),
giuros0192fd9432018-12-03 17:30:00 +000099 })),
morgolocka3598052019-12-31 12:20:47 +0000100
Michele Di Giorgiobc0e1c92020-04-29 17:25:20 +0100101 framework::dataset::make("Expected", { true, true, true, false, false, true, false, false })),
giuros0192fd9432018-12-03 17:30:00 +0000102 input1_info, input2_info, output_info, expected)
103{
morgolocka3598052019-12-31 12:20:47 +0000104 ARM_COMPUTE_EXPECT(bool(NEElementwiseMax::validate(
105 &input1_info.clone()->set_is_resizable(false),
106 &input2_info.clone()->set_is_resizable(false),
107 &output_info.clone()->set_is_resizable(false))
108 ) == expected, framework::LogLevel::ERRORS);
giuros0192fd9432018-12-03 17:30:00 +0000109}
110// clang-format on
111// *INDENT-ON*
112
113TEST_SUITE(S32)
giuros0192fd9432018-12-03 17:30:00 +0000114FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxFixture<int32_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMaxS32Dataset))
115{
116 // Validate output
117 validate(Accessor(_target), _reference);
118}
119TEST_SUITE_END() // S32
120
121TEST_SUITE(S16)
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000122FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMaxS16Dataset))
giuros0192fd9432018-12-03 17:30:00 +0000123{
124 // Validate output
125 validate(Accessor(_target), _reference);
126}
127TEST_SUITE_END() // S16
128
129template <typename T>
130using NEElementwiseMaxQuantizedFixture = ElementwiseMaxValidationQuantizedFixture<Tensor, Accessor, NEElementwiseMax, T>;
131
132TEST_SUITE(Quantized)
133TEST_SUITE(QASYMM8)
giuros0192fd9432018-12-03 17:30:00 +0000134FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
135 ElementwiseMaxQASYMM8Dataset),
136 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
137 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
138 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) })))
139{
140 // Validate output
141 validate(Accessor(_target), _reference, tolerance_fp32, 0.01);
142}
143
144template <typename T>
145using NEElementwiseMaxQuantizedBroadcastFixture = ElementwiseMaxQuantizedBroadcastValidationFixture<Tensor, Accessor, NEElementwiseMax, T>;
146
147FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEElementwiseMaxQuantizedBroadcastFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapesBroadcast(),
148 ElementwiseMaxQASYMM8Dataset),
149 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
150 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
151 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) })))
152{
153 // Validate output
154 validate(Accessor(_target), _reference);
155}
156TEST_SUITE_END()
morgolocka3598052019-12-31 12:20:47 +0000157
158TEST_SUITE(QASYMM8_SIGNED)
159FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
160 ElementwiseMaxQASYMM8SignedDataset),
Michele Di Giorgiobc0e1c92020-04-29 17:25:20 +0100161 framework::dataset::make("QuantizationInfo", { QuantizationInfo(10.f, 20) })),
162 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f, 0) })),
163 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f, -27) })))
morgolocka3598052019-12-31 12:20:47 +0000164{
165 // Validate output
Michele Di Giorgiobc0e1c92020-04-29 17:25:20 +0100166 validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
morgolocka3598052019-12-31 12:20:47 +0000167}
168
169TEST_SUITE_END()
170
giuros0192fd9432018-12-03 17:30:00 +0000171TEST_SUITE_END()
172
173TEST_SUITE(Float)
174#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
175TEST_SUITE(F16)
176FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMaxFP16Dataset))
177{
178 // Validate output
179 validate(Accessor(_target), _reference);
180}
181TEST_SUITE_END() // F16
182#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
183
184TEST_SUITE(F32)
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000185FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMaxFP32Dataset))
giuros0192fd9432018-12-03 17:30:00 +0000186{
187 // Validate output
188 validate(Accessor(_target), _reference);
189}
giuros0192fd9432018-12-03 17:30:00 +0000190template <typename T>
191using NEElementwiseMaxBroadcastFixture = ElementwiseMaxBroadcastValidationFixture<Tensor, Accessor, NEElementwiseMax, T>;
192
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000193FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEElementwiseMaxBroadcastFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapesBroadcast(),
194 ElementwiseMaxFP32Dataset))
giuros0192fd9432018-12-03 17:30:00 +0000195{
196 // Validate output
197 validate(Accessor(_target), _reference);
198}
199TEST_SUITE_END() // F32
200TEST_SUITE_END() // Float
201
202TEST_SUITE_END() // ElementwiseMax
203TEST_SUITE_END() // NEON
204} // namespace validation
205} // namespace test
206} // namespace arm_compute