blob: 6c34fc870a402ff5d82430677ad860d5c8a39034 [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
97/** M0 values to test - Precommit */
98const auto m0_values_precommit = framework::dataset::make("M0", {4, 6});
99
100/** N0 values to test - Precommit */
101const auto n0_values_precommit = framework::dataset::make("N0", { 2, 4 });
102
103/** K0 values to test - Precommit */
104const auto k0_values_precommit = framework::dataset::make("K0", { 4 });
105
106/** H0 values to test - Precommit */
107const auto h0_values_precommit = framework::dataset::make("H0", 1, 3);
108
109/** M0 values to test - Nightly */
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000110const auto m0_values_nightly = framework::dataset::make("M0", 1, 8);
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000111
112/** N0 values to test - Nightly */
113const auto n0_values_nightly = framework::dataset::make("N0", { 2, 3, 4, 8 });
114
115/** K0 values to test - Nightly */
116const auto k0_values_nightly = framework::dataset::make("K0", { 2, 3, 4, 8 });
117
118/** H0 values to test - Nightly */
119const auto h0_values_nightly = framework::dataset::make("H0", 1, 4);
120
121/** Interleave values to test with RHS matrix */
122const auto i_values_rhs = framework::dataset::make("interleave_rhs", { true, false });
123
124/** Transpose values to test with RHS matrix */
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000125const auto t_values_rhs = framework::dataset::make("transpose_rhs", { true, false });
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000126
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100127/** Broadcast bias from vector to matrix */
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100128const auto broadcast_bias_values = framework::dataset::make("broadcast_bias", {false, true} );
129
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000130/** Configuration test */
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100131void 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 +0000132{
133 const unsigned int M = m_value;
134 const unsigned int N = n_value;
135 const unsigned int K = k_value;
136
137 GEMMLHSMatrixInfo lhs_info;
138 lhs_info.m0 = m0_value;
139 lhs_info.k0 = k0_value;
140
141 GEMMRHSMatrixInfo rhs_info;
142 rhs_info.n0 = n0_value;
143 rhs_info.k0 = k0_value;
144 rhs_info.h0 = h0_value;
145 rhs_info.interleave = i_value_rhs;
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000146 rhs_info.transpose = t_value_rhs;
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000147
Gian Marco Iodice7026b302019-06-26 17:18:11 +0100148 GEMMKernelInfo kernel_info;
149 kernel_info.m = M;
150 kernel_info.n = N;
151 kernel_info.k = K;
152 kernel_info.depth_output_gemm3d = 0;
153 kernel_info.reinterpret_input_as_3d = false;
154 kernel_info.broadcast_bias = broadcast_bias;
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000155
156 const TensorShape lhs_shape(K, M, b_value);
157 const TensorShape rhs_shape(N, K, b_value);
158 const TensorShape rhs_shape_reshaped = compute_rhs_reshaped_shape(TensorInfo(rhs_shape, 1, data_type),
159 rhs_info);
160
161 const TensorShape dst_shape = compute_mm_shape(TensorInfo(lhs_shape, 1, data_type),
162 TensorInfo(rhs_shape_reshaped, 1, data_type),
Gian Marco Iodice7026b302019-06-26 17:18:11 +0100163 kernel_info);
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000164
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100165 const TensorShape bias_shape(N,
166 broadcast_bias? 1 : M,
167 broadcast_bias? 1 : b_value);
168
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000169 // Create tensors
170 CLTensor lhs = create_tensor<CLTensor>(lhs_shape, data_type);
171 CLTensor rhs_reshaped = create_tensor<CLTensor>(rhs_shape_reshaped, data_type);
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100172 CLTensor bias = create_tensor<CLTensor>(bias_shape, data_type);
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100173 CLTensor dst = create_tensor<CLTensor>(dst_shape, data_type);
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100174
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000175 ARM_COMPUTE_EXPECT(lhs.info()->is_resizable(), framework::LogLevel::ERRORS);
176 ARM_COMPUTE_EXPECT(rhs_reshaped.info()->is_resizable(), framework::LogLevel::ERRORS);
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100177 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000178 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
179
180 // Create and configure function
181 CLGEMMMatrixMultiplyReshapedOnlyRHS gemm;
Gian Marco Iodice7026b302019-06-26 17:18:11 +0100182 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 +0000183}
184} // namespace
185
186TEST_SUITE(CL)
187TEST_SUITE(GEMMMatrixMultiplyReshapedOnlyRHS)
188TEST_SUITE(Float)
189TEST_SUITE(FP32)
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100190DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000191 m_values,
192 n_values),
193 k_values),
194 framework::dataset::make("batch_size", 1)),
195 m0_values_precommit),
196 n0_values_precommit),
197 k0_values_precommit),
198 h0_values_precommit),
199 i_values_rhs),
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000200 t_values_rhs),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100201 broadcast_bias_values),
202m_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 +0000203{
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100204 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 +0000205}
206
207FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<float>, framework::DatasetMode::ALL,
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100208 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000209 m_values,
210 n_values),
211 k_values),
212 b_values),
213 m0_values_precommit),
214 n0_values_precommit),
215 k0_values_precommit),
216 h0_values_precommit),
217 i_values_rhs),
218 t_values_rhs),
219 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100220 a_values),
221 beta_values),
222 broadcast_bias_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000223{
224 // Validate output
225 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
226}
227
228FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<float>, framework::DatasetMode::NIGHTLY,
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100229 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000230 m_values,
231 n_values),
232 k_values),
233 b_values),
234 m0_values_nightly),
235 n0_values_nightly),
236 k0_values_nightly),
237 h0_values_nightly),
238 i_values_rhs),
239 t_values_rhs),
240 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100241 a_values),
242 beta_values),
243 broadcast_bias_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000244{
245 // Validate output
246 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
247}
248
249FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<float>, framework::DatasetMode::ALL,
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100250 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000251 m_w_values,
252 m_h_values),
253 n_values),
254 k_values),
255 b_values),
256 m0_values_precommit),
257 n0_values_precommit),
258 k0_values_precommit),
259 h0_values_precommit),
260 i_values_rhs),
261 t_values_rhs),
262 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100263 a_values),
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100264 beta_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000265{
266 // Validate output
267 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
268}
269
270FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<float>, framework::DatasetMode::NIGHTLY,
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100271 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000272 m_w_values,
273 m_h_values),
274 n_values),
275 k_values),
276 b_values),
277 m0_values_nightly),
278 n0_values_nightly),
279 k0_values_nightly),
280 h0_values_nightly),
281 i_values_rhs),
282 t_values_rhs),
283 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100284 a_values),
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100285 beta_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000286{
287 // Validate output
288 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
289}
290TEST_SUITE_END() // FP32
291
292TEST_SUITE(FP16)
293FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<half>, framework::DatasetMode::ALL,
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100294 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000295 m_values,
296 n_values),
297 k_values),
298 b_values),
299 m0_values_precommit),
300 n0_values_precommit),
301 k0_values_precommit),
302 h0_values_precommit),
303 i_values_rhs),
304 t_values_rhs),
305 framework::dataset::make("DataType", DataType::F16)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100306 a_values),
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100307 beta_values),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100308 broadcast_bias_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000309{
310 // Validate output
311 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
312}
313
314FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<half>, framework::DatasetMode::NIGHTLY,
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100315 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000316 m_values,
317 n_values),
318 k_values),
319 b_values),
320 m0_values_nightly),
321 n0_values_nightly),
322 k0_values_nightly),
323 h0_values_nightly),
324 i_values_rhs),
325 t_values_rhs),
326 framework::dataset::make("DataType", DataType::F16)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100327 a_values),
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100328 beta_values),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100329 broadcast_bias_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000330{
331 // Validate output
332 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
333}
334
335FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<half>, framework::DatasetMode::ALL,
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100336 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000337 m_w_values,
338 m_h_values),
339 n_values),
340 k_values),
341 b_values),
342 m0_values_precommit),
343 n0_values_precommit),
344 k0_values_precommit),
345 h0_values_precommit),
346 i_values_rhs),
347 t_values_rhs),
348 framework::dataset::make("DataType", DataType::F16)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100349 a_values),
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100350 beta_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000351{
352 // Validate output
353 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
354}
355
356FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<half>, framework::DatasetMode::NIGHTLY,
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100357 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000358 m_w_values,
359 m_h_values),
360 n_values),
361 k_values),
362 b_values),
363 m0_values_nightly),
364 n0_values_nightly),
365 k0_values_nightly),
366 h0_values_nightly),
367 i_values_rhs),
368 t_values_rhs),
369 framework::dataset::make("DataType", DataType::F16)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100370 a_values),
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100371 beta_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000372{
373 // Validate output
374 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
375}
376TEST_SUITE_END() // FP16
377TEST_SUITE_END() // Float
378TEST_SUITE_END() // GEMMMatrixMulipltyReshapedOnlyRHS
379TEST_SUITE_END() // CL
380} // namespace validation
381} // namespace test
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100382} // namespace arm_compute