blob: 23ae0049126b95364bda1cb99c2bb21ede453696 [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"
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 CLGEMMReshapeRHSMatrixKernel
49using CLGEMMReshapeRHSMatrix = CLSynthetizeFunction<CLGEMMReshapeRHSMatrixKernel>;
50
51// Create function for CLGEMMMatrixMultiplyReshapedOnlyRHSKernel
52using CLGEMMMatrixMultiplyReshapedOnlyRHS = CLSynthetizeFunction<CLGEMMMatrixMultiplyReshapedOnlyRHSKernel>;
53
54// Fixture for CLGEMMMatrixMultiplyReshapedOnlyRHS
55template <typename T>
56using CLGEMMMatrixMultiplyReshapedOnlyRHSFixture = GEMMMatrixMultiplyReshapedOnlyRHSValidationFixture<CLTensor, CLAccessor, T, CLGEMMReshapeRHSMatrix, CLGEMMMatrixMultiplyReshapedOnlyRHS>;
57
58// Fixture for CLGEMMMatrixMultiplyReshapedOnlyRHS3D
59template <typename T>
60using CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture = GEMMMatrixMultiplyReshapedOnlyRHS3DValidationFixture<CLTensor, CLAccessor, T, CLGEMMReshapeRHSMatrix, CLGEMMMatrixMultiplyReshapedOnlyRHS>;
61
62namespace
63{
64// *INDENT-OFF*
65// clang-format off
66RelativeTolerance<float> rel_tolerance_f32(0.001f);
67constexpr float abs_tolerance_f32(0.0001f);
68
69RelativeTolerance<half> rel_tolerance_f16(half(0.2));
70constexpr float tolerance_num_f16 = 0.02f;
71
72/** Alpha values to test - Precommit */
73const auto a_values = framework::dataset::make("alpha", {1.0f, -0.75f} );
74
Georgios Pinitasb0f342e2019-05-21 13:32:43 +010075/** Beta values to test - Precommit */
76const auto beta_values = framework::dataset::make("beta", {-0.75f, 0.0f} );
77
Gian Marco Iodiceadc53952019-02-15 11:10:31 +000078/** M values to test */
79const auto m_values = framework::dataset::make("M", 37);
80
81/** M_W values to test */
82const auto m_w_values = framework::dataset::make("M_W", 5);
83
84/** M_H values to test */
85const auto m_h_values = framework::dataset::make("M_H", 7);
86
87/** N values to test */
88const auto n_values = framework::dataset::make("N", 51);
89
90/** K values to test */
91const auto k_values = framework::dataset::make("K", 23);
92
93/** Batch size values to test */
94const auto b_values = framework::dataset::make("batch_size", 1, 3);
95
96/** M0 values to test - Precommit */
97const auto m0_values_precommit = framework::dataset::make("M0", {4, 6});
98
99/** N0 values to test - Precommit */
100const auto n0_values_precommit = framework::dataset::make("N0", { 2, 4 });
101
102/** K0 values to test - Precommit */
103const auto k0_values_precommit = framework::dataset::make("K0", { 4 });
104
105/** H0 values to test - Precommit */
106const auto h0_values_precommit = framework::dataset::make("H0", 1, 3);
107
108/** M0 values to test - Nightly */
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000109const auto m0_values_nightly = framework::dataset::make("M0", 1, 8);
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000110
111/** N0 values to test - Nightly */
112const auto n0_values_nightly = framework::dataset::make("N0", { 2, 3, 4, 8 });
113
114/** K0 values to test - Nightly */
115const auto k0_values_nightly = framework::dataset::make("K0", { 2, 3, 4, 8 });
116
117/** H0 values to test - Nightly */
118const auto h0_values_nightly = framework::dataset::make("H0", 1, 4);
119
120/** Interleave values to test with RHS matrix */
121const auto i_values_rhs = framework::dataset::make("interleave_rhs", { true, false });
122
123/** Transpose values to test with RHS matrix */
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000124const auto t_values_rhs = framework::dataset::make("transpose_rhs", { true, false });
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000125
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100126/**Broadcast bias from vector to matrix */
127const auto broadcast_bias_values = framework::dataset::make("broadcast_bias", {false, true} );
128
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000129/** Configuration test */
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100130void 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)
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000131{
132 const unsigned int M = m_value;
133 const unsigned int N = n_value;
134 const unsigned int K = k_value;
135
136 GEMMLHSMatrixInfo lhs_info;
137 lhs_info.m0 = m0_value;
138 lhs_info.k0 = k0_value;
139
140 GEMMRHSMatrixInfo rhs_info;
141 rhs_info.n0 = n0_value;
142 rhs_info.k0 = k0_value;
143 rhs_info.h0 = h0_value;
144 rhs_info.interleave = i_value_rhs;
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000145 rhs_info.transpose = t_value_rhs;
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000146
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100147 GEMMReshapeInfo gemm_info(M, N, K, false, false, 0, false, broadcast_bias);
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000148
149 const TensorShape lhs_shape(K, M, b_value);
150 const TensorShape rhs_shape(N, K, b_value);
151 const TensorShape rhs_shape_reshaped = compute_rhs_reshaped_shape(TensorInfo(rhs_shape, 1, data_type),
152 rhs_info);
153
154 const TensorShape dst_shape = compute_mm_shape(TensorInfo(lhs_shape, 1, data_type),
155 TensorInfo(rhs_shape_reshaped, 1, data_type),
156 gemm_info);
157
158 // Create tensors
159 CLTensor lhs = create_tensor<CLTensor>(lhs_shape, data_type);
160 CLTensor rhs_reshaped = create_tensor<CLTensor>(rhs_shape_reshaped, data_type);
161 CLTensor dst = create_tensor<CLTensor>(dst_shape, data_type);
162
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100163 TensorShape bias_shape = dst_shape;
164 if (broadcast_bias)
165 {
166 bias_shape[1] = 1;
167 bias_shape[2] = 1;
168 }
169 CLTensor bias = create_tensor<CLTensor>(bias_shape, data_type);
170
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000171 ARM_COMPUTE_EXPECT(lhs.info()->is_resizable(), framework::LogLevel::ERRORS);
172 ARM_COMPUTE_EXPECT(rhs_reshaped.info()->is_resizable(), framework::LogLevel::ERRORS);
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100173 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000174 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
175
176 // Create and configure function
177 CLGEMMMatrixMultiplyReshapedOnlyRHS gemm;
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100178 gemm.configure(&lhs, &rhs_reshaped, &bias, &dst, 1.0f, 1.0f, lhs_info, rhs_info, gemm_info);
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000179}
180} // namespace
181
182TEST_SUITE(CL)
183TEST_SUITE(GEMMMatrixMultiplyReshapedOnlyRHS)
184TEST_SUITE(Float)
185TEST_SUITE(FP32)
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100186DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000187 m_values,
188 n_values),
189 k_values),
190 framework::dataset::make("batch_size", 1)),
191 m0_values_precommit),
192 n0_values_precommit),
193 k0_values_precommit),
194 h0_values_precommit),
195 i_values_rhs),
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000196 t_values_rhs),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100197 broadcast_bias_values),
198m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, h0_value, i_value_rhs, t_value_rhs, broadcast_bias)
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000199{
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100200 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);
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000201}
202
203FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<float>, framework::DatasetMode::ALL,
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100204 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000205 m_values,
206 n_values),
207 k_values),
208 b_values),
209 m0_values_precommit),
210 n0_values_precommit),
211 k0_values_precommit),
212 h0_values_precommit),
213 i_values_rhs),
214 t_values_rhs),
215 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100216 a_values),
217 beta_values),
218 broadcast_bias_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000219{
220 // Validate output
221 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
222}
223
224FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<float>, framework::DatasetMode::NIGHTLY,
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100225 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000226 m_values,
227 n_values),
228 k_values),
229 b_values),
230 m0_values_nightly),
231 n0_values_nightly),
232 k0_values_nightly),
233 h0_values_nightly),
234 i_values_rhs),
235 t_values_rhs),
236 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100237 a_values),
238 beta_values),
239 broadcast_bias_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000240{
241 // Validate output
242 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
243}
244
245FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<float>, framework::DatasetMode::ALL,
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100246 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000247 m_w_values,
248 m_h_values),
249 n_values),
250 k_values),
251 b_values),
252 m0_values_precommit),
253 n0_values_precommit),
254 k0_values_precommit),
255 h0_values_precommit),
256 i_values_rhs),
257 t_values_rhs),
258 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100259 a_values),
260 b_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000261{
262 // Validate output
263 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
264}
265
266FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<float>, framework::DatasetMode::NIGHTLY,
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100267 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000268 m_w_values,
269 m_h_values),
270 n_values),
271 k_values),
272 b_values),
273 m0_values_nightly),
274 n0_values_nightly),
275 k0_values_nightly),
276 h0_values_nightly),
277 i_values_rhs),
278 t_values_rhs),
279 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100280 a_values),
281 b_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000282{
283 // Validate output
284 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
285}
286TEST_SUITE_END() // FP32
287
288TEST_SUITE(FP16)
289FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<half>, framework::DatasetMode::ALL,
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100290 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000291 m_values,
292 n_values),
293 k_values),
294 b_values),
295 m0_values_precommit),
296 n0_values_precommit),
297 k0_values_precommit),
298 h0_values_precommit),
299 i_values_rhs),
300 t_values_rhs),
301 framework::dataset::make("DataType", DataType::F16)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100302 a_values),
303 b_values),
304 broadcast_bias_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000305{
306 // Validate output
307 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
308}
309
310FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<half>, framework::DatasetMode::NIGHTLY,
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100311 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000312 m_values,
313 n_values),
314 k_values),
315 b_values),
316 m0_values_nightly),
317 n0_values_nightly),
318 k0_values_nightly),
319 h0_values_nightly),
320 i_values_rhs),
321 t_values_rhs),
322 framework::dataset::make("DataType", DataType::F16)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100323 a_values),
324 b_values),
325 broadcast_bias_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000326{
327 // Validate output
328 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
329}
330
331FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<half>, framework::DatasetMode::ALL,
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100332 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000333 m_w_values,
334 m_h_values),
335 n_values),
336 k_values),
337 b_values),
338 m0_values_precommit),
339 n0_values_precommit),
340 k0_values_precommit),
341 h0_values_precommit),
342 i_values_rhs),
343 t_values_rhs),
344 framework::dataset::make("DataType", DataType::F16)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100345 a_values),
346 b_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000347{
348 // Validate output
349 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
350}
351
352FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<half>, framework::DatasetMode::NIGHTLY,
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100353 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000354 m_w_values,
355 m_h_values),
356 n_values),
357 k_values),
358 b_values),
359 m0_values_nightly),
360 n0_values_nightly),
361 k0_values_nightly),
362 h0_values_nightly),
363 i_values_rhs),
364 t_values_rhs),
365 framework::dataset::make("DataType", DataType::F16)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100366 a_values),
367 b_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000368{
369 // Validate output
370 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
371}
372TEST_SUITE_END() // FP16
373TEST_SUITE_END() // Float
374TEST_SUITE_END() // GEMMMatrixMulipltyReshapedOnlyRHS
375TEST_SUITE_END() // CL
376} // namespace validation
377} // namespace test
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100378} // namespace arm_compute