blob: 5baab611c60a650c0a54d247520221498ca84346 [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
Gian Marco Iodiceadc53952019-02-15 11:10:31 +000070/** Alpha values to test - Precommit */
71const auto a_values = framework::dataset::make("alpha", {1.0f, -0.75f} );
72
Georgios Pinitasb0f342e2019-05-21 13:32:43 +010073/** Beta values to test - Precommit */
Gian Marco Iodiced820db62019-08-05 14:23:23 +010074const auto beta_values = framework::dataset::make("beta", {-0.35f, 0.0f} );
Georgios Pinitasb0f342e2019-05-21 13:32:43 +010075
Gian Marco Iodiceadc53952019-02-15 11:10:31 +000076/** M values to test */
77const auto m_values = framework::dataset::make("M", 37);
78
79/** M_W values to test */
80const auto m_w_values = framework::dataset::make("M_W", 5);
81
82/** M_H values to test */
83const auto m_h_values = framework::dataset::make("M_H", 7);
84
85/** N values to test */
86const auto n_values = framework::dataset::make("N", 51);
87
88/** K values to test */
89const auto k_values = framework::dataset::make("K", 23);
90
91/** Batch size values to test */
92const auto b_values = framework::dataset::make("batch_size", 1, 3);
93
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +010094/** Activation values to test */
95const auto act_values = framework::dataset::make("Activation",
96{
97 ActivationLayerInfo(),
98 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 8.f, 2.f),
99});
100
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000101/** M0 values to test - Precommit */
102const auto m0_values_precommit = framework::dataset::make("M0", {4, 6});
103
104/** N0 values to test - Precommit */
Gian Marco Iodiced820db62019-08-05 14:23:23 +0100105const auto n0_values_precommit = framework::dataset::make("N0", { 4 });
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000106
107/** K0 values to test - Precommit */
108const auto k0_values_precommit = framework::dataset::make("K0", { 4 });
109
110/** H0 values to test - Precommit */
111const auto h0_values_precommit = framework::dataset::make("H0", 1, 3);
112
113/** M0 values to test - Nightly */
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000114const auto m0_values_nightly = framework::dataset::make("M0", 1, 8);
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000115
116/** N0 values to test - Nightly */
117const auto n0_values_nightly = framework::dataset::make("N0", { 2, 3, 4, 8 });
118
119/** K0 values to test - Nightly */
120const auto k0_values_nightly = framework::dataset::make("K0", { 2, 3, 4, 8 });
121
122/** H0 values to test - Nightly */
123const auto h0_values_nightly = framework::dataset::make("H0", 1, 4);
124
125/** Interleave values to test with RHS matrix */
126const auto i_values_rhs = framework::dataset::make("interleave_rhs", { true, false });
127
128/** Transpose values to test with RHS matrix */
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000129const auto t_values_rhs = framework::dataset::make("transpose_rhs", { true, false });
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000130
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100131/** Broadcast bias from vector to matrix */
Gian Marco Iodiced820db62019-08-05 14:23:23 +0100132const auto broadcast_bias_values = framework::dataset::make("broadcast_bias", { false, true } );
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100133
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000134/** Configuration test */
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100135void 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 +0000136{
137 const unsigned int M = m_value;
138 const unsigned int N = n_value;
139 const unsigned int K = k_value;
140
141 GEMMLHSMatrixInfo lhs_info;
142 lhs_info.m0 = m0_value;
143 lhs_info.k0 = k0_value;
144
145 GEMMRHSMatrixInfo rhs_info;
146 rhs_info.n0 = n0_value;
147 rhs_info.k0 = k0_value;
148 rhs_info.h0 = h0_value;
149 rhs_info.interleave = i_value_rhs;
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000150 rhs_info.transpose = t_value_rhs;
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000151
Gian Marco Iodice7026b302019-06-26 17:18:11 +0100152 GEMMKernelInfo kernel_info;
153 kernel_info.m = M;
154 kernel_info.n = N;
155 kernel_info.k = K;
156 kernel_info.depth_output_gemm3d = 0;
157 kernel_info.reinterpret_input_as_3d = false;
158 kernel_info.broadcast_bias = broadcast_bias;
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100159 kernel_info.activation_info = act_info;
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000160
161 const TensorShape lhs_shape(K, M, b_value);
162 const TensorShape rhs_shape(N, K, b_value);
163 const TensorShape rhs_shape_reshaped = compute_rhs_reshaped_shape(TensorInfo(rhs_shape, 1, data_type),
164 rhs_info);
165
166 const TensorShape dst_shape = compute_mm_shape(TensorInfo(lhs_shape, 1, data_type),
167 TensorInfo(rhs_shape_reshaped, 1, data_type),
Gian Marco Iodice7026b302019-06-26 17:18:11 +0100168 kernel_info);
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000169
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100170 const TensorShape bias_shape(N,
171 broadcast_bias? 1 : M,
172 broadcast_bias? 1 : b_value);
173
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000174 // Create tensors
175 CLTensor lhs = create_tensor<CLTensor>(lhs_shape, data_type);
176 CLTensor rhs_reshaped = create_tensor<CLTensor>(rhs_shape_reshaped, data_type);
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100177 CLTensor bias = create_tensor<CLTensor>(bias_shape, data_type);
Gian Marco Iodicee16c8902019-06-14 16:11:10 +0100178 CLTensor dst = create_tensor<CLTensor>(dst_shape, data_type);
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100179
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000180 ARM_COMPUTE_EXPECT(lhs.info()->is_resizable(), framework::LogLevel::ERRORS);
181 ARM_COMPUTE_EXPECT(rhs_reshaped.info()->is_resizable(), framework::LogLevel::ERRORS);
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100182 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000183 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
184
185 // Create and configure function
186 CLGEMMMatrixMultiplyReshapedOnlyRHS gemm;
Gian Marco Iodice7026b302019-06-26 17:18:11 +0100187 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 +0000188}
189} // namespace
190
191TEST_SUITE(CL)
192TEST_SUITE(GEMMMatrixMultiplyReshapedOnlyRHS)
193TEST_SUITE(Float)
194TEST_SUITE(FP32)
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100195DATA_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 +0000196 m_values,
197 n_values),
198 k_values),
199 framework::dataset::make("batch_size", 1)),
200 m0_values_precommit),
201 n0_values_precommit),
202 k0_values_precommit),
203 h0_values_precommit),
204 i_values_rhs),
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000205 t_values_rhs),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100206 broadcast_bias_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100207 act_values),
208m_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 +0000209{
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100210 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 +0000211}
212
213FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<float>, framework::DatasetMode::ALL,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100214 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000215 m_values,
216 n_values),
217 k_values),
218 b_values),
219 m0_values_precommit),
220 n0_values_precommit),
221 k0_values_precommit),
222 h0_values_precommit),
223 i_values_rhs),
224 t_values_rhs),
225 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100226 a_values),
227 beta_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100228 broadcast_bias_values),
229 act_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000230{
231 // Validate output
232 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
233}
234
235FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<float>, framework::DatasetMode::NIGHTLY,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100236 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000237 m_values,
238 n_values),
239 k_values),
240 b_values),
241 m0_values_nightly),
242 n0_values_nightly),
243 k0_values_nightly),
244 h0_values_nightly),
245 i_values_rhs),
246 t_values_rhs),
247 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100248 a_values),
249 beta_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100250 broadcast_bias_values),
251 act_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000252{
253 // Validate output
254 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
255}
256
257FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<float>, framework::DatasetMode::ALL,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100258 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000259 m_w_values,
260 m_h_values),
261 n_values),
262 k_values),
263 b_values),
264 m0_values_precommit),
265 n0_values_precommit),
266 k0_values_precommit),
267 h0_values_precommit),
268 i_values_rhs),
269 t_values_rhs),
270 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100271 a_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100272 beta_values),
273 act_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000274{
275 // Validate output
276 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
277}
278
279FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<float>, framework::DatasetMode::NIGHTLY,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100280 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000281 m_w_values,
282 m_h_values),
283 n_values),
284 k_values),
285 b_values),
286 m0_values_nightly),
287 n0_values_nightly),
288 k0_values_nightly),
289 h0_values_nightly),
290 i_values_rhs),
291 t_values_rhs),
292 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100293 a_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100294 beta_values),
295 act_values))
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000296{
297 // Validate output
298 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
299}
300TEST_SUITE_END() // FP32
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000301TEST_SUITE_END() // Float
302TEST_SUITE_END() // GEMMMatrixMulipltyReshapedOnlyRHS
303TEST_SUITE_END() // CL
304} // namespace validation
305} // namespace test
Georgios Pinitasb0f342e2019-05-21 13:32:43 +0100306} // namespace arm_compute