blob: 69a05175ad231f198e1f168ee6d0941005dd4768 [file] [log] [blame]
giuros01d5134362019-05-14 16:12:53 +01001/*
Sheri Zhangac6499a2021-02-10 15:32:38 +00002 * Copyright (c) 2019-2021 Arm Limited.
giuros01d5134362019-05-14 16:12:53 +01003 *
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/NEPReluLayer.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/ShapeDatasets.h"
31#include "tests/framework/Asserts.h"
32#include "tests/framework/Macros.h"
33#include "tests/framework/datasets/Datasets.h"
34#include "tests/validation/Validation.h"
35#include "tests/validation/fixtures/ElementwiseOperationsFixture.h"
36
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
Michalis Spyrou8d4d1b82019-11-28 11:31:23 +000045RelativeTolerance<float> tolerance_fp32(0.000001f);
46AbsoluteTolerance<int8_t> tolerance_s8(1);
giuros01d5134362019-05-14 16:12:53 +010047
giuros01d5134362019-05-14 16:12:53 +010048/** Input data sets **/
49const auto PReluLayerQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)),
50 framework::dataset::make("DataType",
51 DataType::QASYMM8));
Michalis Spyrou8d4d1b82019-11-28 11:31:23 +000052const auto PReluLayerQASYMM8SignedDataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8_SIGNED), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
53 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED));
giuros01d5134362019-05-14 16:12:53 +010054const auto PReluLayerFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
55 framework::dataset::make("DataType", DataType::F32));
56
57#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
58RelativeTolerance<float> tolerance_fp16(0.001f);
59
60const auto PReluLayerFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
61 framework::dataset::make("DataType", DataType::F16));
62
63#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
64
65} // namespace
66
67TEST_SUITE(NEON)
68TEST_SUITE(PReluLayer)
69
70// *INDENT-OFF*
71// clang-format off
72DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
73 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
74 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8),
75 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
76 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
77 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
78 }),
79 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
80 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8),
81 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
82 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
83 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
84 })),
85 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
86 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8),
87 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
88 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
89 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
90 })),
91 framework::dataset::make("Expected", { true, true, false, false, false})),
92 input1_info, input2_info, output_info, expected)
93{
94 ARM_COMPUTE_EXPECT(bool(NEPReluLayer::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS);
95}
96// clang-format on
97// *INDENT-ON*
98
99template <typename T>
100using NEPReluLayerFixture = PReluLayerValidationFixture<Tensor, Accessor, NEPReluLayer, T>;
101
102template <typename T>
103using NEPReluLayerQuantizedFixture = PReluLayerValidationQuantizedFixture<Tensor, Accessor, NEPReluLayer, T>;
104
105TEST_SUITE(Quantized)
106TEST_SUITE(QASYMM8)
giuros01d5134362019-05-14 16:12:53 +0100107FIXTURE_DATA_TEST_CASE(RunSmall, NEPReluLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(),
108 PReluLayerQASYMM8Dataset),
109 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
110 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
111 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))
112
113 )
114{
115 // Validate output
116 validate(Accessor(_target), _reference, tolerance_fp32, 0.01);
117}
118
119FIXTURE_DATA_TEST_CASE(RunLarge, NEPReluLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(),
120 PReluLayerQASYMM8Dataset),
121 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
122 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
123 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))
124
125 )
126{
127 // Validate output
128 validate(Accessor(_target), _reference, tolerance_fp32, 0.01);
129}
Michalis Spyrou8d4d1b82019-11-28 11:31:23 +0000130TEST_SUITE_END() // QASYMM8
131
132TEST_SUITE(QASYMM8_SIGNED)
133FIXTURE_DATA_TEST_CASE(RunSmall, NEPReluLayerQuantizedFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(),
134 PReluLayerQASYMM8SignedDataset),
Sheri Zhang5eaf57c2020-05-04 21:38:17 +0100135 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.2f, 127) })),
136 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.1f, 64) })),
137 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, -128) }))
Michalis Spyrou8d4d1b82019-11-28 11:31:23 +0000138
139 )
140{
141 // Validate output
142 validate(Accessor(_target), _reference, tolerance_s8, 0.01);
143}
144
145FIXTURE_DATA_TEST_CASE(RunLarge, NEPReluLayerQuantizedFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(),
146 PReluLayerQASYMM8SignedDataset),
147 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 20) })),
148 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })),
149 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 5) }))
150
151 )
152{
153 // Validate output
154 validate(Accessor(_target), _reference, tolerance_s8, 0.01);
155}
156TEST_SUITE_END() // QASYMM8_SIGNED
157TEST_SUITE_END() // Quantized
giuros01d5134362019-05-14 16:12:53 +0100158
159TEST_SUITE(Float)
160#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
161TEST_SUITE(FP16)
162FIXTURE_DATA_TEST_CASE(RunSmall, NEPReluLayerFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), PReluLayerFP16Dataset))
163{
164 // Validate output
165 validate(Accessor(_target), _reference, tolerance_fp16, 0.01);
166}
167
168FIXTURE_DATA_TEST_CASE(RunLarge, NEPReluLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), PReluLayerFP16Dataset))
169{
170 // Validate output
171 validate(Accessor(_target), _reference, tolerance_fp16, 0.01);
172}
173TEST_SUITE_END() // FP16
174#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
175
176TEST_SUITE(FP32)
giuros01d5134362019-05-14 16:12:53 +0100177FIXTURE_DATA_TEST_CASE(RunSmall, NEPReluLayerFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), PReluLayerFP32Dataset))
178{
179 // Validate output
180 validate(Accessor(_target), _reference, tolerance_fp32);
181}
182
183FIXTURE_DATA_TEST_CASE(RunLarge, NEPReluLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), PReluLayerFP32Dataset))
184{
185 // Validate output
186 validate(Accessor(_target), _reference, tolerance_fp32);
187}
188
189template <typename T>
190using NEPReluLayerBroadcastFixture = PReluLayerBroadcastValidationFixture<Tensor, Accessor, NEPReluLayer, T>;
191
192FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEPReluLayerBroadcastFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapesBroadcast(),
193 PReluLayerFP32Dataset))
194{
195 // Validate output
196 validate(Accessor(_target), _reference, tolerance_fp32);
197}
198
199FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, NEPReluLayerBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapesBroadcast(),
200 PReluLayerFP32Dataset))
201{
202 // Validate output
203 validate(Accessor(_target), _reference, tolerance_fp32);
204}
205TEST_SUITE_END() // FP32
206TEST_SUITE_END() // Float
207
208TEST_SUITE_END() // PReluLayer
Sheri Zhangac6499a2021-02-10 15:32:38 +0000209TEST_SUITE_END() // Neon
giuros01d5134362019-05-14 16:12:53 +0100210} // namespace validation
211} // namespace test
212} // namespace arm_compute