blob: e886b7bd43be3d3896ad4d5dd034e5ad671fef33 [file] [log] [blame]
Gian Marco Iodice3b0a2652018-12-07 11:18: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/CLGEMMReshapeRHSMatrixKernel.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/GEMMReshapeRHSMatrixFixture.h"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45namespace
46{
47// *INDENT-OFF*
48// clang-format off
49/** Data types */
50const auto data_types = framework::dataset::make("DataType", { DataType::QASYMM8, DataType::F16, DataType::F32 });
51
52/** Batch size values to test */
53const auto b_values = framework::dataset::make("batchsize", 1, 3);
54
55/** N0 values to test */
56const auto n0_values = framework::dataset::make("N0", { 2, 4, 8, 16 });
57
58/** H0 values to test */
59const auto h0_values = framework::dataset::make("H0", 1, 4);
60
61/** Interleave values to test */
62const auto i_values = framework::dataset::make("interleave", { true, false });
63
64} // namespace
65
66using namespace arm_compute::misc::shape_calculator;
67
68// Initialize the output tensor with zero and fill the border with zero
69using CLGEMMReshapeRHSMatrix = CLSynthetizeFunctionInitOutputWithZeroAndWithZeroConstantBorder<CLGEMMReshapeRHSMatrixKernel, 16>;
70
71template <typename T>
72using CLGEMMReshapeRHSMatrixFixture = GEMMReshapeRHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeRHSMatrix, T>;
73
74TEST_SUITE(CL)
75TEST_SUITE(GEMMReshapeRHSMatrix)
76
77// This configuration tests only transpose = true
78DATA_TEST_CASE(Configuration0, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
79 b_values),
80 data_types),
81 n0_values),
82 framework::dataset::make("K0", { 4, 8, 16 })),
83 h0_values),
84 i_values),
85shape_in, b_value, data_type, n0_value, k0_value, h0_value, i_value)
86{
87 GEMMRHSMatrixInfo rhs_info;
88 rhs_info.n0 = n0_value;
89 rhs_info.k0 = k0_value;
90 rhs_info.h0 = h0_value;
91 rhs_info.interleave = i_value;
92 rhs_info.transpose = true;
93
94 const TensorShape shape_src(shape_in[0], shape_in[1], b_value);
95 const TensorShape shape_dst = compute_rhs_reshaped_shape(TensorInfo(shape_src, 1, data_type), rhs_info);
96
97 // Create tensors
98 CLTensor src = create_tensor<CLTensor>(shape_src, data_type);
99 CLTensor dst = create_tensor<CLTensor>(shape_dst, data_type);
100
101 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
102 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
103
104 // Create and configure function
105 CLGEMMReshapeRHSMatrixKernel reshape_rhs;
106 reshape_rhs.configure(&src, &dst, rhs_info);
107}
108
109// This configuration tests only transpose = false
110DATA_TEST_CASE(Configuration1, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
111 b_values),
112 data_types),
113 n0_values),
114 framework::dataset::make("K0", { 1, 2, 4, 8, 16 })),
115 h0_values),
116 i_values),
117shape_in, b_value, data_type, n0_value, k0_value, h0_value, i_value)
118{
119 GEMMRHSMatrixInfo rhs_info;
120 rhs_info.n0 = n0_value;
121 rhs_info.k0 = k0_value;
122 rhs_info.h0 = h0_value;
123 rhs_info.interleave = i_value;
124 rhs_info.transpose = false;
125
126 const TensorShape shape_src(shape_in[0], shape_in[1], b_value);
127 const TensorShape shape_dst = compute_rhs_reshaped_shape(TensorInfo(shape_src, 1, data_type), rhs_info);
128
129 // Create tensors
130 CLTensor src = create_tensor<CLTensor>(shape_src, data_type);
131 CLTensor dst = create_tensor<CLTensor>(shape_dst, data_type);
132
133 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
134 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
135
136 // Create and configure function
137 CLGEMMReshapeRHSMatrixKernel reshape_rhs;
138 reshape_rhs.configure(&src, &dst, rhs_info);
139}
140
141TEST_SUITE(S32)
142// RunSmall tests only for transpose = false
143FIXTURE_DATA_TEST_CASE(RunSmall0, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::ALL,
144 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
145 b_values),
146 framework::dataset::make("DataType", DataType::S32)),
147 n0_values),
148 framework::dataset::make("K0", { 1, 2, 4, 8, 16 })),
149 h0_values),
150 i_values),
151 framework::dataset::make("transpose", false)))
152{
153 // Validate output
154 validate(CLAccessor(_target), _reference);
155}
156
157// RunSmall tests only for transpose = true
158FIXTURE_DATA_TEST_CASE(RunSmall1, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::ALL,
159 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
160 b_values),
161 framework::dataset::make("DataType", DataType::S32)),
162 n0_values),
163 framework::dataset::make("K0", { 4, 8, 16 })),
164 h0_values),
165 i_values),
166 framework::dataset::make("transpose", true)))
167{
168 // Validate output
169 validate(CLAccessor(_target), _reference);
170}
171
172// RunLarge tests only for transpose = false
173FIXTURE_DATA_TEST_CASE(RunLarge0, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::NIGHTLY,
174 combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(),
175 b_values),
176 framework::dataset::make("DataType", DataType::S32)),
177 n0_values),
178 framework::dataset::make("K0", { 1, 2, 4, 8, 16 })),
179 h0_values),
180 i_values),
181 framework::dataset::make("transpose", false)))
182{
183 // Validate output
184 validate(CLAccessor(_target), _reference);
185}
186
187// RunLarge tests only for transpose = true
188FIXTURE_DATA_TEST_CASE(RunLarge1, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::NIGHTLY,
189 combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(),
190 b_values),
191 framework::dataset::make("DataType", DataType::S32)),
192 n0_values),
193 framework::dataset::make("K0", { 4, 8, 16 })),
194 h0_values),
195 i_values),
196 framework::dataset::make("transpose", true)))
197{
198 // Validate output
199 validate(CLAccessor(_target), _reference);
200}
201TEST_SUITE_END() // S32
202
203TEST_SUITE(S16)
204// RunSmall tests only for transpose = false
205FIXTURE_DATA_TEST_CASE(RunSmall0, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::ALL,
206 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
207 b_values),
208 framework::dataset::make("DataType", DataType::S16)),
209 n0_values),
210 framework::dataset::make("K0", { 1, 2, 4, 8, 16 })),
211 h0_values),
212 i_values),
213 framework::dataset::make("transpose", false)))
214{
215 // Validate output
216 validate(CLAccessor(_target), _reference);
217}
218
219// RunSmall tests only for transpose = true
220FIXTURE_DATA_TEST_CASE(RunSmall1, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::ALL,
221 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
222 b_values),
223 framework::dataset::make("DataType", DataType::S16)),
224 n0_values),
225 framework::dataset::make("K0", { 4, 8, 16 })),
226 h0_values),
227 i_values),
228 framework::dataset::make("transpose", true)))
229{
230 // Validate output
231 validate(CLAccessor(_target), _reference);
232}
233
234// RunLarge tests only for transpose = false
235FIXTURE_DATA_TEST_CASE(RunLarge0, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::NIGHTLY,
236 combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(),
237 b_values),
238 framework::dataset::make("DataType", DataType::S16)),
239 n0_values),
240 framework::dataset::make("K0", { 1, 2, 4, 8, 16 })),
241 h0_values),
242 i_values),
243 framework::dataset::make("transpose", false)))
244{
245 // Validate output
246 validate(CLAccessor(_target), _reference);
247}
248
249// RunLarge tests only for transpose = true
250FIXTURE_DATA_TEST_CASE(RunLarge1, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::NIGHTLY,
251 combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(),
252 b_values),
253 framework::dataset::make("DataType", DataType::S16)),
254 n0_values),
255 framework::dataset::make("K0", { 4, 8, 16 })),
256 h0_values),
257 i_values),
258 framework::dataset::make("transpose", true)))
259{
260 // Validate output
261 validate(CLAccessor(_target), _reference);
262}
263TEST_SUITE_END() // S16
264
265TEST_SUITE(S8)
266// RunSmall tests only for transpose = false
267FIXTURE_DATA_TEST_CASE(RunSmall0, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::ALL,
268 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
269 b_values),
270 framework::dataset::make("DataType", DataType::S8)),
271 n0_values),
272 framework::dataset::make("K0", { 1, 2, 4, 8, 16 })),
273 h0_values),
274 i_values),
275 framework::dataset::make("transpose", false)))
276{
277 // Validate output
278 validate(CLAccessor(_target), _reference);
279}
280
281// RunSmall tests only for transpose = true
282FIXTURE_DATA_TEST_CASE(RunSmall1, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::ALL,
283 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
284 b_values),
285 framework::dataset::make("DataType", DataType::S8)),
286 n0_values),
287 framework::dataset::make("K0", { 4, 8, 16 })),
288 h0_values),
289 i_values),
290 framework::dataset::make("transpose", true)))
291{
292 // Validate output
293 validate(CLAccessor(_target), _reference);
294}
295
296// RunLarge tests only for transpose = false
297FIXTURE_DATA_TEST_CASE(RunLarge0, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::NIGHTLY,
298 combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(),
299 b_values),
300 framework::dataset::make("DataType", DataType::S8)),
301 n0_values),
302 framework::dataset::make("K0", { 1, 2, 4, 8, 16 })),
303 h0_values),
304 i_values),
305 framework::dataset::make("transpose", false)))
306{
307 // Validate output
308 validate(CLAccessor(_target), _reference);
309}
310
311// RunLarge tests only for transpose = true
312FIXTURE_DATA_TEST_CASE(RunLarge1, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::NIGHTLY,
313 combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(),
314 b_values),
315 framework::dataset::make("DataType", DataType::S8)),
316 n0_values),
317 framework::dataset::make("K0", { 4, 8, 16 })),
318 h0_values),
319 i_values),
320 framework::dataset::make("transpose", true)))
321{
322 // Validate output
323 validate(CLAccessor(_target), _reference);
324}
325TEST_SUITE_END() // S8
326TEST_SUITE_END() // GEMMReshapeRHSMatrix
327TEST_SUITE_END() // CL
328} // namespace validation
329} // namespace test
330} // namespace arm_compute