blob: 9349ff8db81e578d67acff91687e473c5a729e17 [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/NEDirectConvolutionLayer.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/ShapeDatasets.h"
31#include "tests/framework/Asserts.h"
32#include "tests/framework/Macros.h"
33#include "tests/framework/datasets/Datasets.h"
34#include "tests/validation/Validation.h"
35#include "tests/validation/fixtures/DirectConvolutionLayerFixture.h"
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010036
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +010045constexpr AbsoluteTolerance<float> tolerance_qs(1.f); /**< Tolerance for fixed point tests */
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010046#ifdef ARM_COMPUTE_ENABLE_FP16
Moritz Pflanzer6106a4d2017-08-02 09:42:27 +010047constexpr AbsoluteTolerance<float> tolerance_fp16(0.01f); /**< Tolerance for half precision floating point tests */
48#endif /* ARM_COMPUTE_ENABLE_FP16 */
49constexpr AbsoluteTolerance<float> tolerance_fp32(0.001f); /**< Tolerance for floating point tests */
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010050
51/** Direct convolution data set. */
Pablo Tello06da39d2017-08-10 15:10:40 +010052const auto data_pad_f32 = concat(concat(combine(framework::dataset::make("PadX", 0),
53 combine(framework::dataset::make("PadY", 0),
54 framework::dataset::make("KernelSize", 1))),
55 combine(framework::dataset::make("PadX", 0, 2),
56 combine(framework::dataset::make("PadY", 0, 2),
57 framework::dataset::make("KernelSize", 3)))),
58 combine(framework::dataset::make("PadX", 0, 3),
59 combine(framework::dataset::make("PadY", 0, 3),
60 framework::dataset::make("KernelSize", 5))));
61
62const auto data_pad_qs8 = concat(combine(framework::dataset::make("PadX", 0),
63 combine(framework::dataset::make("PadY", 0),
64 framework::dataset::make("KernelSize", 1))),
65 combine(framework::dataset::make("PadX", 0, 2),
66 combine(framework::dataset::make("PadY", 0, 2),
67 framework::dataset::make("KernelSize", 3))));
68
69const auto data_f32 = combine(datasets::SmallDirectConvolutionShapes(),
70 combine(framework::dataset::make("StrideX", 1, 3),
71 combine(framework::dataset::make("StrideY", 1, 3),
72 combine(data_pad_f32,
73 framework::dataset::make("NumKernels", { 1, 4, 8, 16 })))));
74
75const auto data_qs8 = combine(datasets::SmallDirectConvolutionShapes(),
76 combine(framework::dataset::make("StrideX", 1, 3),
77 combine(framework::dataset::make("StrideY", 1, 3),
78 combine(data_pad_qs8,
79 framework::dataset::make("NumKernels", { 1, 4, 8, 16 })))));
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010080
81/** Direct convolution QS16 data set. */
82const auto data_qs16 = combine(datasets::SmallDirectConvolutionShapes(),
83 combine(framework::dataset::make("StrideX", 1, 3),
84 combine(framework::dataset::make("StrideY", 1, 3),
85 combine(framework::dataset::make("PadX", 0),
86 combine(framework::dataset::make("PadY", 0),
87 combine(framework::dataset::make("KernelSize", 1),
88 framework::dataset::make("NumKernels", { 1, 4, 8, 16 })))))));
89} // namespace
90
91TEST_SUITE(NEON)
92TEST_SUITE(DirectConvolutionLayer)
93
94//TODO(COMPMID-415): Configuration tests?
95
96template <typename T>
97using NEDirectConvolutionLayerFixture = DirectConvolutionValidationFixture<Tensor, Accessor, NEDirectConvolutionLayer, T>;
98
99TEST_SUITE(Float)
100#ifdef ARM_COMPUTE_ENABLE_FP16
101TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100102FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixture<half>, framework::DatasetMode::ALL, combine(data_f32, framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100103{
104 // Validate output
105 validate(Accessor(_target), _reference, tolerance_fp16);
106}
107TEST_SUITE_END()
108#endif /* ARM_COMPUTE_ENABLE_FP16 */
109
110TEST_SUITE(FP32)
Georgios Pinitas898a8062017-09-12 19:19:12 +0100111FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixture<float>, framework::DatasetMode::ALL, combine(data_f32, framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100112{
113 // Validate output
114 validate(Accessor(_target), _reference, tolerance_fp32);
115}
116TEST_SUITE_END()
117TEST_SUITE_END()
118
119template <typename T>
120using NEDirectConvolutionLayerFixedPointFixture = DirectConvolutionValidationFixedPointFixture<Tensor, Accessor, NEDirectConvolutionLayer, T>;
121
122TEST_SUITE(Quantized)
123TEST_SUITE(QS8)
124// We test for fixed point precision [4,6]
Pablo Tello06da39d2017-08-10 15:10:40 +0100125FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(data_qs8, framework::dataset::make("DataType", DataType::QS8)),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100126 framework::dataset::make("FractionalBits", 4, 7)))
127{
128 // Validate output
129 validate(Accessor(_target), _reference, tolerance_qs);
130}
131TEST_SUITE_END()
132
133TEST_SUITE(QS16)
134// We test for fixed point precision [4,13]
135FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(data_qs16, framework::dataset::make("DataType", DataType::QS16)),
136 framework::dataset::make("FractionalBits", 4, 14)))
137{
138 // Validate output
139 validate(Accessor(_target), _reference, tolerance_qs);
140}
141TEST_SUITE_END()
142TEST_SUITE_END()
143
144TEST_SUITE_END()
145TEST_SUITE_END()
146} // namespace validation
147} // namespace test
148} // namespace arm_compute