blob: 36c1943f277943f3b342d7b592081f5cbbba218c [file] [log] [blame]
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +01001/*
Michele Di Giorgio223aba92021-04-28 16:03:32 +01002 * Copyright (c) 2017-2021 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"
25#include "arm_compute/runtime/NEON/functions/NEGEMM.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010028#include "src/core/cpu/kernels/CpuGemmInterleave4x4Kernel.h"
Michele Di Giorgio53832b22021-06-21 14:45:44 +010029#include "src/core/cpu/kernels/CpuGemmMatrixMultiplyKernel.h"
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010030#include "src/core/cpu/kernels/CpuGemmTranspose1xWKernel.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010031#include "tests/NEON/Accessor.h"
Pablo Tello2fdc4092017-11-23 15:50:08 +000032#include "tests/NEON/Helper.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010033#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010034#include "tests/datasets/LargeGEMMDataset.h"
35#include "tests/datasets/SmallGEMMDataset.h"
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +000036#include "tests/datasets/TinyGEMMDataset.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010037#include "tests/framework/Asserts.h"
38#include "tests/framework/Macros.h"
39#include "tests/framework/datasets/Datasets.h"
40#include "tests/validation/Validation.h"
41#include "tests/validation/fixtures/GEMMFixture.h"
Pablo Tello2fdc4092017-11-23 15:50:08 +000042#include "tests/validation/fixtures/GEMMInterleave4x4Fixture.h"
Pablo Tello088cc7f2017-12-07 15:20:55 +000043#include "tests/validation/fixtures/GEMMTranspose1xWFixture.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010044
45namespace arm_compute
46{
47namespace test
48{
49namespace validation
50{
51namespace
52{
Gian Marco Iodicefbf3ecc2018-08-23 17:26:21 +010053constexpr AbsoluteTolerance<float> tolerance_f(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for FP32 data types */
54#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
55RelativeTolerance<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 */
56const AbsoluteTolerance<float> abs_tolerance_f16(0.2f); /**< Absolute tolerance value for comparing reference's output against implementation's output for FP16 data types */
57constexpr float tolerance_num = 0.07f; /**< Tolerance number for FP16 data types */
58#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010059/** CNN data types */
60const auto CNNDataTypes = framework::dataset::make("DataType",
61{
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000062#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010063 DataType::F16,
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000064#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010065 DataType::F32,
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010066});
Pablo Tello2fdc4092017-11-23 15:50:08 +000067
68const auto data_interleave = framework::dataset::make("M", 8, 12) * framework::dataset::make("N", 8, 12);
Pablo Tello088cc7f2017-12-07 15:20:55 +000069const auto data_transpose = framework::dataset::make("M", 8, 14) * framework::dataset::make("N", 7, 14);
70
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010071/** Zero padding test */
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +010072template <typename FunctionType>
73bool validate_zero_padding(unsigned int dim0_value, unsigned int dim1_value)
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010074{
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +010075 const TensorShape in_shape(dim0_value, dim1_value);
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010076
77 // Create tensors
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +010078 Tensor in = create_tensor<Tensor>(in_shape, DataType::U32);
79 Tensor dst;
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010080
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +010081 ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS);
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010082
83 // Validate zero-padding
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +010084 FunctionType func;
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010085
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +010086 func.configure(&in, &dst);
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010087
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +010088 return in.info()->padding().empty();
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010089}
90
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010091/** Zero padding test
92 *
93 * TODO(COMPMID-4402): merge with previous when all kernels have been ported
94 */
95template <typename FunctionType>
96bool validate_zero_padding_new(unsigned int dim0_value, unsigned int dim1_value)
97{
98 const TensorShape in_shape(dim0_value, dim1_value);
99 TensorInfo in(in_shape, 1, DataType::U32);
100 TensorInfo dst;
101
102 ARM_COMPUTE_EXPECT(in.is_resizable(), framework::LogLevel::ERRORS);
103
104 // Validate zero-padding
105 FunctionType func;
106
107 func.configure(&in, &dst);
108
109 return in.padding().empty();
110}
111
Michele Di Giorgiocf9e29e2020-10-08 11:54:42 +0100112/* Zero padding test for GEMM kernels */
113bool validate_gemm_zero_padding(const TensorShape shape0, const TensorShape shape1)
114{
115 // Create tensors
Michele Di Giorgio53832b22021-06-21 14:45:44 +0100116 TensorInfo in0(shape0, 1, DataType::F32);
117 TensorInfo in1(shape1, 1, DataType::F32);
118 TensorInfo dst;
Michele Di Giorgiocf9e29e2020-10-08 11:54:42 +0100119
120 // Validate zero-padding
Michele Di Giorgio53832b22021-06-21 14:45:44 +0100121 cpu::kernels::CpuGemmMatrixMultiplyKernel gemm;
Michele Di Giorgiocf9e29e2020-10-08 11:54:42 +0100122 gemm.configure(&in0, &in1, &dst, 1.0, false);
123
Michele Di Giorgio53832b22021-06-21 14:45:44 +0100124 return in0.padding().empty() && in1.padding().empty() && dst.padding().empty();
Michele Di Giorgiocf9e29e2020-10-08 11:54:42 +0100125}
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100126} // namespace
127
128TEST_SUITE(NEON)
129TEST_SUITE(GEMM)
130
Pablo Tello088cc7f2017-12-07 15:20:55 +0000131TEST_SUITE(TRANSPOSE_1XW)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100132using CpuGemmTranspose1xW = NESynthetizeFunctionWithZeroConstantKernelBorder<cpu::kernels::CpuGemmTranspose1xWKernel>;
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100133DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip(
134 framework::dataset::make("N", { 1, 23, 63, 101 }),
135 framework::dataset::make("K", { 1, 47, 29, 27 })),
136 n_value, k_value)
137{
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100138 bool status = validate_zero_padding_new<CpuGemmTranspose1xW>(n_value, k_value);
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100139 ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS);
140}
141
142TEST_SUITE(U32)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100143using CpuGemmTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, CpuGemmTranspose1xW, uint32_t>;
144FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * framework::dataset::make("DataType", DataType::U32))
Pablo Tello088cc7f2017-12-07 15:20:55 +0000145{
146 // Validate output
147 validate(Accessor(_target), _reference);
148}
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100149TEST_SUITE_END() // U32
150
151TEST_SUITE(U16)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100152using CpuGemmTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, CpuGemmTranspose1xW, uint16_t>;
153FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * framework::dataset::make("DataType", DataType::U16))
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100154{
155 // Validate output
156 validate(Accessor(_target), _reference);
157}
158TEST_SUITE_END() // U16
159
160TEST_SUITE(U8)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100161using CpuGemmTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, CpuGemmTranspose1xW, uint8_t>;
162FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * framework::dataset::make("DataType", DataType::U8))
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100163{
164 // Validate output
165 validate(Accessor(_target), _reference);
166}
167TEST_SUITE_END() // U8
Pablo Tello088cc7f2017-12-07 15:20:55 +0000168
Pablo Tello088cc7f2017-12-07 15:20:55 +0000169TEST_SUITE_END() // TRANSPOSE_1XW
170
Pablo Tello2fdc4092017-11-23 15:50:08 +0000171TEST_SUITE(INTERLEAVE_4X4)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100172using CpuGemmInterleave4x4 = NESynthetizeFunctionWithZeroConstantKernelBorder<cpu::kernels::CpuGemmInterleave4x4Kernel>;
Pablo Tello2fdc4092017-11-23 15:50:08 +0000173
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100174DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip(
175 framework::dataset::make("M", { 1, 23, 63, 101 }),
176 framework::dataset::make("K", { 1, 47, 29, 27 })),
177 m_value, k_value)
178{
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100179 bool status = validate_zero_padding_new<cpu::kernels::CpuGemmInterleave4x4Kernel>(m_value, k_value);
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100180 ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS);
181}
182
183TEST_SUITE(U32)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100184using CpuGemmInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, CpuGemmInterleave4x4, uint32_t>;
185FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * framework::dataset::make("DataType", DataType::U32))
Pablo Tello2fdc4092017-11-23 15:50:08 +0000186{
187 // Validate output
188 validate(Accessor(_target), _reference);
189}
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100190TEST_SUITE_END() // U32
191
192TEST_SUITE(U16)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100193using CpuGemmInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, CpuGemmInterleave4x4, uint16_t>;
194FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * framework::dataset::make("DataType", DataType::U16))
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100195{
196 // Validate output
197 validate(Accessor(_target), _reference);
198}
199TEST_SUITE_END() // U16
200
201TEST_SUITE(U8)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100202using CpuGemmInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, CpuGemmInterleave4x4, uint8_t>;
203FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * framework::dataset::make("DataType", DataType::QASYMM8))
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100204{
205 // Validate output
206 validate(Accessor(_target), _reference);
207}
208TEST_SUITE_END() // U8
Pablo Tello2fdc4092017-11-23 15:50:08 +0000209
Pablo Tello2fdc4092017-11-23 15:50:08 +0000210TEST_SUITE_END() // INTERLEAVE_4X4
211
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100212template <typename T>
213using NEGEMMFixture = GEMMValidationFixture<Tensor, Accessor, NEGEMM, T>;
214
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000215template <typename T>
216using NEGEMMFixtureDisabledC = GEMMValidationFixture<Tensor, Accessor, NEGEMM, T, true>;
217
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100218TEST_SUITE(Float)
Michele Di Giorgiocf9e29e2020-10-08 11:54:42 +0100219DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip(framework::dataset::make("In0", { TensorShape(21U, 13U),
220 TensorShape(31U, 1U),
221 TensorShape(31U, 1U),
222 TensorShape(8U, 2U),
223 TensorShape(38U, 12U),
224 TensorShape(32U, 1U)
225 }),
226 framework::dataset::make("In1", { TensorShape(33U, 21U),
227 TensorShape(23U, 31U),
228 TensorShape(23U, 31U),
229 TensorShape(16U, 8U),
230 TensorShape(21U, 38U),
231 TensorShape(17U, 32U)
232 })),
233 shape0, shape1)
234{
235 bool status = validate_gemm_zero_padding(shape0, shape1);
236 ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS);
237}
238
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000239#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100240TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000241FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
242 framework::dataset::make("ReshapeWeights", { true, false })),
243 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100244{
245 // Validate output
Gian Marco Iodicefbf3ecc2018-08-23 17:26:21 +0100246 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100247}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000248FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
249 framework::dataset::make("ReshapeWeights", { true, false })),
250
251 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100252{
253 // Validate output
Gian Marco Iodicefbf3ecc2018-08-23 17:26:21 +0100254 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100255}
256TEST_SUITE_END()
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000257#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100258
259TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000260FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
261 framework::dataset::make("ReshapeWeights", { true, false })),
262
263 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100264{
265 // Validate output
266 validate(Accessor(_target), _reference, tolerance_f);
267}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000268FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
269 framework::dataset::make("ReshapeWeights", { true, false })),
270
271 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100272{
273 // Validate output
274 validate(Accessor(_target), _reference, tolerance_f);
275}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000276TEST_SUITE(DisabledC)
277FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixtureDisabledC<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
278 framework::dataset::make("ReshapeWeights", { true, false })),
279
280 framework::dataset::make("DataType", DataType::F32)))
281{
282 // Validate output
283 validate(Accessor(_target), _reference, tolerance_f);
284}
285TEST_SUITE_END()
286
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100287TEST_SUITE_END()
288TEST_SUITE_END()
289
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100290TEST_SUITE_END()
291TEST_SUITE_END()
292} // namespace validation
293} // namespace test
294} // namespace arm_compute