blob: 0ddf43766f78ec7b495215f0e9d916618f2fee78 [file] [log] [blame]
giuros01b3204e72019-04-01 13:50:22 +01001/*
Jakub Sujak0d27b2e2023-08-24 14:01:20 +01002 * Copyright (c) 2019-2023 Arm Limited.
giuros01b3204e72019-04-01 13:50:22 +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 Iodice7026b302019-06-26 17:18:11 +010024#include "arm_compute/core/KernelDescriptors.h"
giuros01b3204e72019-04-01 13:50:22 +010025#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"
Georgios Pinitas7891a732021-08-20 21:39:25 +010029#include "src/gpu/cl/kernels/ClGemmMatrixMultiplyNativeKernel.h"
giuros01b3204e72019-04-01 13:50:22 +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;
Georgios Pinitas856f66e2021-04-22 21:13:21 +010047using namespace arm_compute::opencl::kernels;
giuros01b3204e72019-04-01 13:50:22 +010048
Georgios Pinitas856f66e2021-04-22 21:13:21 +010049// Create function for ClGemmMatrixMultiplyNativeKernel
50using CLGEMMMatrixMultiplyNative = CLSynthetizeOperator<ClGemmMatrixMultiplyNativeKernel>;
giuros01b3204e72019-04-01 13:50:22 +010051
52// Fixture for CLGEMMMatrixMultiplyNative
53template <typename T>
54using CLGEMMMatrixMultiplyNativeFixture = GEMMMatrixMultiplyNativeValidationFixture<CLTensor, CLAccessor, T, CLGEMMMatrixMultiplyNative>;
55
56// Fixture for CLGEMMMatrixMultiplyNative3D
57template <typename T>
58using CLGEMMMatrixMultiplyNative3DFixture = GEMMMatrixMultiplyNative3DValidationFixture<CLTensor, CLAccessor, T, CLGEMMMatrixMultiplyNative>;
59
60namespace
61{
62// *INDENT-OFF*
63// clang-format off
64RelativeTolerance<float> rel_tolerance_f32(0.001f);
65constexpr float abs_tolerance_f32(0.0001f);
66
giuros01b3204e72019-04-01 13:50:22 +010067/** Alpha values to test - Precommit */
68const auto a_values = framework::dataset::make("alpha", {1.0f, -0.75f} );
69
Gian Marco Iodice944170e2019-06-24 14:40:30 +010070/** Beta values to test - Precommit */
71const auto beta_values = framework::dataset::make("beta", {-0.75f, 0.0f} );
72
giuros01b3204e72019-04-01 13:50:22 +010073/** M values to test */
74const auto m_values = framework::dataset::make("M", 37);
75
76/** M_W values to test */
77const auto m_w_values = framework::dataset::make("M_W", 5);
78
79/** M_H values to test */
80const auto m_h_values = framework::dataset::make("M_H", 7);
81
82/** N values to test */
83const auto n_values = framework::dataset::make("N", 51);
84
85/** K values to test */
86const auto k_values = framework::dataset::make("K", 23);
87
88/** Batch size values to test */
89const auto b_values = framework::dataset::make("batch_size", 1, 3);
90
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +010091/** Activation values to test */
92const auto act_values = framework::dataset::make("Activation",
93{
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +010094 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 8.f, 2.f),
Gian Marco Iodice635013a2022-11-03 09:30:56 +000095 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::ELU),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +010096});
97
giuros01b3204e72019-04-01 13:50:22 +010098/** M0 values to test - Precommit */
Gian Marco Iodiced820db62019-08-05 14:23:23 +010099const auto m0_values_precommit = framework::dataset::make("M0", { 4, 6 });
giuros01b3204e72019-04-01 13:50:22 +0100100
101/** N0 values to test - Precommit */
Gian Marco Iodiced820db62019-08-05 14:23:23 +0100102const auto n0_values_precommit = framework::dataset::make("N0", { 4 });
giuros01b3204e72019-04-01 13:50:22 +0100103
104/** K0 values to test - Precommit */
105const auto k0_values_precommit = framework::dataset::make("K0", { 4 });
106
107/** H0 values to test - Precommit */
108const auto h0_values_precommit = framework::dataset::make("H0", 1, 3);
109
110/** M0 values to test - Nightly */
111const auto m0_values_nightly = framework::dataset::make("M0", 1, 8);
112
113/** N0 values to test - Nightly */
114const auto n0_values_nightly = framework::dataset::make("N0", { 2, 3, 4, 8 });
115
116/** K0 values to test - Nightly */
117const auto k0_values_nightly = framework::dataset::make("K0", { 2, 3, 4, 8 });
118
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100119/** Broadcast bias from vector to matrix */
Gian Marco Iodiced820db62019-08-05 14:23:23 +0100120const auto broadcast_bias_values = framework::dataset::make("broadcast_bias", { false, true } );
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100121
SiCong Lib972ae62020-08-03 15:39:45 +0100122/** Boundary handling cases for testing partial/non-partial (full) block dimensions, resulting from different combinations
123 * of M, M0, N and N0 values.
124 * M0 and N0 are kept constant, while the different test cases need to vary M and N.
125 *
126 * Eg. M = 64 and N = 33 result in a block dimension that has no partial blocks (all full blocks) in Y dimension and
127 * parital blocks in X dimension.
128 */
129const auto boundary_handling_cases = combine(combine(combine(combine(combine(combine(combine(combine(combine(
130 // Large k to force potential out-of-bound reads on input0
131 framework::dataset::make("K", 315),
132 // Batch size == 1 to force potential out-of-bound reads on input0
133 framework::dataset::make("batch_size", 1)),
134 framework::dataset::make("M0", 4)),
135 framework::dataset::make("N0", 4)),
136 framework::dataset::make("K0", 4)),
137 // Only need to test F32 as F16 shares identical boundary handling logics
138 framework::dataset::make("DataType", DataType::F32)),
139 framework::dataset::make("alpha", -0.75f )),
140 framework::dataset::make("beta", -0.35f )),
141 broadcast_bias_values),
142 framework::dataset::make("Activation", ActivationLayerInfo()));
143
giuros01b3204e72019-04-01 13:50:22 +0100144/** Configuration test */
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100145void 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, bool broadcast_bias, DataType data_type, const ActivationLayerInfo &act_info)
giuros01b3204e72019-04-01 13:50:22 +0100146{
147 const unsigned int M = m_value;
148 const unsigned int N = n_value;
149 const unsigned int K = k_value;
150
151 GEMMLHSMatrixInfo lhs_info;
152 lhs_info.m0 = m0_value;
153 lhs_info.k0 = k0_value;
154
155 GEMMRHSMatrixInfo rhs_info;
156 rhs_info.n0 = n0_value;
157 rhs_info.k0 = k0_value;
158
Gian Marco Iodice7026b302019-06-26 17:18:11 +0100159 GEMMKernelInfo kernel_info;
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100160 kernel_info.m = M;
161 kernel_info.n = N;
162 kernel_info.k = K;
163 kernel_info.broadcast_bias = broadcast_bias;
164 kernel_info.activation_info = act_info;
giuros01b3204e72019-04-01 13:50:22 +0100165
166 const TensorShape lhs_shape(K, M, b_value);
167 const TensorShape rhs_shape(N, K, b_value);
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100168 const TensorShape bias_shape(N,
169 broadcast_bias? 1 : M,
170 broadcast_bias? 1 : b_value);
giuros01b3204e72019-04-01 13:50:22 +0100171 const TensorShape dst_shape = compute_mm_shape(TensorInfo(lhs_shape, 1, data_type),
172 TensorInfo(rhs_shape, 1, data_type),
Gian Marco Iodice7026b302019-06-26 17:18:11 +0100173 kernel_info);
174
giuros01b3204e72019-04-01 13:50:22 +0100175 // Create tensors
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100176 CLTensor lhs = create_tensor<CLTensor>(lhs_shape, data_type);
giuros01b3204e72019-04-01 13:50:22 +0100177 CLTensor rhs = create_tensor<CLTensor>(rhs_shape, data_type);
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100178 CLTensor bias = create_tensor<CLTensor>(bias_shape, data_type);
179 CLTensor dst = create_tensor<CLTensor>(dst_shape, data_type);
giuros01b3204e72019-04-01 13:50:22 +0100180
181 ARM_COMPUTE_EXPECT(lhs.info()->is_resizable(), framework::LogLevel::ERRORS);
182 ARM_COMPUTE_EXPECT(rhs.info()->is_resizable(), framework::LogLevel::ERRORS);
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100183 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
giuros01b3204e72019-04-01 13:50:22 +0100184 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
185
186 // Create and configure function
187 CLGEMMMatrixMultiplyNative gemm;
Georgios Pinitas856f66e2021-04-22 21:13:21 +0100188 gemm.configure(lhs.info(), rhs.info(), bias.info(), dst.info(), 1.0f, 1.0f, lhs_info, rhs_info, kernel_info);
giuros01b3204e72019-04-01 13:50:22 +0100189}
190} // namespace
191
192TEST_SUITE(CL)
193TEST_SUITE(GEMMMatrixMultiplyNative)
194TEST_SUITE(Float)
195TEST_SUITE(FP32)
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100196DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine(
giuros01b3204e72019-04-01 13:50:22 +0100197 m_values,
198 n_values),
199 k_values),
200 framework::dataset::make("batch_size", 1)),
201 m0_values_precommit),
202 n0_values_precommit),
203 k0_values_precommit),
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100204 broadcast_bias_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100205 act_values),
206m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, broadcast_bias, act_value)
giuros01b3204e72019-04-01 13:50:22 +0100207{
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100208 validate_configuration(m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, broadcast_bias, DataType::F32, act_value);
giuros01b3204e72019-04-01 13:50:22 +0100209}
210
SiCong Lib972ae62020-08-03 15:39:45 +0100211FIXTURE_DATA_TEST_CASE(RunSmallBoundaryHandlingPartialInXPartialInY, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::ALL,
212 combine(combine(
213 framework::dataset::make("M", 3),
214 framework::dataset::make("N", 1)),
215 boundary_handling_cases))
216{
217 // Validate output
218 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
219}
220
221FIXTURE_DATA_TEST_CASE(RunSmallBoundaryHandlingPartialInXFullInY, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::ALL,
222 combine(combine(
223 framework::dataset::make("M", 64),
224 framework::dataset::make("N", 51)),
225 boundary_handling_cases))
226{
227 // Validate output
228 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
229}
230
231FIXTURE_DATA_TEST_CASE(RunSmallBoundaryHandlingFullInXFullInY, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::ALL,
232 combine(combine(
233 framework::dataset::make("M", 64),
234 framework::dataset::make("N", 32)),
235 boundary_handling_cases))
236{
237 // Validate output
238 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
239}
240
241FIXTURE_DATA_TEST_CASE(RunSmallBoundaryHandlingFullInXPartialInY, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::ALL,
242 combine(combine(
243 framework::dataset::make("M", 37),
244 framework::dataset::make("N", 32)),
245 boundary_handling_cases))
246{
247 // Validate output
248 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
249}
250
giuros01b3204e72019-04-01 13:50:22 +0100251FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::ALL,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100252 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
giuros01b3204e72019-04-01 13:50:22 +0100253 m_values,
254 n_values),
255 k_values),
256 b_values),
257 m0_values_precommit),
258 n0_values_precommit),
259 k0_values_precommit),
260 framework::dataset::make("DataType", DataType::F32)),
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100261 a_values),
262 beta_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100263 broadcast_bias_values),
264 act_values))
giuros01b3204e72019-04-01 13:50:22 +0100265{
266 // Validate output
267 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
268}
269
Michalis Spyrou1d897772019-12-09 18:47:29 +0000270FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::DISABLED,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100271 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
giuros01b3204e72019-04-01 13:50:22 +0100272 m_values,
273 n_values),
274 k_values),
275 b_values),
276 m0_values_nightly),
277 n0_values_nightly),
278 k0_values_nightly),
279 framework::dataset::make("DataType", DataType::F32)),
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100280 a_values),
281 beta_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100282 broadcast_bias_values),
283 act_values))
giuros01b3204e72019-04-01 13:50:22 +0100284{
285 // Validate output
286 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
287}
288
289FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyNative3DFixture<float>, framework::DatasetMode::ALL,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100290 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
giuros01b3204e72019-04-01 13:50:22 +0100291 m_w_values,
292 m_h_values),
293 n_values),
294 k_values),
295 b_values),
296 m0_values_precommit),
297 n0_values_precommit),
298 k0_values_precommit),
299 framework::dataset::make("DataType", DataType::F32)),
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100300 a_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100301 beta_values),
302 act_values))
giuros01b3204e72019-04-01 13:50:22 +0100303{
304 // Validate output
305 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
306}
307
Michalis Spyrou1d897772019-12-09 18:47:29 +0000308FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMMatrixMultiplyNative3DFixture<float>, framework::DatasetMode::DISABLED,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100309 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
giuros01b3204e72019-04-01 13:50:22 +0100310 m_w_values,
311 m_h_values),
312 n_values),
313 k_values),
314 b_values),
315 m0_values_nightly),
316 n0_values_nightly),
317 k0_values_nightly),
318 framework::dataset::make("DataType", DataType::F32)),
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100319 a_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100320 beta_values),
321 act_values))
giuros01b3204e72019-04-01 13:50:22 +0100322{
323 // Validate output
324 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
325}
SiCongLiafa19722021-10-24 19:12:33 +0100326
giuros01b3204e72019-04-01 13:50:22 +0100327TEST_SUITE_END() // FP32
giuros01b3204e72019-04-01 13:50:22 +0100328TEST_SUITE_END() // Float
329TEST_SUITE_END() // GEMMMatrixMulipltyNative
330TEST_SUITE_END() // CL
331} // namespace validation
332} // namespace test
333} // namespace arm_compute