blob: 0bc8b028254d074bb4b8785ccd24518273b086af [file] [log] [blame]
Gian Marco Iodiced1f54762019-07-19 09:54:47 +01001/*
2 * Copyright (c) 2019 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/CL/kernels/CLGEMMMatrixMultiplyKernel.h"
25#include "arm_compute/core/KernelDescriptors.h"
26#include "arm_compute/core/Types.h"
27#include "arm_compute/core/utils/misc/ShapeCalculator.h"
28#include "arm_compute/runtime/CL/CLTensor.h"
29#include "arm_compute/runtime/CL/CLTensorAllocator.h"
30#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
69/** Alpha values to test - Precommit */
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
72/** Beta values to test - Precommit */
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
75/** M values to test - Precommit */
76const auto m_values_precommit = framework::dataset::make("M", {37, 1});
77
78/** N values to test - Precommit */
79const auto n_values_precommit = framework::dataset::make("N", 51);
80
81/** K values to test - Precommit */
82const auto k_values_precommit = framework::dataset::make("K", 23);
83
84/** M values to test - Nightly */
85const auto m_values_nightly = framework::dataset::make("M", {421, 1});
86
87/** N values to test - Nightly */
88const auto n_values_nightly = framework::dataset::make("N", {323, 1103});
89
90/** K values to test - Nightly */
91const auto k_values_nightly = framework::dataset::make("K", 207);
92
93/** M_W values to test - Precommit */
94const auto m_w_values_precommit = framework::dataset::make("M_W", 5);
95
96/** M_H values to test - Precommit */
97const auto m_h_values_precommit = framework::dataset::make("M_H", 7);
98
99/** M_W values to test - Nightly */
100const auto m_w_values_nightly = framework::dataset::make("M_W", 13);
101
102/** M_H values to test - Nightly */
103const auto m_h_values_nightly = framework::dataset::make("M_H", 27);
104
105/** Batch size values to test */
106const auto b_values = framework::dataset::make("batch_size", 1, 3);
107
108/** Activation values to test */
109const auto act_values = framework::dataset::make("Activation",
110{
111 ActivationLayerInfo(),
112 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 8.f, 2.f),
113});
114
115/** Broadcast bias from vector to matrix */
Gian Marco Iodiced820db62019-08-05 14:23:23 +0100116const auto broadcast_bias_values = framework::dataset::make("broadcast_bias", { false, true } );
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100117
118/** GPU architectures values to test */
119const auto gpu_arch_values = framework::dataset::make("GPUArch",
120{
121 GPUTarget::MIDGARD,
122 GPUTarget::BIFROST
123});
124
125/** Data types values to test in the configuration */
126const auto data_type_values = framework::dataset::make("DataType",
127{
128 DataType::F32,
129 DataType::F16
130});
131
132/** M values to test */
133const auto fp16_mixed_precision_values = framework::dataset::make("fp16_mixed_precision", {true, false});
134
135/** Configuration test */
136void validate_configuration(unsigned int m_value, unsigned int n_value, unsigned int k_value, unsigned int b_value, bool broadcast_bias, bool fp16_mixed_precision, const ActivationLayerInfo &act_info, DataType data_type, GPUTarget gpu_arch_value)
137{
138 GEMMReshapeInfo reshape_info(m_value, n_value, k_value, 1, 1, 0, false, broadcast_bias);
139
140 const TensorShape lhs_shape(k_value, m_value, b_value);
141 const TensorShape rhs_shape(n_value, k_value, b_value);
142
143 const TensorShape dst_shape = compute_mm_shape(TensorInfo(lhs_shape, 1, data_type),
144 TensorInfo(rhs_shape, 1, data_type),
145 reshape_info);
146
147 const TensorShape bias_shape(n_value,
148 broadcast_bias? 1 : m_value,
149 broadcast_bias? 1 : b_value);
150
151 // Create tensors
152 CLTensor lhs = create_tensor<CLTensor>(lhs_shape, data_type);
153 CLTensor rhs = create_tensor<CLTensor>(rhs_shape, data_type);
154 CLTensor bias = create_tensor<CLTensor>(bias_shape, data_type);
155 CLTensor dst = create_tensor<CLTensor>(dst_shape, data_type);
156
157 ARM_COMPUTE_EXPECT(lhs.info()->is_resizable(), framework::LogLevel::ERRORS);
158 ARM_COMPUTE_EXPECT(rhs.info()->is_resizable(), framework::LogLevel::ERRORS);
159 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
160 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
161
162 // Create and configure function
163 CLGEMMMatrixMultiplyNative gemm;
164 gemm.configure(gpu_arch_value, &lhs, &rhs, &bias, &dst, 1.0f, 2.0f, false, reshape_info, fp16_mixed_precision, act_info);
165}
166} // namespace
167
168TEST_SUITE(CL)
169TEST_SUITE(GEMMMatrixMultiply)
170TEST_SUITE(Float)
171TEST_SUITE(FP32)
172DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine(
173 m_values_precommit,
174 n_values_precommit),
175 k_values_precommit),
176 framework::dataset::make("batch_size", 1)),
177 broadcast_bias_values),
178 framework::dataset::make("fp16_mixed_precision", false)),
179 act_values),
180 data_type_values),
181 gpu_arch_values),
182m_value, n_value, k_value, b_value, broadcast_bias, fp16_mixed_precision_value, act_value, data_type_value, gpu_arch_value)
183{
184 validate_configuration(m_value, n_value, k_value, b_value, broadcast_bias, fp16_mixed_precision_value, act_value, data_type_value, gpu_arch_value);
185}
186
187FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::ALL,
188 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
189 m_values_precommit,
190 n_values_precommit),
191 k_values_precommit),
192 b_values),
193 alpha_values),
194 beta_values),
195 broadcast_bias_values),
196 framework::dataset::make("fp16_mixed_precision", false)),
197 act_values),
198 framework::dataset::make("DataType", DataType::F32)),
199 gpu_arch_values))
200{
201 // Validate output
202 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
203}
204
205FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::NIGHTLY,
206 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
207 m_values_nightly,
208 n_values_nightly),
209 k_values_nightly),
210 b_values),
211 alpha_values),
212 beta_values),
213 broadcast_bias_values),
214 framework::dataset::make("fp16_mixed_precision", false)),
215 act_values),
216 framework::dataset::make("DataType", DataType::F32)),
217 gpu_arch_values))
218{
219 // Validate output
220 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
221}
222
223FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyNative3DFixture<float>, framework::DatasetMode::ALL,
224 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
225 m_w_values_precommit,
226 m_h_values_precommit),
227 n_values_precommit),
228 k_values_precommit),
229 b_values),
230 alpha_values),
231 beta_values),
232 broadcast_bias_values),
233 framework::dataset::make("fp16_mixed_precision", false)),
234 act_values),
235 framework::dataset::make("DataType", DataType::F32)),
236 gpu_arch_values))
237{
238 // Validate output
239 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
240}
241
242FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMMatrixMultiplyNative3DFixture<float>, framework::DatasetMode::NIGHTLY,
243 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
244 m_w_values_nightly,
245 m_h_values_nightly),
246 n_values_nightly),
247 k_values_nightly),
248 b_values),
249 alpha_values),
250 beta_values),
251 broadcast_bias_values),
252 framework::dataset::make("fp16_mixed_precision", false)),
253 act_values),
254 framework::dataset::make("DataType", DataType::F32)),
255 gpu_arch_values))
256{
257 // Validate output
258 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
259}
260
261TEST_SUITE_END() // FP32
262
263TEST_SUITE(FP16)
264FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyNativeFixture<half>, framework::DatasetMode::ALL,
265 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
266 m_values_precommit,
267 n_values_precommit),
268 k_values_precommit),
269 b_values),
270 alpha_values),
271 beta_values),
272 broadcast_bias_values),
273 fp16_mixed_precision_values),
274 act_values),
275 framework::dataset::make("DataType", DataType::F16)),
276 gpu_arch_values))
277{
278 // Validate output
279 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
280}
281
282FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMMatrixMultiplyNativeFixture<half>, framework::DatasetMode::NIGHTLY,
283 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
284 m_values_nightly,
285 n_values_nightly),
286 k_values_nightly),
287 b_values),
288 alpha_values),
289 beta_values),
290 broadcast_bias_values),
291 fp16_mixed_precision_values),
292 act_values),
293 framework::dataset::make("DataType", DataType::F16)),
294 gpu_arch_values))
295{
296 // Validate output
297 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
298}
299
300FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyNative3DFixture<half>, framework::DatasetMode::ALL,
301 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
302 m_w_values_precommit,
303 m_h_values_precommit),
304 n_values_precommit),
305 k_values_precommit),
306 b_values),
307 alpha_values),
308 beta_values),
309 broadcast_bias_values),
310 fp16_mixed_precision_values),
311 act_values),
312 framework::dataset::make("DataType", DataType::F16)),
313 gpu_arch_values))
314{
315 // Validate output
316 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
317}
318
319FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMMatrixMultiplyNative3DFixture<half>, framework::DatasetMode::NIGHTLY,
320 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
321 m_w_values_nightly,
322 m_h_values_nightly),
323 n_values_nightly),
324 k_values_nightly),
325 b_values),
326 alpha_values),
327 beta_values),
328 broadcast_bias_values),
329 fp16_mixed_precision_values),
330 act_values),
331 framework::dataset::make("DataType", DataType::F16)),
332 gpu_arch_values))
333{
334 // Validate output
335 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
336}
337
338TEST_SUITE_END() // FP16
339TEST_SUITE_END() // Float
340TEST_SUITE_END() // GEMMMatrixMuliplty
341TEST_SUITE_END() // CL
342} // namespace validation
343} // namespace test
344} // namespace arm_compute