blob: d8618bd8813c7e5137829652f81aa25d810872d3 [file] [log] [blame]
Gian Marco Iodice62251f72019-03-11 16:07:12 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 Arm Limited.
Gian Marco Iodice62251f72019-03-11 16:07:12 +00003 *
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/CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel.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/GEMMLowpFixture.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 CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel
52using CLGEMMLowpMatrixMultiplyReshapedOnlyRHS = CLSynthetizeFunction<CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel>;
53
54// Fixture for CLGEMMLowpMatrixMultiplyReshapedOnlyRHS
55using CLGEMMLowpMatrixMultiplyReshapedOnlyRHSFixture = GEMMLowpMatrixMultiplyReshapedOnlyRHSValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeRHSMatrix, CLGEMMLowpMatrixMultiplyReshapedOnlyRHS>;
56
57// Fixture for CLGEMMLowpMatrixMultiplyReshapedOnlyRHS3D
58using CLGEMMLowpMatrixMultiplyReshapedOnlyRHS3DFixture =
59 GEMMLowpMatrixMultiplyReshapedOnlyRHS3DValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeRHSMatrix, CLGEMMLowpMatrixMultiplyReshapedOnlyRHS>;
60
61namespace
62{
63// *INDENT-OFF*
64// clang-format off
65
66/** M values to test */
67const auto m_values = framework::dataset::make("M", 37);
68
69/** M_W values to test */
70const auto m_w_values = framework::dataset::make("M_W", 5);
71
72/** M_H values to test */
73const auto m_h_values = framework::dataset::make("M_H", 7);
74
75/** N values to test */
76const auto n_values = framework::dataset::make("N", 51);
77
78/** K values to test */
79const auto k_values = framework::dataset::make("K", 23);
80
81/** Batch size values to test */
82const auto b_values = framework::dataset::make("batch_size", 1, 3);
83
84/** M0 values to test - Precommit */
Michele Di Giorgiof9179d32019-11-27 16:17:30 +000085const auto m0_values_precommit_1 = framework::dataset::make("M0", {4});
86const auto m0_values_precommit_2 = framework::dataset::make("M0", {6});
Gian Marco Iodice62251f72019-03-11 16:07:12 +000087
88/** N0 values to test - Precommit */
Gian Marco Iodiced820db62019-08-05 14:23:23 +010089const auto n0_values_precommit = framework::dataset::make("N0", { 4 });
Gian Marco Iodice62251f72019-03-11 16:07:12 +000090
91/** K0 values to test - Precommit */
Gian Marco Iodiced820db62019-08-05 14:23:23 +010092const auto k0_values_precommit = framework::dataset::make("K0", { 16 });
Gian Marco Iodice62251f72019-03-11 16:07:12 +000093
94/** H0 values to test - Precommit */
95const auto h0_values_precommit = framework::dataset::make("H0", 1, 3);
96
97/** M0 values to test - Nightly */
98const auto m0_values_nightly = framework::dataset::make("M0", 2, 8);
99
100/** N0 values to test - Nightly */
101const auto n0_values_nightly = framework::dataset::make("N0", { 2, 3, 4, 8 });
102
103/** K0 values to test - Nightly */
Gian Marco Iodiced820db62019-08-05 14:23:23 +0100104const auto k0_values_nightly = framework::dataset::make("K0", { 2, 3, 4, 8, 16 });
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000105
106/** H0 values to test - Nightly */
107const auto h0_values_nightly = framework::dataset::make("H0", 1, 4);
108
109/** Interleave values to test with RHS matrix */
110const auto i_values_rhs = framework::dataset::make("interleave_rhs", { true, false });
111
112/** Transpose values to test with RHS matrix */
113const auto t_values_rhs = framework::dataset::make("transpose_rhs", { true });
114
115/** Configuration test */
116void 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)
117{
118 const unsigned int M = m_value;
119 const unsigned int N = n_value;
120 const unsigned int K = k_value;
121
122 GEMMLHSMatrixInfo lhs_info;
123 lhs_info.m0 = m0_value;
124 lhs_info.k0 = k0_value;
125
126 GEMMRHSMatrixInfo rhs_info;
127 rhs_info.n0 = n0_value;
128 rhs_info.k0 = k0_value;
129 rhs_info.h0 = h0_value;
130 rhs_info.interleave = i_value_rhs;
131 rhs_info.transpose = true;
132
Michele Di Giorgiob54ba282020-01-14 15:31:55 +0000133 GEMMKernelInfo gemm_info;
134 gemm_info.m = M;
135 gemm_info.n = N;
136 gemm_info.k = K;
137 gemm_info.lhs_info = lhs_info;
138 gemm_info.rhs_info = rhs_info;
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000139
140 const TensorShape lhs_shape(K, M, b_value);
141 const TensorShape rhs_shape(N, K, b_value);
142 const TensorShape rhs_shape_reshaped = compute_rhs_reshaped_shape(TensorInfo(rhs_shape, 1, DataType::QASYMM8),
143 rhs_info);
144
145 const TensorShape dst_shape = compute_mm_shape(TensorInfo(lhs_shape, 1, DataType::QASYMM8),
146 TensorInfo(rhs_shape_reshaped, 1, DataType::QASYMM8),
147 gemm_info);
148
149 // Create tensors
150 CLTensor lhs = create_tensor<CLTensor>(lhs_shape, DataType::QASYMM8);
151 CLTensor rhs_reshaped = create_tensor<CLTensor>(rhs_shape_reshaped, DataType::QASYMM8);
152 CLTensor dst = create_tensor<CLTensor>(dst_shape, DataType::S32);
153
154 ARM_COMPUTE_EXPECT(lhs.info()->is_resizable(), framework::LogLevel::ERRORS);
155 ARM_COMPUTE_EXPECT(rhs_reshaped.info()->is_resizable(), framework::LogLevel::ERRORS);
156 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
157
158 // Create and configure function
159 CLGEMMLowpMatrixMultiplyReshapedOnlyRHS gemm;
Michele Di Giorgiob54ba282020-01-14 15:31:55 +0000160 gemm.configure(&lhs, &rhs_reshaped, &dst, gemm_info);
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000161}
162} // namespace
163
164TEST_SUITE(CL)
165TEST_SUITE(GEMMLowpMatrixMultiplyReshapedOnlyRHS)
166DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine(
167 m_values,
168 n_values),
169 k_values),
170 framework::dataset::make("batch_size", 1)),
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000171 m0_values_precommit_1),
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000172 n0_values_precommit),
173 k0_values_precommit),
174 h0_values_precommit),
175 i_values_rhs),
176m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, h0_value, i_value_rhs)
177{
178 validate_configuration(m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, h0_value, i_value_rhs);
179}
180
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000181FIXTURE_DATA_TEST_CASE(RunSmall_1, CLGEMMLowpMatrixMultiplyReshapedOnlyRHSFixture, framework::DatasetMode::ALL,
182 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000183 m_values,
184 n_values),
185 k_values),
186 b_values),
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000187 m0_values_precommit_1),
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000188 n0_values_precommit),
189 k0_values_precommit),
190 h0_values_precommit),
191 i_values_rhs),
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000192 t_values_rhs),
193 framework::dataset::make("DataType", { DataType::QASYMM8 })))
194{
195 // Validate output
196 validate(CLAccessor(_target), _reference);
197}
198
199FIXTURE_DATA_TEST_CASE(RunSmall_2, CLGEMMLowpMatrixMultiplyReshapedOnlyRHSFixture, framework::DatasetMode::ALL,
200 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
201 m_values,
202 n_values),
203 k_values),
204 b_values),
205 m0_values_precommit_2),
206 n0_values_precommit),
207 k0_values_precommit),
208 h0_values_precommit),
209 i_values_rhs),
210 t_values_rhs),
211 framework::dataset::make("DataType", { DataType::QASYMM8_SIGNED })))
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000212{
213 // Validate output
214 validate(CLAccessor(_target), _reference);
215}
216
Michalis Spyrou1d897772019-12-09 18:47:29 +0000217FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyReshapedOnlyRHSFixture, framework::DatasetMode::DISABLED,
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000218 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000219 m_values,
220 n_values),
221 k_values),
222 b_values),
223 m0_values_nightly),
224 n0_values_nightly),
225 k0_values_nightly),
226 h0_values_nightly),
227 i_values_rhs),
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000228 t_values_rhs),
229 framework::dataset::make("DataType", { DataType::QASYMM8 })))
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000230{
231 // Validate output
232 validate(CLAccessor(_target), _reference);
233}
234
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000235FIXTURE_DATA_TEST_CASE(RunSmall3D_1, CLGEMMLowpMatrixMultiplyReshapedOnlyRHS3DFixture, framework::DatasetMode::ALL,
236 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000237 m_w_values,
238 m_h_values),
239 n_values),
240 k_values),
241 b_values),
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000242 m0_values_precommit_1),
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000243 n0_values_precommit),
244 k0_values_precommit),
245 h0_values_precommit),
246 i_values_rhs),
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000247 t_values_rhs),
248 framework::dataset::make("DataType", { DataType::QASYMM8 })))
249{
250 // Validate output
251 validate(CLAccessor(_target), _reference);
252}
253
254FIXTURE_DATA_TEST_CASE(RunSmall3D_2, CLGEMMLowpMatrixMultiplyReshapedOnlyRHS3DFixture, framework::DatasetMode::ALL,
255 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
256 m_w_values,
257 m_h_values),
258 n_values),
259 k_values),
260 b_values),
261 m0_values_precommit_2),
262 n0_values_precommit),
263 k0_values_precommit),
264 h0_values_precommit),
265 i_values_rhs),
266 t_values_rhs),
267 framework::dataset::make("DataType", { DataType::QASYMM8_SIGNED })))
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000268{
269 // Validate output
270 validate(CLAccessor(_target), _reference);
271}
272
Michalis Spyrou1d897772019-12-09 18:47:29 +0000273FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMLowpMatrixMultiplyReshapedOnlyRHS3DFixture, framework::DatasetMode::DISABLED,
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000274 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000275 m_w_values,
276 m_h_values),
277 n_values),
278 k_values),
279 b_values),
280 m0_values_nightly),
281 n0_values_nightly),
282 k0_values_nightly),
283 h0_values_nightly),
284 i_values_rhs),
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000285 t_values_rhs),
286 framework::dataset::make("DataType", { DataType::QASYMM8 })))
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000287{
288 // Validate output
289 validate(CLAccessor(_target), _reference);
290}
291TEST_SUITE_END() // GEMMLowpMatrixMultiplyReshapedOnlyRHS
292TEST_SUITE_END() // CL
293} // namespace validation
294} // namespace test
295} // namespace arm_compute