Compute Library
 21.11
Convolution3D.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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  */
27 #include "tests/CL/CLAccessor.h"
28 #include "tests/framework/Macros.h"
31 #include "tests/validation/fixtures/DirectConvolution3DFixture.h"
32 
33 namespace arm_compute
34 {
35 namespace test
36 {
37 namespace validation
38 {
39 namespace
40 {
41 RelativeTolerance<half> tolerance_fp16(half(0.2)); /**< Tolerance for floating point tests */
42 RelativeTolerance<float> tolerance_fp32(0.05f); /**< Tolerance for floating point tests */
43 constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance for quantized tests */
44 constexpr float abs_tolerance_f32(0.0001f); /**< Absolute tolerance for FP32 tests*/
45 constexpr float tolerance_num = 0.07f; /**< Tolerance number */
46 } // namespace
47 
48 TEST_SUITE(CL)
49 TEST_SUITE(DirectConvolution3D)
50 
51 // *INDENT-OFF*
52 // clang-format off
53 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(zip(zip(
54  framework::dataset::make("InputShape", { TensorShape(27U, 13U, 5U, 3U), // Unsupported data layout
55  TensorShape(27U, 13U, 5U, 3U), // Unsupported activation enabled
56  TensorShape(27U, 13U, 5U, 3U), // Mismatching data type
57  TensorShape(27U, 13U, 5U, 3U), // Unsupported data type
58  TensorShape(27U, 13U, 5U, 3U), // Mismatching input feature maps
59  TensorShape(27U, 13U, 5U, 3U), // Mismatching output feature maps
60  TensorShape(27U, 13U, 5U, 3U), // Mismatching bias shape
61  TensorShape(27U, 13U, 5U, 3U), // Unsupported number of weights dimensions
62  TensorShape(27U, 13U, 5U, 3U), // Unsupported number of biases dimensions
63  TensorShape(27U, 13U, 5U, 3U), // Mismatching output shape
64  TensorShape(27U, 13U, 5U, 3U)
65  }),
66  framework::dataset::make("WeightsShape", { TensorShape(4U, 27U, 3U, 3U, 3U),
67  TensorShape(4U, 27U, 3U, 3U, 3U),
68  TensorShape(4U, 27U, 3U, 3U, 3U),
69  TensorShape(4U, 27U, 3U, 3U, 3U),
70  TensorShape(4U, 32U, 3U, 3U, 3U),
71  TensorShape(8U, 27U, 3U, 3U, 3U),
72  TensorShape(4U, 27U, 3U, 3U, 3U),
73  TensorShape(4U, 27U, 3U, 3U, 3U, 2U),
74  TensorShape(4U, 27U, 3U, 3U, 3U),
75  TensorShape(4U, 27U, 3U, 3U, 3U),
76  TensorShape(4U, 27U, 3U, 3U, 3U)
77  })),
78  framework::dataset::make("BiasesShape", { TensorShape(4U),
79  TensorShape(4U),
80  TensorShape(4U),
81  TensorShape(4U),
82  TensorShape(4U),
83  TensorShape(4U),
84  TensorShape(8U),
85  TensorShape(4U),
86  TensorShape(4U),
87  TensorShape(4U),
88  TensorShape(4U)
89  })),
90  framework::dataset::make("OutputShape", { TensorShape(4U, 13U, 5U, 3U),
91  TensorShape(4U, 13U, 5U, 3U),
92  TensorShape(4U, 13U, 5U, 3U),
93  TensorShape(4U, 13U, 5U, 3U),
94  TensorShape(4U, 13U, 5U, 3U),
95  TensorShape(4U, 13U, 5U, 3U),
96  TensorShape(4U, 13U, 5U, 3U),
97  TensorShape(4U, 13U, 5U, 3U),
98  TensorShape(4U, 13U, 5U, 3U, 2U),
99  TensorShape(4U, 11U, 5U, 3U),
100  TensorShape(4U, 13U, 5U, 3U)
101  })),
113  })),
114  framework::dataset::make("SrcDataType", { DataType::F32,
124  DataType::F32
125  })),
126  framework::dataset::make("WeightsDataType", { DataType::F32,
136  DataType::F32
137  })),
148  DataLayout::NDHWC
149  })),
150  framework::dataset::make("Expected", { false, false, false, false, false, false, false, false, false, false, true })),
151  input_shape, weights_shape, biases_shape, output_shape, conv3d_info, src_data_type, weights_data_type, data_layout, expected)
152 {
153  TensorInfo input_info = TensorInfo(input_shape, 1, src_data_type);
154  TensorInfo weights_info = TensorInfo(weights_shape, 1, weights_data_type);
155  TensorInfo biases_info = TensorInfo(biases_shape, 1, src_data_type);
156  TensorInfo output_info = TensorInfo(output_shape, 1, src_data_type);
157 
158  input_info.set_data_layout(data_layout);
159  weights_info.set_data_layout(data_layout);
160  biases_info.set_data_layout(data_layout);
161  output_info.set_data_layout(data_layout);
162 
163  bool is_valid = bool(CLConv3D::validate(&input_info.clone()->set_is_resizable(false), &weights_info.clone()->set_is_resizable(false), &biases_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), conv3d_info));
165 }
166 
167 template <typename T>
168 using CLDirectConvolution3DFixture = DirectConvolution3DValidationFixture<CLTensor, CLAccessor, CLConv3D, T>;
169 template <typename T>
170 using CLDirectConvolution3DQuantizedFixture = DirectConvolution3DValidationQuantizedFixture<CLTensor, CLAccessor, CLConv3D, T>;
171 
172 TEST_SUITE(NDHWC)
173 TEST_SUITE(FP16)
176  framework::dataset::make("InputShape", { TensorShape(7U, 5U, 3U, 13U, 3U),
177  TensorShape(15U, 7U, 11U, 7U),
178  TensorShape(19U, 5U, 16U, 4U),
179  TensorShape(13U, 5U, 17U, 2U)
180  }),
181  framework::dataset::make("StrideX", { 1, 3, 2, 1 })),
182  framework::dataset::make("StrideY", { 2, 1, 3, 1 })),
183  framework::dataset::make("StrideZ", { 3, 2, 1, 1 })),
184  framework::dataset::make("PadX", { 0, 2, 1, 0 })),
185  framework::dataset::make("PadY", { 1, 0, 2, 0 })),
186  framework::dataset::make("PadZ", { 2, 1, 0, 0 })),
187  framework::dataset::make("KernelWidth", { 3, 7, 5, 1 })),
188  framework::dataset::make("KernelHeight", { 5, 3, 7, 1 })),
189  framework::dataset::make("KernelDepth", { 7, 5, 3, 1 })),
190  framework::dataset::make("NumKernels", { 5, 3, 1, 11 })),
191  framework::dataset::make("HasBias", { true, true, true, false })),
195 {
196  validate(CLAccessor(_target), _reference, tolerance_fp16, tolerance_num);
197 }
198 
199 TEST_SUITE_END() // FP16
200 
201 TEST_SUITE(FP32)
202 FIXTURE_DATA_TEST_CASE(RunSmall, CLDirectConvolution3DFixture<float>, framework::DatasetMode::PRECOMMIT,
204  framework::dataset::make("InputShape", { TensorShape(7U, 5U, 3U, 13U, 3U),
205  TensorShape(15U, 7U, 11U, 7U),
206  TensorShape(19U, 5U, 16U, 4U),
207  TensorShape(13U, 5U, 17U, 2U)
208  }),
209  framework::dataset::make("StrideX", { 1, 3, 2, 1 })),
210  framework::dataset::make("StrideY", { 2, 1, 3, 1 })),
211  framework::dataset::make("StrideZ", { 3, 2, 1, 1 })),
212  framework::dataset::make("PadX", { 0, 2, 1, 0 })),
213  framework::dataset::make("PadY", { 1, 0, 2, 0 })),
214  framework::dataset::make("PadZ", { 2, 1, 0, 0 })),
215  framework::dataset::make("KernelWidth", { 3, 7, 5, 1 })),
216  framework::dataset::make("KernelHeight", { 5, 3, 7, 1 })),
217  framework::dataset::make("KernelDepth", { 7, 5, 3, 1 })),
218  framework::dataset::make("NumKernels", { 5, 3, 1, 11 })),
219  framework::dataset::make("HasBias", { true, true, true, false })),
223 {
224  validate(CLAccessor(_target), _reference, tolerance_fp32, 0.0, abs_tolerance_f32);
225 }
226 
227 // clang-format on
228 // *INDENT-ON*
229 TEST_SUITE_END() // FP32
230 
234  framework::dataset::make("InputShape", { TensorShape(7U, 5U, 3U, 13U, 3U),
235  TensorShape(15U, 7U, 11U, 7U),
236  TensorShape(19U, 5U, 16U, 4U),
237  TensorShape(13U, 5U, 17U, 2U)
238  }),
239  framework::dataset::make("StrideX", { 1, 3, 2, 1 })),
240  framework::dataset::make("StrideY", { 2, 1, 3, 1 })),
241  framework::dataset::make("StrideZ", { 3, 2, 1, 1 })),
242  framework::dataset::make("PadX", { 0, 2, 1, 0 })),
243  framework::dataset::make("PadY", { 1, 0, 2, 0 })),
244  framework::dataset::make("PadZ", { 2, 1, 0, 0 })),
245  framework::dataset::make("KernelWidth", { 3, 7, 5, 1 })),
246  framework::dataset::make("KernelHeight", { 5, 3, 7, 1 })),
247  framework::dataset::make("KernelDepth", { 7, 5, 3, 1 })),
248  framework::dataset::make("NumKernels", { 5, 3, 1, 11 })),
249  framework::dataset::make("HasBias", { true, true, true, false })),
253  framework::dataset::make("SrcQuantizationInfo", QuantizationInfo(0.1f, 10))),
254  framework::dataset::make("WeightsQuantizationInfo", QuantizationInfo(0.3f, 20))),
255  framework::dataset::make("DstQuantizationInfo", QuantizationInfo(0.2f, 5))))
256 {
257  validate(CLAccessor(_target), _reference, tolerance_qasymm8);
258 }
259 
260 TEST_SUITE_END() // QASYMM8
261 
265  framework::dataset::make("InputShape", { TensorShape(7U, 5U, 3U, 13U, 3U),
266  TensorShape(15U, 7U, 11U, 7U),
267  TensorShape(19U, 5U, 16U, 4U),
268  TensorShape(13U, 5U, 17U, 2U)
269  }),
270  framework::dataset::make("StrideX", { 1, 3, 2, 1 })),
271  framework::dataset::make("StrideY", { 2, 1, 3, 1 })),
272  framework::dataset::make("StrideZ", { 3, 2, 1, 1 })),
273  framework::dataset::make("PadX", { 0, 2, 1, 0 })),
274  framework::dataset::make("PadY", { 1, 0, 2, 0 })),
275  framework::dataset::make("PadZ", { 2, 1, 0, 0 })),
276  framework::dataset::make("KernelWidth", { 3, 7, 5, 1 })),
277  framework::dataset::make("KernelHeight", { 5, 3, 7, 1 })),
278  framework::dataset::make("KernelDepth", { 7, 5, 3, 1 })),
279  framework::dataset::make("NumKernels", { 5, 3, 1, 11 })),
280  framework::dataset::make("HasBias", { true, true, true, false })),
284  framework::dataset::make("SrcQuantizationInfo", QuantizationInfo(0.1f, 10))),
285  framework::dataset::make("WeightsQuantizationInfo", QuantizationInfo(0.3f, 20))),
286  framework::dataset::make("DstQuantizationInfo", QuantizationInfo(0.2f, 5))))
287 {
288  validate(CLAccessor(_target), _reference, tolerance_qasymm8);
289 }
290 
291 TEST_SUITE_END() // QASYMM8_SIGNED
292 
293 TEST_SUITE_END() // NDHWC
294 TEST_SUITE_END() // DirectConvolution3D
295 TEST_SUITE_END() // CL
296 
297 } // namespace validation
298 } // namespace test
299 } // namespace arm_compute
Shape of a tensor.
Definition: TensorShape.h:39
Descriptor used by the 3d Convolution function.
std::unique_ptr< ITensorInfo > clone() const override
Provide a clone of the current object of class T.
Definition: TensorInfo.cpp:282
Class for specifying the size of a 3D shape or object.
Definition: Size3D.h:32
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.
RelativeTolerance< float > tolerance_fp32(0.001f)
Activation Layer Information class.
Definition: Types.h:1509
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
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)
DirectConvolution3DValidationFixture< CLTensor, CLAccessor, CLConv3D, T > CLDirectConvolution3DFixture
const auto 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
ITensorInfo & set_data_layout(const DataLayout &data_layout) override
Set the data layout of the tensor.
Definition: TensorInfo.cpp:352
static Status validate(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const Conv3dInfo &conv3d_info)
Static function to check if given info will lead to a valid configuration of CLConv3D.
Definition: CLConv3D.cpp:68
1 channel, 1 U32 per channel
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
quantized, asymmetric fixed-point 8-bit number unsigned
Accessor implementation for CLTensor objects.
Definition: CLAccessor.h:36
TEST_SUITE(U8_to_S8) FIXTURE_DATA_TEST_CASE(RunSmall
validate(CLAccessor(output_state), expected_output)
Num samples, depth, height, width, channels.
Num samples, channels, depth, height, width.
DirectConvolution3DValidationQuantizedFixture< CLTensor, CLAccessor, CLConv3D, T > CLDirectConvolution3DQuantizedFixture
FIXTURE_DATA_TEST_CASE(RunSmall, CLAbsLayerFixture< half >, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Definition: AbsLayer.cpp:50
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:43
quantized, asymmetric fixed-point 8-bit number signed
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}))
constexpr float abs_tolerance_f32(0.0001f)
F32 Absolute tolerance value for comparing reference&#39;s output against implementation&#39;s output for flo...
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65
Padding information for 3D operations like Conv3d.
Definition: Types.h:773