blob: 0dac2e80395a8e92afb8468e6e214c0d8ed60605 [file] [log] [blame]
giuros01b3204e72019-04-01 13:50:22 +01001/*
2 * Copyright (c) 2019 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/CLGEMMMatrixMultiplyNativeKernel.h"
Gian Marco Iodice7026b302019-06-26 17:18:11 +010025#include "arm_compute/core/KernelDescriptors.h"
giuros01b3204e72019-04-01 13:50:22 +010026#include "arm_compute/core/Types.h"
27#include "arm_compute/core/utils/misc/ShapeCalculator.h"
28#include "arm_compute/runtime/CL/CLTensor.h"
29#include "arm_compute/runtime/CL/CLTensorAllocator.h"
30#include "tests/CL/CLAccessor.h"
31#include "tests/CL/Helper.h"
32#include "tests/PaddingCalculator.h"
33#include "tests/datasets/ShapeDatasets.h"
34#include "tests/framework/Asserts.h"
35#include "tests/framework/Macros.h"
36#include "tests/framework/datasets/Datasets.h"
37#include "tests/validation/Validation.h"
38#include "tests/validation/fixtures/GEMMFixture.h"
39
40namespace arm_compute
41{
42namespace test
43{
44namespace validation
45{
46using namespace arm_compute::misc::shape_calculator;
47
48// Create function for CLGEMMMatrixMultiplyNativeKernel
49using CLGEMMMatrixMultiplyNative = CLSynthetizeFunction<CLGEMMMatrixMultiplyNativeKernel>;
50
51// Fixture for CLGEMMMatrixMultiplyNative
52template <typename T>
53using CLGEMMMatrixMultiplyNativeFixture = GEMMMatrixMultiplyNativeValidationFixture<CLTensor, CLAccessor, T, CLGEMMMatrixMultiplyNative>;
54
55// Fixture for CLGEMMMatrixMultiplyNative3D
56template <typename T>
57using CLGEMMMatrixMultiplyNative3DFixture = GEMMMatrixMultiplyNative3DValidationFixture<CLTensor, CLAccessor, T, CLGEMMMatrixMultiplyNative>;
58
59namespace
60{
61// *INDENT-OFF*
62// clang-format off
63RelativeTolerance<float> rel_tolerance_f32(0.001f);
64constexpr float abs_tolerance_f32(0.0001f);
65
giuros01b3204e72019-04-01 13:50:22 +010066/** Alpha values to test - Precommit */
67const auto a_values = framework::dataset::make("alpha", {1.0f, -0.75f} );
68
Gian Marco Iodice944170e2019-06-24 14:40:30 +010069/** Beta values to test - Precommit */
70const auto beta_values = framework::dataset::make("beta", {-0.75f, 0.0f} );
71
giuros01b3204e72019-04-01 13:50:22 +010072/** M values to test */
73const auto m_values = framework::dataset::make("M", 37);
74
75/** M_W values to test */
76const auto m_w_values = framework::dataset::make("M_W", 5);
77
78/** M_H values to test */
79const auto m_h_values = framework::dataset::make("M_H", 7);
80
81/** N values to test */
82const auto n_values = framework::dataset::make("N", 51);
83
84/** K values to test */
85const auto k_values = framework::dataset::make("K", 23);
86
87/** Batch size values to test */
88const auto b_values = framework::dataset::make("batch_size", 1, 3);
89
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +010090/** Activation values to test */
91const auto act_values = framework::dataset::make("Activation",
92{
93 ActivationLayerInfo(),
94 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 8.f, 2.f),
95});
96
giuros01b3204e72019-04-01 13:50:22 +010097/** M0 values to test - Precommit */
Gian Marco Iodiced820db62019-08-05 14:23:23 +010098const auto m0_values_precommit = framework::dataset::make("M0", { 4, 6 });
giuros01b3204e72019-04-01 13:50:22 +010099
100/** N0 values to test - Precommit */
Gian Marco Iodiced820db62019-08-05 14:23:23 +0100101const auto n0_values_precommit = framework::dataset::make("N0", { 4 });
giuros01b3204e72019-04-01 13:50:22 +0100102
103/** K0 values to test - Precommit */
104const auto k0_values_precommit = framework::dataset::make("K0", { 4 });
105
106/** H0 values to test - Precommit */
107const auto h0_values_precommit = framework::dataset::make("H0", 1, 3);
108
109/** M0 values to test - Nightly */
110const auto m0_values_nightly = framework::dataset::make("M0", 1, 8);
111
112/** N0 values to test - Nightly */
113const auto n0_values_nightly = framework::dataset::make("N0", { 2, 3, 4, 8 });
114
115/** K0 values to test - Nightly */
116const auto k0_values_nightly = framework::dataset::make("K0", { 2, 3, 4, 8 });
117
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100118/** Broadcast bias from vector to matrix */
Gian Marco Iodiced820db62019-08-05 14:23:23 +0100119const auto broadcast_bias_values = framework::dataset::make("broadcast_bias", { false, true } );
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100120
giuros01b3204e72019-04-01 13:50:22 +0100121/** Configuration test */
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100122void validate_configuration(unsigned int m_value, unsigned int n_value, unsigned int k_value, unsigned int b_value, unsigned int m0_value, unsigned int n0_value, unsigned int k0_value, bool broadcast_bias, DataType data_type, const ActivationLayerInfo &act_info)
giuros01b3204e72019-04-01 13:50:22 +0100123{
124 const unsigned int M = m_value;
125 const unsigned int N = n_value;
126 const unsigned int K = k_value;
127
128 GEMMLHSMatrixInfo lhs_info;
129 lhs_info.m0 = m0_value;
130 lhs_info.k0 = k0_value;
131
132 GEMMRHSMatrixInfo rhs_info;
133 rhs_info.n0 = n0_value;
134 rhs_info.k0 = k0_value;
135
Gian Marco Iodice7026b302019-06-26 17:18:11 +0100136 GEMMKernelInfo kernel_info;
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100137 kernel_info.m = M;
138 kernel_info.n = N;
139 kernel_info.k = K;
140 kernel_info.broadcast_bias = broadcast_bias;
141 kernel_info.activation_info = act_info;
giuros01b3204e72019-04-01 13:50:22 +0100142
143 const TensorShape lhs_shape(K, M, b_value);
144 const TensorShape rhs_shape(N, K, b_value);
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100145 const TensorShape bias_shape(N,
146 broadcast_bias? 1 : M,
147 broadcast_bias? 1 : b_value);
giuros01b3204e72019-04-01 13:50:22 +0100148 const TensorShape dst_shape = compute_mm_shape(TensorInfo(lhs_shape, 1, data_type),
149 TensorInfo(rhs_shape, 1, data_type),
Gian Marco Iodice7026b302019-06-26 17:18:11 +0100150 kernel_info);
151
giuros01b3204e72019-04-01 13:50:22 +0100152 // Create tensors
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100153 CLTensor lhs = create_tensor<CLTensor>(lhs_shape, data_type);
giuros01b3204e72019-04-01 13:50:22 +0100154 CLTensor rhs = create_tensor<CLTensor>(rhs_shape, data_type);
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100155 CLTensor bias = create_tensor<CLTensor>(bias_shape, data_type);
156 CLTensor dst = create_tensor<CLTensor>(dst_shape, data_type);
giuros01b3204e72019-04-01 13:50:22 +0100157
158 ARM_COMPUTE_EXPECT(lhs.info()->is_resizable(), framework::LogLevel::ERRORS);
159 ARM_COMPUTE_EXPECT(rhs.info()->is_resizable(), framework::LogLevel::ERRORS);
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100160 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
giuros01b3204e72019-04-01 13:50:22 +0100161 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
162
163 // Create and configure function
164 CLGEMMMatrixMultiplyNative gemm;
Gian Marco Iodice7026b302019-06-26 17:18:11 +0100165 gemm.configure(&lhs, &rhs, &bias, &dst, 1.0f, 1.0f, lhs_info, rhs_info, kernel_info);
giuros01b3204e72019-04-01 13:50:22 +0100166}
167} // namespace
168
169TEST_SUITE(CL)
170TEST_SUITE(GEMMMatrixMultiplyNative)
171TEST_SUITE(Float)
172TEST_SUITE(FP32)
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100173DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine(
giuros01b3204e72019-04-01 13:50:22 +0100174 m_values,
175 n_values),
176 k_values),
177 framework::dataset::make("batch_size", 1)),
178 m0_values_precommit),
179 n0_values_precommit),
180 k0_values_precommit),
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100181 broadcast_bias_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100182 act_values),
183m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, broadcast_bias, act_value)
giuros01b3204e72019-04-01 13:50:22 +0100184{
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100185 validate_configuration(m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, broadcast_bias, DataType::F32, act_value);
giuros01b3204e72019-04-01 13:50:22 +0100186}
187
188FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::ALL,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100189 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
giuros01b3204e72019-04-01 13:50:22 +0100190 m_values,
191 n_values),
192 k_values),
193 b_values),
194 m0_values_precommit),
195 n0_values_precommit),
196 k0_values_precommit),
197 framework::dataset::make("DataType", DataType::F32)),
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100198 a_values),
199 beta_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100200 broadcast_bias_values),
201 act_values))
giuros01b3204e72019-04-01 13:50:22 +0100202{
203 // Validate output
204 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
205}
206
207FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::NIGHTLY,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100208 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
giuros01b3204e72019-04-01 13:50:22 +0100209 m_values,
210 n_values),
211 k_values),
212 b_values),
213 m0_values_nightly),
214 n0_values_nightly),
215 k0_values_nightly),
216 framework::dataset::make("DataType", DataType::F32)),
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100217 a_values),
218 beta_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100219 broadcast_bias_values),
220 act_values))
giuros01b3204e72019-04-01 13:50:22 +0100221{
222 // Validate output
223 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
224}
225
226FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyNative3DFixture<float>, framework::DatasetMode::ALL,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100227 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
giuros01b3204e72019-04-01 13:50:22 +0100228 m_w_values,
229 m_h_values),
230 n_values),
231 k_values),
232 b_values),
233 m0_values_precommit),
234 n0_values_precommit),
235 k0_values_precommit),
236 framework::dataset::make("DataType", DataType::F32)),
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100237 a_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100238 beta_values),
239 act_values))
giuros01b3204e72019-04-01 13:50:22 +0100240{
241 // Validate output
242 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
243}
244
245FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMMatrixMultiplyNative3DFixture<float>, framework::DatasetMode::NIGHTLY,
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100246 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
giuros01b3204e72019-04-01 13:50:22 +0100247 m_w_values,
248 m_h_values),
249 n_values),
250 k_values),
251 b_values),
252 m0_values_nightly),
253 n0_values_nightly),
254 k0_values_nightly),
255 framework::dataset::make("DataType", DataType::F32)),
Gian Marco Iodice944170e2019-06-24 14:40:30 +0100256 a_values),
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +0100257 beta_values),
258 act_values))
giuros01b3204e72019-04-01 13:50:22 +0100259{
260 // Validate output
261 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
262}
263TEST_SUITE_END() // FP32
giuros01b3204e72019-04-01 13:50:22 +0100264TEST_SUITE_END() // Float
265TEST_SUITE_END() // GEMMMatrixMulipltyNative
266TEST_SUITE_END() // CL
267} // namespace validation
268} // namespace test
269} // namespace arm_compute