blob: 25e881f4ceb4fbd8530555a15e444624867fd298 [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/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLDirectConvolutionLayer.h"
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010028#include "tests/CL/CLAccessor.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{
steniu013e05e4e2017-08-25 17:18:01 +010045// COMPMID-517 Invesitgate the mismatch to see whether it is a real bug
Georgios Pinitas583137c2017-08-31 18:12:42 +010046RelativeTolerance<half> tolerance_fp16(half(0.2)); /**< Tolerance for floating point tests */
47RelativeTolerance<float> tolerance_fp32(0.02f); /**< Tolerance for floating point tests */
48constexpr float tolerance_num = 0.07f; /**< Tolerance number */
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010049
Michalis Spyroudef665a2017-08-14 11:26:37 +010050constexpr AbsoluteTolerance<int8_t> tolerance_qs8(0); /**< Tolerance for fixed point tests */
51constexpr AbsoluteTolerance<int16_t> tolerance_qs16(0); /**< Tolerance for fixed point tests */
52
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010053/** Direct convolution data set. */
steniu01db006682017-08-09 16:26:22 +010054const auto data_quantized = combine(datasets::SmallDirectConvolutionShapes(),
55 combine(framework::dataset::make("StrideX", 1, 3),
56 combine(framework::dataset::make("StrideY", 1, 3),
57 combine(concat(combine(framework::dataset::make("PadX", 0),
58 combine(framework::dataset::make("PadY", 0),
59 framework::dataset::make("KernelSize", 1))),
60 combine(framework::dataset::make("PadX", 0, 2),
61 combine(framework::dataset::make("PadY", 0, 2),
62 framework::dataset::make("KernelSize", { 3 })))),
63 framework::dataset::make("NumKernels", { 1, 4, 8, 16 })))));
64
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010065const auto data = combine(datasets::SmallDirectConvolutionShapes(),
66 combine(framework::dataset::make("StrideX", 1, 3),
67 combine(framework::dataset::make("StrideY", 1, 3),
68 combine(concat(combine(framework::dataset::make("PadX", 0),
69 combine(framework::dataset::make("PadY", 0),
70 framework::dataset::make("KernelSize", 1))),
71 combine(framework::dataset::make("PadX", 0, 2),
72 combine(framework::dataset::make("PadY", 0, 2),
steniu01db006682017-08-09 16:26:22 +010073 framework::dataset::make("KernelSize", { 3, 5 })))),
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010074 framework::dataset::make("NumKernels", { 1, 4, 8, 16 })))));
75} // namespace
76
77TEST_SUITE(CL)
78TEST_SUITE(DirectConvolutionLayer)
79
80//TODO(COMPMID-415): Configuration tests?
81
82template <typename T>
83using CLDirectConvolutionLayerFixture = DirectConvolutionValidationFixture<CLTensor, CLAccessor, CLDirectConvolutionLayer, T>;
84
85TEST_SUITE(Float)
86TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +010087FIXTURE_DATA_TEST_CASE(Run, CLDirectConvolutionLayerFixture<half>, framework::DatasetMode::ALL, combine(data, framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010088{
89 // Validate output
steniu013e05e4e2017-08-25 17:18:01 +010090 validate(CLAccessor(_target), _reference, tolerance_fp16, tolerance_num);
Moritz Pflanzerb3d25792017-07-26 11:49:37 +010091}
92TEST_SUITE_END()
93
94TEST_SUITE(FP32)
95FIXTURE_DATA_TEST_CASE(Run, CLDirectConvolutionLayerFixture<float>, framework::DatasetMode::ALL, combine(data, framework::dataset::make("DataType", DataType::F32)))
96{
97 // Validate output
98 validate(CLAccessor(_target), _reference, tolerance_fp32);
99}
100TEST_SUITE_END()
101TEST_SUITE_END()
102
Michalis Spyroudef665a2017-08-14 11:26:37 +0100103template <typename T>
104using CLDirectConvolutionLayerFixedPointFixture = DirectConvolutionValidationFixedPointFixture<CLTensor, CLAccessor, CLDirectConvolutionLayer, T>;
105
106TEST_SUITE(Quantized)
107TEST_SUITE(QS8)
steniu01db006682017-08-09 16:26:22 +0100108FIXTURE_DATA_TEST_CASE(Run, CLDirectConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(data_quantized, framework::dataset::make("DataType", DataType::QS8)),
Michalis Spyroudef665a2017-08-14 11:26:37 +0100109 framework::dataset::make("FractionalBits", 2, 7)))
110{
111 // Validate output
112 validate(CLAccessor(_target), _reference, tolerance_qs8);
113}
114TEST_SUITE_END()
115
116TEST_SUITE(QS16)
steniu01db006682017-08-09 16:26:22 +0100117FIXTURE_DATA_TEST_CASE(Run, CLDirectConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(data_quantized, framework::dataset::make("DataType", DataType::QS16)),
Michalis Spyroudef665a2017-08-14 11:26:37 +0100118 framework::dataset::make("FractionalBits", 2, 15)))
119{
120 // Validate output
121 validate(CLAccessor(_target), _reference, tolerance_qs16);
122}
123TEST_SUITE_END()
124TEST_SUITE_END()
125
Moritz Pflanzerb3d25792017-07-26 11:49:37 +0100126TEST_SUITE_END()
127TEST_SUITE_END()
128} // namespace validation
129} // namespace test
130} // namespace arm_compute