Compute Library
 22.05
DilatedConvolutionLayer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2021 Arm Limited.
3  *
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"
30 #include "tests/NEON/Accessor.h"
32 #include "tests/datasets/DilatedConvolutionLayerDataset.h"
34 #include "tests/framework/Macros.h"
37 #include "tests/validation/fixtures/ConvolutionLayerFixture.h"
38 
39 namespace arm_compute
40 {
41 namespace test
42 {
43 namespace validation
44 {
45 namespace
46 {
47 const 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
49 const AbsoluteTolerance<float> abs_tolerance_f16(0.3f); /**< Absolute tolerance value for comparing reference's output against implementation's output for DataType::F16 */
50 const 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 */
51 constexpr float tolerance_num_f16 = 0.07f; /**< Tolerance number for FP16 */
52 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
53 constexpr AbsoluteTolerance<float> tolerance_qasymm8(0.0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
54 
55 /** CNN data types */
56 const auto CNNDataTypes = framework::dataset::make("DataType",
57 {
58 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
60 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
63 });
64 } // namespace
65 
66 TEST_SUITE(NEON)
67 TEST_SUITE(DilatedConvolutionLayer)
68 
69 // *INDENT-OFF*
70 // clang-format off
71 DATA_TEST_CASE(ValidateConvolutionMethod, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
72  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  })),
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  })),
99 {
100  ConvolutionMethod is_valid = cpu::CpuConv2d::get_convolution_method(&input_info.clone()->set_is_resizable(false),
101  &weights_info.clone()->set_is_resizable(false),
102  &output_info.clone()->set_is_resizable(false),
103  conv_info, WeightsInfo(), dilation);
105 }
106 // clang-format on
107 // *INDENT-ON*
108 TEST_SUITE_END() // DilatedConvolutionLayer
109 
110 TEST_SUITE(GEMMDilatedConvolutionLayer)
111 
112 template <typename T>
113 using NEGEMMDilatedConvolutionLayerFixture = ConvolutionValidationFixture<Tensor, Accessor, NEConvolutionLayer, T>;
114 
115 TEST_SUITE(Float)
116 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
117 TEST_SUITE(FP16)
118 FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
119  framework::dataset::make("ReshapeWeights", { true })),
121  framework::dataset::make("DataLayout", { DataLayout::NCHW })),
122  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
123 {
124  // Validate output
125  validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16);
126 }
127 FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
128  framework::dataset::make("ReshapeWeights", { true })),
130  framework::dataset::make("DataLayout", { DataLayout::NCHW })),
131  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
132 {
133  // Validate output
134  validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16);
135 }
136 TEST_SUITE_END() // FP16
137 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
138 
139 TEST_SUITE(FP32)
140 FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
141  framework::dataset::make("ReshapeWeights", { true })),
144  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
145 {
146  // Validate output
147  validate(Accessor(_target), _reference, tolerance_f32);
148 }
149 FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
150  framework::dataset::make("ReshapeWeights", { true })),
153  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
154 {
155  // Validate output
156  validate(Accessor(_target), _reference, tolerance_f32);
157 }
158 TEST_SUITE_END() // FP32
159 TEST_SUITE_END() // Float
160 
161 template <typename T>
162 using NEGEMMDilatedConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<Tensor, Accessor, NEGEMMConvolutionLayer, T>;
163 
164 TEST_SUITE(Quantized)
166 FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
167  combine(combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
168  framework::dataset::make("ReshapeWeights", { true })),
170  framework::dataset::make("DataLayout", { DataLayout::NCHW })),
171  framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
172  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
173 {
174  // Validate output
175  validate(Accessor(_target), _reference, tolerance_qasymm8);
176 }
177 FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY,
178  combine(combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
179  framework::dataset::make("ReshapeWeights", { true })),
181  framework::dataset::make("DataLayout", { DataLayout::NCHW })),
182  framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
183  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
184 {
185  // Validate output
186  validate(Accessor(_target), _reference, tolerance_qasymm8);
187 }
188 TEST_SUITE_END() // QASYMM8
189 TEST_SUITE_END() // Quantized
190 
191 TEST_SUITE_END() // GEMMDilatedConvolutionLayer
192 TEST_SUITE_END() // Neon
193 } // namespace validation
194 } // namespace test
195 } // namespace arm_compute
Shape of a tensor.
Definition: TensorShape.h:39
RelativeTolerance< float > tolerance_f32(0.001f)
F32 Tolerance value for comparing reference&#39;s output against implementation&#39;s output for floating poi...
constexpr float tolerance_num_f16
F16 Tolerance number.
Definition: cl_gemm.cpp:75
half_float::half half
16-bit floating point type
Definition: Types.h:48
1 channel, 1 F32 per channel
ARM_COMPUTE_EXPECT(has_error==expected, framework::LogLevel::ERRORS)
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
ConvolutionMethod
Available ConvolutionMethod.
Definition: Types.h:134
Activation Layer Information class.
Definition: Types.h:1625
Copyright (c) 2017-2022 Arm Limited.
1 channel, 1 F16 per channel
Convolution Layer Weights Information class.
Definition: Types.h:1844
Quantization information.
DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), }), framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), })), framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::SQRT), })), framework::dataset::make("Expected", { false, true, true, true, false, false, true, true, false })), input_info, output_info, act_info, expected)
Accessor implementation for Tensor objects.
Definition: Accessor.h:35
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
quantized, asymmetric fixed-point 8-bit number unsigned
Padding and stride information class.
Definition: Types.h:669
validate(CLAccessor(output_state), expected_output)
static ConvolutionMethod get_convolution_method(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info, const WeightsInfo &weights_info=WeightsInfo(), const Size2D &dilation=Size2D(1U, 1U), const ActivationLayerInfo &act_info=ActivationLayerInfo(), bool enable_fast_math=false)
Static function to check if given info will return the convolution called by CpuConv2d.
Definition: CpuConv2d.cpp:123
Num samples, channels, height, width.
FIXTURE_DATA_TEST_CASE(RunSmall, CLAbsLayerFixture< half >, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Definition: AbsLayer.cpp:50
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
Num samples, height, width, channels.
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:43
zip(zip(framework::dataset::make("Weights", { TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U, 1U), 1, DataType::F32), }), framework::dataset::make("MVBGInfo",{ TensorInfo(TensorShape(2U), 1, DataType::F32), TensorInfo(TensorShape(2U), 1, DataType::F16), TensorInfo(TensorShape(5U), 1, DataType::F32), })), framework::dataset::make("Expected", { true, false, false}))
TEST_SUITE(QASYMM8_to_F32) FIXTURE_DATA_TEST_CASE(RunSmall
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65
Convolution using GEMM.