blob: 5f6a40220430a7b88f8fa5cbdaccfe73d53c7140 [file] [log] [blame]
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +01001/*
Radu Salavatf1f1f872024-02-27 18:32:26 +00002 * Copyright (c) 2017-2024 Arm Limited.
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +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/Types.h"
Matthew Bentham314d3e22023-06-23 10:53:52 +000025#include "arm_compute/core/utils/StringUtils.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010026#include "arm_compute/runtime/NEON/functions/NEGEMM.h"
27#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
Michele Di Giorgio4dfc5532021-06-30 12:05:34 +010029#include "src/core/helpers/MemoryHelpers.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010030#include "src/cpu/kernels/CpuGemmInterleave4x4Kernel.h"
31#include "src/cpu/kernels/CpuGemmMatrixMultiplyKernel.h"
32#include "src/cpu/kernels/CpuGemmTranspose1xWKernel.h"
33#include "src/cpu/operators/CpuGemm.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010034#include "tests/NEON/Accessor.h"
Pablo Tello2fdc4092017-11-23 15:50:08 +000035#include "tests/NEON/Helper.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010036#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010037#include "tests/datasets/LargeGEMMDataset.h"
38#include "tests/datasets/SmallGEMMDataset.h"
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +000039#include "tests/datasets/TinyGEMMDataset.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010040#include "tests/framework/Asserts.h"
41#include "tests/framework/Macros.h"
42#include "tests/framework/datasets/Datasets.h"
43#include "tests/validation/Validation.h"
44#include "tests/validation/fixtures/GEMMFixture.h"
Pablo Tello2fdc4092017-11-23 15:50:08 +000045#include "tests/validation/fixtures/GEMMInterleave4x4Fixture.h"
Pablo Tello088cc7f2017-12-07 15:20:55 +000046#include "tests/validation/fixtures/GEMMTranspose1xWFixture.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010047
48namespace arm_compute
49{
50namespace test
51{
52namespace validation
53{
Radu Salavatf1f1f872024-02-27 18:32:26 +000054using framework::dataset::make;
55
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010056namespace
57{
Gian Marco Iodicefbf3ecc2018-08-23 17:26:21 +010058constexpr AbsoluteTolerance<float> tolerance_f(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for FP32 data types */
59#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
60RelativeTolerance<half_float::half> rel_tolerance_f16(half(0.2)); /**< Relative tolerance value for comparing reference's output against implementation's output for FP16 data types */
61const AbsoluteTolerance<float> abs_tolerance_f16(0.2f); /**< Absolute tolerance value for comparing reference's output against implementation's output for FP16 data types */
62constexpr float tolerance_num = 0.07f; /**< Tolerance number for FP16 data types */
63#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010064/** CNN data types */
Radu Salavatf1f1f872024-02-27 18:32:26 +000065const auto CNNDataTypes = make("DataType",
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010066{
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000067#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010068 DataType::F16,
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000069#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010070 DataType::F32,
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010071});
Pablo Tello2fdc4092017-11-23 15:50:08 +000072
Radu Salavatf1f1f872024-02-27 18:32:26 +000073const auto data_interleave = make("M", 8, 12) * make("N", 8, 12);
74const auto data_transpose = make("M", 8, 14) * make("N", 7, 14);
Pablo Tello088cc7f2017-12-07 15:20:55 +000075
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010076/** Zero padding test */
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +010077template <typename FunctionType>
78bool validate_zero_padding(unsigned int dim0_value, unsigned int dim1_value)
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010079{
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +010080 const TensorShape in_shape(dim0_value, dim1_value);
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010081 TensorInfo in(in_shape, 1, DataType::U32);
82 TensorInfo dst;
83
84 ARM_COMPUTE_EXPECT(in.is_resizable(), framework::LogLevel::ERRORS);
85
86 // Validate zero-padding
87 FunctionType func;
88
89 func.configure(&in, &dst);
90
91 return in.padding().empty();
92}
93
Michele Di Giorgiocf9e29e2020-10-08 11:54:42 +010094/* Zero padding test for GEMM kernels */
95bool validate_gemm_zero_padding(const TensorShape shape0, const TensorShape shape1)
96{
97 // Create tensors
Michele Di Giorgio53832b22021-06-21 14:45:44 +010098 TensorInfo in0(shape0, 1, DataType::F32);
99 TensorInfo in1(shape1, 1, DataType::F32);
100 TensorInfo dst;
Michele Di Giorgiocf9e29e2020-10-08 11:54:42 +0100101
102 // Validate zero-padding
Michele Di Giorgio53832b22021-06-21 14:45:44 +0100103 cpu::kernels::CpuGemmMatrixMultiplyKernel gemm;
Michele Di Giorgiocf9e29e2020-10-08 11:54:42 +0100104 gemm.configure(&in0, &in1, &dst, 1.0, false);
105
Michele Di Giorgio53832b22021-06-21 14:45:44 +0100106 return in0.padding().empty() && in1.padding().empty() && dst.padding().empty();
Michele Di Giorgiocf9e29e2020-10-08 11:54:42 +0100107}
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100108} // namespace
109
110TEST_SUITE(NEON)
111TEST_SUITE(GEMM)
112
Michele Di Giorgio4dfc5532021-06-30 12:05:34 +0100113/** Test case for memory injection in @ref cpu::CpuGemm.
114 *
115 * Configure the operator once and inject memory at run-time in multiple executions.
116 *
117 * Checks performed in order:
118 * - Both runs compute the same output
119 */
120TEST_CASE(MemoryInjection, framework::DatasetMode::ALL)
121{
122 auto gemm = std::make_unique<cpu::CpuGemm>();
123 const auto lhs_info = TensorInfo(TensorShape(3U, 3U), 1, DataType::F32);
124 const auto rhs_info = TensorInfo(TensorShape(4U, 3U), 1, DataType::F32);
125 const auto c_info = TensorInfo(TensorShape(4U, 3U), 1, DataType::F32);
126 auto dst_info = TensorInfo(TensorShape(4U, 3U), 1, DataType::F32);
127 const auto gemm_info = GEMMInfo{};
128 gemm->configure(&lhs_info, &rhs_info, &c_info, &dst_info, 1.f, 1.f, gemm_info);
129
130 // telhs are newly created every call of this lambda function
131 auto lhs = create_tensor<Tensor>(lhs_info);
132 auto rhs = create_tensor<Tensor>(rhs_info);
133 auto c = create_tensor<Tensor>(c_info);
134 lhs.allocator()->allocate();
135 rhs.allocator()->allocate();
136 c.allocator()->allocate();
137
138 ITensorPack run_pack{ { TensorType::ACL_SRC_0, &lhs }, { TensorType::ACL_SRC_1, &rhs }, { TensorType::ACL_SRC_2, &c } };
139 ITensorPack prep_pack{ { TensorType::ACL_SRC_1, &rhs }, { TensorType::ACL_SRC_2, &c } };
140
141 auto mg = MemoryGroup{};
142 auto ws = manage_workspace<Tensor>(gemm->workspace(), mg, run_pack, prep_pack);
143
144 auto run_conv = [&]() -> Tensor
145 {
146 auto dst = create_tensor<Tensor>(dst_info);
147 dst.allocator()->allocate();
148 run_pack.add_tensor(TensorType::ACL_DST, &dst);
149
150 library->fill_tensor_value(Accessor(lhs), 1.f);
151 library->fill_tensor_value(Accessor(rhs), 2.f);
152 library->fill_tensor_value(Accessor(c), 3.f);
153 // This operator is configured once and captured by this lambda.
154 gemm->prepare(prep_pack);
155 gemm->run(run_pack);
156 return dst;
157 };
158 auto result_0 = run_conv();
159 auto result_1 = run_conv();
160 for(size_t i = 0; i < result_0.info()->tensor_shape().total_size(); ++i)
161 {
162 ARM_COMPUTE_EXPECT(((float *)result_0.buffer())[i] == ((float *)result_1.buffer())[i], framework::LogLevel::ERRORS);
163 }
164}
165
166/** Test case for memory injection in @ref NEGEMM.
167 *
168 * Make sure @ref NEGEMM still works through injecting the memory at configure time using the old API.
169 *
170 * Checks performed in order:
171 * - Both runs compute the same output
172 */
173TEST_CASE(MultipleExecutionWithConfigure, framework::DatasetMode::ALL)
174{
175 auto gemm = std::make_unique<NEGEMM>();
176 const auto lhs_info = TensorInfo(TensorShape(3U, 3U), 1, DataType::F32);
177 const auto rhs_info = TensorInfo(TensorShape(4U, 3U), 1, DataType::F32);
178 const auto c_info = TensorInfo(TensorShape(4U, 3U), 1, DataType::F32);
179 auto dst_info = TensorInfo(TensorShape(4U, 3U), 1, DataType::F32);
180 const auto gemm_info = GEMMInfo{};
181 auto run_conv = [&]()
182 {
183 auto lhs = create_tensor<Tensor>(lhs_info);
184 auto rhs = create_tensor<Tensor>(rhs_info);
185 auto c = create_tensor<Tensor>(c_info);
186 auto dst = create_tensor<Tensor>(dst_info);
187 gemm->configure(&lhs, &rhs, &c, &dst, 1.f, 1.f, gemm_info);
188 lhs.allocator()->allocate();
189 rhs.allocator()->allocate();
190 c.allocator()->allocate();
191 dst.allocator()->allocate();
192 library->fill_tensor_value(Accessor(lhs), 1.f);
193 library->fill_tensor_value(Accessor(rhs), 2.f);
194 library->fill_tensor_value(Accessor(c), 3.f);
195 gemm->run();
196 return dst;
197 };
198 auto result_0 = run_conv();
199 auto result_1 = run_conv();
200 for(size_t i = 0; i < result_0.info()->tensor_shape().total_size(); ++i)
201 {
202 ARM_COMPUTE_EXPECT(((float *)result_0.buffer())[i] == ((float *)result_1.buffer())[i], framework::LogLevel::ERRORS);
203 }
204}
205
SiCong Li13bab712023-01-13 15:29:39 +0000206// *INDENT-OFF*
207// clang-format off
208DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Radu Salavatf1f1f872024-02-27 18:32:26 +0000209 make("LhsInfo", { TensorInfo(TensorShape(27U, 13U), 1, DataType::S32), // Unsupported data type
SiCong Li13bab712023-01-13 15:29:39 +0000210 TensorInfo(TensorShape(27U, 13U), 1, DataType::F32),
211 }),
Radu Salavatf1f1f872024-02-27 18:32:26 +0000212 make("RhsInfo",{ TensorInfo(TensorShape(8U, 27U), 1, DataType::S32),
SiCong Li13bab712023-01-13 15:29:39 +0000213 TensorInfo(TensorShape(8U, 27U), 1, DataType::F32),
214 })),
Radu Salavatf1f1f872024-02-27 18:32:26 +0000215 make("OutputInfo",{ TensorInfo(TensorShape(8U, 13U), 1, DataType::S32),
SiCong Li13bab712023-01-13 15:29:39 +0000216 TensorInfo(TensorShape(8U, 13U), 1, DataType::F32),
217 })),
Radu Salavatf1f1f872024-02-27 18:32:26 +0000218 make("Expected", { false, true })),
SiCong Li13bab712023-01-13 15:29:39 +0000219 lhs_info, rhs_info, output_info, expected)
220{
221 constexpr float alpha = 1.0;
222 constexpr float beta = 0.0;
223 const auto gemm_info = GEMMInfo();
224 bool is_valid = bool(NEGEMM::validate(&lhs_info.clone()->set_is_resizable(true), &rhs_info.clone()->set_is_resizable(true), nullptr, &output_info.clone()->set_is_resizable(true), alpha, beta, gemm_info));
225 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
226}
227// clang-format on
228// *INDENT-ON*
Dana Zlotnik256ac622022-02-02 15:06:11 +0200229TEST_SUITE(KERNEL_SELECTION)
230DATA_TEST_CASE(KernelSelection_mul_and_add, framework::DatasetMode::ALL,
Radu Salavatf1f1f872024-02-27 18:32:26 +0000231 combine(make("CpuExt", std::string("NEON")),
232 make("DataType", { DataType::F32,
Dana Zlotnik256ac622022-02-02 15:06:11 +0200233 DataType::F16
234 })),
235 cpu_ext, data_type)
236{
237 using namespace cpu::kernels;
238
239 cpuinfo::CpuIsaInfo cpu_isa{};
240 cpu_isa.neon = (cpu_ext == "NEON");
241 cpu_isa.fp16 = (data_type == DataType::F16);
242
243 const auto *selected_impl_mul = CpuGemmMatrixMultiplyKernel::get_implementation(DataTypeISASelectorData{ data_type, cpu_isa }, cpu::KernelSelectionType::Preferred);
244
245 ARM_COMPUTE_ERROR_ON_NULLPTR(selected_impl_mul);
246
247 std::string expected = lower_string(cpu_ext) + "_" + cpu_impl_dt(data_type) + "_gemm_matrix_mul";
248 std::string actual = selected_impl_mul->name;
249
250 ARM_COMPUTE_EXPECT_EQUAL(expected, actual, framework::LogLevel::ERRORS);
251
252 const auto *selected_impl_add = CpuGemmMatrixAdditionKernel::get_implementation(DataTypeISASelectorData{ data_type, cpu_isa }, cpu::KernelSelectionType::Preferred);
253
254 ARM_COMPUTE_ERROR_ON_NULLPTR(selected_impl_add);
255
256 expected = lower_string(cpu_ext) + "_" + cpu_impl_dt(data_type) + "_gemm_matrix_add";
257 actual = selected_impl_add->name;
258
259 ARM_COMPUTE_EXPECT_EQUAL(expected, actual, framework::LogLevel::ERRORS);
260}
261TEST_SUITE_END() // KERNEL_SELECTION
262
Pablo Tello088cc7f2017-12-07 15:20:55 +0000263TEST_SUITE(TRANSPOSE_1XW)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100264using CpuGemmTranspose1xW = NESynthetizeFunctionWithZeroConstantKernelBorder<cpu::kernels::CpuGemmTranspose1xWKernel>;
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100265DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip(
Radu Salavatf1f1f872024-02-27 18:32:26 +0000266 make("N", { 1, 23, 63, 101 }),
267 make("K", { 1, 47, 29, 27 })),
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100268 n_value, k_value)
269{
Michele Di Giorgio4dfc5532021-06-30 12:05:34 +0100270 bool status = validate_zero_padding<CpuGemmTranspose1xW>(n_value, k_value);
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100271 ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS);
272}
273
274TEST_SUITE(U32)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100275using CpuGemmTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, CpuGemmTranspose1xW, uint32_t>;
Radu Salavatf1f1f872024-02-27 18:32:26 +0000276FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * make("DataType", DataType::U32))
Pablo Tello088cc7f2017-12-07 15:20:55 +0000277{
278 // Validate output
279 validate(Accessor(_target), _reference);
280}
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100281TEST_SUITE_END() // U32
282
283TEST_SUITE(U16)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100284using CpuGemmTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, CpuGemmTranspose1xW, uint16_t>;
Radu Salavatf1f1f872024-02-27 18:32:26 +0000285FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * make("DataType", DataType::U16))
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100286{
287 // Validate output
288 validate(Accessor(_target), _reference);
289}
290TEST_SUITE_END() // U16
291
292TEST_SUITE(U8)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100293using CpuGemmTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, CpuGemmTranspose1xW, uint8_t>;
Radu Salavatf1f1f872024-02-27 18:32:26 +0000294FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * make("DataType", DataType::U8))
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100295{
296 // Validate output
297 validate(Accessor(_target), _reference);
298}
299TEST_SUITE_END() // U8
Pablo Tello088cc7f2017-12-07 15:20:55 +0000300
Pablo Tello088cc7f2017-12-07 15:20:55 +0000301TEST_SUITE_END() // TRANSPOSE_1XW
302
Pablo Tello2fdc4092017-11-23 15:50:08 +0000303TEST_SUITE(INTERLEAVE_4X4)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100304using CpuGemmInterleave4x4 = NESynthetizeFunctionWithZeroConstantKernelBorder<cpu::kernels::CpuGemmInterleave4x4Kernel>;
Pablo Tello2fdc4092017-11-23 15:50:08 +0000305
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100306DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip(
Radu Salavatf1f1f872024-02-27 18:32:26 +0000307 make("M", { 1, 23, 63, 101 }),
308 make("K", { 1, 47, 29, 27 })),
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100309 m_value, k_value)
310{
Michele Di Giorgio4dfc5532021-06-30 12:05:34 +0100311 bool status = validate_zero_padding<cpu::kernels::CpuGemmInterleave4x4Kernel>(m_value, k_value);
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100312 ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS);
313}
314
315TEST_SUITE(U32)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100316using CpuGemmInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, CpuGemmInterleave4x4, uint32_t>;
Radu Salavatf1f1f872024-02-27 18:32:26 +0000317FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * make("DataType", DataType::U32))
Pablo Tello2fdc4092017-11-23 15:50:08 +0000318{
319 // Validate output
320 validate(Accessor(_target), _reference);
321}
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100322TEST_SUITE_END() // U32
323
324TEST_SUITE(U16)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100325using CpuGemmInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, CpuGemmInterleave4x4, uint16_t>;
Radu Salavatf1f1f872024-02-27 18:32:26 +0000326FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * make("DataType", DataType::U16))
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100327{
328 // Validate output
329 validate(Accessor(_target), _reference);
330}
331TEST_SUITE_END() // U16
332
333TEST_SUITE(U8)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100334using CpuGemmInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, CpuGemmInterleave4x4, uint8_t>;
Radu Salavatf1f1f872024-02-27 18:32:26 +0000335FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * make("DataType", DataType::QASYMM8))
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100336{
337 // Validate output
338 validate(Accessor(_target), _reference);
339}
340TEST_SUITE_END() // U8
Pablo Tello2fdc4092017-11-23 15:50:08 +0000341
Pablo Tello2fdc4092017-11-23 15:50:08 +0000342TEST_SUITE_END() // INTERLEAVE_4X4
343
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100344template <typename T>
345using NEGEMMFixture = GEMMValidationFixture<Tensor, Accessor, NEGEMM, T>;
346
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000347template <typename T>
Adnan AlSinan26c9d1a2022-09-07 13:54:53 +0100348using NEBatchedMatMulFixture = GEMMValidationFixture<Tensor, Accessor, NEGEMM, T, true, false, false, false, false, true>;
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000349
Radu Salavatf1f1f872024-02-27 18:32:26 +0000350template <typename T>
351using NEGEMMAccumulateFixture = GEMMAccumulateValidationFixture<Tensor, Accessor, NEGEMM, T>;
352
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100353TEST_SUITE(Float)
Radu Salavatf1f1f872024-02-27 18:32:26 +0000354DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip(make("In0", { TensorShape(21U, 13U),
Michele Di Giorgiocf9e29e2020-10-08 11:54:42 +0100355 TensorShape(31U, 1U),
356 TensorShape(31U, 1U),
357 TensorShape(8U, 2U),
358 TensorShape(38U, 12U),
359 TensorShape(32U, 1U)
360 }),
Radu Salavatf1f1f872024-02-27 18:32:26 +0000361 make("In1", { TensorShape(33U, 21U),
Michele Di Giorgiocf9e29e2020-10-08 11:54:42 +0100362 TensorShape(23U, 31U),
363 TensorShape(23U, 31U),
364 TensorShape(16U, 8U),
365 TensorShape(21U, 38U),
366 TensorShape(17U, 32U)
367 })),
368 shape0, shape1)
369{
370 bool status = validate_gemm_zero_padding(shape0, shape1);
371 ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS);
372}
373
Radu Salavatf1f1f872024-02-27 18:32:26 +0000374DATA_TEST_CASE(ValidateAccumulate, framework::DatasetMode::ALL, combine(
375 zip(make("In0",{ TensorShape(21U, 13U) }),
376 make("In1", { TensorShape(33U, 21U) }),
377 make("Dst", { TensorShape(33U, 13U) })),
378 zip(
379 make("alpha", { 1.0, 100.0, 1.0, 1.0 }),
380 make("beta", { 0.0, 0.0, 1.0, 1.0 }),
381 make("is_c_null", { false, false, false, true }),
382 make("Expected", { true, false, false, true }))),
383 shape_a, shape_b, shape_dst, alpha, beta, is_c_null, expected)
384{
385 /* Accumulation test for GEMM kernels */
386 // Create tensors
387 TensorInfo in_a(shape_a, 1, DataType::F32);
388 TensorInfo in_b(shape_b, 1, DataType::F32);
389 TensorInfo in_c(shape_dst, 1, DataType::F32);
390 TensorInfo dst(shape_dst, 1, DataType::F32);
391
392 GEMMInfo gemm_info = GEMMInfo();
393 gemm_info.set_accumulate(true);
394
395 // Validate accumulation
396 cpu::CpuGemm gemm;
397 Status status = gemm.validate(&in_a, &in_b, (is_c_null ? nullptr : &in_c), &dst, alpha, beta, gemm_info);
398 ARM_COMPUTE_EXPECT((expected == bool(status)), framework::LogLevel::ERRORS);
399}
400
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000401#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100402TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000403FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
Radu Salavatf1f1f872024-02-27 18:32:26 +0000404 make("ReshapeWeights", { true, false })),
405 make("DataType", DataType::F16)))
406{
407 // Validate output
408 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16);
409}
410FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
411 make("ReshapeWeights", { true, false })),
412 make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100413{
414 // Validate output
Gian Marco Iodicefbf3ecc2018-08-23 17:26:21 +0100415 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100416}
Adnan AlSinan304dfdb2022-09-21 13:20:45 +0100417
418TEST_SUITE(BATCHED_MATMUL)
Adnan AlSinan304dfdb2022-09-21 13:20:45 +0100419FIXTURE_DATA_TEST_CASE(RunSmall, NEBatchedMatMulFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallBatchedMatMulDataset(),
Radu Salavatf1f1f872024-02-27 18:32:26 +0000420 make("ReshapeWeights", { false })),
421 make("DataType", DataType::F16)))
Adnan AlSinan304dfdb2022-09-21 13:20:45 +0100422{
423 // Validate output
424 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16);
425}
Radu Salavatf1f1f872024-02-27 18:32:26 +0000426TEST_SUITE_END() // BATCHED_MATMUL
Adnan AlSinan304dfdb2022-09-21 13:20:45 +0100427
Radu Salavatf1f1f872024-02-27 18:32:26 +0000428TEST_SUITE_END() // FP16
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000429#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100430
431TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000432FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
Radu Salavatf1f1f872024-02-27 18:32:26 +0000433 make("ReshapeWeights", { true, false })),
434 make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100435{
436 // Validate output
437 validate(Accessor(_target), _reference, tolerance_f);
438}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000439FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
Radu Salavatf1f1f872024-02-27 18:32:26 +0000440 make("ReshapeWeights", { true, false })),
441 make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100442{
443 // Validate output
444 validate(Accessor(_target), _reference, tolerance_f);
445}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000446
Adnan AlSinan26c9d1a2022-09-07 13:54:53 +0100447TEST_SUITE(BATCHED_MATMUL)
Adnan AlSinan26c9d1a2022-09-07 13:54:53 +0100448FIXTURE_DATA_TEST_CASE(RunSmall, NEBatchedMatMulFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallBatchedMatMulDataset(),
Radu Salavatf1f1f872024-02-27 18:32:26 +0000449 make("ReshapeWeights", { false })),
450 make("DataType", DataType::F32)))
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000451{
452 // Validate output
453 validate(Accessor(_target), _reference, tolerance_f);
454}
Radu Salavatf1f1f872024-02-27 18:32:26 +0000455TEST_SUITE_END() // BATCHED_MATMUL
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000456
Radu Salavatf1f1f872024-02-27 18:32:26 +0000457TEST_SUITE(ACCUMULATE)
458FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMAccumulateFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallAccumulateGEMMDataset(),
459 make("ReshapeWeights", { false }),
460 make("DataType", DataType::F32)))
461{
462 // Validate output
463 validate(Accessor(_target), _reference, tolerance_f);
464}
465FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMAccumulateFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeAccumulateGEMMDataset(),
466 make("ReshapeWeights", { false }),
467 make("DataType", DataType::F32)))
468{
469 // Validate output
470 validate(Accessor(_target), _reference, tolerance_f);
471}
472TEST_SUITE_END() // ACCUMULATE
Gian Marco Iodice37a46112021-08-04 15:22:28 +0100473
Radu Salavatf1f1f872024-02-27 18:32:26 +0000474TEST_SUITE_END() // FP32
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100475
Radu Salavatf1f1f872024-02-27 18:32:26 +0000476TEST_SUITE_END() // Float
477TEST_SUITE_END() // GEMM
478TEST_SUITE_END() // NEON
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100479} // namespace validation
480} // namespace test
481} // namespace arm_compute