blob: 16ca14f1d679512aed6d9c3bb87b99625f5d4bf6 [file] [log] [blame]
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +01001/*
SiCong Li13bab712023-01-13 15:29:39 +00002 * Copyright (c) 2017-2023 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 */
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/CLGEMM.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010028#include "tests/CL/CLAccessor.h"
Pablo Tello1d1c0262017-12-08 16:02:38 +000029#include "tests/CL/Helper.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010030#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010031#include "tests/datasets/LargeGEMMDataset.h"
32#include "tests/datasets/SmallGEMMDataset.h"
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +000033#include "tests/datasets/TinyGEMMDataset.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010034#include "tests/framework/Asserts.h"
35#include "tests/framework/Macros.h"
36#include "tests/framework/datasets/Datasets.h"
37#include "tests/validation/Validation.h"
38#include "tests/validation/fixtures/GEMMFixture.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010039
40namespace arm_compute
41{
42namespace test
43{
44namespace validation
45{
46namespace
47{
Michele Di Giorgioff6c2602018-02-26 15:22:16 +000048RelativeTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for floating point data types */
49constexpr float abs_tolerance_f32(
50 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 +010051RelativeTolerance<half_float::half> tolerance_f16(half(0.2)); /**< Tolerance value for comparing reference's output against implementation's output for floating point data types */
SiCong Li6bc4e962020-12-03 12:52:28 +000052constexpr float tolerance_num = 0.02f; /**< Tolerance number */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010053
54/** CNN data types */
55const auto CNNDataTypes = framework::dataset::make("DataType",
56{
57 DataType::F16,
58 DataType::F32,
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010059});
60} // namespace
61
62TEST_SUITE(CL)
63TEST_SUITE(GEMM)
64
SiCong Li13bab712023-01-13 15:29:39 +000065// *INDENT-OFF*
66// clang-format off
67DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
68 framework::dataset::make("LhsInfo", { TensorInfo(TensorShape(27U, 13U), 1, DataType::S32), // Unsupported data type
69 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32),
70 }),
71 framework::dataset::make("RhsInfo",{ TensorInfo(TensorShape(8U, 27U), 1, DataType::S32),
72 TensorInfo(TensorShape(8U, 27U), 1, DataType::F32),
73 })),
74 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(8U, 13U), 1, DataType::S32),
75 TensorInfo(TensorShape(8U, 13U), 1, DataType::F32),
76 })),
77 framework::dataset::make("Expected", { false, true })),
78 lhs_info, rhs_info, output_info, expected)
79{
80 constexpr float alpha = 1.0;
81 constexpr float beta = 0.0;
82 const auto gemm_info = GEMMInfo();
83 bool is_valid = bool(CLGEMM::validate(&lhs_info.clone()->set_is_resizable(true), &rhs_info.clone()->set_is_resizable(true), nullptr, &output_info.clone()->set_is_resizable(true), alpha, beta, gemm_info));
84 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
85}
86// clang-format on
87// *INDENT-ON*
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010088template <typename T>
89using CLGEMMFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T>;
90
Gian Marco Iodice68a3f562018-07-26 11:44:03 +010091template <typename T>
Pablo Tello0e37b5c2018-10-30 11:18:37 +000092using CLGEMMOutput3DFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T, false, false, true>;
Gian Marco Iodice68a3f562018-07-26 11:44:03 +010093
94template <typename T>
Pablo Tello0e37b5c2018-10-30 11:18:37 +000095using CLGEMMInputOutput3DFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T, false, true, true>;
Gian Marco Iodice68a3f562018-07-26 11:44:03 +010096
Mohammed Suhail Munshi13a2d002022-09-05 11:57:34 +010097template <typename T>
98using CLBatchedMatMulFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T, true, false, false, false, false, true>;
99
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100100TEST_SUITE(Float)
101TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000102FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
103 framework::dataset::make("ReshapeWeights", { true, false })),
104 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100105{
106 // Validate output
steniu01f81652d2017-09-11 15:29:12 +0100107 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100108}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000109FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
110 framework::dataset::make("ReshapeWeights", { true })),
111 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100112{
113 // Validate output
steniu01f81652d2017-09-11 15:29:12 +0100114 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100115}
116TEST_SUITE_END()
117
118TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000119FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
120 framework::dataset::make("ReshapeWeights", { true, false })),
121 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100122{
123 // Validate output
124 validate(CLAccessor(_target), _reference, tolerance_f32);
125}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000126FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
127 framework::dataset::make("ReshapeWeights", { true, false })),
128 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100129{
130 // Validate output
Michele Di Giorgioff6c2602018-02-26 15:22:16 +0000131 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100132}
133TEST_SUITE_END()
134TEST_SUITE_END()
135
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100136TEST_SUITE(INPUT_OUTPUT_3D)
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000137TEST_SUITE(Float)
138TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000139FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMInputOutput3DFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMInputOutput3DDataset(),
140 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100141 framework::dataset::make("DataType", DataType::F32)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000142{
143 // Validate output
144 validate(CLAccessor(_target), _reference, tolerance_f32);
145}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000146FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMInputOutput3DFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMInputOutput3DDataset(),
147 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100148 framework::dataset::make("DataType", DataType::F32)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000149{
150 // Validate output
151 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
152}
153TEST_SUITE_END() // FP32
154
155TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000156FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMInputOutput3DFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMInputOutput3DDataset(),
157 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100158 framework::dataset::make("DataType", DataType::F16)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000159{
160 // Validate output
161 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
162}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000163FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMInputOutput3DFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMInputOutput3DDataset(),
164 framework::dataset::make("ReshapeWeights", { true, false })),
165 framework::dataset::make("DataType", DataType::F16)))
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100166{
167 // Validate output
168 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
169}
170TEST_SUITE_END() // FP16
171
172TEST_SUITE_END() // Float
173TEST_SUITE_END() // INPUT_OUTPUT_3D
174
175TEST_SUITE(OUTPUT_3D)
176TEST_SUITE(Float)
177TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000178FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMOutput3DFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMOutput3DDataset(),
179 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100180 framework::dataset::make("DataType", DataType::F32)))
181{
182 // Validate output
183 validate(CLAccessor(_target), _reference, tolerance_f32);
184}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000185FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMOutput3DFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMOutput3DDataset(),
186 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100187 framework::dataset::make("DataType", DataType::F32)))
188{
189 // Validate output
190 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
191}
192TEST_SUITE_END() // FP32
193
194TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000195FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMOutput3DFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMOutput3DDataset(),
196 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100197 framework::dataset::make("DataType", DataType::F16)))
198{
199 // Validate output
200 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
201}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000202FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMOutput3DFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMOutput3DDataset(),
203 framework::dataset::make("ReshapeWeights", { true, false })),
204 framework::dataset::make("DataType", DataType::F16)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000205{
206 // Validate output
207 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
208}
209TEST_SUITE_END() // FP16
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000210TEST_SUITE_END() // Float
211TEST_SUITE_END() // OUTPUT_3D
212
Mohammed Suhail Munshi13a2d002022-09-05 11:57:34 +0100213TEST_SUITE(BATCHED_MATMUL)
214
215TEST_SUITE(FP32)
216FIXTURE_DATA_TEST_CASE(RunSmall, CLBatchedMatMulFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallBatchedMatMulDataset(),
SiCong Li13bab712023-01-13 15:29:39 +0000217 framework::dataset::make("ReshapeWeights", { false })),
218 framework::dataset::make("DataType", DataType::F32)))
Mohammed Suhail Munshi13a2d002022-09-05 11:57:34 +0100219{
220 // Validate output
221 validate(CLAccessor(_target), _reference, tolerance_f32, tolerance_num);
222}
223TEST_SUITE_END()
224
225TEST_SUITE(FP16)
226FIXTURE_DATA_TEST_CASE(RunSmall, CLBatchedMatMulFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallBatchedMatMulDataset(),
SiCong Li13bab712023-01-13 15:29:39 +0000227 framework::dataset::make("ReshapeWeights", { false })),
228 framework::dataset::make("DataType", DataType::F16)))
Mohammed Suhail Munshi13a2d002022-09-05 11:57:34 +0100229{
230 // Validate output
231 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
232}
233TEST_SUITE_END()
234TEST_SUITE_END() // BATCHED_MATMUL
235
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000236TEST_SUITE_END() // GEMM
237TEST_SUITE_END() // CL
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100238} // namespace validation
239} // namespace test
240} // namespace arm_compute