blob: 62671e34d7bd90c8ce890ef57953268bcbcd5be5 [file] [log] [blame]
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
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"
29#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010030#include "tests/datasets/LargeGEMMDataset.h"
31#include "tests/datasets/SmallGEMMDataset.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Macros.h"
34#include "tests/framework/datasets/Datasets.h"
35#include "tests/validation/Validation.h"
36#include "tests/validation/fixtures/GEMMFixture.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010037
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
steniu01f81652d2017-09-11 15:29:12 +010046RelativeTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for floating point data types */
47RelativeTolerance<half_float::half> tolerance_f16(half(0.2)); /**< Tolerance value for comparing reference's output against implementation's output for floating point data types */
48constexpr AbsoluteTolerance<float> tolerance_q(1.0f); /**< Tolerance value for comparing reference's output against implementation's output for fixed point data types */
49constexpr float tolerance_num = 0.02f; /**< Tolerance number */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010050
51/** CNN data types */
52const auto CNNDataTypes = framework::dataset::make("DataType",
53{
54 DataType::F16,
55 DataType::F32,
56 DataType::QS8,
57 DataType::QS16,
58});
59} // namespace
60
61TEST_SUITE(CL)
62TEST_SUITE(GEMM)
63
64DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallGEMMDataset(), datasets::LargeGEMMDataset()), CNNDataTypes),
65 shape_a, shape_b, shape_c, output_shape, alpha, beta, data_type)
66{
67 // Set fixed point position data type allowed
68 const int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0;
69
70 // Create tensors
71 CLTensor a = create_tensor<CLTensor>(shape_a, data_type, 1, fixed_point_position);
72 CLTensor b = create_tensor<CLTensor>(shape_b, data_type, 1, fixed_point_position);
73 CLTensor c = create_tensor<CLTensor>(shape_c, data_type, 1, fixed_point_position);
74 CLTensor dst = create_tensor<CLTensor>(output_shape, data_type, 1, fixed_point_position);
75
76 ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS);
77 ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS);
78 ARM_COMPUTE_EXPECT(c.info()->is_resizable(), framework::LogLevel::ERRORS);
79 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
80
81 // Create and configure function
82 CLGEMM gemm;
83 gemm.configure(&a, &b, &c, &dst, alpha, beta);
84
85 //TODO(COMPMID-415): Validate valid region
86}
87
88template <typename T>
89using CLGEMMFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T>;
90
91TEST_SUITE(Float)
92TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +010093FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallGEMMDataset(), framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010094{
95 // Validate output
steniu01f81652d2017-09-11 15:29:12 +010096 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010097}
Georgios Pinitas583137c2017-08-31 18:12:42 +010098FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMDataset(), framework::dataset::make("DataType",
99 DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100100{
101 // Validate output
steniu01f81652d2017-09-11 15:29:12 +0100102 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100103}
104TEST_SUITE_END()
105
106TEST_SUITE(FP32)
107FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallGEMMDataset(), framework::dataset::make("DataType", DataType::F32)))
108{
109 // Validate output
110 validate(CLAccessor(_target), _reference, tolerance_f32);
111}
112FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMDataset(), framework::dataset::make("DataType", DataType::F32)))
113{
114 // Validate output
115 validate(CLAccessor(_target), _reference, tolerance_f32);
116}
117TEST_SUITE_END()
118TEST_SUITE_END()
119
120template <typename T>
121using CLGEMMFixedPointFixture = GEMMValidationFixedPointFixture<CLTensor, CLAccessor, CLGEMM, T>;
122
123TEST_SUITE(Quantized)
124TEST_SUITE(QS8)
125FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
126 framework::dataset::make("DataType",
127 DataType::QS8)),
128 framework::dataset::make("FractionalBits", 1, 7)))
129{
130 // Validate output
131 validate(CLAccessor(_target), _reference, tolerance_q);
132}
133FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
134 framework::dataset::make("DataType",
135 DataType::QS8)),
136 framework::dataset::make("FractionalBits", 1, 7)))
137{
138 // Validate output
139 validate(CLAccessor(_target), _reference, tolerance_q);
140}
141TEST_SUITE_END()
142
143TEST_SUITE(QS16)
144FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
145 framework::dataset::make("DataType",
146 DataType::QS16)),
147 framework::dataset::make("FractionalBits", 1, 14)))
148{
149 // Validate output
150 validate(CLAccessor(_target), _reference, tolerance_q);
151}
152FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
153 framework::dataset::make("DataType",
154 DataType::QS16)),
155 framework::dataset::make("FractionalBits", 1, 14)))
156{
157 // Validate output
158 validate(CLAccessor(_target), _reference, tolerance_q);
159}
160TEST_SUITE_END()
161TEST_SUITE_END()
162
163TEST_SUITE_END()
164TEST_SUITE_END()
165} // namespace validation
166} // namespace test
167} // namespace arm_compute