Compute Library
 20.08
DilatedConvolutionLayer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019 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"
29 #include "tests/NEON/Accessor.h"
31 #include "tests/datasets/DilatedConvolutionLayerDataset.h"
33 #include "tests/framework/Macros.h"
36 #include "tests/validation/fixtures/ConvolutionLayerFixture.h"
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 namespace
45 {
46 const 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
48 const AbsoluteTolerance<float> abs_tolerance_f16(0.3f); /**< Absolute tolerance value for comparing reference's output against implementation's output for DataType::F16 */
49 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 */
50 constexpr float tolerance_num_f16 = 0.07f; /**< Tolerance number for FP16 */
51 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
52 constexpr AbsoluteTolerance<float> tolerance_qasymm8(0.0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
53 
54 /** CNN data types */
55 const auto CNNDataTypes = framework::dataset::make("DataType",
56 {
57 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
59 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
62 });
63 } // namespace
64 
65 TEST_SUITE(NEON)
66 TEST_SUITE(DilatedConvolutionLayer)
67 
68 // *INDENT-OFF*
69 // clang-format off
70 DATA_TEST_CASE(ValidateConvolutionMethod, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
71  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  })),
98 {
99  ConvolutionMethod is_valid = NEConvolutionLayer::get_convolution_method(&input_info.clone()->set_is_resizable(false),
100  &weights_info.clone()->set_is_resizable(false),
101  &output_info.clone()->set_is_resizable(false),
102  conv_info, WeightsInfo(), dilation);
104 }
105 // clang-format on
106 // *INDENT-ON*
107 TEST_SUITE_END() // DilatedConvolutionLayer
108 
109 TEST_SUITE(GEMMDilatedConvolutionLayer)
110 
111 DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallDilatedConvolutionLayerDataset(),
112  CNNDataTypes),
114 {
116 
117  // Create tensors
118  Tensor src = create_tensor<Tensor>(input_shape, data_type, 1, QuantizationInfo(2.f / 255.f, 127));
119  Tensor weights = create_tensor<Tensor>(weights_shape, data_type, 1, QuantizationInfo(2.f / 255.f, 127));
120  Tensor bias = create_tensor<Tensor>(bias_shape, bias_data_type, 1, QuantizationInfo(2.f / 255.f, 127));
121  Tensor dst = create_tensor<Tensor>(output_shape, data_type, 1, QuantizationInfo(2.f / 255.f, 127));
122 
123  ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
127 
128  const QuantizationInfo src_quantization_info = src.info()->quantization_info();
130 
131  // Create and configure function
133  conv.configure(&src, &weights, &bias, &dst, info, WeightsInfo(), dilation);
134 
135  // Validate valid region
140 
141  validate(src.info()->valid_region(), src_valid_region);
145 
146  // Validate QuantizationInfo
149 
150  // Validate padding
151  //TODO(COMPMID-415) Need to validate padding?
152 }
153 
154 template <typename T>
155 using NEGEMMDilatedConvolutionLayerFixture = ConvolutionValidationFixture<Tensor, Accessor, NEConvolutionLayer, T>;
156 
157 TEST_SUITE(Float)
158 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
159 TEST_SUITE(FP16)
161  framework::dataset::make("ReshapeWeights", { true })),
163  framework::dataset::make("DataLayout", { DataLayout::NCHW })),
164  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
165 {
166  // Validate output
167  validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16);
168 }
169 FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
170  framework::dataset::make("ReshapeWeights", { true })),
172  framework::dataset::make("DataLayout", { DataLayout::NCHW })),
173  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
174 {
175  // Validate output
176  validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16);
177 }
178 TEST_SUITE_END() // FP16
179 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
180 
181 TEST_SUITE(FP32)
182 FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
183  framework::dataset::make("ReshapeWeights", { true })),
186  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
187 {
188  // Validate output
189  validate(Accessor(_target), _reference, tolerance_f32);
190 }
192  framework::dataset::make("ReshapeWeights", { true })),
195  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
196 {
197  // Validate output
198  validate(Accessor(_target), _reference, tolerance_f32);
199 }
200 TEST_SUITE_END() // FP32
201 TEST_SUITE_END() // Float
202 
203 template <typename T>
204 using NEGEMMDilatedConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<Tensor, Accessor, NEGEMMConvolutionLayer, T>;
205 
206 TEST_SUITE(Quantized)
207 TEST_SUITE(QASYMM8)
208 FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
209  combine(combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
210  framework::dataset::make("ReshapeWeights", { true })),
212  framework::dataset::make("DataLayout", { DataLayout::NCHW })),
213  framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
214  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
215 {
216  // Validate output
217  validate(Accessor(_target), _reference, tolerance_qasymm8);
218 }
219 FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY,
220  combine(combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
221  framework::dataset::make("ReshapeWeights", { true })),
223  framework::dataset::make("DataLayout", { DataLayout::NCHW })),
224  framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
225  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
226 {
227  // Validate output
228  validate(Accessor(_target), _reference, tolerance_qasymm8);
229 }
230 TEST_SUITE_END() // QASYMM8
231 TEST_SUITE_END() // Quantized
232 
233 TEST_SUITE_END() // GEMMDilatedConvolutionLayer
234 TEST_SUITE_END() // NEON
235 } // namespace validation
236 } // namespace test
237 } // namespace arm_compute
Shape of a tensor.
Definition: TensorShape.h:39
RelativeTolerance< float > tolerance_f32(0.001f)
F32 Tolerance value for comparing reference's output against implementation's output for floating poi...
constexpr float tolerance_num_f16
F16 Tolerance number.
Definition: cl_gemm.cpp:60
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor's metadata.
Definition: CLTensor.cpp:41
bool is_resizable() const override
Flag indicating whether the size of the tensor can be changed.
Definition: TensorInfo.h:285
ValidRegion valid_region() const override
Valid region of the tensor.
Definition: TensorInfo.h:303
half_float::half half
16-bit floating point type
Definition: Types.h:46
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.
const QuantizationInfo src_quantization_info
ConvolutionMethod
Available ConvolutionMethod.
Definition: Types.h:138
Activation Layer Information class.
Definition: Types.h:1517
Basic function to compute the convolution layer.
Copyright (c) 2017-2020 Arm Limited.
ConvolutionValidationFixture< Tensor, Accessor, NEConvolutionLayer, T > NEGEMMDilatedConvolutionLayerFixture
1 channel, 1 F16 per channel
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
ITensorInfo * info() const override
Interface to be implemented by the child class to return the tensor's metadata.
Definition: Tensor.cpp:33
std::array< int16_t, 25 > conv
Convolution Layer Weights Information class.
Definition: Types.h:1694
1 channel, 1 S32 per channel
virtual bool is_resizable() const =0
Flag indicating whether the size of the tensor can be changed.
Quantization information.
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
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
Basic implementation of the tensor interface.
Definition: Tensor.h:37
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
Num samples, channels, height, width.
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
Definition: Utils.h:1143
FIXTURE_DATA_TEST_CASE(RunSmall, CLAbsLayerFixture< half >, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Definition: AbsLayer.cpp:50
validate(dst.info() ->valid_region(), valid_region)
const ValidRegion dst_valid_region
static ConvolutionMethod get_convolution_method(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *output, 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 NEConvolutionLayer.
Num samples, height, width, channels.
const QuantizationInfo weights_quantization_info
Store the tensor's metadata.
Definition: TensorInfo.h:45
Container for valid region of a window.
Definition: Types.h:187
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}))
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65
TEST_SUITE(U8_to_S8) DATA_TEST_CASE(Configuration
ValidRegion shape_to_valid_region(const TensorShape &a_shape, bool border_undefined=false, BorderSize border_size=BorderSize(0))
Create a valid region based on tensor shape, border mode and border size.
Definition: Utils.h:225
cast configure & src
Definition: Cast.cpp:169
DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), AbsoluteDifferenceU8Dataset), shape, data_type0, data_type1, output_data_type)