blob: 1145d0b79e7592048139584eb23629db0ecb1e2e [file] [log] [blame]
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +01001/*
Pablo Tello088cc7f2017-12-07 15:20:55 +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 Tello2fdc4092017-11-23 15:50:08 +000024#include "arm_compute/core/NEON/kernels/NEGEMMInterleave4x4Kernel.h"
Pablo Tello088cc7f2017-12-07 15:20:55 +000025#include "arm_compute/core/NEON/kernels/NEGEMMTranspose1xWKernel.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010026#include "arm_compute/core/Types.h"
27#include "arm_compute/runtime/NEON/functions/NEGEMM.h"
28#include "arm_compute/runtime/Tensor.h"
29#include "arm_compute/runtime/TensorAllocator.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010030#include "tests/NEON/Accessor.h"
Pablo Tello2fdc4092017-11-23 15:50:08 +000031#include "tests/NEON/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"
35#include "tests/framework/Asserts.h"
36#include "tests/framework/Macros.h"
37#include "tests/framework/datasets/Datasets.h"
38#include "tests/validation/Validation.h"
39#include "tests/validation/fixtures/GEMMFixture.h"
Pablo Tello2fdc4092017-11-23 15:50:08 +000040#include "tests/validation/fixtures/GEMMInterleave4x4Fixture.h"
Pablo Tello088cc7f2017-12-07 15:20:55 +000041#include "tests/validation/fixtures/GEMMTranspose1xWFixture.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010042
43namespace arm_compute
44{
45namespace test
46{
47namespace validation
48{
49namespace
50{
51constexpr AbsoluteTolerance<float> tolerance_f(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for floating point data types */
52constexpr AbsoluteTolerance<float> tolerance_q(1.0f); /**< Tolerance value for comparing reference's output against implementation's output for fixed point data types */
53
54/** CNN data types */
55const auto CNNDataTypes = framework::dataset::make("DataType",
56{
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000057#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010058 DataType::F16,
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000059#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010060 DataType::F32,
61 DataType::QS8,
62 DataType::QS16,
63});
Pablo Tello2fdc4092017-11-23 15:50:08 +000064
65const auto data_interleave = framework::dataset::make("M", 8, 12) * framework::dataset::make("N", 8, 12);
Pablo Tello088cc7f2017-12-07 15:20:55 +000066const auto data_transpose = framework::dataset::make("M", 8, 14) * framework::dataset::make("N", 7, 14);
67
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010068} // namespace
69
70TEST_SUITE(NEON)
71TEST_SUITE(GEMM)
72
Pablo Tello088cc7f2017-12-07 15:20:55 +000073TEST_SUITE(TRANSPOSE_1XW)
74using NEGEMMTranspose1xW = NESynthetizeFunctionWithZeroConstantBorder<NEGEMMTranspose1xWKernel, 4>;
75using NEGEMMTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, NEGEMMTranspose1xW, float>;
76TEST_SUITE(FP32)
77FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * framework::dataset::make("DataType", DataType::F32))
78{
79 // Validate output
80 validate(Accessor(_target), _reference);
81}
82TEST_SUITE_END() // FP32
83
84TEST_SUITE(Quantized)
85TEST_SUITE(QS8)
86using NEGEMMTranspose1xW = NESynthetizeFunctionWithZeroConstantBorder<NEGEMMTranspose1xWKernel, 16>;
87using NEGEMMTranspose1xWFixture = GEMMTranspose1xWValidationFixedPointFixture<Tensor, Accessor, NEGEMMTranspose1xW, int8_t>;
88FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose *
89 framework::dataset::make("DataType", DataType::QS8)
90 * framework::dataset::make("FractionalBits", 1, 7))
91{
92 // Validate output
93 validate(Accessor(_target), _reference);
94}
95TEST_SUITE_END()
96
97TEST_SUITE(QS16)
98using NEGEMMTranspose1xW = NESynthetizeFunctionWithZeroConstantBorder<NEGEMMTranspose1xWKernel, 8>;
99using NEGEMMTranspose1xWFixture = GEMMTranspose1xWValidationFixedPointFixture<Tensor, Accessor, NEGEMMTranspose1xW, int16_t>;
100FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose *
101 framework::dataset::make("DataType", DataType::QS16)
102 * framework::dataset::make("FractionalBits", 1, 14))
103{
104 // Validate output
105 validate(Accessor(_target), _reference);
106}
107TEST_SUITE_END()
108
109TEST_SUITE_END()
110
111TEST_SUITE_END() // TRANSPOSE_1XW
112
Pablo Tello2fdc4092017-11-23 15:50:08 +0000113TEST_SUITE(INTERLEAVE_4X4)
114using NEGEMMInterleave4x4 = NESynthetizeFunctionWithZeroConstantBorder<NEGEMMInterleave4x4Kernel, 4>;
115
116TEST_SUITE(FP32)
117using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, NEGEMMInterleave4x4, float>;
118FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * framework::dataset::make("DataType", DataType::F32))
119{
120 // Validate output
121 validate(Accessor(_target), _reference);
122}
123TEST_SUITE_END() // FP32
124
125TEST_SUITE(Quantized)
126TEST_SUITE(QS8)
127using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixedPointFixture<Tensor, Accessor, NEGEMMInterleave4x4, int8_t>;
128FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave *
129 framework::dataset::make("DataType", DataType::QS8)
130 * framework::dataset::make("FractionalBits", 1, 7))
131{
132 // Validate output
133 validate(Accessor(_target), _reference);
134}
135TEST_SUITE_END()
136
137TEST_SUITE(QS16)
138using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixedPointFixture<Tensor, Accessor, NEGEMMInterleave4x4, int16_t>;
139FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave *
140 framework::dataset::make("DataType", DataType::QS16)
141 * framework::dataset::make("FractionalBits", 1, 14))
142{
143 // Validate output
144 validate(Accessor(_target), _reference);
145}
146TEST_SUITE_END()
147
148TEST_SUITE_END()
149
150TEST_SUITE_END() // INTERLEAVE_4X4
151
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100152DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallGEMMDataset(), datasets::LargeGEMMDataset()), CNNDataTypes),
153 shape_a, shape_b, shape_c, output_shape, alpha, beta, data_type)
154{
155 // Set fixed point position data type allowed
156 const int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0;
157
158 // Create tensors
159 Tensor a = create_tensor<Tensor>(shape_a, data_type, 1, fixed_point_position);
160 Tensor b = create_tensor<Tensor>(shape_b, data_type, 1, fixed_point_position);
161 Tensor c = create_tensor<Tensor>(shape_c, data_type, 1, fixed_point_position);
162 Tensor dst = create_tensor<Tensor>(output_shape, data_type, 1, fixed_point_position);
163
164 ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS);
165 ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS);
166 ARM_COMPUTE_EXPECT(c.info()->is_resizable(), framework::LogLevel::ERRORS);
167 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
168
169 // Create and configure function
170 NEGEMM gemm;
171 gemm.configure(&a, &b, &c, &dst, alpha, beta);
172
173 //TODO(COMPMID-415): Validate valid region
174}
175
176template <typename T>
177using NEGEMMFixture = GEMMValidationFixture<Tensor, Accessor, NEGEMM, T>;
178
179TEST_SUITE(Float)
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000180#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100181TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100182FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallGEMMDataset(), framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100183{
184 // Validate output
185 validate(Accessor(_target), _reference, tolerance_f);
186}
Georgios Pinitas583137c2017-08-31 18:12:42 +0100187FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMDataset(), framework::dataset::make("DataType",
188 DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100189{
190 // Validate output
191 validate(Accessor(_target), _reference, tolerance_f);
192}
193TEST_SUITE_END()
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000194#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100195
196TEST_SUITE(FP32)
197FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallGEMMDataset(), framework::dataset::make("DataType", DataType::F32)))
198{
199 // Validate output
200 validate(Accessor(_target), _reference, tolerance_f);
201}
202FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMDataset(), framework::dataset::make("DataType", DataType::F32)))
203{
204 // Validate output
205 validate(Accessor(_target), _reference, tolerance_f);
206}
207TEST_SUITE_END()
208TEST_SUITE_END()
209
210template <typename T>
211using NEGEMMFixedPointFixture = GEMMValidationFixedPointFixture<Tensor, Accessor, NEGEMM, T>;
212
213TEST_SUITE(Quantized)
214TEST_SUITE(QS8)
215FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
216 framework::dataset::make("DataType",
217 DataType::QS8)),
218 framework::dataset::make("FractionalBits", 1, 7)))
219{
220 // Validate output
221 validate(Accessor(_target), _reference, tolerance_q);
222}
223FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
224 framework::dataset::make("DataType",
225 DataType::QS8)),
226 framework::dataset::make("FractionalBits", 1, 7)))
227{
228 // Validate output
229 validate(Accessor(_target), _reference, tolerance_q);
230}
231TEST_SUITE_END()
232
233TEST_SUITE(QS16)
234FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
235 framework::dataset::make("DataType",
236 DataType::QS16)),
237 framework::dataset::make("FractionalBits", 1, 14)))
238{
239 // Validate output
240 validate(Accessor(_target), _reference, tolerance_q);
241}
242FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
243 framework::dataset::make("DataType",
244 DataType::QS16)),
245 framework::dataset::make("FractionalBits", 1, 14)))
246{
247 // Validate output
248 validate(Accessor(_target), _reference, tolerance_q);
249}
250TEST_SUITE_END()
251TEST_SUITE_END()
252
253TEST_SUITE_END()
254TEST_SUITE_END()
255} // namespace validation
256} // namespace test
257} // namespace arm_compute