Compute Library
 22.05
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  */
25 #include "arm_compute/core/Types.h"
29 #include "tests/NEON/Accessor.h"
31 #include "tests/datasets/ShapeDatasets.h"
33 #include "tests/framework/Macros.h"
36 #include "tests/validation/fixtures/DirectConvolution3DFixture.h"
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 namespace
45 {
46 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
47 const RelativeTolerance<half_float::half> rel_tolerance_f16(half_float::half(0.2f)); /**< Relative tolerance value for FP16 types */
48 const AbsoluteTolerance<float> abs_tolerance_f16(0.2f); /**< Absolute tolerance for FP16 types */
49 constexpr float tolerance_num = 0.07f; /**< Tolerance number for the FP16 implementation */
50 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
51 constexpr AbsoluteTolerance<float> tolerance_fp32(0.001f); /**< Tolerance for floating point tests */
52 constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance for quantized tests */
53 
54 /** Activation function Dataset*/
55 const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
56 {
57  ActivationLayerInfo(),
59 });
60 
61 const auto data_precommit = combine(combine(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(
62  datasets::SmallDirectConv3DShapes(),
63  framework::dataset::make("StrideX", { 1, 5, 8 })),
64  framework::dataset::make("StrideY", { 1, 2, 3 })),
65  framework::dataset::make("StrideZ", { 1, 2, 1 })),
66  framework::dataset::make("PadX", { 0, 1, 2 })),
67  framework::dataset::make("PadY", { 0, 2, 1 })),
68  framework::dataset::make("PadZ", { 0, 3, 5 })),
69  framework::dataset::make("KernelWidth", { 3, 5, 9 })),
70  framework::dataset::make("KernelHeight", { 2, 1, 3 })),
71  framework::dataset::make("KernelDepth", { 1, 2, 3 })),
72  framework::dataset::make("NumKernels", { 2, 3, 8 })),
73  framework::dataset::make("HasBias", { true, false })),
74  ActivationFunctionsDataset);
75 } // namespace
76 
77 TEST_SUITE(NEON)
78 TEST_SUITE(Convolution3D)
79 
80 // *INDENT-OFF*
81 // clang-format off
82 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
83  framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U, 4U), 1U, DataType::F32, DataLayout::NDHWC), // Mismatching data type input/weights
84  TensorInfo(TensorShape(27U, 13U, 2U, 4U), 1U, DataType::F32, DataLayout::NDHWC), // Mismatching input feature maps
85  TensorInfo(TensorShape(27U, 13U, 2U, 4U), 1U, DataType::F32, DataLayout::NDHWC), // Invalid weights dimensions
86  TensorInfo(TensorShape(27U, 13U, 2U, 4U), 1U, DataType::F32, DataLayout::NHWC), // Invalid data layout
87  TensorInfo(TensorShape(27U, 13U, 2U, 4U), 1U, DataType::F32, DataLayout::NDHWC), // Invalid biases size
88  TensorInfo(TensorShape(27U, 13U, 2U, 4U), 1U, DataType::F32, DataLayout::NDHWC), // Invalid biases dimensions
89  TensorInfo(TensorShape(27U, 13U, 2U, 4U), 1U, DataType::F32, DataLayout::NDHWC), // Invalid output size
90  TensorInfo(TensorShape(27U, 13U, 2U, 4U), 1U, DataType::U32, DataLayout::NDHWC), // Invalid data type
91  }),
92  framework::dataset::make("WeightsInfo",{ TensorInfo(TensorShape(4U, 3U, 3U, 3U, 2U), 1U, DataType::F16),
93  TensorInfo(TensorShape(4U, 3U, 3U, 3U, 3U), 1U, DataType::F32),
94  TensorInfo(TensorShape(4U, 3U, 3U, 3U, 2U, 3U), 1U, DataType::F32),
95  TensorInfo(TensorShape(4U, 3U, 3U, 3U, 2U), 1U, DataType::F32),
96  TensorInfo(TensorShape(4U, 3U, 3U, 3U, 2U), 1U, DataType::F32),
97  TensorInfo(TensorShape(4U, 3U, 3U, 3U, 2U), 1U, DataType::F32),
98  TensorInfo(TensorShape(4U, 3U, 3U, 3U, 2U), 1U, DataType::F32),
99  TensorInfo(TensorShape(4U, 3U, 3U, 3U, 2U), 1U, DataType::U32),
100  })),
109  })),
110  framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 4U), 1U, DataType::F32),
111  TensorInfo(TensorShape(25U, 11U, 4U), 1U, DataType::F32),
112  TensorInfo(TensorShape(25U, 11U, 4U), 1U, DataType::F32),
113  TensorInfo(TensorShape(25U, 11U, 4U), 1U, DataType::F32),
114  TensorInfo(TensorShape(25U, 11U, 4U), 1U, DataType::F32),
115  TensorInfo(TensorShape(25U, 11U, 4U), 1U, DataType::F32),
116  TensorInfo(TensorShape(26U, 11U, 4U), 1U, DataType::F32),
117  TensorInfo(TensorShape(25U, 11U, 4U), 1U, DataType::U32),
118  })),
119  framework::dataset::make("Expected", { false, false, false, false, false, false, false, false})),
121 {
122  const Conv3dInfo conv3d_info(Size3D(1, 1, 1), Padding3D(0, 0, 0), ActivationLayerInfo(), Size3D(1U, 1U, 1U), DimensionRoundingType::FLOOR, false);
123  bool is_valid = bool(NEConv3D::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));
125 }
126 // clang-format on
127 // *INDENT-ON*
128 
129 template <typename T>
130 using NEDirectConvolution3DFixture = DirectConvolution3DValidationFixture<Tensor, Accessor, NEConv3D, T>;
131 
132 TEST_SUITE(Float)
133 TEST_SUITE(FP32)
134 FIXTURE_DATA_TEST_CASE(RunSmall, NEDirectConvolution3DFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(data_precommit,
135  framework::dataset::make("DataType", DataType::F32)),
136  framework::dataset::make("DataLayout", { DataLayout::NDHWC })))
137 {
138  // Validate output
139  validate(Accessor(_target), _reference, tolerance_fp32);
140 }
141 TEST_SUITE_END() // FP32
142 
143 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
144 TEST_SUITE(FP16)
147  framework::dataset::make("DataLayout", { DataLayout::NDHWC })))
148 {
149  // Validate output
150  validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16);
151 }
152 TEST_SUITE_END() // FP16
153 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
154 
155 TEST_SUITE_END() // Float
156 
157 template <typename T>
158 using NEDirectConvolution3DQuantizedFixture = DirectConvolution3DValidationQuantizedFixture<Tensor, Accessor, NEConv3D, T>;
159 
160 TEST_SUITE(Quantized)
162 FIXTURE_DATA_TEST_CASE(RunSmall, NEDirectConvolution3DQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
164  framework::dataset::make("InputShape", { TensorShape(7U, 5U, 3U, 13U, 3U),
165  TensorShape(15U, 7U, 11U, 7U),
166  TensorShape(19U, 5U, 16U, 4U),
167  TensorShape(13U, 5U, 17U, 2U)
168  }),
169  framework::dataset::make("StrideX", { 1, 3, 2, 1 })),
170  framework::dataset::make("StrideY", { 2, 1, 3, 1 })),
171  framework::dataset::make("StrideZ", { 3, 2, 1, 1 })),
172  framework::dataset::make("PadX", { 0, 2, 1, 0 })),
173  framework::dataset::make("PadY", { 1, 0, 2, 0 })),
174  framework::dataset::make("PadZ", { 2, 1, 0, 0 })),
175  framework::dataset::make("KernelWidth", { 3, 7, 5, 1 })),
176  framework::dataset::make("KernelHeight", { 5, 3, 7, 1 })),
177  framework::dataset::make("KernelDepth", { 7, 5, 3, 1 })),
178  framework::dataset::make("NumKernels", { 5, 3, 1, 11 })),
179  framework::dataset::make("HasBias", { true, true, true, false })),
183  framework::dataset::make("SrcQuantizationInfo", QuantizationInfo(0.1f, 10))),
184  framework::dataset::make("WeightsQuantizationInfo", QuantizationInfo(0.3f, 20))),
185  framework::dataset::make("DstQuantizationInfo", QuantizationInfo(0.2f, 5))))
186 {
187  validate(Accessor(_target), _reference, tolerance_qasymm8);
188 }
189 
190 TEST_SUITE_END() // QASYMM8
191 
193 FIXTURE_DATA_TEST_CASE(RunSmall, NEDirectConvolution3DQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT,
195  framework::dataset::make("InputShape", { TensorShape(7U, 5U, 3U, 13U, 3U),
196  TensorShape(15U, 7U, 11U, 7U),
197  TensorShape(19U, 5U, 16U, 4U),
198  TensorShape(13U, 5U, 17U, 2U)
199  }),
200  framework::dataset::make("StrideX", { 1, 3, 2, 1 })),
201  framework::dataset::make("StrideY", { 2, 1, 3, 1 })),
202  framework::dataset::make("StrideZ", { 3, 2, 1, 1 })),
203  framework::dataset::make("PadX", { 0, 2, 1, 0 })),
204  framework::dataset::make("PadY", { 1, 0, 2, 0 })),
205  framework::dataset::make("PadZ", { 2, 1, 0, 0 })),
206  framework::dataset::make("KernelWidth", { 3, 7, 5, 1 })),
207  framework::dataset::make("KernelHeight", { 5, 3, 7, 1 })),
208  framework::dataset::make("KernelDepth", { 7, 5, 3, 1 })),
209  framework::dataset::make("NumKernels", { 5, 3, 1, 11 })),
210  framework::dataset::make("HasBias", { true, true, true, false })),
214  framework::dataset::make("SrcQuantizationInfo", QuantizationInfo(0.1f, 10))),
215  framework::dataset::make("WeightsQuantizationInfo", QuantizationInfo(0.3f, 20))),
216  framework::dataset::make("DstQuantizationInfo", QuantizationInfo(0.2f, 5))))
217 {
218  validate(Accessor(_target), _reference, tolerance_qasymm8);
219 }
220 
221 TEST_SUITE_END() // QASYMM8_SIGNED
222 TEST_SUITE_END() // Quantized
223 
224 TEST_SUITE_END() // Convolution3D
225 TEST_SUITE_END() // Neon
226 } // namespace validation
227 } // namespace test
228 } // namespace arm_compute
Shape of a tensor.
Definition: TensorShape.h:39
Descriptor used by the 3d Convolution function.
DirectConvolution3DValidationFixture< Tensor, Accessor, NEConv3D, T > NEDirectConvolution3DFixture
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:1625
Copyright (c) 2017-2022 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)
Accessor implementation for Tensor objects.
Definition: Accessor.h:35
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
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
validate(CLAccessor(output_state), expected_output)
Num samples, depth, height, width, channels.
FIXTURE_DATA_TEST_CASE(RunSmall, CLAbsLayerFixture< half >, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Definition: AbsLayer.cpp:50
Num samples, height, width, channels.
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:43
quantized, asymmetric fixed-point 8-bit number signed
static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const Conv3dInfo &conv_info)
Static function to check if given info will lead to a valid configuration.
Definition: NEConv3D.cpp:66
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
DataType
Available data types.
Definition: Types.h:79
DataLayout
[DataLayout enum definition]
Definition: Types.h:113
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65
Padding information for 3D operations like Conv3d.
Definition: Types.h:786