blob: 838920c29d627fd3978aed7b33f326f0b73213e6 [file] [log] [blame]
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +01001/*
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +01002 * Copyright (c) 2017-2020 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
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010065template <typename T>
66using CLGEMMFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T>;
67
Gian Marco Iodice68a3f562018-07-26 11:44:03 +010068template <typename T>
Pablo Tello0e37b5c2018-10-30 11:18:37 +000069using CLGEMMOutput3DFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T, false, false, true>;
Gian Marco Iodice68a3f562018-07-26 11:44:03 +010070
71template <typename T>
Pablo Tello0e37b5c2018-10-30 11:18:37 +000072using CLGEMMInputOutput3DFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T, false, true, true>;
Gian Marco Iodice68a3f562018-07-26 11:44:03 +010073
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010074TEST_SUITE(Float)
75TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +000076FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
77 framework::dataset::make("ReshapeWeights", { true, false })),
78 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010079{
80 // Validate output
steniu01f81652d2017-09-11 15:29:12 +010081 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010082}
Pablo Tello0e37b5c2018-10-30 11:18:37 +000083FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
84 framework::dataset::make("ReshapeWeights", { true })),
85 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010086{
87 // Validate output
steniu01f81652d2017-09-11 15:29:12 +010088 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010089}
90TEST_SUITE_END()
91
92TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +000093FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
94 framework::dataset::make("ReshapeWeights", { true, false })),
95 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010096{
97 // Validate output
98 validate(CLAccessor(_target), _reference, tolerance_f32);
99}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000100FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
101 framework::dataset::make("ReshapeWeights", { true, false })),
102 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100103{
104 // Validate output
Michele Di Giorgioff6c2602018-02-26 15:22:16 +0000105 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100106}
107TEST_SUITE_END()
108TEST_SUITE_END()
109
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100110TEST_SUITE(INPUT_OUTPUT_3D)
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000111TEST_SUITE(Float)
112TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000113FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMInputOutput3DFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMInputOutput3DDataset(),
114 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100115 framework::dataset::make("DataType", DataType::F32)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000116{
117 // Validate output
118 validate(CLAccessor(_target), _reference, tolerance_f32);
119}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000120FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMInputOutput3DFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMInputOutput3DDataset(),
121 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100122 framework::dataset::make("DataType", DataType::F32)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000123{
124 // Validate output
125 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
126}
127TEST_SUITE_END() // FP32
128
129TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000130FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMInputOutput3DFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMInputOutput3DDataset(),
131 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100132 framework::dataset::make("DataType", DataType::F16)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000133{
134 // Validate output
135 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
136}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000137FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMInputOutput3DFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMInputOutput3DDataset(),
138 framework::dataset::make("ReshapeWeights", { true, false })),
139 framework::dataset::make("DataType", DataType::F16)))
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100140{
141 // Validate output
142 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
143}
144TEST_SUITE_END() // FP16
145
146TEST_SUITE_END() // Float
147TEST_SUITE_END() // INPUT_OUTPUT_3D
148
149TEST_SUITE(OUTPUT_3D)
150TEST_SUITE(Float)
151TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000152FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMOutput3DFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMOutput3DDataset(),
153 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100154 framework::dataset::make("DataType", DataType::F32)))
155{
156 // Validate output
157 validate(CLAccessor(_target), _reference, tolerance_f32);
158}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000159FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMOutput3DFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMOutput3DDataset(),
160 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100161 framework::dataset::make("DataType", DataType::F32)))
162{
163 // Validate output
164 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
165}
166TEST_SUITE_END() // FP32
167
168TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000169FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMOutput3DFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMOutput3DDataset(),
170 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100171 framework::dataset::make("DataType", DataType::F16)))
172{
173 // Validate output
174 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
175}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000176FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMOutput3DFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMOutput3DDataset(),
177 framework::dataset::make("ReshapeWeights", { true, false })),
178 framework::dataset::make("DataType", DataType::F16)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000179{
180 // Validate output
181 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
182}
183TEST_SUITE_END() // FP16
184
185TEST_SUITE_END() // Float
186TEST_SUITE_END() // OUTPUT_3D
187
188TEST_SUITE_END() // GEMM
189TEST_SUITE_END() // CL
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100190} // namespace validation
191} // namespace test
192} // namespace arm_compute