blob: fbfe8b8a7af4c8ab036511370273c2bc0a8505a0 [file] [log] [blame]
Alex Gilday7da29b62018-03-23 14:16:00 +00001/*
Gunes Bayir43ba0dd2024-03-19 15:31:11 +00002 * Copyright (c) 2018-2021, 2023-2024 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"
Georgios Pinitas7891a732021-08-20 21:39:25 +010029#include "src/cpu/operators/CpuConv2d.h"
Alex Gilday7da29b62018-03-23 14:16:00 +000030#include "tests/NEON/Accessor.h"
31#include "tests/PaddingCalculator.h"
32#include "tests/datasets/DilatedConvolutionLayerDataset.h"
33#include "tests/framework/Asserts.h"
34#include "tests/framework/Macros.h"
35#include "tests/framework/datasets/Datasets.h"
36#include "tests/validation/Validation.h"
37#include "tests/validation/fixtures/ConvolutionLayerFixture.h"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45namespace
46{
47const AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
48#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Gian Marco Iodice35aea372018-08-24 14:30:36 +010049const AbsoluteTolerance<float> abs_tolerance_f16(0.3f); /**< Absolute tolerance value for comparing reference's output against implementation's output for DataType::F16 */
50const 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 */
51constexpr float tolerance_num_f16 = 0.07f; /**< Tolerance number for FP16 */
52#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Gunes Bayir43ba0dd2024-03-19 15:31:11 +000053constexpr AbsoluteTolerance<int32_t> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
Alex Gilday7da29b62018-03-23 14:16:00 +000054
55/** CNN data types */
56const auto CNNDataTypes = framework::dataset::make("DataType",
57{
58#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
59 DataType::F16,
60#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
61 DataType::F32,
Alex Gilday7da29b62018-03-23 14:16:00 +000062 DataType::QASYMM8,
63});
64} // namespace
65
66TEST_SUITE(NEON)
Alex Gilday7da29b62018-03-23 14:16:00 +000067TEST_SUITE(DilatedConvolutionLayer)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000068
69// *INDENT-OFF*
70// clang-format off
Andrew Mundy4d9379a2018-03-15 16:47:03 +000071DATA_TEST_CASE(ValidateConvolutionMethod, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000072 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(8U, 8U, 2U), 1, DataType::F32),
73 TensorInfo(TensorShape(23U, 27U, 5U, 4U), 1, DataType::F32),
74 TensorInfo(TensorShape(3U, 3U, 2U, 1U), 1, DataType::F32),
75 TensorInfo(TensorShape(33U, 27U, 7U, 4U), 1, DataType::F32)
76 }),
77 framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32),
78 TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32),
79 TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32),
80 TensorInfo(TensorShape(5U, 5U, 7U, 16U), 1, DataType::F16)
81 })),
82 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(6U, 6U, 1U), 1, DataType::F32),
83 TensorInfo(TensorShape(21U, 25U, 21U, 4U), 1, DataType::F32),
84 TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32),
85 TensorInfo(TensorShape(11U, 12U, 16U, 4U), 1, DataType::F32)
86 })),
87 framework::dataset::make("ConvInfo", { PadStrideInfo(1, 1, 0, 0),
88 PadStrideInfo(1, 1, 0, 0),
89 PadStrideInfo(2, 1, 0, 0),
90 PadStrideInfo(3, 2, 1, 0)
91 })),
92 framework::dataset::make("Dilation", { Size2D(1U, 2U),
93 Size2D(2U, 1U),
94 Size2D(2U, 2U),
95 Size2D(3U, 3U)
96 })),
97 framework::dataset::make("Expected", { ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM })),
Andrew Mundy4d9379a2018-03-15 16:47:03 +000098 input_info, weights_info, output_info, conv_info, dilation, expected)
Alex Gilday7da29b62018-03-23 14:16:00 +000099{
Michalis Spyroub55f8e82021-07-22 11:23:11 +0100100 ConvolutionMethod is_valid = cpu::CpuConv2d::get_convolution_method(&input_info.clone()->set_is_resizable(false),
Alex Gilday7da29b62018-03-23 14:16:00 +0000101 &weights_info.clone()->set_is_resizable(false),
Alex Gilday7da29b62018-03-23 14:16:00 +0000102 &output_info.clone()->set_is_resizable(false),
103 conv_info, WeightsInfo(), dilation);
104 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
105}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000106// clang-format on
107// *INDENT-ON*
108TEST_SUITE_END() // DilatedConvolutionLayer
Alex Gilday7da29b62018-03-23 14:16:00 +0000109
110TEST_SUITE(GEMMDilatedConvolutionLayer)
111
Alex Gilday7da29b62018-03-23 14:16:00 +0000112template <typename T>
113using NEGEMMDilatedConvolutionLayerFixture = ConvolutionValidationFixture<Tensor, Accessor, NEConvolutionLayer, T>;
114
115TEST_SUITE(Float)
116#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
117TEST_SUITE(FP16)
Michalis Spyroue2503892018-04-23 15:17:31 +0100118FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
119 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000120 framework::dataset::make("DataType", DataType::F16)),
Michalis Spyroue2503892018-04-23 15:17:31 +0100121 framework::dataset::make("DataLayout", { DataLayout::NCHW })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000122 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000123{
124 // Validate output
Gian Marco Iodice35aea372018-08-24 14:30:36 +0100125 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16);
Alex Gilday7da29b62018-03-23 14:16:00 +0000126}
Michalis Spyroue2503892018-04-23 15:17:31 +0100127FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
128 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000129 framework::dataset::make("DataType", DataType::F16)),
Michalis Spyroue2503892018-04-23 15:17:31 +0100130 framework::dataset::make("DataLayout", { DataLayout::NCHW })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000131 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000132{
133 // Validate output
Gian Marco Iodice35aea372018-08-24 14:30:36 +0100134 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16);
Alex Gilday7da29b62018-03-23 14:16:00 +0000135}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000136TEST_SUITE_END() // FP16
137#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Alex Gilday7da29b62018-03-23 14:16:00 +0000138
139TEST_SUITE(FP32)
Michalis Spyroue2503892018-04-23 15:17:31 +0100140FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
141 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000142 framework::dataset::make("DataType", DataType::F32)),
Michalis Spyroue2503892018-04-23 15:17:31 +0100143 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000144 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000145{
146 // Validate output
147 validate(Accessor(_target), _reference, tolerance_f32);
148}
Michalis Spyroue2503892018-04-23 15:17:31 +0100149FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
150 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000151 framework::dataset::make("DataType", DataType::F32)),
Michalis Spyroue2503892018-04-23 15:17:31 +0100152 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000153 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000154{
155 // Validate output
156 validate(Accessor(_target), _reference, tolerance_f32);
157}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000158TEST_SUITE_END() // FP32
159TEST_SUITE_END() // Float
Alex Gilday7da29b62018-03-23 14:16:00 +0000160
161template <typename T>
Alex Gilday7da29b62018-03-23 14:16:00 +0000162using NEGEMMDilatedConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<Tensor, Accessor, NEGEMMConvolutionLayer, T>;
163
164TEST_SUITE(Quantized)
Gunes Bayir93a77cd2023-10-13 16:58:41 +0100165/// @note: Every asymmetric quantized test where there's no fused activation will have its quantization info ignored
166/// This is because instead of using the same quantization information for all the tensors, the fixture generates
167/// separate quantization info for each input and the output tensor.
168/// When we can also support dynamic quantization with the presence of activation, we can remove the explicit
169/// quantization info.
Alex Gilday7da29b62018-03-23 14:16:00 +0000170TEST_SUITE(QASYMM8)
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000171FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
Georgios Pinitas19ea4192018-06-19 13:09:53 +0100172 combine(combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
173 framework::dataset::make("ReshapeWeights", { true })),
174 framework::dataset::make("DataType", DataType::QASYMM8)),
175 framework::dataset::make("DataLayout", { DataLayout::NCHW })),
Gunes Bayir93a77cd2023-10-13 16:58:41 +0100176 framework::dataset::make("IgnoredQuantizationInfo", { QuantizationInfo() })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000177 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000178{
179 // Validate output
180 validate(Accessor(_target), _reference, tolerance_qasymm8);
181}
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000182FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY,
Georgios Pinitas19ea4192018-06-19 13:09:53 +0100183 combine(combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
184 framework::dataset::make("ReshapeWeights", { true })),
185 framework::dataset::make("DataType", DataType::QASYMM8)),
186 framework::dataset::make("DataLayout", { DataLayout::NCHW })),
Gunes Bayir93a77cd2023-10-13 16:58:41 +0100187 framework::dataset::make("IgnoredQuantizationInfo", { QuantizationInfo() })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000188 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000189{
190 // Validate output
191 validate(Accessor(_target), _reference, tolerance_qasymm8);
192}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000193TEST_SUITE_END() // QASYMM8
194TEST_SUITE_END() // Quantized
Alex Gilday7da29b62018-03-23 14:16:00 +0000195
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000196TEST_SUITE_END() // GEMMDilatedConvolutionLayer
Sheri Zhangac6499a2021-02-10 15:32:38 +0000197TEST_SUITE_END() // Neon
Alex Gilday7da29b62018-03-23 14:16:00 +0000198} // namespace validation
199} // namespace test
200} // namespace arm_compute