blob: 106d650109101a1932fdcc2a22880f14ca6ac765 [file] [log] [blame]
Gian Marco Iodice62251f72019-03-11 16:07:12 +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/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
133 GEMMReshapeInfo gemm_info(M, N, K);
134
135 const TensorShape lhs_shape(K, M, b_value);
136 const TensorShape rhs_shape(N, K, b_value);
137 const TensorShape rhs_shape_reshaped = compute_rhs_reshaped_shape(TensorInfo(rhs_shape, 1, DataType::QASYMM8),
138 rhs_info);
139
140 const TensorShape dst_shape = compute_mm_shape(TensorInfo(lhs_shape, 1, DataType::QASYMM8),
141 TensorInfo(rhs_shape_reshaped, 1, DataType::QASYMM8),
142 gemm_info);
143
144 // Create tensors
145 CLTensor lhs = create_tensor<CLTensor>(lhs_shape, DataType::QASYMM8);
146 CLTensor rhs_reshaped = create_tensor<CLTensor>(rhs_shape_reshaped, DataType::QASYMM8);
147 CLTensor dst = create_tensor<CLTensor>(dst_shape, DataType::S32);
148
149 ARM_COMPUTE_EXPECT(lhs.info()->is_resizable(), framework::LogLevel::ERRORS);
150 ARM_COMPUTE_EXPECT(rhs_reshaped.info()->is_resizable(), framework::LogLevel::ERRORS);
151 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
152
153 // Create and configure function
154 CLGEMMLowpMatrixMultiplyReshapedOnlyRHS gemm;
155 gemm.configure(&lhs, &rhs_reshaped, &dst, lhs_info, rhs_info, gemm_info);
156}
157} // namespace
158
159TEST_SUITE(CL)
160TEST_SUITE(GEMMLowpMatrixMultiplyReshapedOnlyRHS)
161DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine(
162 m_values,
163 n_values),
164 k_values),
165 framework::dataset::make("batch_size", 1)),
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000166 m0_values_precommit_1),
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000167 n0_values_precommit),
168 k0_values_precommit),
169 h0_values_precommit),
170 i_values_rhs),
171m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, h0_value, i_value_rhs)
172{
173 validate_configuration(m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, h0_value, i_value_rhs);
174}
175
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000176FIXTURE_DATA_TEST_CASE(RunSmall_1, CLGEMMLowpMatrixMultiplyReshapedOnlyRHSFixture, framework::DatasetMode::ALL,
177 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000178 m_values,
179 n_values),
180 k_values),
181 b_values),
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000182 m0_values_precommit_1),
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000183 n0_values_precommit),
184 k0_values_precommit),
185 h0_values_precommit),
186 i_values_rhs),
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000187 t_values_rhs),
188 framework::dataset::make("DataType", { DataType::QASYMM8 })))
189{
190 // Validate output
191 validate(CLAccessor(_target), _reference);
192}
193
194FIXTURE_DATA_TEST_CASE(RunSmall_2, CLGEMMLowpMatrixMultiplyReshapedOnlyRHSFixture, framework::DatasetMode::ALL,
195 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
196 m_values,
197 n_values),
198 k_values),
199 b_values),
200 m0_values_precommit_2),
201 n0_values_precommit),
202 k0_values_precommit),
203 h0_values_precommit),
204 i_values_rhs),
205 t_values_rhs),
206 framework::dataset::make("DataType", { DataType::QASYMM8_SIGNED })))
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000207{
208 // Validate output
209 validate(CLAccessor(_target), _reference);
210}
211
212FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyReshapedOnlyRHSFixture, framework::DatasetMode::NIGHTLY,
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000213 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000214 m_values,
215 n_values),
216 k_values),
217 b_values),
218 m0_values_nightly),
219 n0_values_nightly),
220 k0_values_nightly),
221 h0_values_nightly),
222 i_values_rhs),
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000223 t_values_rhs),
224 framework::dataset::make("DataType", { DataType::QASYMM8 })))
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000225{
226 // Validate output
227 validate(CLAccessor(_target), _reference);
228}
229
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000230FIXTURE_DATA_TEST_CASE(RunSmall3D_1, CLGEMMLowpMatrixMultiplyReshapedOnlyRHS3DFixture, framework::DatasetMode::ALL,
231 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000232 m_w_values,
233 m_h_values),
234 n_values),
235 k_values),
236 b_values),
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000237 m0_values_precommit_1),
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000238 n0_values_precommit),
239 k0_values_precommit),
240 h0_values_precommit),
241 i_values_rhs),
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000242 t_values_rhs),
243 framework::dataset::make("DataType", { DataType::QASYMM8 })))
244{
245 // Validate output
246 validate(CLAccessor(_target), _reference);
247}
248
249FIXTURE_DATA_TEST_CASE(RunSmall3D_2, CLGEMMLowpMatrixMultiplyReshapedOnlyRHS3DFixture, framework::DatasetMode::ALL,
250 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
251 m_w_values,
252 m_h_values),
253 n_values),
254 k_values),
255 b_values),
256 m0_values_precommit_2),
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::QASYMM8_SIGNED })))
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000263{
264 // Validate output
265 validate(CLAccessor(_target), _reference);
266}
267
268FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMLowpMatrixMultiplyReshapedOnlyRHS3DFixture, framework::DatasetMode::NIGHTLY,
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000269 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000270 m_w_values,
271 m_h_values),
272 n_values),
273 k_values),
274 b_values),
275 m0_values_nightly),
276 n0_values_nightly),
277 k0_values_nightly),
278 h0_values_nightly),
279 i_values_rhs),
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000280 t_values_rhs),
281 framework::dataset::make("DataType", { DataType::QASYMM8 })))
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000282{
283 // Validate output
284 validate(CLAccessor(_target), _reference);
285}
286TEST_SUITE_END() // GEMMLowpMatrixMultiplyReshapedOnlyRHS
287TEST_SUITE_END() // CL
288} // namespace validation
289} // namespace test
290} // namespace arm_compute