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