blob: 1efff024284c485e80395d462ff6e0afb3547f94 [file] [log] [blame]
Moritz Pflanzerb3d25792017-07-26 11:49:37 +01001/*
2 * Copyright (c) 2017 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"
25#include "arm_compute/runtime/NEON/functions/NEConvolutionLayer.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
28#include "framework/Asserts.h"
29#include "framework/Macros.h"
30#include "framework/datasets/Datasets.h"
31#include "tests/NEON/Accessor.h"
32#include "tests/PaddingCalculator.h"
33#include "tests/datasets_new/LargeConvolutionLayerDataset.h"
34#include "tests/datasets_new/SmallConvolutionLayerDataset.h"
35#include "tests/validation_new/Validation.h"
36#include "tests/validation_new/fixtures/ConvolutionLayerFixture.h"
37#include "tests/validation_new/half.h"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45namespace
46{
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +010047const AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010048#ifdef ARM_COMPUTE_ENABLE_FP16
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +010049const AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F16 */
50#endif /* ARM_COMPUTE_ENABLE_FP16 */
51const AbsoluteTolerance<float> tolerance_q(1.0f); /**< Tolerance value for comparing reference's output against implementation's output for fixed point data types */
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010052
53/** CNN data types */
54const auto CNNDataTypes = framework::dataset::make("DataType",
55{
56#ifdef ARM_COMPUTE_ENABLE_FP16
57 DataType::F16,
58#endif /* ARM_COMPUTE_ENABLE_FP16 */
59 DataType::F32,
60 DataType::QS8,
61 DataType::QS16,
62});
63} // namespace
64
65TEST_SUITE(NEON)
66TEST_SUITE(ConvolutionLayer)
67
68DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallConvolutionLayerDataset(), datasets::LargeConvolutionLayerDataset()), CNNDataTypes),
69 input_shape, weights_shape, bias_shape, output_shape, info, data_type)
70{
71 // Set fixed point position data type allowed
72 int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0;
73
74 // Create tensors
75 Tensor src = create_tensor<Tensor>(input_shape, data_type, 1, fixed_point_position);
76 Tensor weights = create_tensor<Tensor>(weights_shape, data_type, 1, fixed_point_position);
77 Tensor bias = create_tensor<Tensor>(bias_shape, data_type, 1, fixed_point_position);
78 Tensor dst = create_tensor<Tensor>(output_shape, data_type, 1, fixed_point_position);
79
80 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
81 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
82 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
83 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
84
85 // Create and configure function
86 NEConvolutionLayer conv;
87 conv.configure(&src, &weights, &bias, &dst, info);
88
89 // Validate valid region
90 const ValidRegion src_valid_region = shape_to_valid_region(input_shape);
91 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
92 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
93 const ValidRegion dst_valid_region = shape_to_valid_region(output_shape);
94
95 validate(src.info()->valid_region(), src_valid_region);
96 validate(weights.info()->valid_region(), weights_valid_region);
97 validate(bias.info()->valid_region(), bias_valid_region);
98 validate(dst.info()->valid_region(), dst_valid_region);
99
100 // Validate padding
101 //TODO(COMPMID-415) Need to validate padding?
102}
103
104template <typename T>
105using NEConvolutionLayerFixture = ConvolutionValidationFixture<Tensor, Accessor, NEConvolutionLayer, T>;
106
107TEST_SUITE(Float)
108#ifdef ARM_COMPUTE_ENABLE_FP16
109TEST_SUITE(FP16)
110FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixture<half_float::half>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallConvolutionLayerDataset(),
111 framework::dataset::make("DataType",
112 DataType::F16)))
113{
114 // Validate output
115 validate(Accessor(_target), _reference, tolerance_f16);
116}
117FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixture<half_float::half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeConvolutionLayerDataset(),
118 framework::dataset::make("DataType",
119 DataType::F16)))
120{
121 // Validate output
122 validate(Accessor(_target), _reference, tolerance_f16);
123}
124TEST_SUITE_END()
125#endif /* ARM_COMPUTE_ENABLE_FP16 */
126
127TEST_SUITE(FP32)
128FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallConvolutionLayerDataset(), framework::dataset::make("DataType",
129 DataType::F32)))
130{
131 // Validate output
132 validate(Accessor(_target), _reference, tolerance_f32);
133}
134FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeConvolutionLayerDataset(), framework::dataset::make("DataType",
135 DataType::F32)))
136{
137 // Validate output
138 validate(Accessor(_target), _reference, tolerance_f32);
139}
140TEST_SUITE_END()
141TEST_SUITE_END()
142
143template <typename T>
144using NEConvolutionLayerFixedPointFixture = ConvolutionValidationFixedPointFixture<Tensor, Accessor, NEConvolutionLayer, T>;
145
146TEST_SUITE(Quantized)
147TEST_SUITE(QS8)
148// We test for fixed point precision [4,6]
149FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
150 framework::dataset::make("DataType",
151 DataType::QS8)),
152 framework::dataset::make("FractionalBits", 4, 7)))
153{
154 // Validate output
155 validate(Accessor(_target), _reference, tolerance_q);
156}
157FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
158 framework::dataset::make("DataType",
159 DataType::QS8)),
160 framework::dataset::make("FractionalBits", 4, 7)))
161{
162 // Validate output
163 validate(Accessor(_target), _reference, tolerance_q);
164}
165TEST_SUITE_END()
166
167TEST_SUITE(QS16)
168// Testing for fixed point position [1,14)
169FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
170 framework::dataset::make("DataType",
171 DataType::QS16)),
172 framework::dataset::make("FractionalBits", 1, 14)))
173{
174 // Validate output
175 validate(Accessor(_target), _reference, tolerance_q);
176}
177FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
178 framework::dataset::make("DataType",
179 DataType::QS16)),
180 framework::dataset::make("FractionalBits", 1, 14)))
181{
182 // Validate output
183 validate(Accessor(_target), _reference, tolerance_q);
184}
185TEST_SUITE_END()
186TEST_SUITE_END()
187
188TEST_SUITE_END()
189TEST_SUITE_END()
190} // namespace validation
191} // namespace test
192} // namespace arm_compute