blob: 6ead11ab23783f083c42ab424e7199ebf05c77ea [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 */
85const auto m0_values_precommit = framework::dataset::make("M0", {4, 6});
86
87/** N0 values to test - Precommit */
Gian Marco Iodiced820db62019-08-05 14:23:23 +010088const auto n0_values_precommit = framework::dataset::make("N0", { 4 });
Gian Marco Iodice62251f72019-03-11 16:07:12 +000089
90/** K0 values to test - Precommit */
Gian Marco Iodiced820db62019-08-05 14:23:23 +010091const auto k0_values_precommit = framework::dataset::make("K0", { 16 });
Gian Marco Iodice62251f72019-03-11 16:07:12 +000092
93/** H0 values to test - Precommit */
94const auto h0_values_precommit = framework::dataset::make("H0", 1, 3);
95
96/** M0 values to test - Nightly */
97const auto m0_values_nightly = framework::dataset::make("M0", 2, 8);
98
99/** N0 values to test - Nightly */
100const auto n0_values_nightly = framework::dataset::make("N0", { 2, 3, 4, 8 });
101
102/** K0 values to test - Nightly */
Gian Marco Iodiced820db62019-08-05 14:23:23 +0100103const auto k0_values_nightly = framework::dataset::make("K0", { 2, 3, 4, 8, 16 });
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000104
105/** H0 values to test - Nightly */
106const auto h0_values_nightly = framework::dataset::make("H0", 1, 4);
107
108/** Interleave values to test with RHS matrix */
109const auto i_values_rhs = framework::dataset::make("interleave_rhs", { true, false });
110
111/** Transpose values to test with RHS matrix */
112const auto t_values_rhs = framework::dataset::make("transpose_rhs", { true });
113
114/** Configuration test */
115void 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)
116{
117 const unsigned int M = m_value;
118 const unsigned int N = n_value;
119 const unsigned int K = k_value;
120
121 GEMMLHSMatrixInfo lhs_info;
122 lhs_info.m0 = m0_value;
123 lhs_info.k0 = k0_value;
124
125 GEMMRHSMatrixInfo rhs_info;
126 rhs_info.n0 = n0_value;
127 rhs_info.k0 = k0_value;
128 rhs_info.h0 = h0_value;
129 rhs_info.interleave = i_value_rhs;
130 rhs_info.transpose = true;
131
132 GEMMReshapeInfo gemm_info(M, N, K);
133
134 const TensorShape lhs_shape(K, M, b_value);
135 const TensorShape rhs_shape(N, K, b_value);
136 const TensorShape rhs_shape_reshaped = compute_rhs_reshaped_shape(TensorInfo(rhs_shape, 1, DataType::QASYMM8),
137 rhs_info);
138
139 const TensorShape dst_shape = compute_mm_shape(TensorInfo(lhs_shape, 1, DataType::QASYMM8),
140 TensorInfo(rhs_shape_reshaped, 1, DataType::QASYMM8),
141 gemm_info);
142
143 // Create tensors
144 CLTensor lhs = create_tensor<CLTensor>(lhs_shape, DataType::QASYMM8);
145 CLTensor rhs_reshaped = create_tensor<CLTensor>(rhs_shape_reshaped, DataType::QASYMM8);
146 CLTensor dst = create_tensor<CLTensor>(dst_shape, DataType::S32);
147
148 ARM_COMPUTE_EXPECT(lhs.info()->is_resizable(), framework::LogLevel::ERRORS);
149 ARM_COMPUTE_EXPECT(rhs_reshaped.info()->is_resizable(), framework::LogLevel::ERRORS);
150 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
151
152 // Create and configure function
153 CLGEMMLowpMatrixMultiplyReshapedOnlyRHS gemm;
154 gemm.configure(&lhs, &rhs_reshaped, &dst, lhs_info, rhs_info, gemm_info);
155}
156} // namespace
157
158TEST_SUITE(CL)
159TEST_SUITE(GEMMLowpMatrixMultiplyReshapedOnlyRHS)
160DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine(
161 m_values,
162 n_values),
163 k_values),
164 framework::dataset::make("batch_size", 1)),
165 m0_values_precommit),
166 n0_values_precommit),
167 k0_values_precommit),
168 h0_values_precommit),
169 i_values_rhs),
170m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, h0_value, i_value_rhs)
171{
172 validate_configuration(m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, h0_value, i_value_rhs);
173}
174
175FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyReshapedOnlyRHSFixture, framework::DatasetMode::ALL,
176 combine(combine(combine(combine(combine(combine(combine(combine(combine(
177 m_values,
178 n_values),
179 k_values),
180 b_values),
181 m0_values_precommit),
182 n0_values_precommit),
183 k0_values_precommit),
184 h0_values_precommit),
185 i_values_rhs),
186 t_values_rhs))
187{
188 // Validate output
189 validate(CLAccessor(_target), _reference);
190}
191
192FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyReshapedOnlyRHSFixture, framework::DatasetMode::NIGHTLY,
193 combine(combine(combine(combine(combine(combine(combine(combine(combine(
194 m_values,
195 n_values),
196 k_values),
197 b_values),
198 m0_values_nightly),
199 n0_values_nightly),
200 k0_values_nightly),
201 h0_values_nightly),
202 i_values_rhs),
203 t_values_rhs))
204{
205 // Validate output
206 validate(CLAccessor(_target), _reference);
207}
208
209FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMLowpMatrixMultiplyReshapedOnlyRHS3DFixture, framework::DatasetMode::ALL,
210 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
211 m_w_values,
212 m_h_values),
213 n_values),
214 k_values),
215 b_values),
216 m0_values_precommit),
217 n0_values_precommit),
218 k0_values_precommit),
219 h0_values_precommit),
220 i_values_rhs),
221 t_values_rhs))
222{
223 // Validate output
224 validate(CLAccessor(_target), _reference);
225}
226
227FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMLowpMatrixMultiplyReshapedOnlyRHS3DFixture, framework::DatasetMode::NIGHTLY,
228 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
229 m_w_values,
230 m_h_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{
241 // Validate output
242 validate(CLAccessor(_target), _reference);
243}
244TEST_SUITE_END() // GEMMLowpMatrixMultiplyReshapedOnlyRHS
245TEST_SUITE_END() // CL
246} // namespace validation
247} // namespace test
248} // namespace arm_compute