blob: d6507a06c45810dcbd585d791082da75903816bd [file] [log] [blame]
Gian Marco Iodiced1f54762019-07-19 09:54:47 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 Arm Limited.
Gian Marco Iodiced1f54762019-07-19 09:54:47 +01003 *
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 Iodiced1f54762019-07-19 09:54:47 +010024#include "arm_compute/core/KernelDescriptors.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"
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010029#include "src/core/CL/kernels/CLGEMMMatrixMultiplyKernel.h"
30#include "src/core/CL/kernels/CLGEMMReshapeLHSMatrixKernel.h"
31#include "src/core/CL/kernels/CLGEMMReshapeRHSMatrixKernel.h"
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010032#include "tests/CL/CLAccessor.h"
33#include "tests/CL/Helper.h"
34#include "tests/PaddingCalculator.h"
35#include "tests/datasets/ShapeDatasets.h"
36#include "tests/framework/Asserts.h"
37#include "tests/framework/Macros.h"
38#include "tests/framework/datasets/Datasets.h"
39#include "tests/validation/Validation.h"
40#include "tests/validation/fixtures/GEMMFixture.h"
41
42namespace arm_compute
43{
44namespace test
45{
46namespace validation
47{
48using namespace arm_compute::misc::shape_calculator;
49
50// Create function for CLGEMMReshapeLHSMatrixKernel
51using CLGEMMReshapeLHSMatrix = CLSynthetizeFunction<CLGEMMReshapeLHSMatrixKernel>;
52
53// Create function for CLGEMMReshapeRHSMatrixKernel
54using CLGEMMReshapeRHSMatrix = CLSynthetizeFunction<CLGEMMReshapeRHSMatrixKernel>;
55
56// Create function for CLGEMMMatrixMultiplyKernel
57using CLGEMMMatrixMultiplyReshaped = CLSynthetizeFunction<CLGEMMMatrixMultiplyKernel>;
58
59// Fixture for GEMMMatrixMultiplyInterleavedTransposedValidationFixture
60template <typename T>
61using CLGEMMMatrixMultiplyReshapedFixture =
62 GEMMMatrixMultiplyInterleavedTransposedValidationFixture<CLTensor, CLAccessor, T, CLGEMMReshapeLHSMatrix, CLGEMMReshapeRHSMatrix, CLGEMMMatrixMultiplyReshaped>;
63
64// Fixture for GEMMMatrixMultiplyInterleavedTransposed3DValidationFixture
65template <typename T>
66using CLGEMMMatrixMultiplyReshaped3DFixture =
67 GEMMMatrixMultiplyInterleavedTransposed3DValidationFixture<CLTensor, CLAccessor, T, CLGEMMReshapeLHSMatrix, CLGEMMReshapeRHSMatrix, CLGEMMMatrixMultiplyReshaped>;
68
69namespace
70{
71// *INDENT-OFF*
72// clang-format off
73RelativeTolerance<float> rel_tolerance_f32(0.001f);
74constexpr float abs_tolerance_f32(0.0001f);
75
76RelativeTolerance<half> rel_tolerance_f16(half(0.2));
77constexpr float tolerance_num_f16 = 0.02f;
78
Gian Marco Iodicec630e942020-05-11 12:15:54 +010079/** Alpha values to test */
Gian Marco Iodicef3622be2019-07-29 14:27:16 +010080const auto alpha_values = framework::dataset::make("alpha", {1.0f, -0.75f} );
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010081
Gian Marco Iodicec630e942020-05-11 12:15:54 +010082/** Beta values to test */
Gian Marco Iodiced820db62019-08-05 14:23:23 +010083const auto beta_values = framework::dataset::make("beta", {-0.35f, 0.0f} );
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010084
SiCong Li7e5b7bf2020-11-17 09:41:13 +000085/** M, N combinations to test
86 * 1: Special 1x1 case
87 * 2: Special multples of processor size in both dimensions
88 * 3: Non multiples of processor size in both dimensions
89*/
90const auto m_n_values = zip(
91 framework::dataset::make("M", {1, 16, 37}),
92 framework::dataset::make("N", {1, 16, 51})
93 );
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010094
Gian Marco Iodicec630e942020-05-11 12:15:54 +010095/** N values to test */
96const auto n_values = framework::dataset::make("N", 51);
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010097
Gian Marco Iodicec630e942020-05-11 12:15:54 +010098/** K values to test */
99const auto k_values = framework::dataset::make("K", 23);
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100100
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100101/** M_W values to test */
102const auto m_w_values = framework::dataset::make("M_W", 5);
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100103
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100104/** M_H values to test */
105const auto m_h_values = framework::dataset::make("M_H", 7);
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100106
107/** Batch size values to test */
108const auto b_values = framework::dataset::make("batch_size", 1, 3);
109
110/** Activation values to test */
111const auto act_values = framework::dataset::make("Activation",
112{
113 ActivationLayerInfo(),
114 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 8.f, 2.f),
115});
116
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100117/** V0 values to test */
118const auto v0_values = framework::dataset::make("V0", 2);
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100119
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100120/** H0 values to test */
121const auto h0_values = framework::dataset::make("H0", 4);
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100122
123/** Broadcast bias from vector to matrix */
124const auto broadcast_bias_values = framework::dataset::make("broadcast_bias", {false, true} );
125
126/** GPU architectures values to test */
127const auto gpu_arch_values = framework::dataset::make("GPUArch",
128{
129 GPUTarget::MIDGARD,
130 GPUTarget::BIFROST
131});
132
133/** Data types values to test in the configuration */
134const auto data_type_values = framework::dataset::make("DataType",
135{
136 DataType::F32,
137 DataType::F16
138});
139
140/** M values to test */
141const auto fp16_mixed_precision_values = framework::dataset::make("fp16_mixed_precision", {true, false});
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100142} // namespace
143
144TEST_SUITE(CL)
145TEST_SUITE(GEMMMatrixMultiplyInterleavedTransposed)
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100146TEST_CASE(Negative, framework::DatasetMode::ALL)
147{
148 // The following tests are already integrated in the GEMMMatrixMultiply validation because
149 // in common with this validation
150 // - Unsupported QASYMM8 data type
151 // - Unsupported SIZE_T data type
152 // - Mixed precision with F32
153 // - Max number of dimensions LHS matrix
154 // - Max number of dimensions RHS matrix
155
156 // Invalid LHS dimensions
157 {
158 // The correct shape should be: lhs = TensorInfo(TensorShape(256U, 1U, 1U, 1U), 1, DataType::F32);
159 const auto lhs = TensorInfo(TensorShape(256U, 2U, 1U, 1U), 1, DataType::F32);
160 const auto rhs = TensorInfo(TensorShape(104U, 3U, 1U, 1U), 1, DataType::F32);
161 const auto bias = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
162 const auto out = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
163 constexpr float alpha = 1.3f;
164 constexpr float beta = 0.7f;
165 const bool is_interleaved_transposed = true;
166 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(16, 24, 13, 2, 4, 0, false, false);
167 const GPUTarget gpu_target = GPUTarget::MIDGARD;
168 const bool fp_mixed_precision = false;
169 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, &bias, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target, fp_mixed_precision);
170 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
171 }
172
173 // Invalid RHS dimensions
174 {
175 const auto lhs = TensorInfo(TensorShape(256U, 1U, 1U, 1U), 1, DataType::F32);
176 // The correct shape should be rhs = TensorInfo(TensorShape(104U, 3U, 1U, 1U), 1, DataType::F32);
177 const auto rhs = TensorInfo(TensorShape(104U, 4U, 1U, 1U), 1, DataType::F32);
178 const auto bias = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
179 const auto out = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
180 constexpr float alpha = 1.3f;
181 constexpr float beta = 0.7f;
182 const bool is_interleaved_transposed = true;
183 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(16, 24, 13, 2, 4, 0, false, false);
184 const GPUTarget gpu_target = GPUTarget::MIDGARD;
185 const bool fp_mixed_precision = false;
186 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, &bias, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target, fp_mixed_precision);
187 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
188 }
189
190 // Broadcast bias
191 {
192 const auto lhs = TensorInfo(TensorShape(256U, 1U, 1U, 1U), 1, DataType::F32);
193 const auto rhs = TensorInfo(TensorShape(104U, 3U, 1U, 1U), 1, DataType::F32);
194 // The correct shape should be bias = TensorInfo(TensorShape(24U, 1U, 1U, 1U), 1, DataType::F32);
195 const auto bias = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
196 const auto out = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
197 constexpr float alpha = 1.3f;
198 constexpr float beta = 0.7f;
199 const bool is_interleaved_transposed = true;
200 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(16, 24, 13, 2, 4, 0, false, true);
201 const GPUTarget gpu_target = GPUTarget::MIDGARD;
202 const bool fp_mixed_precision = false;
203 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, &bias, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target, fp_mixed_precision);
204 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
205 }
206
207 // Invalid dimensions for the bias
208 {
209 const auto lhs = TensorInfo(TensorShape(256U, 1U, 1U, 1U), 1, DataType::F32);
210 const auto rhs = TensorInfo(TensorShape(104U, 3U, 1U, 1U), 1, DataType::F32);
211 // The correct shape should be bias = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
212 const auto bias = TensorInfo(TensorShape(25U, 16U, 1U, 1U), 1, DataType::F32);
213 const auto out = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
214 constexpr float alpha = 1.3f;
215 constexpr float beta = 0.7f;
216 const bool is_interleaved_transposed = true;
217 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(16, 24, 13, 2, 4, 0, false, false);
218 const GPUTarget gpu_target = GPUTarget::MIDGARD;
219 const bool fp_mixed_precision = false;
220 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, &bias, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target, fp_mixed_precision);
221 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
222 }
223
224 // Invalid dimensions for the output
225 {
226 const auto lhs = TensorInfo(TensorShape(256U, 1U, 1U, 1U), 1, DataType::F32);
227 const auto rhs = TensorInfo(TensorShape(104U, 3U, 1U, 1U), 1, DataType::F32);
228 const auto bias = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
229 // The correct shape should be out = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
230 const auto out = TensorInfo(TensorShape(24U, 13U, 1U, 1U), 1, DataType::F32);
231 constexpr float alpha = 1.3f;
232 constexpr float beta = 0.7f;
233 const bool is_interleaved_transposed = true;
234 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(16, 24, 13, 2, 4, 0, false, false);
235 const GPUTarget gpu_target = GPUTarget::MIDGARD;
236 const bool fp_mixed_precision = false;
237 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, &bias, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target, fp_mixed_precision);
238 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
239 }
240}
241
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100242TEST_SUITE(Float)
243TEST_SUITE(FP32)
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100244FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyReshapedFixture<float>, framework::DatasetMode::ALL,
SiCong Li7e5b7bf2020-11-17 09:41:13 +0000245 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
246 m_n_values,
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100247 k_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100248 b_values),
249 alpha_values),
250 beta_values),
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100251 v0_values),
252 h0_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100253 broadcast_bias_values),
254 framework::dataset::make("fp16_mixed_precision", false)),
255 act_values),
256 framework::dataset::make("DataType", DataType::F32)),
257 gpu_arch_values))
258{
259 // Validate output
260 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
261}
262
263FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyReshaped3DFixture<float>, framework::DatasetMode::ALL,
264 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100265 m_w_values,
266 m_h_values),
267 n_values),
268 k_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100269 b_values),
270 alpha_values),
271 beta_values),
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100272 v0_values),
273 h0_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100274 broadcast_bias_values),
275 framework::dataset::make("fp16_mixed_precision", false)),
276 act_values),
277 framework::dataset::make("DataType", DataType::F32)),
278 gpu_arch_values))
279{
280 // Validate output
281 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
282}
283
284TEST_SUITE_END() // FP32
285
286TEST_SUITE(FP16)
287FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyReshapedFixture<half>, framework::DatasetMode::ALL,
SiCong Li7e5b7bf2020-11-17 09:41:13 +0000288 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
289 m_n_values,
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100290 k_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100291 b_values),
292 alpha_values),
293 beta_values),
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100294 v0_values),
295 h0_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100296 broadcast_bias_values),
297 fp16_mixed_precision_values),
298 act_values),
299 framework::dataset::make("DataType", DataType::F16)),
300 gpu_arch_values))
301{
302 // Validate output
303 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
304}
305
306FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyReshaped3DFixture<half>, framework::DatasetMode::ALL,
307 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100308 m_w_values,
309 m_h_values),
310 n_values),
311 k_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100312 b_values),
313 alpha_values),
314 beta_values),
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100315 v0_values),
316 h0_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100317 broadcast_bias_values),
318 fp16_mixed_precision_values),
319 act_values),
320 framework::dataset::make("DataType", DataType::F16)),
321 gpu_arch_values))
322{
323 // Validate output
324 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
325}
326
327TEST_SUITE_END() // FP16
328TEST_SUITE_END() // Float
329TEST_SUITE_END() // GEMMMatrixMulipltyInterleavedTransposed
330TEST_SUITE_END() // CL
331} // namespace validation
332} // namespace test
333} // namespace arm_compute