1 /*
2 * Copyright (c) 2019-2021 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/Types.h"
25 #include "arm_compute/core/utils/misc/ShapeCalculator.h"
26 #include "src/gpu/cl/kernels/ClGemmLowpMatrixMultiplyReshapedKernel.h"
27 #include "src/gpu/cl/kernels/ClGemmReshapeLhsMatrixKernel.h"
28 #include "src/gpu/cl/kernels/ClGemmReshapeRhsMatrixKernel.h"
29 #include "tests/CL/CLAccessor.h"
30 #include "tests/CL/Helper.h"
31 #include "tests/framework/Asserts.h"
32 #include "tests/framework/Macros.h"
33 #include "tests/framework/datasets/Datasets.h"
34 #include "tests/validation/Validation.h"
35 #include "tests/validation/fixtures/GEMMLowpFixture.h"
36
37 namespace arm_compute
38 {
39 namespace test
40 {
41 namespace validation
42 {
43 using namespace arm_compute::misc::shape_calculator;
44
45 // Create function for ClGemmReshapeLhsMatrixKernel
46 using CLGEMMReshapeLHSMatrix = CLSynthetizeOperator<opencl::kernels::ClGemmReshapeLhsMatrixKernel>;
47
48 // Create function for ClGemmReshapeRhsMatrixKernel
49 using CLGEMMReshapeRHSMatrix = CLSynthetizeOperator<opencl::kernels::ClGemmReshapeRhsMatrixKernel>;
50
51 // Create function for CLGEMMLowpMatrixMultiplyReshapedKernel
52 using CLGEMMLowpMatrixMultiplyReshaped = CLSynthetizeOperator<opencl::kernels::ClGemmLowpMatrixMultiplyReshapedKernel>;
53
54 // Fixture for CLGEMMLowpMatrixMultiplyReshaped
55 using CLGEMMLowpMatrixMultiplyReshapedFixture = GEMMLowpMatrixMultiplyReshapedValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeLHSMatrix, CLGEMMReshapeRHSMatrix, CLGEMMLowpMatrixMultiplyReshaped>;
56
57 // Fixture for CLGEMMMatrixMultiplyReshaped3D
58 using CLGEMMLowpMatrixMultiplyReshaped3DFixture =
59 GEMMLowpMatrixMultiplyReshaped3DValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeLHSMatrix, CLGEMMReshapeRHSMatrix, CLGEMMLowpMatrixMultiplyReshaped>;
60
61 namespace
62 {
63 // *INDENT-OFF*
64 // clang-format off
65
66 /** M, N combinations to test
67 * 1: Special 1x1 case
68 * 2: Special multples of processor size in both dimensions
69 * 3: Non multiples of processor size in both dimensions
70 */
71 const auto m_n_values = zip(
72 framework::dataset::make("M", {1, 16, 37}),
73 framework::dataset::make("N", {1, 16, 51})
74 );
75
76 /** M values to test */
77 const auto m_values = framework::dataset::make("M", {1, 37});
78
79 /** M_W values to test */
80 const auto m_w_values = framework::dataset::make("M_W", 5);
81
82 /** M_H values to test */
83 const auto m_h_values = framework::dataset::make("M_H", 7);
84
85 /** N values to test */
86 const auto n_values = framework::dataset::make("N", {1, 51});
87
88 /** K values to test */
89 const auto k_values = framework::dataset::make("K", 23);
90
91 /** Batch size values to test */
92 const auto b_values = framework::dataset::make("batch_size", 1, 3);
93
94 /** M0 values to test - Precommit */
95 const auto m0_values_precommit_1 = framework::dataset::make("M0", { 4 });
96 const auto m0_values_precommit_2 = framework::dataset::make("M0", { 6 });
97
98 /** N0 values to test - Precommit */
99 const auto n0_values_precommit = framework::dataset::make("N0", { 4 });
100
101 /** K0 values to test - Precommit */
102 const auto k0_values_precommit = framework::dataset::make("K0", { 16 });
103
104 /** V0 values to test - Precommit */
105 const auto v0_values_precommit = framework::dataset::make("V0", 1, 3);
106
107 /** H0 values to test - Precommit */
108 const auto h0_values_precommit = framework::dataset::make("H0", 1, 3);
109
110 /** M0 values to test - Nightly */
111 const auto m0_values_nightly = framework::dataset::make("M0", 2, 7);
112
113 /** N0 values to test - Nightly */
114 const auto n0_values_nightly = framework::dataset::make("N0", { 2, 3, 4, 8 });
115
116 /** K0 values to test - Nightly */
117 const auto k0_values_nightly = framework::dataset::make("K0", { 2, 3, 4, 8, 16 });
118
119 /** V0 values to test - Nightly */
120 const auto v0_values_nightly = framework::dataset::make("V0", 1, 4);
121
122 /** H0 values to test - Nightly */
123 const auto h0_values_nightly = framework::dataset::make("H0", 1, 4);
124
125 /** Interleave values to test with LHS matrix */
126 const auto i_values_lhs = framework::dataset::make("interleave_lhs", { true, false });
127
128 /** Interleave values to test with RHS matrix */
129 const auto i_values_rhs = framework::dataset::make("interleave_rhs", { true, false });
130 } // namespace
131
132 TEST_SUITE(CL)
TEST_SUITE(GEMMLowpMatrixMultiplyReshaped)133 TEST_SUITE(GEMMLowpMatrixMultiplyReshaped)
134
135 TEST_SUITE(QUANTIZED)
136
137 TEST_SUITE(QASYMM8)
138 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyReshapedFixture, framework::DatasetMode::ALL,
139 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
140 m_n_values,
141 k_values),
142 b_values),
143 m0_values_precommit_1),
144 n0_values_precommit),
145 k0_values_precommit),
146 v0_values_precommit),
147 h0_values_precommit),
148 i_values_lhs),
149 i_values_rhs),
150 framework::dataset::make("DataType", { DataType::QASYMM8 })))
151 {
152 // Validate output
153 validate(CLAccessor(_target), _reference);
154 }
155
156 FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyReshapedFixture, framework::DatasetMode::DISABLED,
157 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
158 m_values,
159 n_values),
160 k_values),
161 b_values),
162 m0_values_nightly),
163 n0_values_nightly),
164 k0_values_nightly),
165 v0_values_nightly),
166 h0_values_nightly),
167 i_values_lhs),
168 i_values_rhs),
169 framework::dataset::make("DataType", { DataType::QASYMM8 })))
170 {
171 // Validate output
172 validate(CLAccessor(_target), _reference);
173 }
174
175 FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMLowpMatrixMultiplyReshaped3DFixture, framework::DatasetMode::ALL,
176 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
177 m_w_values,
178 m_h_values),
179 n_values),
180 k_values),
181 b_values),
182 m0_values_precommit_1),
183 n0_values_precommit),
184 k0_values_precommit),
185 v0_values_precommit),
186 h0_values_precommit),
187 i_values_lhs),
188 i_values_rhs),
189 framework::dataset::make("DataType", { DataType::QASYMM8 })))
190 {
191 // Validate output
192 validate(CLAccessor(_target), _reference);
193 }
194
195 FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMLowpMatrixMultiplyReshaped3DFixture, framework::DatasetMode::DISABLED,
196 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
197 m_w_values,
198 m_h_values),
199 n_values),
200 k_values),
201 b_values),
202 m0_values_nightly),
203 n0_values_nightly),
204 k0_values_nightly),
205 v0_values_nightly),
206 h0_values_nightly),
207 i_values_lhs),
208 i_values_rhs),
209 framework::dataset::make("DataType", { DataType::QASYMM8 })))
210 {
211 // Validate output
212 validate(CLAccessor(_target), _reference);
213 }
214 TEST_SUITE_END() // QASYMM8
215
TEST_SUITE(QASYMM8_SIGNED)216 TEST_SUITE(QASYMM8_SIGNED)
217 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyReshapedFixture, framework::DatasetMode::ALL,
218 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
219 m_n_values,
220 k_values),
221 b_values),
222 m0_values_precommit_2),
223 n0_values_precommit),
224 k0_values_precommit),
225 v0_values_precommit),
226 h0_values_precommit),
227 i_values_lhs),
228 i_values_rhs),
229 framework::dataset::make("DataType", { DataType::QASYMM8_SIGNED })))
230 {
231 // Validate output
232 validate(CLAccessor(_target), _reference);
233 }
234 FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMLowpMatrixMultiplyReshaped3DFixture, framework::DatasetMode::ALL,
235 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
236 m_w_values,
237 m_h_values),
238 n_values),
239 k_values),
240 b_values),
241 m0_values_precommit_2),
242 n0_values_precommit),
243 k0_values_precommit),
244 v0_values_precommit),
245 h0_values_precommit),
246 i_values_lhs),
247 i_values_rhs),
248 framework::dataset::make("DataType", { DataType::QASYMM8_SIGNED })))
249 {
250 // Validate output
251 validate(CLAccessor(_target), _reference);
252 }
253 TEST_SUITE_END() // QASYMM8_SIGNED
254
255 TEST_SUITE_END() // QUANTIZED
256 TEST_SUITE_END() // GEMMLowpMatrixMultiplyReshaped
257 TEST_SUITE_END() // CL
258 } // namespace validation
259 } // namespace test
260 } // namespace arm_compute
261