blob: 376032c382d18e7f9b135144de975905f06602f2 [file] [log] [blame]
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +01001/*
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +00002 * Copyright (c) 2017-2018 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 +010086DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallGEMMDataset(), datasets::LargeGEMMDataset()), CNNDataTypes),
87 shape_a, shape_b, shape_c, output_shape, alpha, beta, data_type)
88{
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010089 // Create tensors
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010090 CLTensor a = create_tensor<CLTensor>(shape_a, data_type, 1);
91 CLTensor b = create_tensor<CLTensor>(shape_b, data_type, 1);
92 CLTensor c = create_tensor<CLTensor>(shape_c, data_type, 1);
93 CLTensor dst = create_tensor<CLTensor>(output_shape, data_type, 1);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010094
95 ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS);
96 ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS);
97 ARM_COMPUTE_EXPECT(c.info()->is_resizable(), framework::LogLevel::ERRORS);
98 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
99
100 // Create and configure function
101 CLGEMM gemm;
102 gemm.configure(&a, &b, &c, &dst, alpha, beta);
103
104 //TODO(COMPMID-415): Validate valid region
105}
106
107template <typename T>
108using CLGEMMFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T>;
109
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100110template <typename T>
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000111using CLGEMMOutput3DFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T, false, false, true>;
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100112
113template <typename T>
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000114using CLGEMMInputOutput3DFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T, false, true, true>;
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100115
Pablo Tello088cc7f2017-12-07 15:20:55 +0000116TEST_SUITE(TRANSPOSE_1XW)
117using CLGEMMTranspose1xW = CLSynthetizeFunctionWithZeroConstantBorder<CLGEMMTranspose1xWKernel, 4>;
118using CLGEMMTranspose1xWFixture = GEMMTranspose1xWValidationFixture<CLTensor, CLAccessor, CLGEMMTranspose1xW, float>;
119TEST_SUITE(FP32)
120FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * framework::dataset::make("DataType", DataType::F32))
121{
122 // Validate output
123 validate(CLAccessor(_target), _reference);
124}
125TEST_SUITE_END() // FP32
126
Pablo Tello088cc7f2017-12-07 15:20:55 +0000127TEST_SUITE_END() //TRANSPOSE_1XW
128
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100129TEST_SUITE(Float)
130TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000131FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
132 framework::dataset::make("ReshapeWeights", { true, false })),
133 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100134{
135 // Validate output
steniu01f81652d2017-09-11 15:29:12 +0100136 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100137}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000138FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
139 framework::dataset::make("ReshapeWeights", { true })),
140 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100141{
142 // Validate output
steniu01f81652d2017-09-11 15:29:12 +0100143 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100144}
145TEST_SUITE_END()
146
147TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000148FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
149 framework::dataset::make("ReshapeWeights", { true, false })),
150 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100151{
152 // Validate output
153 validate(CLAccessor(_target), _reference, tolerance_f32);
154}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000155FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
156 framework::dataset::make("ReshapeWeights", { true, false })),
157 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100158{
159 // Validate output
Michele Di Giorgioff6c2602018-02-26 15:22:16 +0000160 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100161}
162TEST_SUITE_END()
163TEST_SUITE_END()
164
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100165TEST_SUITE(INPUT_OUTPUT_3D)
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000166TEST_SUITE(Float)
167TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000168FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMInputOutput3DFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMInputOutput3DDataset(),
169 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100170 framework::dataset::make("DataType", DataType::F32)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000171{
172 // Validate output
173 validate(CLAccessor(_target), _reference, tolerance_f32);
174}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000175FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMInputOutput3DFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMInputOutput3DDataset(),
176 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100177 framework::dataset::make("DataType", DataType::F32)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000178{
179 // Validate output
180 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
181}
182TEST_SUITE_END() // FP32
183
184TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000185FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMInputOutput3DFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMInputOutput3DDataset(),
186 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100187 framework::dataset::make("DataType", DataType::F16)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000188{
189 // Validate output
190 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
191}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000192FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMInputOutput3DFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMInputOutput3DDataset(),
193 framework::dataset::make("ReshapeWeights", { true, false })),
194 framework::dataset::make("DataType", DataType::F16)))
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100195{
196 // Validate output
197 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
198}
199TEST_SUITE_END() // FP16
200
201TEST_SUITE_END() // Float
202TEST_SUITE_END() // INPUT_OUTPUT_3D
203
204TEST_SUITE(OUTPUT_3D)
205TEST_SUITE(Float)
206TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000207FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMOutput3DFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMOutput3DDataset(),
208 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100209 framework::dataset::make("DataType", DataType::F32)))
210{
211 // Validate output
212 validate(CLAccessor(_target), _reference, tolerance_f32);
213}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000214FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMOutput3DFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMOutput3DDataset(),
215 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100216 framework::dataset::make("DataType", DataType::F32)))
217{
218 // Validate output
219 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
220}
221TEST_SUITE_END() // FP32
222
223TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000224FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMOutput3DFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMOutput3DDataset(),
225 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100226 framework::dataset::make("DataType", DataType::F16)))
227{
228 // Validate output
229 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
230}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000231FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMOutput3DFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMOutput3DDataset(),
232 framework::dataset::make("ReshapeWeights", { true, false })),
233 framework::dataset::make("DataType", DataType::F16)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000234{
235 // Validate output
236 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
237}
238TEST_SUITE_END() // FP16
239
240TEST_SUITE_END() // Float
241TEST_SUITE_END() // OUTPUT_3D
242
243TEST_SUITE_END() // GEMM
244TEST_SUITE_END() // CL
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100245} // namespace validation
246} // namespace test
247} // namespace arm_compute