blob: 3003409062a509734fd2123ba7cf1b7e28b08a5b [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"
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010037
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +010046const AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +010047#ifdef ARM_COMPUTE_AARCH64_V8_2
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +010048const AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F16 */
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +010049#endif /* ARM_COMPUTE_AARCH64_V8_2 */
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +010050const 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 +010051
52/** CNN data types */
53const auto CNNDataTypes = framework::dataset::make("DataType",
54{
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +010055#ifdef ARM_COMPUTE_AARCH64_V8_2
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010056 DataType::F16,
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +010057#endif /* ARM_COMPUTE_AARCH64_V8_2 */
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010058 DataType::F32,
59 DataType::QS8,
60 DataType::QS16,
61});
62} // namespace
63
64TEST_SUITE(NEON)
65TEST_SUITE(ConvolutionLayer)
66
67DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallConvolutionLayerDataset(), datasets::LargeConvolutionLayerDataset()), CNNDataTypes),
68 input_shape, weights_shape, bias_shape, output_shape, info, data_type)
69{
70 // Set fixed point position data type allowed
71 int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0;
72
73 // Create tensors
74 Tensor src = create_tensor<Tensor>(input_shape, data_type, 1, fixed_point_position);
75 Tensor weights = create_tensor<Tensor>(weights_shape, data_type, 1, fixed_point_position);
76 Tensor bias = create_tensor<Tensor>(bias_shape, data_type, 1, fixed_point_position);
77 Tensor dst = create_tensor<Tensor>(output_shape, data_type, 1, fixed_point_position);
78
79 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
80 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
81 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
82 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
83
84 // Create and configure function
85 NEConvolutionLayer conv;
86 conv.configure(&src, &weights, &bias, &dst, info);
87
88 // Validate valid region
89 const ValidRegion src_valid_region = shape_to_valid_region(input_shape);
90 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
91 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
92 const ValidRegion dst_valid_region = shape_to_valid_region(output_shape);
93
94 validate(src.info()->valid_region(), src_valid_region);
95 validate(weights.info()->valid_region(), weights_valid_region);
96 validate(bias.info()->valid_region(), bias_valid_region);
97 validate(dst.info()->valid_region(), dst_valid_region);
98
99 // Validate padding
100 //TODO(COMPMID-415) Need to validate padding?
101}
102
103template <typename T>
104using NEConvolutionLayerFixture = ConvolutionValidationFixture<Tensor, Accessor, NEConvolutionLayer, T>;
105
106TEST_SUITE(Float)
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +0100107#ifdef ARM_COMPUTE_AARCH64_V8_2
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100108TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100109FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
110 framework::dataset::make("ReshapeWeights", { true, false })),
111 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100112{
113 // Validate output
114 validate(Accessor(_target), _reference, tolerance_f16);
115}
Georgios Pinitas583137c2017-08-31 18:12:42 +0100116FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
117 framework::dataset::make("ReshapeWeights", { true, false })),
118 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100119{
120 // Validate output
121 validate(Accessor(_target), _reference, tolerance_f16);
122}
123TEST_SUITE_END()
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +0100124#endif /* ARM_COMPUTE_AARCH64_V8_2 */
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100125
126TEST_SUITE(FP32)
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100127FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
128 framework::dataset::make("ReshapeWeights", { true, false })),
129 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100130{
131 // Validate output
132 validate(Accessor(_target), _reference, tolerance_f32);
133}
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100134FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
135 framework::dataset::make("ReshapeWeights", { true, false })),
136 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100137{
138 // Validate output
139 validate(Accessor(_target), _reference, tolerance_f32);
140}
141TEST_SUITE_END()
142TEST_SUITE_END()
143
144template <typename T>
145using NEConvolutionLayerFixedPointFixture = ConvolutionValidationFixedPointFixture<Tensor, Accessor, NEConvolutionLayer, T>;
146
147TEST_SUITE(Quantized)
148TEST_SUITE(QS8)
149// We test for fixed point precision [4,6]
Georgios Pinitasce54b562017-09-14 17:21:51 +0100150FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
151 framework::dataset::make("ReshapeWeights", { true, false })),
152 framework::dataset::make("DataType", DataType::QS8)),
153 framework::dataset::make("FractionalBits", 4, 7)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100154{
155 // Validate output
156 validate(Accessor(_target), _reference, tolerance_q);
157}
Georgios Pinitasce54b562017-09-14 17:21:51 +0100158FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
159 framework::dataset::make("ReshapeWeights", { true, false })),
160 framework::dataset::make("DataType", DataType::QS8)),
161 framework::dataset::make("FractionalBits", 4, 7)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100162{
163 // Validate output
164 validate(Accessor(_target), _reference, tolerance_q);
165}
166TEST_SUITE_END()
167
168TEST_SUITE(QS16)
169// Testing for fixed point position [1,14)
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100170FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
171 framework::dataset::make("ReshapeWeights", { true, false })),
172 framework::dataset::make("DataType", DataType::QS16)),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100173 framework::dataset::make("FractionalBits", 1, 14)))
174{
175 // Validate output
176 validate(Accessor(_target), _reference, tolerance_q);
177}
Moritz Pflanzercde1e8a2017-09-08 09:53:14 +0100178FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
179 framework::dataset::make("ReshapeWeights", { true, false })),
180 framework::dataset::make("DataType", DataType::QS16)),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100181 framework::dataset::make("FractionalBits", 1, 14)))
182{
183 // Validate output
184 validate(Accessor(_target), _reference, tolerance_q);
185}
186TEST_SUITE_END()
187TEST_SUITE_END()
188
189TEST_SUITE_END()
190TEST_SUITE_END()
191} // namespace validation
192} // namespace test
193} // namespace arm_compute