blob: 5d2e211d919901ac5a3a11f33fdb4b75daf8ec45 [file] [log] [blame]
Gian Marco Iodiced1f54762019-07-19 09:54:47 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 Arm Limited.
Gian Marco Iodiced1f54762019-07-19 09:54:47 +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 */
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010024#include "arm_compute/core/KernelDescriptors.h"
25#include "arm_compute/core/Types.h"
26#include "arm_compute/core/utils/misc/ShapeCalculator.h"
27#include "arm_compute/runtime/CL/CLTensor.h"
28#include "arm_compute/runtime/CL/CLTensorAllocator.h"
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010029#include "src/core/CL/kernels/CLGEMMMatrixMultiplyKernel.h"
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010030#include "tests/CL/CLAccessor.h"
31#include "tests/CL/Helper.h"
32#include "tests/PaddingCalculator.h"
33#include "tests/datasets/ShapeDatasets.h"
34#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"
39
40namespace arm_compute
41{
42namespace test
43{
44namespace validation
45{
46using namespace arm_compute::misc::shape_calculator;
47
48// Create function for CLGEMMMatrixMultiplyKernel
49using CLGEMMMatrixMultiplyNative = CLSynthetizeFunction<CLGEMMMatrixMultiplyKernel>;
50
51// Fixture for GEMMMatrixMultiplyValidationFixture
52template <typename T>
53using CLGEMMMatrixMultiplyNativeFixture = GEMMMatrixMultiplyValidationFixture<CLTensor, CLAccessor, T, CLGEMMMatrixMultiplyNative>;
54
55// Fixture for GEMMMatrixMultiply3DValidationFixture
56template <typename T>
57using CLGEMMMatrixMultiplyNative3DFixture = GEMMMatrixMultiply3DValidationFixture<CLTensor, CLAccessor, T, CLGEMMMatrixMultiplyNative>;
58
59namespace
60{
61// *INDENT-OFF*
62// clang-format off
63RelativeTolerance<float> rel_tolerance_f32(0.001f);
64constexpr float abs_tolerance_f32(0.0001f);
65
66RelativeTolerance<half> rel_tolerance_f16(half(0.2));
67constexpr float tolerance_num_f16 = 0.02f;
68
Gian Marco Iodicec630e942020-05-11 12:15:54 +010069/** Alpha values to test */
Gian Marco Iodicef3622be2019-07-29 14:27:16 +010070const auto alpha_values = framework::dataset::make("alpha", {1.0f, -0.75f} );
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010071
Gian Marco Iodicec630e942020-05-11 12:15:54 +010072/** Beta values to test */
Gian Marco Iodiced820db62019-08-05 14:23:23 +010073const auto beta_values = framework::dataset::make("beta", {-0.35f, 0.0f} );
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010074
Gian Marco Iodicec630e942020-05-11 12:15:54 +010075/** M values to test */
76const auto m_values = framework::dataset::make("M", {37, 1});
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010077
Gian Marco Iodicec630e942020-05-11 12:15:54 +010078/** N values to test */
79const auto n_values = framework::dataset::make("N", {51, 1003});
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010080
Gian Marco Iodicec630e942020-05-11 12:15:54 +010081/** K values to test */
82const auto k_values = framework::dataset::make("K", 23);
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010083
Gian Marco Iodicec630e942020-05-11 12:15:54 +010084/** M_W values to test */
85const auto m_w_values = framework::dataset::make("M_W", 5);
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010086
Gian Marco Iodicec630e942020-05-11 12:15:54 +010087/** M_H values to test */
88const auto m_h_values = framework::dataset::make("M_H", 7);
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010089
90/** Batch size values to test */
91const auto b_values = framework::dataset::make("batch_size", 1, 3);
92
93/** Activation values to test */
94const auto act_values = framework::dataset::make("Activation",
95{
96 ActivationLayerInfo(),
97 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 8.f, 2.f),
98});
99
100/** Broadcast bias from vector to matrix */
Gian Marco Iodiced820db62019-08-05 14:23:23 +0100101const auto broadcast_bias_values = framework::dataset::make("broadcast_bias", { false, true } );
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100102
103/** GPU architectures values to test */
104const auto gpu_arch_values = framework::dataset::make("GPUArch",
105{
106 GPUTarget::MIDGARD,
107 GPUTarget::BIFROST
108});
109
110/** Data types values to test in the configuration */
111const auto data_type_values = framework::dataset::make("DataType",
112{
113 DataType::F32,
114 DataType::F16
115});
116
117/** M values to test */
118const auto fp16_mixed_precision_values = framework::dataset::make("fp16_mixed_precision", {true, false});
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100119} // namespace
120
121TEST_SUITE(CL)
122TEST_SUITE(GEMMMatrixMultiply)
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100123TEST_CASE(Negative, framework::DatasetMode::ALL)
124{
125 // Unsupported QASYMM8 data type
126 {
127 const auto lhs = TensorInfo(TensorShape(13U, 12U, 1U, 1U), 1, DataType::QASYMM8);
128 const auto rhs = TensorInfo(TensorShape(14U, 13U, 1U, 1U), 1, DataType::QASYMM8);
129 const auto out = TensorInfo(TensorShape(14U, 12U, 1U, 1U), 1, DataType::QASYMM8);
130 constexpr float alpha = 1.3f;
131 constexpr float beta = 0.7f;
132 const bool is_interleaved_transposed = false;
133 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(12, 14, 13, 1, 1, 0, false, false);
134 const GPUTarget gpu_target = GPUTarget::MIDGARD;
135 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, nullptr, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target);
136 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
137 }
138
139 // Unsupported SIZE_T data type
140 {
141 const auto lhs = TensorInfo(TensorShape(13U, 12U, 1U, 1U), 1, DataType::SIZET);
142 const auto rhs = TensorInfo(TensorShape(14U, 13U, 1U, 1U), 1, DataType::SIZET);
143 const auto out = TensorInfo(TensorShape(14U, 12U, 1U, 1U), 1, DataType::SIZET);
144 constexpr float alpha = 1.3f;
145 constexpr float beta = 0.7f;
146 const bool is_interleaved_transposed = false;
147 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(12, 14, 13, 1, 1, 0, false, false);
148 const GPUTarget gpu_target = GPUTarget::MIDGARD;
149 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, nullptr, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target);
150 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
151 }
152
153 // Mixed precision with F32
154 {
155 const auto lhs = TensorInfo(TensorShape(13U, 12U, 1U, 1U), 1, DataType::F32);
156 const auto rhs = TensorInfo(TensorShape(14U, 13U, 1U, 1U), 1, DataType::F32);
157 const auto out = TensorInfo(TensorShape(14U, 12U, 1U, 1U), 1, DataType::F32);
158 constexpr float alpha = 1.3f;
159 constexpr float beta = 0.7f;
160 const bool is_interleaved_transposed = false;
161 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(12, 14, 13, 1, 1, 0, false, false);
162 const GPUTarget gpu_target = GPUTarget::MIDGARD;
163 const bool fp_mixed_precision = true;
164 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, nullptr, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target, fp_mixed_precision);
165 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
166 }
167
168 // Max number of dimensions LHS matrix
169 {
170 const auto lhs = TensorInfo(TensorShape(13U, 12U, 1U, 1U, 4U), 1, DataType::F32);
171 const auto rhs = TensorInfo(TensorShape(14U, 13U, 1U, 1U), 1, DataType::F32);
172 const auto out = TensorInfo(TensorShape(14U, 12U, 1U, 1U), 1, DataType::F32);
173 constexpr float alpha = 1.3f;
174 constexpr float beta = 0.7f;
175 const bool is_interleaved_transposed = false;
176 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(12, 14, 13, 1, 1, 0, false, false);
177 const GPUTarget gpu_target = GPUTarget::MIDGARD;
178 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, nullptr, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target);
179 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
180 }
181
182 // Max number of dimensions RHS matrix
183 {
184 const auto lhs = TensorInfo(TensorShape(13U, 12U, 1U, 4U), 1, DataType::F32);
185 const auto rhs = TensorInfo(TensorShape(14U, 13U, 1U, 4U), 1, DataType::F32);
186 const auto out = TensorInfo(TensorShape(14U, 12U, 1U, 4U), 1, DataType::F32);
187 constexpr float alpha = 1.3f;
188 constexpr float beta = 0.7f;
189 const bool is_interleaved_transposed = false;
190 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(12, 14, 13, 1, 1, 0, false, false);
191 const GPUTarget gpu_target = GPUTarget::MIDGARD;
192 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, nullptr, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target);
193 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
194 }
195
196 // Broadcast bias
197 {
198 const auto lhs = TensorInfo(TensorShape(13U, 12U, 1U, 1U), 1, DataType::F16);
199 const auto rhs = TensorInfo(TensorShape(14U, 13U, 1U, 1U), 1, DataType::F16);
200 // The correct shape should be bias = TensorInfo(TensorShape(14U, 1U, 1U, 1U), 1, DataType::F32);
201 const auto bias = TensorInfo(TensorShape(14U, 12U, 1U, 1U), 1, DataType::F16);
202 const auto out = TensorInfo(TensorShape(14U, 12U, 1U, 1U), 1, DataType::F16);
203 constexpr float alpha = 1.3f;
204 constexpr float beta = 0.7f;
205 const bool is_interleaved_transposed = false;
206 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(12, 14, 13, 1, 1, 0, false, true);
207 const GPUTarget gpu_target = GPUTarget::MIDGARD;
208 const bool fp_mixed_precision = false;
209 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, &bias, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target, fp_mixed_precision);
210 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
211 }
212
213 // Invalid dimensions for the bias
214 {
215 const auto lhs = TensorInfo(TensorShape(13U, 12U, 1U, 1U), 1, DataType::F32);
216 const auto rhs = TensorInfo(TensorShape(14U, 13U, 1U, 1U), 1, DataType::F32);
217 // The correct shape should be bias = TensorInfo(TensorShape(14U, 12U, 1U, 1U), 1, DataType::F32);
218 const auto bias = TensorInfo(TensorShape(14U, 8U, 1U, 1U), 1, DataType::F32);
219 const auto out = TensorInfo(TensorShape(14U, 12U, 1U, 1U), 1, DataType::F32);
220 constexpr float alpha = 1.3f;
221 constexpr float beta = 0.7f;
222 const bool is_interleaved_transposed = false;
223 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(12, 14, 13, 1, 1, 0, false, false);
224 const GPUTarget gpu_target = GPUTarget::MIDGARD;
225 const bool fp_mixed_precision = false;
226 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, &bias, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target, fp_mixed_precision);
227 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
228 }
229
230 // Invalid dimensions for the output
231 {
232 const auto lhs = TensorInfo(TensorShape(13U, 12U, 1U, 1U), 1, DataType::F32);
233 const auto rhs = TensorInfo(TensorShape(14U, 13U, 1U, 1U), 1, DataType::F32);
234 // The correct shape should be out = TensorInfo(TensorShape(14U, 12U, 1U, 1U), 1, DataType::F32);
235 const auto out = TensorInfo(TensorShape(14U, 7U, 1U, 1U), 1, DataType::F32);
236 constexpr float alpha = 1.3f;
237 constexpr float beta = 0.7f;
238 const bool is_interleaved_transposed = false;
239 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(12, 14, 13, 1, 1, 0, false, false);
240 const GPUTarget gpu_target = GPUTarget::MIDGARD;
241 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, nullptr, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target);
242 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
243 }
244}
245
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100246TEST_SUITE(Float)
247TEST_SUITE(FP32)
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100248
249FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::ALL,
250 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100251 m_values,
252 n_values),
253 k_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100254 b_values),
255 alpha_values),
256 beta_values),
257 broadcast_bias_values),
258 framework::dataset::make("fp16_mixed_precision", false)),
259 act_values),
260 framework::dataset::make("DataType", DataType::F32)),
261 gpu_arch_values))
262{
263 // Validate output
264 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
265}
266
267FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyNative3DFixture<float>, framework::DatasetMode::ALL,
268 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100269 m_w_values,
270 m_h_values),
271 n_values),
272 k_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100273 b_values),
274 alpha_values),
275 beta_values),
276 broadcast_bias_values),
277 framework::dataset::make("fp16_mixed_precision", false)),
278 act_values),
279 framework::dataset::make("DataType", DataType::F32)),
280 gpu_arch_values))
281{
282 // Validate output
283 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
284}
285
286TEST_SUITE_END() // FP32
287
288TEST_SUITE(FP16)
289FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyNativeFixture<half>, framework::DatasetMode::ALL,
290 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100291 m_values,
292 n_values),
293 k_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100294 b_values),
295 alpha_values),
296 beta_values),
297 broadcast_bias_values),
298 fp16_mixed_precision_values),
299 act_values),
300 framework::dataset::make("DataType", DataType::F16)),
301 gpu_arch_values))
302{
303 // Validate output
304 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
305}
306
307FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyNative3DFixture<half>, framework::DatasetMode::ALL,
308 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100309 m_w_values,
310 m_h_values),
311 n_values),
312 k_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100313 b_values),
314 alpha_values),
315 beta_values),
316 broadcast_bias_values),
317 fp16_mixed_precision_values),
318 act_values),
319 framework::dataset::make("DataType", DataType::F16)),
320 gpu_arch_values))
321{
322 // Validate output
323 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
324}
325
326TEST_SUITE_END() // FP16
327TEST_SUITE_END() // Float
328TEST_SUITE_END() // GEMMMatrixMuliplty
329TEST_SUITE_END() // CL
330} // namespace validation
331} // namespace test
332} // namespace arm_compute