blob: cf2f5f2ea4d7ee9fb1b3e62d68b3843a6afbbd11 [file] [log] [blame]
Alex Gilday7da29b62018-03-23 14:16:00 +00001/*
Michalis Spyroud175ece2020-07-30 23:39:32 +01002 * Copyright (c) 2018-2020 Arm Limited.
Alex Gilday7da29b62018-03-23 14:16: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,
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/NEConvolutionLayer.h"
26#include "arm_compute/runtime/NEON/functions/NEGEMMConvolutionLayer.h"
27#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
29#include "tests/NEON/Accessor.h"
30#include "tests/PaddingCalculator.h"
31#include "tests/datasets/DilatedConvolutionLayerDataset.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/ConvolutionLayerFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46const AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
47#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Gian Marco Iodice35aea372018-08-24 14:30:36 +010048const AbsoluteTolerance<float> abs_tolerance_f16(0.3f); /**< Absolute tolerance value for comparing reference's output against implementation's output for DataType::F16 */
49const RelativeTolerance<half_float::half> rel_tolerance_f16(half_float::half(0.2f)); /**< Relative tolerance value for comparing reference's output against implementation's output for DataType::F16 */
50constexpr float tolerance_num_f16 = 0.07f; /**< Tolerance number for FP16 */
51#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
52constexpr AbsoluteTolerance<float> tolerance_qasymm8(0.0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
Alex Gilday7da29b62018-03-23 14:16:00 +000053
54/** CNN data types */
55const auto CNNDataTypes = framework::dataset::make("DataType",
56{
57#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
58 DataType::F16,
59#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
60 DataType::F32,
Alex Gilday7da29b62018-03-23 14:16:00 +000061 DataType::QASYMM8,
62});
63} // namespace
64
65TEST_SUITE(NEON)
Alex Gilday7da29b62018-03-23 14:16:00 +000066TEST_SUITE(DilatedConvolutionLayer)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000067
68// *INDENT-OFF*
69// clang-format off
Andrew Mundy4d9379a2018-03-15 16:47:03 +000070DATA_TEST_CASE(ValidateConvolutionMethod, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000071 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(8U, 8U, 2U), 1, DataType::F32),
72 TensorInfo(TensorShape(23U, 27U, 5U, 4U), 1, DataType::F32),
73 TensorInfo(TensorShape(3U, 3U, 2U, 1U), 1, DataType::F32),
74 TensorInfo(TensorShape(33U, 27U, 7U, 4U), 1, DataType::F32)
75 }),
76 framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32),
77 TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32),
78 TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32),
79 TensorInfo(TensorShape(5U, 5U, 7U, 16U), 1, DataType::F16)
80 })),
81 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(6U, 6U, 1U), 1, DataType::F32),
82 TensorInfo(TensorShape(21U, 25U, 21U, 4U), 1, DataType::F32),
83 TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32),
84 TensorInfo(TensorShape(11U, 12U, 16U, 4U), 1, DataType::F32)
85 })),
86 framework::dataset::make("ConvInfo", { PadStrideInfo(1, 1, 0, 0),
87 PadStrideInfo(1, 1, 0, 0),
88 PadStrideInfo(2, 1, 0, 0),
89 PadStrideInfo(3, 2, 1, 0)
90 })),
91 framework::dataset::make("Dilation", { Size2D(1U, 2U),
92 Size2D(2U, 1U),
93 Size2D(2U, 2U),
94 Size2D(3U, 3U)
95 })),
96 framework::dataset::make("Expected", { ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM })),
Andrew Mundy4d9379a2018-03-15 16:47:03 +000097 input_info, weights_info, output_info, conv_info, dilation, expected)
Alex Gilday7da29b62018-03-23 14:16:00 +000098{
99 ConvolutionMethod is_valid = NEConvolutionLayer::get_convolution_method(&input_info.clone()->set_is_resizable(false),
100 &weights_info.clone()->set_is_resizable(false),
Alex Gilday7da29b62018-03-23 14:16:00 +0000101 &output_info.clone()->set_is_resizable(false),
102 conv_info, WeightsInfo(), dilation);
103 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
104}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000105// clang-format on
106// *INDENT-ON*
107TEST_SUITE_END() // DilatedConvolutionLayer
Alex Gilday7da29b62018-03-23 14:16:00 +0000108
109TEST_SUITE(GEMMDilatedConvolutionLayer)
110
Alex Gilday7da29b62018-03-23 14:16:00 +0000111template <typename T>
112using NEGEMMDilatedConvolutionLayerFixture = ConvolutionValidationFixture<Tensor, Accessor, NEConvolutionLayer, T>;
113
114TEST_SUITE(Float)
115#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
116TEST_SUITE(FP16)
Michalis Spyroue2503892018-04-23 15:17:31 +0100117FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
118 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000119 framework::dataset::make("DataType", DataType::F16)),
Michalis Spyroue2503892018-04-23 15:17:31 +0100120 framework::dataset::make("DataLayout", { DataLayout::NCHW })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000121 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000122{
123 // Validate output
Gian Marco Iodice35aea372018-08-24 14:30:36 +0100124 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16);
Alex Gilday7da29b62018-03-23 14:16:00 +0000125}
Michalis Spyroue2503892018-04-23 15:17:31 +0100126FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
127 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000128 framework::dataset::make("DataType", DataType::F16)),
Michalis Spyroue2503892018-04-23 15:17:31 +0100129 framework::dataset::make("DataLayout", { DataLayout::NCHW })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000130 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000131{
132 // Validate output
Gian Marco Iodice35aea372018-08-24 14:30:36 +0100133 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16);
Alex Gilday7da29b62018-03-23 14:16:00 +0000134}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000135TEST_SUITE_END() // FP16
136#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Alex Gilday7da29b62018-03-23 14:16:00 +0000137
138TEST_SUITE(FP32)
Michalis Spyroue2503892018-04-23 15:17:31 +0100139FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
140 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000141 framework::dataset::make("DataType", DataType::F32)),
Michalis Spyroue2503892018-04-23 15:17:31 +0100142 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000143 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000144{
145 // Validate output
146 validate(Accessor(_target), _reference, tolerance_f32);
147}
Michalis Spyroue2503892018-04-23 15:17:31 +0100148FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
149 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000150 framework::dataset::make("DataType", DataType::F32)),
Michalis Spyroue2503892018-04-23 15:17:31 +0100151 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000152 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000153{
154 // Validate output
155 validate(Accessor(_target), _reference, tolerance_f32);
156}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000157TEST_SUITE_END() // FP32
158TEST_SUITE_END() // Float
Alex Gilday7da29b62018-03-23 14:16:00 +0000159
160template <typename T>
Alex Gilday7da29b62018-03-23 14:16:00 +0000161using NEGEMMDilatedConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<Tensor, Accessor, NEGEMMConvolutionLayer, T>;
162
163TEST_SUITE(Quantized)
164TEST_SUITE(QASYMM8)
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000165FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
Georgios Pinitas19ea4192018-06-19 13:09:53 +0100166 combine(combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
167 framework::dataset::make("ReshapeWeights", { true })),
168 framework::dataset::make("DataType", DataType::QASYMM8)),
169 framework::dataset::make("DataLayout", { DataLayout::NCHW })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000170 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
171 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000172{
173 // Validate output
174 validate(Accessor(_target), _reference, tolerance_qasymm8);
175}
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000176FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY,
Georgios Pinitas19ea4192018-06-19 13:09:53 +0100177 combine(combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
178 framework::dataset::make("ReshapeWeights", { true })),
179 framework::dataset::make("DataType", DataType::QASYMM8)),
180 framework::dataset::make("DataLayout", { DataLayout::NCHW })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000181 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
182 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000183{
184 // Validate output
185 validate(Accessor(_target), _reference, tolerance_qasymm8);
186}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000187TEST_SUITE_END() // QASYMM8
188TEST_SUITE_END() // Quantized
Alex Gilday7da29b62018-03-23 14:16:00 +0000189
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000190TEST_SUITE_END() // GEMMDilatedConvolutionLayer
191TEST_SUITE_END() // NEON
Alex Gilday7da29b62018-03-23 14:16:00 +0000192} // namespace validation
193} // namespace test
194} // namespace arm_compute