blob: f8462058a6cb9f1e9fe56d7d3cef6ed9e043026e [file] [log] [blame]
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +00001/*
Georgios Pinitas856f66e2021-04-22 21:13:21 +01002 * Copyright (c) 2018-2021 Arm Limited.
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +00003 *
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 */
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000024#include "arm_compute/core/Types.h"
25#include "arm_compute/core/utils/misc/ShapeCalculator.h"
26#include "arm_compute/runtime/CL/CLTensor.h"
27#include "arm_compute/runtime/CL/CLTensorAllocator.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010028#include "src/gpu/cl/kernels/ClGemmReshapeRhsMatrixKernel.h"
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000029#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
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000049/** Batch size values to test */
50const auto b_values = framework::dataset::make("batchsize", 1, 3);
51
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +010052/** N0 values to test */
53const auto n0_values_nt_s32 = framework::dataset::make("N0", { 1, 2, 3 });
54const auto n0_values_nt_s16 = framework::dataset::make("N0", { 4, 8 });
55const auto n0_values_nt_s8 = framework::dataset::make("N0", { 16 });
56const auto n0_values_t_s32 = framework::dataset::make("N0", { 4, 8 });
57const auto n0_values_t_s16 = framework::dataset::make("N0", { 16 });
58const auto n0_values_t_s8 = framework::dataset::make("N0", { 2, 3 });
Gian Marco Iodice89124342018-12-19 14:17:22 +000059
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +010060/** K0 values to test */
61const auto k0_values_nt_s32 = framework::dataset::make("K0", { 1, 2 });
62const auto k0_values_nt_s16 = framework::dataset::make("K0", { 16 });
63const auto k0_values_nt_s8 = framework::dataset::make("K0", { 3,4 });
64const auto k0_values_t_s32 = framework::dataset::make("K0", { 2, 3 });
65const auto k0_values_t_s16 = framework::dataset::make("K0", { 4, 8 });
66const auto k0_values_t_s8 = framework::dataset::make("K0", { 16 });
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000067
68/** H0 values to test */
69const auto h0_values = framework::dataset::make("H0", 1, 4);
70
71/** Interleave values to test */
72const auto i_values = framework::dataset::make("interleave", { true, false });
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000073} // namespace
74
75using namespace arm_compute::misc::shape_calculator;
Georgios Pinitas856f66e2021-04-22 21:13:21 +010076using namespace arm_compute::opencl::kernels;
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000077
78// Initialize the output tensor with zero and fill the border with zero
Georgios Pinitas856f66e2021-04-22 21:13:21 +010079using CLGEMMReshapeRHSMatrix = CLSynthetizeOperatorInitOutputWithZeroAndWithZeroConstantBorder<ClGemmReshapeRhsMatrixKernel, 16>;
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000080
81template <typename T>
82using CLGEMMReshapeRHSMatrixFixture = GEMMReshapeRHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeRHSMatrix, T>;
83
84TEST_SUITE(CL)
85TEST_SUITE(GEMMReshapeRHSMatrix)
86
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +010087// *INDENT-OFF*
88// clang-format off
89DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
90 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32),
91 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Mismatching data types
92 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Wrong n0 value
93 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Wrong k0 value
94 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Wrong h0 value
95 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // n0 > 16
96 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // k0 > 16
97 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // k0 == 1 && transpose
98 }),
99 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(64U, 2U, 2U), 1, DataType::F32),
100 TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F16),
101 TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
102 TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
103 TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
104 TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
105 TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
106 TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
107 })),
108 framework::dataset::make("N0",{ 4, 0, 4, 4, 4, 17, 4, 4 })),
109 framework::dataset::make("K0",{ 4, 4, 0, 4, 4, 4, 17, 1 })),
110 framework::dataset::make("H0",{ 4, 4, 4, 0, 4, 4, 4, 4 })),
111 framework::dataset::make("Expected", { false, false, false, false, false, false, false})),
112 input_info, output_info, n0, k0, h0, expected)
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000113{
114 GEMMRHSMatrixInfo rhs_info;
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100115 rhs_info.n0 = n0;
116 rhs_info.k0 = k0;
117 rhs_info.h0 = h0;
118 rhs_info.transpose = true;
119 rhs_info.interleave = true;
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000120
Georgios Pinitas856f66e2021-04-22 21:13:21 +0100121 bool has_error = bool(ClGemmReshapeRhsMatrixKernel::validate(&input_info.clone()->set_is_resizable(false), (output_info.total_size() == 0) ? nullptr : &output_info.clone()->set_is_resizable(false), rhs_info));
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100122 ARM_COMPUTE_EXPECT(has_error == expected, framework::LogLevel::ERRORS);
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000123}
Gian Marco Iodicea98dee22020-06-02 12:12:35 +0100124
SiCong Li5bdde852020-08-26 13:55:15 +0100125DATA_TEST_CASE(ValidatePadding, framework::DatasetMode::ALL, combine(combine(combine(combine(
Gian Marco Iodicea98dee22020-06-02 12:12:35 +0100126 framework::dataset::make("InputShape", { TensorShape(32U, 16U, 1U),
127 TensorShape(32U, 16U, 2U)
128 }),
129 framework::dataset::make("N0",{ 4 })),
Gian Marco Iodicee3a849a2020-06-10 17:59:30 +0100130 framework::dataset::make("K0",{ 4, 8, 16 })),
Gian Marco Iodicea98dee22020-06-02 12:12:35 +0100131 framework::dataset::make("H0",{ 1, 2, 4 })),
SiCong Li5bdde852020-08-26 13:55:15 +0100132 framework::dataset::make("DataType",{ DataType::F32, DataType::F16 })),
133 input_shape, n0, k0, h0, data_type)
Gian Marco Iodicea98dee22020-06-02 12:12:35 +0100134{
135 CLTensor input;
136 CLTensor output;
137
SiCong Li5bdde852020-08-26 13:55:15 +0100138 input.info()->init(input_shape, 1, data_type);
Gian Marco Iodicea98dee22020-06-02 12:12:35 +0100139
140 unsigned int padding = 0;
141
142 GEMMRHSMatrixInfo rhs_info;
143 rhs_info.n0 = n0;
144 rhs_info.k0 = k0;
145 rhs_info.h0 = h0;
146 rhs_info.transpose = true;
147 rhs_info.interleave = true;
148 rhs_info.export_to_cl_image = image2d_from_buffer_supported(CLKernelLibrary::get().get_device()) && (get_cl_image_pitch_alignment(CLKernelLibrary::get().get_device()) != 0);
149
150 if(rhs_info.export_to_cl_image)
151 {
152 TensorShape output_shape = compute_rhs_reshaped_shape(*input.info(), rhs_info);
153 constexpr unsigned int num_floats_per_pixel = 4;
154
155 const unsigned int pixel_aligment = get_cl_image_pitch_alignment(CLKernelLibrary::get().get_device());
156 const unsigned int row_pitch_alignment = pixel_aligment * num_floats_per_pixel;
157 const unsigned int round_up_width = ((output_shape[0] + row_pitch_alignment - 1) / row_pitch_alignment) * row_pitch_alignment;
158
159 padding = round_up_width - output_shape[0];
160 }
161
Georgios Pinitas856f66e2021-04-22 21:13:21 +0100162 ClGemmReshapeRhsMatrixKernel kernel;
Gian Marco Iodicea98dee22020-06-02 12:12:35 +0100163
Georgios Pinitas856f66e2021-04-22 21:13:21 +0100164 kernel.configure(CLKernelLibrary::get().get_compile_context(), input.info(), output.info(), rhs_info);
Gian Marco Iodicea98dee22020-06-02 12:12:35 +0100165
166 ARM_COMPUTE_EXPECT((output.info()->padding().right == padding), framework::LogLevel::ERRORS);
167}
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100168// clang-format on
169// *INDENT-ON*
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000170
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100171// Run S32 tests only for transpose = false
172FIXTURE_DATA_TEST_CASE(S32_NT, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::ALL,
173 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
174 b_values),
175 framework::dataset::make("DataType", DataType::S32)),
176 n0_values_nt_s32),
177 k0_values_nt_s32),
178 h0_values),
179 i_values),
180 framework::dataset::make("transpose", false)))
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000181{
182 // Validate output
183 validate(CLAccessor(_target), _reference);
184}
185
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100186// Run S32 tests only for transpose = true
187FIXTURE_DATA_TEST_CASE(S32_T, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::ALL,
188 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
189 b_values),
190 framework::dataset::make("DataType", DataType::S32)),
191 n0_values_t_s32),
192 k0_values_t_s32),
193 h0_values),
194 i_values),
195 framework::dataset::make("transpose", true)))
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000196{
197 // Validate output
198 validate(CLAccessor(_target), _reference);
199}
200
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100201// Run S16 tests only for transpose = false
202FIXTURE_DATA_TEST_CASE(S16_NT, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::ALL,
203 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
204 b_values),
205 framework::dataset::make("DataType", DataType::S16)),
206 n0_values_nt_s16),
207 k0_values_nt_s16),
208 h0_values),
209 i_values),
210 framework::dataset::make("transpose", false)))
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000211{
212 // Validate output
213 validate(CLAccessor(_target), _reference);
214}
215
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100216// Run S16 tests only for transpose = true
217FIXTURE_DATA_TEST_CASE(S16_T, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::ALL,
218 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
219 b_values),
220 framework::dataset::make("DataType", DataType::S16)),
221 n0_values_t_s16),
222 k0_values_t_s16),
223 h0_values),
224 i_values),
225 framework::dataset::make("transpose", true)))
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000226{
227 // Validate output
228 validate(CLAccessor(_target), _reference);
229}
230
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100231// Run S8 tests only for transpose = false
232FIXTURE_DATA_TEST_CASE(S8_NT, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::ALL,
233 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
234 b_values),
235 framework::dataset::make("DataType", DataType::S8)),
236 n0_values_nt_s8),
237 k0_values_nt_s8),
238 h0_values),
239 i_values),
240 framework::dataset::make("transpose", false)))
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000241{
242 // Validate output
243 validate(CLAccessor(_target), _reference);
244}
245
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100246// Run S8 tests only for transpose = true
247FIXTURE_DATA_TEST_CASE(S8_T, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::ALL,
248 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
249 b_values),
250 framework::dataset::make("DataType", DataType::S8)),
251 n0_values_t_s8),
252 k0_values_t_s8),
253 h0_values),
254 i_values),
255 framework::dataset::make("transpose", true)))
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000256{
257 // Validate output
258 validate(CLAccessor(_target), _reference);
259}
260
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000261TEST_SUITE_END() // GEMMReshapeRHSMatrix
262TEST_SUITE_END() // CL
263} // namespace validation
264} // namespace test
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100265} // namespace arm_compute