blob: 1bfac900c05e255426d7ed96f978e0600923c2a3 [file] [log] [blame]
Freddie Liardetf727ef42021-10-18 13:28:57 +01001/*
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 */
24#include "arm_compute/core/Helpers.h"
25#include "arm_compute/core/Types.h"
26#include "arm_compute/runtime/NEON/functions/NEConv3D.h"
27#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
29#include "tests/NEON/Accessor.h"
30#include "tests/PaddingCalculator.h"
31#include "tests/datasets/ShapeDatasets.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Macros.h"
34#include "tests/framework/datasets/Datasets.h"
35#include "tests/validation/Validation.h"
36#include "tests/validation/fixtures/DirectConvolution3DFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
47const RelativeTolerance<half_float::half> rel_tolerance_f16(half_float::half(0.2f)); /**< Relative tolerance value for FP16 types */
48const AbsoluteTolerance<float> abs_tolerance_f16(0.2f); /**< Absolute tolerance for FP16 types */
49constexpr float tolerance_num = 0.07f; /**< Tolerance number for the FP16 implementation */
50#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
51constexpr AbsoluteTolerance<float> tolerance_fp32(0.001f); /**< Tolerance for floating point tests */
52constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance for quantized tests */
53
54/** Activation function Dataset*/
55const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
56{
57 ActivationLayerInfo(),
58 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 0.5f)
59});
60
61const 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
77TEST_SUITE(NEON)
78TEST_SUITE(Convolution3D)
79
80// *INDENT-OFF*
81// clang-format off
82DATA_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 }),
91 framework::dataset::make("WeightsInfo",{ TensorInfo(TensorShape(4U, 3U, 3U, 3U, 2U), 1U, DataType::F16),
92 TensorInfo(TensorShape(4U, 3U, 3U, 3U, 3U), 1U, DataType::F32),
93 TensorInfo(TensorShape(4U, 3U, 3U, 3U, 2U, 3U), 1U, DataType::F32),
94 TensorInfo(TensorShape(4U, 3U, 3U, 3U, 2U), 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 })),
99 framework::dataset::make("BiasesInfo",{ TensorInfo(TensorShape(4U), 1U, DataType::F32),
100 TensorInfo(TensorShape(4U), 1U, DataType::F32),
101 TensorInfo(TensorShape(4U), 1U, DataType::F32),
102 TensorInfo(TensorShape(4U), 1U, DataType::F32),
103 TensorInfo(TensorShape(3U), 1U, DataType::F32),
104 TensorInfo(TensorShape(4U, 2U), 1U, DataType::F32),
105 TensorInfo(TensorShape(4U), 1U, DataType::F32),
106 })),
107 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 4U), 1U, DataType::F32),
108 TensorInfo(TensorShape(25U, 11U, 4U), 1U, DataType::F32),
109 TensorInfo(TensorShape(25U, 11U, 4U), 1U, DataType::F32),
110 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(26U, 11U, 4U), 1U, DataType::F32),
114 })),
115 framework::dataset::make("Expected", { false, false, false, false, false, false, false })),
116 input_info, weights_info, biases_info, output_info, expected)
117{
118 const Conv3dInfo conv3d_info(Size3D(1, 1, 1), Padding3D(0, 0, 0), ActivationLayerInfo(), Size3D(1U, 1U, 1U), DimensionRoundingType::FLOOR, false);
119 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));
120 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
121}
122// clang-format on
123// *INDENT-ON*
124
125template <typename T>
126using NEDirectConvolution3DFixture = DirectConvolution3DValidationFixture<Tensor, Accessor, NEConv3D, T>;
127
128TEST_SUITE(Float)
129TEST_SUITE(FP32)
130FIXTURE_DATA_TEST_CASE(RunSmall, NEDirectConvolution3DFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(data_precommit,
131 framework::dataset::make("DataType", DataType::F32)),
132 framework::dataset::make("DataLayout", { DataLayout::NDHWC })))
133{
134 // Validate output
135 validate(Accessor(_target), _reference, tolerance_fp32);
136}
137TEST_SUITE_END() // FP32
138
139#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
140TEST_SUITE(FP16)
141FIXTURE_DATA_TEST_CASE(RunSmall, NEDirectConvolution3DFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(data_precommit,
142 framework::dataset::make("DataType", DataType::F16)),
143 framework::dataset::make("DataLayout", { DataLayout::NDHWC })))
144{
145 // Validate output
146 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16);
147}
148TEST_SUITE_END() // FP16
149#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
150
151TEST_SUITE_END() // Float
152
153template <typename T>
154using NEDirectConvolution3DQuantizedFixture = DirectConvolution3DValidationQuantizedFixture<Tensor, Accessor, NEConv3D, T>;
155
156TEST_SUITE(Quantized)
157TEST_SUITE(QASYMM8)
158FIXTURE_DATA_TEST_CASE(RunSmall, NEDirectConvolution3DQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
159 combine(combine(combine(combine(combine(combine(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(
160 framework::dataset::make("InputShape", { TensorShape(7U, 5U, 3U, 13U, 3U),
161 TensorShape(15U, 7U, 11U, 7U),
162 TensorShape(19U, 5U, 16U, 4U),
163 TensorShape(13U, 5U, 17U, 2U)
164 }),
165 framework::dataset::make("StrideX", { 1, 3, 2, 1 })),
166 framework::dataset::make("StrideY", { 2, 1, 3, 1 })),
167 framework::dataset::make("StrideZ", { 3, 2, 1, 1 })),
168 framework::dataset::make("PadX", { 0, 2, 1, 0 })),
169 framework::dataset::make("PadY", { 1, 0, 2, 0 })),
170 framework::dataset::make("PadZ", { 2, 1, 0, 0 })),
171 framework::dataset::make("KernelWidth", { 3, 7, 5, 1 })),
172 framework::dataset::make("KernelHeight", { 5, 3, 7, 1 })),
173 framework::dataset::make("KernelDepth", { 7, 5, 3, 1 })),
174 framework::dataset::make("NumKernels", { 5, 3, 1, 11 })),
175 framework::dataset::make("HasBias", { true, true, true, false })),
176 framework::dataset::make("Activation", ActivationLayerInfo())),
177 framework::dataset::make("DataType", DataType::QASYMM8)),
178 framework::dataset::make("DataLayout", DataLayout::NDHWC)),
179 framework::dataset::make("SrcQuantizationInfo", QuantizationInfo(0.1f, 10))),
180 framework::dataset::make("WeightsQuantizationInfo", QuantizationInfo(0.3f, 20))),
181 framework::dataset::make("DstQuantizationInfo", QuantizationInfo(0.2f, 5))))
182{
183 validate(Accessor(_target), _reference, tolerance_qasymm8);
184}
185
186TEST_SUITE_END() // QASYMM8
187
188TEST_SUITE(QASYMM8_SIGNED)
189FIXTURE_DATA_TEST_CASE(RunSmall, NEDirectConvolution3DQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT,
190 combine(combine(combine(combine(combine(combine(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(
191 framework::dataset::make("InputShape", { TensorShape(7U, 5U, 3U, 13U, 3U),
192 TensorShape(15U, 7U, 11U, 7U),
193 TensorShape(19U, 5U, 16U, 4U),
194 TensorShape(13U, 5U, 17U, 2U)
195 }),
196 framework::dataset::make("StrideX", { 1, 3, 2, 1 })),
197 framework::dataset::make("StrideY", { 2, 1, 3, 1 })),
198 framework::dataset::make("StrideZ", { 3, 2, 1, 1 })),
199 framework::dataset::make("PadX", { 0, 2, 1, 0 })),
200 framework::dataset::make("PadY", { 1, 0, 2, 0 })),
201 framework::dataset::make("PadZ", { 2, 1, 0, 0 })),
202 framework::dataset::make("KernelWidth", { 3, 7, 5, 1 })),
203 framework::dataset::make("KernelHeight", { 5, 3, 7, 1 })),
204 framework::dataset::make("KernelDepth", { 7, 5, 3, 1 })),
205 framework::dataset::make("NumKernels", { 5, 3, 1, 11 })),
206 framework::dataset::make("HasBias", { true, true, true, false })),
207 framework::dataset::make("Activation", ActivationLayerInfo())),
208 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
209 framework::dataset::make("DataLayout", DataLayout::NDHWC)),
210 framework::dataset::make("SrcQuantizationInfo", QuantizationInfo(0.1f, 10))),
211 framework::dataset::make("WeightsQuantizationInfo", QuantizationInfo(0.3f, 20))),
212 framework::dataset::make("DstQuantizationInfo", QuantizationInfo(0.2f, 5))))
213{
214 validate(Accessor(_target), _reference, tolerance_qasymm8);
215}
216
217TEST_SUITE_END() // QASYMM8_SIGNED
218TEST_SUITE_END() // Quantized
219
220TEST_SUITE_END() // Convolution3D
221TEST_SUITE_END() // Neon
222} // namespace validation
223} // namespace test
224} // namespace arm_compute