blob: fcbf8ce110ab6cd33acb5e87b0f6db77850bb9c1 [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 */
24#include "arm_compute/core/CL/kernels/CLGEMMMatrixMultiplyKernel.h"
25#include "arm_compute/core/CL/kernels/CLGEMMReshapeLHSMatrixKernel.h"
26#include "arm_compute/core/CL/kernels/CLGEMMReshapeRHSMatrixKernel.h"
27#include "arm_compute/core/KernelDescriptors.h"
28#include "arm_compute/core/Types.h"
29#include "arm_compute/core/utils/misc/ShapeCalculator.h"
30#include "arm_compute/runtime/CL/CLTensor.h"
31#include "arm_compute/runtime/CL/CLTensorAllocator.h"
32#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
Gian Marco Iodicec630e942020-05-11 12:15:54 +010085/** M values to test */
86const auto m_values = framework::dataset::make("M", {37, 1});
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010087
Gian Marco Iodicec630e942020-05-11 12:15:54 +010088/** N values to test */
89const auto n_values = framework::dataset::make("N", 51);
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010090
Gian Marco Iodicec630e942020-05-11 12:15:54 +010091/** K values to test */
92const auto k_values = framework::dataset::make("K", 23);
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010093
Gian Marco Iodicec630e942020-05-11 12:15:54 +010094/** M_W values to test */
95const auto m_w_values = framework::dataset::make("M_W", 5);
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010096
Gian Marco Iodicec630e942020-05-11 12:15:54 +010097/** M_H values to test */
98const auto m_h_values = framework::dataset::make("M_H", 7);
Gian Marco Iodiced1f54762019-07-19 09:54:47 +010099
100/** Batch size values to test */
101const auto b_values = framework::dataset::make("batch_size", 1, 3);
102
103/** Activation values to test */
104const auto act_values = framework::dataset::make("Activation",
105{
106 ActivationLayerInfo(),
107 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 8.f, 2.f),
108});
109
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100110/** V0 values to test */
111const auto v0_values = framework::dataset::make("V0", 2);
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100112
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100113/** H0 values to test */
114const auto h0_values = framework::dataset::make("H0", 4);
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100115
116/** Broadcast bias from vector to matrix */
117const auto broadcast_bias_values = framework::dataset::make("broadcast_bias", {false, true} );
118
119/** GPU architectures values to test */
120const auto gpu_arch_values = framework::dataset::make("GPUArch",
121{
122 GPUTarget::MIDGARD,
123 GPUTarget::BIFROST
124});
125
126/** Data types values to test in the configuration */
127const auto data_type_values = framework::dataset::make("DataType",
128{
129 DataType::F32,
130 DataType::F16
131});
132
133/** M values to test */
134const auto fp16_mixed_precision_values = framework::dataset::make("fp16_mixed_precision", {true, false});
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100135} // namespace
136
137TEST_SUITE(CL)
138TEST_SUITE(GEMMMatrixMultiplyInterleavedTransposed)
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100139TEST_CASE(Negative, framework::DatasetMode::ALL)
140{
141 // The following tests are already integrated in the GEMMMatrixMultiply validation because
142 // in common with this validation
143 // - Unsupported QASYMM8 data type
144 // - Unsupported SIZE_T data type
145 // - Mixed precision with F32
146 // - Max number of dimensions LHS matrix
147 // - Max number of dimensions RHS matrix
148
149 // Invalid LHS dimensions
150 {
151 // The correct shape should be: lhs = TensorInfo(TensorShape(256U, 1U, 1U, 1U), 1, DataType::F32);
152 const auto lhs = TensorInfo(TensorShape(256U, 2U, 1U, 1U), 1, DataType::F32);
153 const auto rhs = TensorInfo(TensorShape(104U, 3U, 1U, 1U), 1, DataType::F32);
154 const auto bias = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
155 const auto out = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
156 constexpr float alpha = 1.3f;
157 constexpr float beta = 0.7f;
158 const bool is_interleaved_transposed = true;
159 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(16, 24, 13, 2, 4, 0, false, false);
160 const GPUTarget gpu_target = GPUTarget::MIDGARD;
161 const bool fp_mixed_precision = false;
162 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, &bias, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target, fp_mixed_precision);
163 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
164 }
165
166 // Invalid RHS dimensions
167 {
168 const auto lhs = TensorInfo(TensorShape(256U, 1U, 1U, 1U), 1, DataType::F32);
169 // The correct shape should be rhs = TensorInfo(TensorShape(104U, 3U, 1U, 1U), 1, DataType::F32);
170 const auto rhs = TensorInfo(TensorShape(104U, 4U, 1U, 1U), 1, DataType::F32);
171 const auto bias = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
172 const auto out = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
173 constexpr float alpha = 1.3f;
174 constexpr float beta = 0.7f;
175 const bool is_interleaved_transposed = true;
176 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(16, 24, 13, 2, 4, 0, false, false);
177 const GPUTarget gpu_target = GPUTarget::MIDGARD;
178 const bool fp_mixed_precision = false;
179 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, &bias, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target, fp_mixed_precision);
180 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
181 }
182
183 // Broadcast bias
184 {
185 const auto lhs = TensorInfo(TensorShape(256U, 1U, 1U, 1U), 1, DataType::F32);
186 const auto rhs = TensorInfo(TensorShape(104U, 3U, 1U, 1U), 1, DataType::F32);
187 // The correct shape should be bias = TensorInfo(TensorShape(24U, 1U, 1U, 1U), 1, DataType::F32);
188 const auto bias = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
189 const auto out = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
190 constexpr float alpha = 1.3f;
191 constexpr float beta = 0.7f;
192 const bool is_interleaved_transposed = true;
193 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(16, 24, 13, 2, 4, 0, false, true);
194 const GPUTarget gpu_target = GPUTarget::MIDGARD;
195 const bool fp_mixed_precision = false;
196 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, &bias, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target, fp_mixed_precision);
197 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
198 }
199
200 // Invalid dimensions for the bias
201 {
202 const auto lhs = TensorInfo(TensorShape(256U, 1U, 1U, 1U), 1, DataType::F32);
203 const auto rhs = TensorInfo(TensorShape(104U, 3U, 1U, 1U), 1, DataType::F32);
204 // The correct shape should be bias = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
205 const auto bias = TensorInfo(TensorShape(25U, 16U, 1U, 1U), 1, DataType::F32);
206 const auto out = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
207 constexpr float alpha = 1.3f;
208 constexpr float beta = 0.7f;
209 const bool is_interleaved_transposed = true;
210 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(16, 24, 13, 2, 4, 0, false, false);
211 const GPUTarget gpu_target = GPUTarget::MIDGARD;
212 const bool fp_mixed_precision = false;
213 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, &bias, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target, fp_mixed_precision);
214 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
215 }
216
217 // Invalid dimensions for the output
218 {
219 const auto lhs = TensorInfo(TensorShape(256U, 1U, 1U, 1U), 1, DataType::F32);
220 const auto rhs = TensorInfo(TensorShape(104U, 3U, 1U, 1U), 1, DataType::F32);
221 const auto bias = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
222 // The correct shape should be out = TensorInfo(TensorShape(24U, 16U, 1U, 1U), 1, DataType::F32);
223 const auto out = TensorInfo(TensorShape(24U, 13U, 1U, 1U), 1, DataType::F32);
224 constexpr float alpha = 1.3f;
225 constexpr float beta = 0.7f;
226 const bool is_interleaved_transposed = true;
227 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(16, 24, 13, 2, 4, 0, false, false);
228 const GPUTarget gpu_target = GPUTarget::MIDGARD;
229 const bool fp_mixed_precision = false;
230 const auto status = CLGEMMMatrixMultiplyKernel::validate(&lhs, &rhs, &bias, &out, alpha, beta, is_interleaved_transposed, reshape_info, gpu_target, fp_mixed_precision);
231 ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
232 }
233}
234
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100235TEST_SUITE(Float)
236TEST_SUITE(FP32)
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100237FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyReshapedFixture<float>, framework::DatasetMode::ALL,
238 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100239 m_values,
240 n_values),
241 k_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100242 b_values),
243 alpha_values),
244 beta_values),
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100245 v0_values),
246 h0_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100247 broadcast_bias_values),
248 framework::dataset::make("fp16_mixed_precision", false)),
249 act_values),
250 framework::dataset::make("DataType", DataType::F32)),
251 gpu_arch_values))
252{
253 // Validate output
254 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
255}
256
257FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyReshaped3DFixture<float>, framework::DatasetMode::ALL,
258 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100259 m_w_values,
260 m_h_values),
261 n_values),
262 k_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100263 b_values),
264 alpha_values),
265 beta_values),
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100266 v0_values),
267 h0_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100268 broadcast_bias_values),
269 framework::dataset::make("fp16_mixed_precision", false)),
270 act_values),
271 framework::dataset::make("DataType", DataType::F32)),
272 gpu_arch_values))
273{
274 // Validate output
275 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
276}
277
278TEST_SUITE_END() // FP32
279
280TEST_SUITE(FP16)
281FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyReshapedFixture<half>, framework::DatasetMode::ALL,
282 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100283 m_values,
284 n_values),
285 k_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100286 b_values),
287 alpha_values),
288 beta_values),
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100289 v0_values),
290 h0_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100291 broadcast_bias_values),
292 fp16_mixed_precision_values),
293 act_values),
294 framework::dataset::make("DataType", DataType::F16)),
295 gpu_arch_values))
296{
297 // Validate output
298 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
299}
300
301FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyReshaped3DFixture<half>, framework::DatasetMode::ALL,
302 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100303 m_w_values,
304 m_h_values),
305 n_values),
306 k_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100307 b_values),
308 alpha_values),
309 beta_values),
Gian Marco Iodicec630e942020-05-11 12:15:54 +0100310 v0_values),
311 h0_values),
Gian Marco Iodiced1f54762019-07-19 09:54:47 +0100312 broadcast_bias_values),
313 fp16_mixed_precision_values),
314 act_values),
315 framework::dataset::make("DataType", DataType::F16)),
316 gpu_arch_values))
317{
318 // Validate output
319 validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
320}
321
322TEST_SUITE_END() // FP16
323TEST_SUITE_END() // Float
324TEST_SUITE_END() // GEMMMatrixMulipltyInterleavedTransposed
325TEST_SUITE_END() // CL
326} // namespace validation
327} // namespace test
328} // namespace arm_compute