blob: a46f5a5dcc9ebbb164e1c682ad814859ea905e39 [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"
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/ShapeDatasets.h"
34#include "tests/validation_new/Validation.h"
35#include "tests/validation_new/fixtures/DirectConvolutionLayerFixture.h"
36#include "tests/validation_new/half.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46constexpr float tolerance_qs = 1.f; /**< Tolerance for fixed point tests */
47#ifdef ARM_COMPUTE_ENABLE_FP16
48constexpr float tolerance_fp16 = 0.01f; /**< Tolerance for half precision floating point tests */
49#endif /* ARM_COMPUTE_ENABLE_FP16 */
50constexpr float tolerance_fp32 = 0.001f; /**< Tolerance for floating point tests */
51
52/** Direct convolution data set. */
53const auto data = combine(datasets::SmallDirectConvolutionShapes(),
54 combine(framework::dataset::make("StrideX", 1, 3),
55 combine(framework::dataset::make("StrideY", 1, 3),
56 combine(concat(combine(framework::dataset::make("PadX", 0),
57 combine(framework::dataset::make("PadY", 0),
58 framework::dataset::make("KernelSize", 1))),
59 combine(framework::dataset::make("PadX", 0, 2),
60 combine(framework::dataset::make("PadY", 0, 2),
61 framework::dataset::make("KernelSize", 3)))),
62 framework::dataset::make("NumKernels", { 1, 4, 8, 16 })))));
63
64/** Direct convolution QS16 data set. */
65const auto data_qs16 = combine(datasets::SmallDirectConvolutionShapes(),
66 combine(framework::dataset::make("StrideX", 1, 3),
67 combine(framework::dataset::make("StrideY", 1, 3),
68 combine(framework::dataset::make("PadX", 0),
69 combine(framework::dataset::make("PadY", 0),
70 combine(framework::dataset::make("KernelSize", 1),
71 framework::dataset::make("NumKernels", { 1, 4, 8, 16 })))))));
72} // namespace
73
74TEST_SUITE(NEON)
75TEST_SUITE(DirectConvolutionLayer)
76
77//TODO(COMPMID-415): Configuration tests?
78
79template <typename T>
80using NEDirectConvolutionLayerFixture = DirectConvolutionValidationFixture<Tensor, Accessor, NEDirectConvolutionLayer, T>;
81
82TEST_SUITE(Float)
83#ifdef ARM_COMPUTE_ENABLE_FP16
84TEST_SUITE(FP16)
85FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixture<half_float::half>, framework::DatasetMode::ALL, combine(data, framework::dataset::make("DataType", DataType::F16)))
86{
87 // Validate output
88 validate(Accessor(_target), _reference, tolerance_fp16);
89}
90TEST_SUITE_END()
91#endif /* ARM_COMPUTE_ENABLE_FP16 */
92
93TEST_SUITE(FP32)
94FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixture<float>, framework::DatasetMode::ALL, combine(data, framework::dataset::make("DataType", DataType::F32)))
95{
96 // Validate output
97 validate(Accessor(_target), _reference, tolerance_fp32);
98}
99TEST_SUITE_END()
100TEST_SUITE_END()
101
102template <typename T>
103using NEDirectConvolutionLayerFixedPointFixture = DirectConvolutionValidationFixedPointFixture<Tensor, Accessor, NEDirectConvolutionLayer, T>;
104
105TEST_SUITE(Quantized)
106TEST_SUITE(QS8)
107// We test for fixed point precision [4,6]
108FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(data, framework::dataset::make("DataType", DataType::QS8)),
109 framework::dataset::make("FractionalBits", 4, 7)))
110{
111 // Validate output
112 validate(Accessor(_target), _reference, tolerance_qs);
113}
114TEST_SUITE_END()
115
116TEST_SUITE(QS16)
117// We test for fixed point precision [4,13]
118FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(data_qs16, framework::dataset::make("DataType", DataType::QS16)),
119 framework::dataset::make("FractionalBits", 4, 14)))
120{
121 // Validate output
122 validate(Accessor(_target), _reference, tolerance_qs);
123}
124TEST_SUITE_END()
125TEST_SUITE_END()
126
127TEST_SUITE_END()
128TEST_SUITE_END()
129} // namespace validation
130} // namespace test
131} // namespace arm_compute