blob: c9540c352a3a350d169ac7e51ab5fd7b0841c3c3 [file] [log] [blame]
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * 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 */
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 */
Pablo Tello1d1c0262017-12-08 16:02:38 +000052constexpr float tolerance_num = 0.02f; /**< Tolerance number */
53const auto data_interleave = framework::dataset::make("M", 8, 14) * framework::dataset::make("N", 7, 14);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010054
55/** CNN data types */
56const auto CNNDataTypes = framework::dataset::make("DataType",
57{
58 DataType::F16,
59 DataType::F32,
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010060});
61} // namespace
62
Pablo Tello088cc7f2017-12-07 15:20:55 +000063const auto data_transpose = framework::dataset::make("M", 8, 14) * framework::dataset::make("N", 7, 14);
64
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010065TEST_SUITE(CL)
66TEST_SUITE(GEMM)
67
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010068template <typename T>
69using CLGEMMFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T>;
70
Gian Marco Iodice68a3f562018-07-26 11:44:03 +010071template <typename T>
Pablo Tello0e37b5c2018-10-30 11:18:37 +000072using CLGEMMOutput3DFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T, false, false, true>;
Gian Marco Iodice68a3f562018-07-26 11:44:03 +010073
74template <typename T>
Pablo Tello0e37b5c2018-10-30 11:18:37 +000075using CLGEMMInputOutput3DFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T, false, true, true>;
Gian Marco Iodice68a3f562018-07-26 11:44:03 +010076
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010077TEST_SUITE(Float)
78TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +000079FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
80 framework::dataset::make("ReshapeWeights", { true, false })),
81 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010082{
83 // Validate output
steniu01f81652d2017-09-11 15:29:12 +010084 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010085}
Pablo Tello0e37b5c2018-10-30 11:18:37 +000086FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
87 framework::dataset::make("ReshapeWeights", { true })),
88 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010089{
90 // Validate output
steniu01f81652d2017-09-11 15:29:12 +010091 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010092}
93TEST_SUITE_END()
94
95TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +000096FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
97 framework::dataset::make("ReshapeWeights", { true, false })),
98 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010099{
100 // Validate output
101 validate(CLAccessor(_target), _reference, tolerance_f32);
102}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000103FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
104 framework::dataset::make("ReshapeWeights", { true, false })),
105 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100106{
107 // Validate output
Michele Di Giorgioff6c2602018-02-26 15:22:16 +0000108 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100109}
110TEST_SUITE_END()
111TEST_SUITE_END()
112
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100113TEST_SUITE(INPUT_OUTPUT_3D)
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000114TEST_SUITE(Float)
115TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000116FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMInputOutput3DFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMInputOutput3DDataset(),
117 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100118 framework::dataset::make("DataType", DataType::F32)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000119{
120 // Validate output
121 validate(CLAccessor(_target), _reference, tolerance_f32);
122}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000123FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMInputOutput3DFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMInputOutput3DDataset(),
124 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100125 framework::dataset::make("DataType", DataType::F32)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000126{
127 // Validate output
128 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
129}
130TEST_SUITE_END() // FP32
131
132TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000133FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMInputOutput3DFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMInputOutput3DDataset(),
134 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100135 framework::dataset::make("DataType", DataType::F16)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000136{
137 // Validate output
138 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
139}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000140FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMInputOutput3DFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMInputOutput3DDataset(),
141 framework::dataset::make("ReshapeWeights", { true, false })),
142 framework::dataset::make("DataType", DataType::F16)))
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100143{
144 // Validate output
145 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
146}
147TEST_SUITE_END() // FP16
148
149TEST_SUITE_END() // Float
150TEST_SUITE_END() // INPUT_OUTPUT_3D
151
152TEST_SUITE(OUTPUT_3D)
153TEST_SUITE(Float)
154TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000155FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMOutput3DFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMOutput3DDataset(),
156 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100157 framework::dataset::make("DataType", DataType::F32)))
158{
159 // Validate output
160 validate(CLAccessor(_target), _reference, tolerance_f32);
161}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000162FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMOutput3DFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMOutput3DDataset(),
163 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100164 framework::dataset::make("DataType", DataType::F32)))
165{
166 // Validate output
167 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
168}
169TEST_SUITE_END() // FP32
170
171TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000172FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMOutput3DFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMOutput3DDataset(),
173 framework::dataset::make("ReshapeWeights", { true, false })),
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100174 framework::dataset::make("DataType", DataType::F16)))
175{
176 // Validate output
177 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
178}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000179FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMOutput3DFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMOutput3DDataset(),
180 framework::dataset::make("ReshapeWeights", { true, false })),
181 framework::dataset::make("DataType", DataType::F16)))
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000182{
183 // Validate output
184 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
185}
186TEST_SUITE_END() // FP16
187
188TEST_SUITE_END() // Float
189TEST_SUITE_END() // OUTPUT_3D
190
191TEST_SUITE_END() // GEMM
192TEST_SUITE_END() // CL
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100193} // namespace validation
194} // namespace test
195} // namespace arm_compute