blob: dd993af481640625a6d4fdb8928f4a1db465df80 [file] [log] [blame]
Gian Marco Iodiceadc53952019-02-15 11:10:31 +00001/*
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/CLGEMMMatrixMultiplyReshapedOnlyRHSKernel.h"
25#include "arm_compute/core/CL/kernels/CLGEMMReshapeRHSMatrixKernel.h"
Gian Marco Iodice7026b302019-06-26 17:18:11 +010026#include "arm_compute/core/KernelDescriptors.h"
Gian Marco Iodiceadc53952019-02-15 11:10:31 +000027#include "arm_compute/core/Types.h"
28#include "arm_compute/core/utils/misc/ShapeCalculator.h"
29#include "arm_compute/runtime/CL/CLTensor.h"
30#include "arm_compute/runtime/CL/CLTensorAllocator.h"
31#include "tests/CL/CLAccessor.h"
32#include "tests/CL/Helper.h"
33#include "tests/PaddingCalculator.h"
34#include "tests/datasets/ShapeDatasets.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"
40
41namespace arm_compute
42{
43namespace test
44{
45namespace validation
46{
47using namespace arm_compute::misc::shape_calculator;
48
49// Create function for CLGEMMReshapeRHSMatrixKernel
50using CLGEMMReshapeRHSMatrix = CLSynthetizeFunction<CLGEMMReshapeRHSMatrixKernel>;
51
52// Create function for CLGEMMMatrixMultiplyReshapedOnlyRHSKernel
53using CLGEMMMatrixMultiplyReshapedOnlyRHS = CLSynthetizeFunction<CLGEMMMatrixMultiplyReshapedOnlyRHSKernel>;
54
55// Fixture for CLGEMMMatrixMultiplyReshapedOnlyRHS
56template <typename T>
57using CLGEMMMatrixMultiplyReshapedOnlyRHSFixture = GEMMMatrixMultiplyReshapedOnlyRHSValidationFixture<CLTensor, CLAccessor, T, CLGEMMReshapeRHSMatrix, CLGEMMMatrixMultiplyReshapedOnlyRHS>;
58
59// Fixture for CLGEMMMatrixMultiplyReshapedOnlyRHS3D
60template <typename T>
61using CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture = GEMMMatrixMultiplyReshapedOnlyRHS3DValidationFixture<CLTensor, CLAccessor, T, CLGEMMReshapeRHSMatrix, CLGEMMMatrixMultiplyReshapedOnlyRHS>;
62
63namespace
64{
65// *INDENT-OFF*
66// clang-format off
67RelativeTolerance<float> rel_tolerance_f32(0.001f);
68constexpr float abs_tolerance_f32(0.0001f);
69
70RelativeTolerance<half> rel_tolerance_f16(half(0.2));
71constexpr float tolerance_num_f16 = 0.02f;
72
73/** Alpha values to test - Precommit */
74const auto a_values = framework::dataset::make("alpha", {1.0f, -0.75f} );
75
Georgios Pinitasb0f342e2019-05-21 13:32:43 +010076/** Beta values to test - Precommit */
77const auto beta_values = framework::dataset::make("beta", {-0.75f, 0.0f} );
78
Gian Marco Iodiceadc53952019-02-15 11:10:31 +000079/** M values to test */
80const auto m_values = framework::dataset::make("M", 37);
81
82/** M_W values to test */
83const auto m_w_values = framework::dataset::make("M_W", 5);
84
85/** M_H values to test */
86const auto m_h_values = framework::dataset::make("M_H", 7);
87
88/** N values to test */
89const auto n_values = framework::dataset::make("N", 51);
90
91/** K values to test */
92const auto k_values = framework::dataset::make("K", 23);
93
94/** Batch size values to test */
95const auto b_values = framework::dataset::make("batch_size", 1, 3);
96
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +010097/** Activation values to test */
98const auto act_values = framework::dataset::make("Activation",
99{
100 ActivationLayerInfo(),
101 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 8.f, 2.f),
102});
103
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000104/** M0 values to test - Precommit */
105const auto m0_values_precommit = framework::dataset::make("M0", {4, 6});
106
107/** N0 values to test - Precommit */
108const auto n0_values_precommit = framework::dataset::make("N0", { 2, 4 });
109
110/** K0 values to test - Precommit */
111const auto k0_values_precommit = framework::dataset::make("K0", { 4 });
112
113/** H0 values to test - Precommit */
114const auto h0_values_precommit = framework::dataset::make("H0", 1, 3);
115
116/** M0 values to test - Nightly */
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000117const auto m0_values_nightly = framework::dataset::make("M0", 1, 8);
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000118
119/** N0 values to test - Nightly */
120const auto n0_values_nightly = framework::dataset::make("N0", { 2, 3, 4, 8 });
121
122/** K0 values to test - Nightly */
123const auto k0_values_nightly = framework::dataset::make("K0", { 2, 3, 4, 8 });
124
125/** H0 values to test - Nightly */
126const auto h0_values_nightly = framework::dataset::make("H0", 1, 4);
127
128/** Interleave values to test with RHS matrix */
129const auto i_values_rhs = framework::dataset::make("interleave_rhs", { true, false });
130
131/** Transpose values to test with RHS matrix */
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000132const auto t_values_rhs = framework::dataset::make("transpose_rhs", { true, false });
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000133
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100134/** Broadcast bias from vector to matrix */
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100135const auto broadcast_bias_values = framework::dataset::make("broadcast_bias", {false, true} );
136
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000137/** Configuration test */
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100138void validate_configuration(unsigned int m_value, unsigned int n_value, unsigned int k_value, unsigned int b_value, unsigned int m0_value, unsigned int n0_value, unsigned int k0_value, unsigned int h0_value, bool i_value_rhs, bool t_value_rhs, bool broadcast_bias, DataType data_type, const ActivationLayerInfo &act_info)
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000139{
140 const unsigned int M = m_value;
141 const unsigned int N = n_value;
142 const unsigned int K = k_value;
143
144 GEMMLHSMatrixInfo lhs_info;
145 lhs_info.m0 = m0_value;
146 lhs_info.k0 = k0_value;
147
148 GEMMRHSMatrixInfo rhs_info;
149 rhs_info.n0 = n0_value;
150 rhs_info.k0 = k0_value;
151 rhs_info.h0 = h0_value;
152 rhs_info.interleave = i_value_rhs;
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000153 rhs_info.transpose = t_value_rhs;
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000154
Gian Marco Iodice7026b302019-06-26 17:18:11 +0100155 GEMMKernelInfo kernel_info;
156 kernel_info.m = M;
157 kernel_info.n = N;
158 kernel_info.k = K;
159 kernel_info.depth_output_gemm3d = 0;
160 kernel_info.reinterpret_input_as_3d = false;
161 kernel_info.broadcast_bias = broadcast_bias;
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100162 kernel_info.activation_info = act_info;
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000163
164 const TensorShape lhs_shape(K, M, b_value);
165 const TensorShape rhs_shape(N, K, b_value);
166 const TensorShape rhs_shape_reshaped = compute_rhs_reshaped_shape(TensorInfo(rhs_shape, 1, data_type),
167 rhs_info);
168
169 const TensorShape dst_shape = compute_mm_shape(TensorInfo(lhs_shape, 1, data_type),
170 TensorInfo(rhs_shape_reshaped, 1, data_type),
Gian Marco Iodice7026b302019-06-26 17:18:11 +0100171 kernel_info);
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000172
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100173 const TensorShape bias_shape(N,
174 broadcast_bias? 1 : M,
175 broadcast_bias? 1 : b_value);
176
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000177 // Create tensors
178 CLTensor lhs = create_tensor<CLTensor>(lhs_shape, data_type);
179 CLTensor rhs_reshaped = create_tensor<CLTensor>(rhs_shape_reshaped, data_type);
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100180 CLTensor bias = create_tensor<CLTensor>(bias_shape, data_type);
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100181 CLTensor dst = create_tensor<CLTensor>(dst_shape, data_type);
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100182
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000183 ARM_COMPUTE_EXPECT(lhs.info()->is_resizable(), framework::LogLevel::ERRORS);
184 ARM_COMPUTE_EXPECT(rhs_reshaped.info()->is_resizable(), framework::LogLevel::ERRORS);
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100185 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000186 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
187
188 // Create and configure function
189 CLGEMMMatrixMultiplyReshapedOnlyRHS gemm;
Gian Marco Iodice7026b302019-06-26 17:18:11 +0100190 gemm.configure(&lhs, &rhs_reshaped, &bias, &dst, 1.0f, 1.0f, lhs_info, rhs_info, kernel_info);
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000191}
192} // namespace
193
194TEST_SUITE(CL)
195TEST_SUITE(GEMMMatrixMultiplyReshapedOnlyRHS)
196TEST_SUITE(Float)
197TEST_SUITE(FP32)
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100198DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000199 m_values,
200 n_values),
201 k_values),
202 framework::dataset::make("batch_size", 1)),
203 m0_values_precommit),
204 n0_values_precommit),
205 k0_values_precommit),
206 h0_values_precommit),
207 i_values_rhs),
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000208 t_values_rhs),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100209 broadcast_bias_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100210 act_values),
211m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, h0_value, i_value_rhs, t_value_rhs, broadcast_bias, act_value)
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000212{
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100213 validate_configuration(m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, h0_value, i_value_rhs, t_value_rhs, broadcast_bias, DataType::F32, act_value);
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000214}
215
216FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<float>, framework::DatasetMode::ALL,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100217 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000218 m_values,
219 n_values),
220 k_values),
221 b_values),
222 m0_values_precommit),
223 n0_values_precommit),
224 k0_values_precommit),
225 h0_values_precommit),
226 i_values_rhs),
227 t_values_rhs),
228 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100229 a_values),
230 beta_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100231 broadcast_bias_values),
232 act_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000233{
234 // Validate output
235 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
236}
237
238FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<float>, framework::DatasetMode::NIGHTLY,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100239 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000240 m_values,
241 n_values),
242 k_values),
243 b_values),
244 m0_values_nightly),
245 n0_values_nightly),
246 k0_values_nightly),
247 h0_values_nightly),
248 i_values_rhs),
249 t_values_rhs),
250 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100251 a_values),
252 beta_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100253 broadcast_bias_values),
254 act_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000255{
256 // Validate output
257 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
258}
259
260FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<float>, framework::DatasetMode::ALL,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100261 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000262 m_w_values,
263 m_h_values),
264 n_values),
265 k_values),
266 b_values),
267 m0_values_precommit),
268 n0_values_precommit),
269 k0_values_precommit),
270 h0_values_precommit),
271 i_values_rhs),
272 t_values_rhs),
273 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100274 a_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100275 beta_values),
276 act_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000277{
278 // Validate output
279 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
280}
281
282FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<float>, framework::DatasetMode::NIGHTLY,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100283 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000284 m_w_values,
285 m_h_values),
286 n_values),
287 k_values),
288 b_values),
289 m0_values_nightly),
290 n0_values_nightly),
291 k0_values_nightly),
292 h0_values_nightly),
293 i_values_rhs),
294 t_values_rhs),
295 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100296 a_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100297 beta_values),
298 act_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000299{
300 // Validate output
301 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
302}
303TEST_SUITE_END() // FP32
304
305TEST_SUITE(FP16)
306FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<half>, framework::DatasetMode::ALL,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100307 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000308 m_values,
309 n_values),
310 k_values),
311 b_values),
312 m0_values_precommit),
313 n0_values_precommit),
314 k0_values_precommit),
315 h0_values_precommit),
316 i_values_rhs),
317 t_values_rhs),
318 framework::dataset::make("DataType", DataType::F16)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100319 a_values),
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100320 beta_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100321 broadcast_bias_values),
322 act_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000323{
324 // Validate output
325 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
326}
327
328FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<half>, framework::DatasetMode::NIGHTLY,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100329 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000330 m_values,
331 n_values),
332 k_values),
333 b_values),
334 m0_values_nightly),
335 n0_values_nightly),
336 k0_values_nightly),
337 h0_values_nightly),
338 i_values_rhs),
339 t_values_rhs),
340 framework::dataset::make("DataType", DataType::F16)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100341 a_values),
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100342 beta_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100343 broadcast_bias_values),
344 act_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000345{
346 // Validate output
347 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
348}
349
350FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<half>, framework::DatasetMode::ALL,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100351 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000352 m_w_values,
353 m_h_values),
354 n_values),
355 k_values),
356 b_values),
357 m0_values_precommit),
358 n0_values_precommit),
359 k0_values_precommit),
360 h0_values_precommit),
361 i_values_rhs),
362 t_values_rhs),
363 framework::dataset::make("DataType", DataType::F16)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100364 a_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100365 beta_values),
366 act_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000367{
368 // Validate output
369 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
370}
371
372FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<half>, framework::DatasetMode::NIGHTLY,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100373 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000374 m_w_values,
375 m_h_values),
376 n_values),
377 k_values),
378 b_values),
379 m0_values_nightly),
380 n0_values_nightly),
381 k0_values_nightly),
382 h0_values_nightly),
383 i_values_rhs),
384 t_values_rhs),
385 framework::dataset::make("DataType", DataType::F16)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100386 a_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100387 beta_values),
388 act_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000389{
390 // Validate output
391 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
392}
393TEST_SUITE_END() // FP16
394TEST_SUITE_END() // Float
395TEST_SUITE_END() // GEMMMatrixMulipltyReshapedOnlyRHS
396TEST_SUITE_END() // CL
397} // namespace validation
398} // namespace test
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100399} // namespace arm_compute