blob: 5880a7eda2655c12220a464fff5dcdec795ce5c7 [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"
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010028#include "tests/NEON/Accessor.h"
29#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010030#include "tests/datasets/LargeConvolutionLayerDataset.h"
31#include "tests/datasets/SmallConvolutionLayerDataset.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/ConvolutionLayerFixture.h"
37#include "tests/validation/half.h"
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010038
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)
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100110FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixture<half_float::half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
111 framework::dataset::make("ReshapeWeights", { true, false })),
112 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100113{
114 // Validate output
115 validate(Accessor(_target), _reference, tolerance_f16);
116}
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100117FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixture<half_float::half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
118 framework::dataset::make("ReshapeWeights", { true, false })),
119 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100120{
121 // Validate output
122 validate(Accessor(_target), _reference, tolerance_f16);
123}
124TEST_SUITE_END()
125#endif /* ARM_COMPUTE_ENABLE_FP16 */
126
127TEST_SUITE(FP32)
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100128FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
129 framework::dataset::make("ReshapeWeights", { true, false })),
130 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100131{
132 // Validate output
133 validate(Accessor(_target), _reference, tolerance_f32);
134}
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100135FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
136 framework::dataset::make("ReshapeWeights", { true, false })),
137 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100138{
139 // Validate output
140 validate(Accessor(_target), _reference, tolerance_f32);
141}
142TEST_SUITE_END()
143TEST_SUITE_END()
144
145template <typename T>
146using NEConvolutionLayerFixedPointFixture = ConvolutionValidationFixedPointFixture<Tensor, Accessor, NEConvolutionLayer, T>;
147
148TEST_SUITE(Quantized)
149TEST_SUITE(QS8)
150// We test for fixed point precision [4,6]
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100151FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
152 framework::dataset::make("ReshapeWeights", { true, false })),
153 framework::dataset::make("DataType", DataType::QS8)),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100154 framework::dataset::make("FractionalBits", 4, 7)))
155{
156 // Validate output
157 validate(Accessor(_target), _reference, tolerance_q);
158}
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100159FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
160 framework::dataset::make("ReshapeWeights", { true, false })),
161 framework::dataset::make("DataType", DataType::QS8)),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100162 framework::dataset::make("FractionalBits", 4, 7)))
163{
164 // Validate output
165 validate(Accessor(_target), _reference, tolerance_q);
166}
167TEST_SUITE_END()
168
169TEST_SUITE(QS16)
170// Testing for fixed point position [1,14)
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100171FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
172 framework::dataset::make("ReshapeWeights", { true, false })),
173 framework::dataset::make("DataType", DataType::QS16)),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100174 framework::dataset::make("FractionalBits", 1, 14)))
175{
176 // Validate output
177 validate(Accessor(_target), _reference, tolerance_q);
178}
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100179FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
180 framework::dataset::make("ReshapeWeights", { true, false })),
181 framework::dataset::make("DataType", DataType::QS16)),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100182 framework::dataset::make("FractionalBits", 1, 14)))
183{
184 // Validate output
185 validate(Accessor(_target), _reference, tolerance_q);
186}
187TEST_SUITE_END()
188TEST_SUITE_END()
189
190TEST_SUITE_END()
191TEST_SUITE_END()
192} // namespace validation
193} // namespace test
194} // namespace arm_compute