blob: 2bebc90d7f2bd7e1f41bcb8b9ecf6ed948028cc7 [file] [log] [blame]
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +01001/*
Michalis Spyrou80943252019-01-10 17:19:50 +00002 * Copyright (c) 2017-2019 ARM Limited.
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +01003 *
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 */
Pablo Tello1d1c0262017-12-08 16:02:38 +000024#include "arm_compute/core/CL/kernels/CLGEMMInterleave4x4Kernel.h"
Pablo Tello088cc7f2017-12-07 15:20:55 +000025#include "arm_compute/core/CL/kernels/CLGEMMTranspose1xWKernel.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010026#include "arm_compute/core/Types.h"
27#include "arm_compute/runtime/CL/CLTensor.h"
28#include "arm_compute/runtime/CL/CLTensorAllocator.h"
29#include "arm_compute/runtime/CL/functions/CLGEMM.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010030#include "tests/CL/CLAccessor.h"
Pablo Tello1d1c0262017-12-08 16:02:38 +000031#include "tests/CL/Helper.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010032#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010033#include "tests/datasets/LargeGEMMDataset.h"
34#include "tests/datasets/SmallGEMMDataset.h"
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +000035#include "tests/datasets/TinyGEMMDataset.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010036#include "tests/framework/Asserts.h"
37#include "tests/framework/Macros.h"
38#include "tests/framework/datasets/Datasets.h"
39#include "tests/validation/Validation.h"
40#include "tests/validation/fixtures/GEMMFixture.h"
Pablo Tello1d1c0262017-12-08 16:02:38 +000041#include "tests/validation/fixtures/GEMMInterleave4x4Fixture.h"
Pablo Tello088cc7f2017-12-07 15:20:55 +000042#include "tests/validation/fixtures/GEMMTranspose1xWFixture.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010043
44namespace arm_compute
45{
46namespace test
47{
48namespace validation
49{
50namespace
51{
Michele Di Giorgioff6c2602018-02-26 15:22:16 +000052RelativeTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for floating point data types */
53constexpr float abs_tolerance_f32(
54 0.0001f); /**< Absolute tolerance value for comparing reference's output against implementation's output for floating point data types in case using relative tolerance fails because of small values */
steniu01f81652d2017-09-11 15:29:12 +010055RelativeTolerance<half_float::half> tolerance_f16(half(0.2)); /**< Tolerance value for comparing reference's output against implementation's output for floating point data types */
Pablo Tello1d1c0262017-12-08 16:02:38 +000056constexpr float tolerance_num = 0.02f; /**< Tolerance number */
57const auto data_interleave = framework::dataset::make("M", 8, 14) * framework::dataset::make("N", 7, 14);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010058
59/** CNN data types */
60const auto CNNDataTypes = framework::dataset::make("DataType",
61{
62 DataType::F16,
63 DataType::F32,
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010064});
65} // namespace
66
Pablo Tello088cc7f2017-12-07 15:20:55 +000067const auto data_transpose = framework::dataset::make("M", 8, 14) * framework::dataset::make("N", 7, 14);
68
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010069TEST_SUITE(CL)
70TEST_SUITE(GEMM)
71
Pablo Tello1d1c0262017-12-08 16:02:38 +000072TEST_SUITE(INTERLEAVE_4X4)
73using CLGEMMInterleave4x4 = CLSynthetizeFunctionWithZeroConstantBorder<CLGEMMInterleave4x4Kernel, 4>;
74
75TEST_SUITE(FP32)
76using CLGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<CLTensor, CLAccessor, CLGEMMInterleave4x4, float>;
77FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * framework::dataset::make("DataType", DataType::F32))
78{
79 // Validate output
80 validate(CLAccessor(_target), _reference);
81}
82TEST_SUITE_END() // FP32
83
Pablo Tello1d1c0262017-12-08 16:02:38 +000084TEST_SUITE_END() // INTERLEAVE_4X4
85
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010086template <typename T>
87using CLGEMMFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T>;
88
Gian Marco Iodice68a3f562018-07-26 11:44:03 +010089template <typename T>
Pablo Tello0e37b5c2018-10-30 11:18:37 +000090using CLGEMMOutput3DFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T, false, false, true>;
Gian Marco Iodice68a3f562018-07-26 11:44:03 +010091
92template <typename T>
Pablo Tello0e37b5c2018-10-30 11:18:37 +000093using CLGEMMInputOutput3DFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T, false, true, true>;
Gian Marco Iodice68a3f562018-07-26 11:44:03 +010094
Pablo Tello088cc7f2017-12-07 15:20:55 +000095TEST_SUITE(TRANSPOSE_1XW)
96using CLGEMMTranspose1xW = CLSynthetizeFunctionWithZeroConstantBorder<CLGEMMTranspose1xWKernel, 4>;
97using CLGEMMTranspose1xWFixture = GEMMTranspose1xWValidationFixture<CLTensor, CLAccessor, CLGEMMTranspose1xW, float>;
98TEST_SUITE(FP32)
99FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * framework::dataset::make("DataType", DataType::F32))
100{
101 // Validate output
102 validate(CLAccessor(_target), _reference);
103}
104TEST_SUITE_END() // FP32
105
Pablo Tello088cc7f2017-12-07 15:20:55 +0000106TEST_SUITE_END() //TRANSPOSE_1XW
107
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100108TEST_SUITE(Float)
109TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000110FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
111 framework::dataset::make("ReshapeWeights", { true, false })),
112 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100113{
114 // Validate output
steniu01f81652d2017-09-11 15:29:12 +0100115 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100116}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000117FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
118 framework::dataset::make("ReshapeWeights", { true })),
119 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100120{
121 // Validate output
steniu01f81652d2017-09-11 15:29:12 +0100122 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100123}
124TEST_SUITE_END()
125
126TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000127FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
128 framework::dataset::make("ReshapeWeights", { true, false })),
129 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100130{
131 // Validate output
132 validate(CLAccessor(_target), _reference, tolerance_f32);
133}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000134FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
135 framework::dataset::make("ReshapeWeights", { true, false })),
136 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100137{
138 // Validate output
Michele Di Giorgioff6c2602018-02-26 15:22:16 +0000139 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100140}
141TEST_SUITE_END()
142TEST_SUITE_END()
143
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100144TEST_SUITE(INPUT_OUTPUT_3D)
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000145TEST_SUITE(Float)
146TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000147FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMInputOutput3DFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMInputOutput3DDataset(),
148 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100149 framework::dataset::make("DataType", DataType::F32)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000150{
151 // Validate output
152 validate(CLAccessor(_target), _reference, tolerance_f32);
153}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000154FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMInputOutput3DFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMInputOutput3DDataset(),
155 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100156 framework::dataset::make("DataType", DataType::F32)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000157{
158 // Validate output
159 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
160}
161TEST_SUITE_END() // FP32
162
163TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000164FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMInputOutput3DFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMInputOutput3DDataset(),
165 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100166 framework::dataset::make("DataType", DataType::F16)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000167{
168 // Validate output
169 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
170}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000171FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMInputOutput3DFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMInputOutput3DDataset(),
172 framework::dataset::make("ReshapeWeights", { true, false })),
173 framework::dataset::make("DataType", DataType::F16)))
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100174{
175 // Validate output
176 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
177}
178TEST_SUITE_END() // FP16
179
180TEST_SUITE_END() // Float
181TEST_SUITE_END() // INPUT_OUTPUT_3D
182
183TEST_SUITE(OUTPUT_3D)
184TEST_SUITE(Float)
185TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000186FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMOutput3DFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMOutput3DDataset(),
187 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100188 framework::dataset::make("DataType", DataType::F32)))
189{
190 // Validate output
191 validate(CLAccessor(_target), _reference, tolerance_f32);
192}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000193FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMOutput3DFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMOutput3DDataset(),
194 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100195 framework::dataset::make("DataType", DataType::F32)))
196{
197 // Validate output
198 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
199}
200TEST_SUITE_END() // FP32
201
202TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000203FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMOutput3DFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMOutput3DDataset(),
204 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100205 framework::dataset::make("DataType", DataType::F16)))
206{
207 // Validate output
208 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
209}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000210FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMOutput3DFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMOutput3DDataset(),
211 framework::dataset::make("ReshapeWeights", { true, false })),
212 framework::dataset::make("DataType", DataType::F16)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000213{
214 // Validate output
215 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
216}
217TEST_SUITE_END() // FP16
218
219TEST_SUITE_END() // Float
220TEST_SUITE_END() // OUTPUT_3D
221
222TEST_SUITE_END() // GEMM
223TEST_SUITE_END() // CL
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100224} // namespace validation
225} // namespace test
226} // namespace arm_compute