blob: a2dd9c2a0a6161463fe42eb8c1bcf50ce1b0840c [file] [log] [blame]
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +00001/*
2 * Copyright (c) 2018 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/CLGEMMReshapeLHSMatrixKernel.h"
25#include "arm_compute/core/Types.h"
26#include "arm_compute/core/utils/misc/ShapeCalculator.h"
27#include "arm_compute/runtime/CL/CLTensor.h"
28#include "arm_compute/runtime/CL/CLTensorAllocator.h"
29#include "tests/CL/CLAccessor.h"
30#include "tests/CL/Helper.h"
31#include "tests/PaddingCalculator.h"
32#include "tests/datasets/ShapeDatasets.h"
33#include "tests/framework/Asserts.h"
34#include "tests/framework/Macros.h"
35#include "tests/framework/datasets/Datasets.h"
36#include "tests/validation/Validation.h"
37#include "tests/validation/fixtures/GEMMReshapeLHSMatrixFixture.h"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +000045using namespace arm_compute::misc::shape_calculator;
46
47// Initialize the output tensor with zero and fill the border with zero
48using CLGEMMReshapeLHSMatrix = CLSynthetizeFunctionInitOutputWithZeroAndWithZeroConstantBorder<CLGEMMReshapeLHSMatrixKernel, 16>;
49
50template <typename T>
51using CLGEMMReshapeLHSMatrixFixture = GEMMReshapeLHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeLHSMatrix, T, false>;
52
53// Fixture to use when the input has to be reinterpreted as 3D
54template <typename T>
55using CLGEMMReshapeLHSMatrix3DFixture = GEMMReshapeLHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeLHSMatrix, T, true>;
56
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +000057// *INDENT-OFF*
58// clang-format off
59/** Data types */
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +000060
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +000061namespace
62{
63const auto data_types = framework::dataset::make("DataType", { DataType::QASYMM8, DataType::F16, DataType::F32 });
64
65/** Batch size values to test */
66const auto b_values = framework::dataset::make("batchsize", 1, 3);
67
68/** M0 values to test - Precommit */
69const auto m0_values_precommit = framework::dataset::make("M0", { 2, 4, 5 });
70
71/** K0 values to test - Precommit */
72const auto k0_values_precommit = framework::dataset::make("K0", { 2, 4 });
73
74/** M0 values to test - Precommit */
75const auto m0_values_nightly = framework::dataset::make("M0", 2, 9);
76
77/** K0 values to test - Precommit */
78const auto k0_values_nightly = framework::dataset::make("K0", { 2, 4, 8, 16 });
79
80/** V0 values to test */
81const auto v0_values = framework::dataset::make("V0", 1, 4);
82
83/** Interleave values to test */
84const auto i_values = framework::dataset::make("interleave", { true, false });
85
86/** Transpose values to test */
87const auto t_values = framework::dataset::make("transpose", { true, false });
88
89/** Configuration test */
90void validate_configuration(TensorShape shape_in, unsigned int b_value, DataType data_type, unsigned int m0_value, unsigned int k0_value, unsigned int v0_value, bool i_value, bool t_value, bool reinterpret_input_as_3d)
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +000091{
92 GEMMLHSMatrixInfo lhs_info;
93 lhs_info.m0 = m0_value;
94 lhs_info.k0 = k0_value;
95 lhs_info.v0 = v0_value;
96 lhs_info.interleave = i_value;
97 lhs_info.transpose = t_value;
98
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +000099 TensorShape shape_src = shape_in;
100 shape_src.set(shape_src.num_dimensions(), b_value);
101
102 const TensorShape shape_dst = compute_lhs_reshaped_shape(TensorInfo(shape_src, 1, data_type), lhs_info, reinterpret_input_as_3d);
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000103
104 // Create tensors
105 CLTensor src = create_tensor<CLTensor>(shape_src, data_type);
106 CLTensor dst = create_tensor<CLTensor>(shape_dst, data_type);
107
108 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
109 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
110
111 // Create and configure function
112 CLGEMMReshapeLHSMatrixKernel reshape_lhs;
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000113 reshape_lhs.configure(&src, &dst, lhs_info, reinterpret_input_as_3d);
114}
115} // namespace
116
117TEST_SUITE(CL)
118TEST_SUITE(GEMMReshapeLHSMatrix)
119
120DATA_TEST_CASE(ConfigurationSmall, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
121 b_values),
122 data_types),
123 m0_values_precommit),
124 k0_values_precommit),
125 v0_values),
126 i_values),
127 t_values),
128shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value)
129{
130 validate_configuration(shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value, false);
131}
132
133DATA_TEST_CASE(ConfigurationLarge, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(),
134 b_values),
135 data_types),
136 m0_values_nightly),
137 k0_values_nightly),
138 v0_values),
139 i_values),
140 t_values),
141shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value)
142{
143 validate_configuration(shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value, false);
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000144}
145
146TEST_SUITE(S32)
147FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMReshapeLHSMatrixFixture<int>, framework::DatasetMode::ALL,
148 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
149 b_values),
150 framework::dataset::make("DataType", DataType::S32)),
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000151 m0_values_precommit),
152 k0_values_precommit),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000153 v0_values),
154 i_values),
155 t_values))
156{
157 // Validate output
158 validate(CLAccessor(_target), _reference);
159}
160
161FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMReshapeLHSMatrixFixture<int>, framework::DatasetMode::NIGHTLY,
162 combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(),
163 b_values),
164 framework::dataset::make("DataType", DataType::S32)),
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000165 m0_values_nightly),
166 k0_values_nightly),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000167 v0_values),
168 i_values),
169 t_values))
170{
171 // Validate output
172 validate(CLAccessor(_target), _reference);
173}
174TEST_SUITE_END() // S32
175
176TEST_SUITE(S16)
177FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMReshapeLHSMatrixFixture<short>, framework::DatasetMode::ALL,
178 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
179 b_values),
180 framework::dataset::make("DataType", DataType::S16)),
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000181 m0_values_precommit),
182 k0_values_precommit),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000183 v0_values),
184 i_values),
185 t_values))
186{
187 // Validate output
188 validate(CLAccessor(_target), _reference);
189}
190
191FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMReshapeLHSMatrixFixture<short>, framework::DatasetMode::NIGHTLY,
192 combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(),
193 b_values),
194 framework::dataset::make("DataType", DataType::S16)),
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000195 m0_values_nightly),
196 k0_values_nightly),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000197 v0_values),
198 i_values),
199 t_values))
200{
201 // Validate output
202 validate(CLAccessor(_target), _reference);
203}
204TEST_SUITE_END() // S16
205
206TEST_SUITE(S8)
207FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMReshapeLHSMatrixFixture<char>, framework::DatasetMode::ALL,
208 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
209 b_values),
210 framework::dataset::make("DataType", DataType::S8)),
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000211 m0_values_precommit),
212 k0_values_precommit),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000213 v0_values),
214 i_values),
215 t_values))
216{
217 // Validate output
218 validate(CLAccessor(_target), _reference);
219}
220
221FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMReshapeLHSMatrixFixture<char>, framework::DatasetMode::NIGHTLY,
222 combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(),
223 b_values),
224 framework::dataset::make("DataType", DataType::S8)),
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000225 m0_values_nightly),
226 k0_values_nightly),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000227 v0_values),
228 i_values),
229 t_values))
230{
231 // Validate output
232 validate(CLAccessor(_target), _reference);
233}
234TEST_SUITE_END() // S8
235
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000236TEST_SUITE(ReinterpretInputAs3D)
237DATA_TEST_CASE(ConfigurationSmall, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000238 b_values),
239 data_types),
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000240 m0_values_precommit),
241 k0_values_precommit),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000242 v0_values),
243 i_values),
244 t_values),
245shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value)
246{
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000247 validate_configuration(shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value, true);
248}
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000249
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000250DATA_TEST_CASE(ConfigurationLarge, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape3DShapes(),
251 b_values),
252 data_types),
253 m0_values_nightly),
254 k0_values_nightly),
255 v0_values),
256 i_values),
257 t_values),
258shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value)
259{
260 validate_configuration(shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value, true);
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000261}
262
263TEST_SUITE(S32)
264FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMReshapeLHSMatrix3DFixture<int>, framework::DatasetMode::ALL,
265 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(),
266 b_values),
267 framework::dataset::make("DataType", DataType::S32)),
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000268 m0_values_precommit),
269 k0_values_precommit),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000270 v0_values),
271 i_values),
272 t_values))
273{
274 // Validate output
275 validate(CLAccessor(_target), _reference);
276}
277
278FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMReshapeLHSMatrix3DFixture<int>, framework::DatasetMode::NIGHTLY,
279 combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape3DShapes(),
280 b_values),
281 framework::dataset::make("DataType", DataType::S32)),
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000282 m0_values_nightly),
283 k0_values_nightly),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000284 v0_values),
285 i_values),
286 t_values))
287{
288 // Validate output
289 validate(CLAccessor(_target), _reference);
290}
291TEST_SUITE_END() // S32
292
293TEST_SUITE(S16)
294FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMReshapeLHSMatrix3DFixture<short>, framework::DatasetMode::ALL,
295 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(),
296 b_values),
297 framework::dataset::make("DataType", DataType::S16)),
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000298 m0_values_precommit),
299 k0_values_precommit),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000300 v0_values),
301 i_values),
302 t_values))
303{
304 // Validate output
305 validate(CLAccessor(_target), _reference);
306}
307
308FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMReshapeLHSMatrix3DFixture<short>, framework::DatasetMode::NIGHTLY,
309 combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape3DShapes(),
310 b_values),
311 framework::dataset::make("DataType", DataType::S16)),
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000312 m0_values_nightly),
313 k0_values_nightly),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000314 v0_values),
315 i_values),
316 t_values))
317{
318 // Validate output
319 validate(CLAccessor(_target), _reference);
320}
321TEST_SUITE_END() // S16
322
323TEST_SUITE(S8)
324FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMReshapeLHSMatrix3DFixture<char>, framework::DatasetMode::ALL,
325 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(),
326 b_values),
327 framework::dataset::make("DataType", DataType::S8)),
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000328 m0_values_precommit),
329 k0_values_precommit),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000330 v0_values),
331 i_values),
332 t_values))
333{
334 // Validate output
335 validate(CLAccessor(_target), _reference);
336}
337
338FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMReshapeLHSMatrix3DFixture<char>, framework::DatasetMode::NIGHTLY,
339 combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape3DShapes(),
340 b_values),
341 framework::dataset::make("DataType", DataType::S8)),
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000342 m0_values_nightly),
343 k0_values_nightly),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000344 v0_values),
345 i_values),
346 t_values))
347{
348 // Validate output
349 validate(CLAccessor(_target), _reference);
350}
351TEST_SUITE_END() // S8
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000352TEST_SUITE_END() // ReinterpretInputAs3D
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000353TEST_SUITE_END() // GEMMReshapeLHSMatrix
354TEST_SUITE_END() // CL
355} // namespace validation
356} // namespace test
357} // namespace arm_compute