blob: ff40cf5b741c9b2efa02ab5377bc18536546d38c [file] [log] [blame]
Sheri Zhang6d9c9822021-09-24 16:02: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 */
52
53/* The following tests are from real use-case that made DirectConvolution
54 * overflows in terms of its tensor indexing. This test case is using
55 * a separate tolerance due to the following reason.
56 * - It has shown that it requires generally larger absolute tolerance
57 * for large numbers or larger relative tolerance for small numbers.
58 * - With the first reason, since it is mainly testing index overflow,
59 * a value with a margin is used to avoid uninteded test failures
60 * during nightly.
61 */
62constexpr AbsoluteTolerance<float> usecase_tolerance_fp32(0.05f);
63
64/** Activation function Dataset*/
65const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
66{
67 ActivationLayerInfo(),
68 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 0.5f)
69});
70
71const auto data_precommit = combine(combine(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(
72 datasets::SmallDirectConv3DShapes(),
73 framework::dataset::make("StrideX", { 1, 5, 8 })),
74 framework::dataset::make("StrideY", { 1, 2, 3 })),
75 framework::dataset::make("StrideZ", { 1, 2, 1 })),
76 framework::dataset::make("PadX", { 0, 1, 2 })),
77 framework::dataset::make("PadY", { 0, 2, 1 })),
78 framework::dataset::make("PadZ", { 0, 3, 5 })),
79 framework::dataset::make("KernelWidth", { 3, 5, 9 })),
80 framework::dataset::make("KernelHeight", { 2, 1, 3 })),
81 framework::dataset::make("KernelDepth", { 1, 2, 3 })),
82 framework::dataset::make("NumKernels", { 2, 3, 8 })),
83 framework::dataset::make("HasBias", { true, false })),
84 ActivationFunctionsDataset);
85} // namespace
86
87TEST_SUITE(NEON)
88TEST_SUITE(Convolution3D)
89
90// *INDENT-OFF*
91// clang-format off
92DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
93 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U, 4U), 1U, DataType::F32, DataLayout::NDHWC), // Mismatching data type input/weights
94 TensorInfo(TensorShape(27U, 13U, 2U, 4U), 1U, DataType::F32, DataLayout::NDHWC), // Mismatching input feature maps
95 TensorInfo(TensorShape(27U, 13U, 2U, 4U), 1U, DataType::F32, DataLayout::NDHWC), // Invalid weights dimensions
96 TensorInfo(TensorShape(27U, 13U, 2U, 4U), 1U, DataType::F32, DataLayout::NHWC), // Invalid data layout
97 TensorInfo(TensorShape(27U, 13U, 2U, 4U), 1U, DataType::F32, DataLayout::NDHWC), // Invalid biases size
98 TensorInfo(TensorShape(27U, 13U, 2U, 4U), 1U, DataType::F32, DataLayout::NDHWC), // Invalid biases dimensions
99 TensorInfo(TensorShape(27U, 13U, 2U, 4U), 1U, DataType::F32, DataLayout::NDHWC), // Invalid output size
100 }),
101 framework::dataset::make("WeightsInfo",{ TensorInfo(TensorShape(4U, 3U, 3U, 3U, 2U), 1U, DataType::F16),
102 TensorInfo(TensorShape(4U, 3U, 3U, 3U, 3U), 1U, DataType::F32),
103 TensorInfo(TensorShape(4U, 3U, 3U, 3U, 2U, 3U), 1U, DataType::F32),
104 TensorInfo(TensorShape(4U, 3U, 3U, 3U, 2U), 1U, DataType::F32),
105 TensorInfo(TensorShape(4U, 3U, 3U, 3U, 2U), 1U, DataType::F32),
106 TensorInfo(TensorShape(4U, 3U, 3U, 3U, 2U), 1U, DataType::F32),
107 TensorInfo(TensorShape(4U, 3U, 3U, 3U, 2U), 1U, DataType::F32),
108 })),
109 framework::dataset::make("BiasesInfo",{ TensorInfo(TensorShape(4U), 1U, DataType::F32),
110 TensorInfo(TensorShape(4U), 1U, DataType::F32),
111 TensorInfo(TensorShape(4U), 1U, DataType::F32),
112 TensorInfo(TensorShape(4U), 1U, DataType::F32),
113 TensorInfo(TensorShape(3U), 1U, DataType::F32),
114 TensorInfo(TensorShape(4U, 2U), 1U, DataType::F32),
115 TensorInfo(TensorShape(4U), 1U, DataType::F32),
116 })),
117 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 4U), 1U, DataType::F32),
118 TensorInfo(TensorShape(25U, 11U, 4U), 1U, DataType::F32),
119 TensorInfo(TensorShape(25U, 11U, 4U), 1U, DataType::F32),
120 TensorInfo(TensorShape(25U, 11U, 4U), 1U, DataType::F32),
121 TensorInfo(TensorShape(25U, 11U, 4U), 1U, DataType::F32),
122 TensorInfo(TensorShape(25U, 11U, 4U), 1U, DataType::F32),
123 TensorInfo(TensorShape(26U, 11U, 4U), 1U, DataType::F32),
124 })),
125 framework::dataset::make("Expected", { false, false, false, false, false, false, false })),
126 input_info, weights_info, biases_info, output_info, expected)
127{
128 const Conv3dInfo conv3d_info(Size3D(1, 1, 1), Padding3D(0, 0, 0), ActivationLayerInfo(), Size3D(1U, 1U, 1U), DimensionRoundingType::FLOOR, false);
129 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));
130 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
131}
132// clang-format on
133// *INDENT-ON*
134
135template <typename T>
136using NEDirectConvolution3DFixture = DirectConvolution3DValidationFixture<Tensor, Accessor, NEConv3D, T>;
137
138TEST_SUITE(Float)
139TEST_SUITE(FP32)
140FIXTURE_DATA_TEST_CASE(RunSmall, NEDirectConvolution3DFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(data_precommit,
141 framework::dataset::make("DataType", DataType::F32)),
142 framework::dataset::make("DataLayout", { DataLayout::NDHWC })))
143{
144 // Validate output
145 validate(Accessor(_target), _reference, tolerance_fp32);
146}
147TEST_SUITE_END() // FP32
148
149#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
150TEST_SUITE(FP16)
151FIXTURE_DATA_TEST_CASE(RunSmall, NEDirectConvolution3DFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(data_precommit,
152 framework::dataset::make("DataType", DataType::F16)),
153 framework::dataset::make("DataLayout", { DataLayout::NDHWC })))
154{
155 // Validate output
156 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16);
157}
158TEST_SUITE_END() // FP16
159#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
160
161TEST_SUITE_END() // Float
162TEST_SUITE_END() // Convolution3D
163TEST_SUITE_END() // Neon
164} // namespace validation
165} // namespace test
166} // namespace arm_compute