blob: ce678d9aea1481457760e6e7668d6577ded625c6 [file] [log] [blame]
giuros011e6e1b82019-05-14 16:12:53 +01001/*
Michele Di Giorgiocbbed282019-12-20 13:26:08 +00002 * Copyright (c) 2019-2020 ARM Limited.
giuros011e6e1b82019-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/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLPReluLayer.h"
28#include "tests/CL/CLAccessor.h"
29#include "tests/PaddingCalculator.h"
30#include "tests/datasets/ConvertPolicyDataset.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/ElementwiseOperationsFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46RelativeTolerance<float> tolerance_fp32(0.000001f);
47RelativeTolerance<float> tolerance_fp16(0.001f);
48
49constexpr unsigned int num_elems_processed_per_iteration = 16;
50/** Input data sets **/
51const auto PReluLayerU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)),
52 framework::dataset::make("DataType",
53 DataType::U8));
54const auto PReluLayerQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)),
55 framework::dataset::make("DataType",
56 DataType::QASYMM8));
Michele Di Giorgiocbbed282019-12-20 13:26:08 +000057const auto PReluLayerQASYMM8SIGNEDDataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8_SIGNED), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
58 framework::dataset::make("DataType",
59 DataType::QASYMM8_SIGNED));
giuros011e6e1b82019-05-14 16:12:53 +010060const auto PReluLayerS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
61 framework::dataset::make("DataType", DataType::S16));
62const auto PReluLayerFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
63 framework::dataset::make("DataType", DataType::F16));
64const auto PReluLayerFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
65 framework::dataset::make("DataType", DataType::F32));
66} // namespace
67
68TEST_SUITE(CL)
69TEST_SUITE(PReluLayer)
70
71// *INDENT-OFF*
72// clang-format off
73DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
74 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
75 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
76 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
77 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
78 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
79 }),
80 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
81 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
82 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
83 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
84 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
85 })),
86 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
87 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
88 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
89 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
90 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
91 })),
92 framework::dataset::make("Expected", { true, true, false, false, false})),
93 input1_info, input2_info, output_info, expected)
94{
95 ARM_COMPUTE_EXPECT(bool(CLPReluLayer::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);
96}
97// clang-format on
98// *INDENT-ON*
99
100template <typename T>
101using CLPReluLayerFixture = PReluLayerValidationFixture<CLTensor, CLAccessor, CLPReluLayer, T>;
102
103TEST_SUITE(U8)
104DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
105 shape)
106{
107 // Create tensors
108 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
109 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
110 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
111
112 // Create and Configure function
113 CLPReluLayer prelu;
114 prelu.configure(&ref_src1, &ref_src2, &dst);
115
116 // Validate valid region
117 const ValidRegion valid_region = shape_to_valid_region(shape);
118 validate(dst.info()->valid_region(), valid_region);
119
120 // Validate padding
121 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
122 validate(ref_src1.info()->padding(), padding);
123 validate(ref_src2.info()->padding(), padding);
124 validate(dst.info()->padding(), padding);
125}
126
127FIXTURE_DATA_TEST_CASE(RunSmall, CLPReluLayerFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), PReluLayerU8Dataset))
128{
129 // Validate output
130 validate(CLAccessor(_target), _reference);
131}
132TEST_SUITE_END()
133
134template <typename T>
135using CLPReluLayerQuantizedFixture = PReluLayerValidationQuantizedFixture<CLTensor, CLAccessor, CLPReluLayer, T>;
136
137TEST_SUITE(Quantized)
138TEST_SUITE(QASYMM8)
139DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
140 shape)
141{
142 // Create tensors
143 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
144 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
145 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8);
146
147 // Create and Configure function
148 CLPReluLayer prelu;
149 prelu.configure(&ref_src1, &ref_src2, &dst);
150
151 // Validate valid region
152 const ValidRegion valid_region = shape_to_valid_region(shape);
153 validate(dst.info()->valid_region(), valid_region);
154
155 // Validate padding
156 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
157 validate(ref_src1.info()->padding(), padding);
158 validate(ref_src2.info()->padding(), padding);
159 validate(dst.info()->padding(), padding);
160}
161
162FIXTURE_DATA_TEST_CASE(RunSmall, CLPReluLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
163 PReluLayerQASYMM8Dataset),
164 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
165 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
166 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))
167
168 )
169{
170 // Validate output
Michele Di Giorgiocbbed282019-12-20 13:26:08 +0000171 validate(CLAccessor(_target), _reference);
172}
173TEST_SUITE_END()
174
175TEST_SUITE(QASYMM8_SIGNED)
176FIXTURE_DATA_TEST_CASE(RunSmall, CLPReluLayerQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
177 PReluLayerQASYMM8SIGNEDDataset),
178 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 127.f, 20) })),
179 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 127.f, 10) })),
180 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 127.f, 5) }))
181
182 )
183{
184 // Validate output
185 validate(CLAccessor(_target), _reference);
giuros011e6e1b82019-05-14 16:12:53 +0100186}
187TEST_SUITE_END()
188TEST_SUITE_END()
189
190TEST_SUITE(S16)
191DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
192 shape, data_type)
193{
194 // Create tensors
195 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
196 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
197 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
198
199 // Create and Configure function
200 CLPReluLayer prelu;
201 prelu.configure(&ref_src1, &ref_src2, &dst);
202
203 // Validate valid region
204 const ValidRegion valid_region = shape_to_valid_region(shape);
205 validate(dst.info()->valid_region(), valid_region);
206
207 // Validate padding
208 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
209 validate(ref_src1.info()->padding(), padding);
210 validate(ref_src2.info()->padding(), padding);
211 validate(dst.info()->padding(), padding);
212}
213
214FIXTURE_DATA_TEST_CASE(RunSmall, CLPReluLayerFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), PReluLayerS16Dataset))
215{
216 // Validate output
217 validate(CLAccessor(_target), _reference);
218}
219TEST_SUITE_END()
220
221TEST_SUITE(Float)
222TEST_SUITE(FP16)
223FIXTURE_DATA_TEST_CASE(RunSmall, CLPReluLayerFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), PReluLayerFP16Dataset))
224{
225 // Validate output
226 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
227}
228TEST_SUITE_END()
229
230TEST_SUITE(FP32)
Michele Di Giorgiocbbed282019-12-20 13:26:08 +0000231DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(), shape)
giuros011e6e1b82019-05-14 16:12:53 +0100232{
233 // Create tensors
234 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
235 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
236 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
237
238 // Create and Configure function
239 CLPReluLayer prelu;
240 prelu.configure(&ref_src1, &ref_src2, &dst);
241
242 // Validate valid region
243 const ValidRegion valid_region = shape_to_valid_region(shape);
244 validate(dst.info()->valid_region(), valid_region);
245
246 // Validate padding
247 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
248 validate(ref_src1.info()->padding(), padding);
249 validate(ref_src2.info()->padding(), padding);
250 validate(dst.info()->padding(), padding);
251}
252
253FIXTURE_DATA_TEST_CASE(RunSmall, CLPReluLayerFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), PReluLayerFP32Dataset))
254{
255 // Validate output
256 validate(CLAccessor(_target), _reference, tolerance_fp32);
257}
258template <typename T>
259using CLPReluLayerBroadcastFixture = PReluLayerBroadcastValidationFixture<CLTensor, CLAccessor, CLPReluLayer, T>;
260
261FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLPReluLayerBroadcastFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapesBroadcast(),
262 PReluLayerFP32Dataset))
263{
264 // Validate output
265 validate(CLAccessor(_target), _reference, tolerance_fp32);
266}
267TEST_SUITE_END()
268TEST_SUITE_END()
269
270TEST_SUITE_END()
271TEST_SUITE_END()
272} // namespace validation
273} // namespace test
274} // namespace arm_compute