blob: 2d8c61164b622feb9e776a9f1e1a5be654f7b635 [file] [log] [blame]
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +01001/*
Gian Marco Iodicefeaea102020-09-03 13:20:34 +01002 * Copyright (c) 2017-2020 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"
Michalis Spyrouebcebf12020-10-21 00:04:14 +010028#include "src/core/NEON/kernels/NEGEMMInterleave4x4Kernel.h"
29#include "src/core/NEON/kernels/NEGEMMMatrixMultiplyKernel.h"
30#include "src/core/NEON/kernels/NEGEMMTranspose1xWKernel.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 Giorgiocf9e29e2020-10-08 11:54:42 +010091/* Zero padding test for GEMM kernels */
92bool validate_gemm_zero_padding(const TensorShape shape0, const TensorShape shape1)
93{
94 // Create tensors
95 Tensor in0 = create_tensor<Tensor>(shape0, DataType::F32);
96 Tensor in1 = create_tensor<Tensor>(shape1, DataType::F32);
97 Tensor dst;
98
99 // Validate zero-padding
100 NEGEMMMatrixMultiplyKernel gemm;
101 gemm.configure(&in0, &in1, &dst, 1.0, false);
102
103 return in0.info()->padding().empty() && in1.info()->padding().empty() && dst.info()->padding().empty();
104}
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100105} // namespace
106
107TEST_SUITE(NEON)
108TEST_SUITE(GEMM)
109
Pablo Tello088cc7f2017-12-07 15:20:55 +0000110TEST_SUITE(TRANSPOSE_1XW)
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100111using NEGEMMTranspose1xW = NESynthetizeFunctionWithZeroConstantBorder<NEGEMMTranspose1xWKernel, 4>;
112DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip(
113 framework::dataset::make("N", { 1, 23, 63, 101 }),
114 framework::dataset::make("K", { 1, 47, 29, 27 })),
115 n_value, k_value)
116{
117 bool status = validate_zero_padding<NEGEMMTranspose1xWKernel>(n_value, k_value);
118 ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS);
119}
120
121TEST_SUITE(U32)
122using NEGEMMTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, NEGEMMTranspose1xW, uint32_t>;
123FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * framework::dataset::make("DataType", DataType::U32))
Pablo Tello088cc7f2017-12-07 15:20:55 +0000124{
125 // Validate output
126 validate(Accessor(_target), _reference);
127}
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100128TEST_SUITE_END() // U32
129
130TEST_SUITE(U16)
131using NEGEMMTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, NEGEMMTranspose1xW, uint16_t>;
132FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * framework::dataset::make("DataType", DataType::U16))
133{
134 // Validate output
135 validate(Accessor(_target), _reference);
136}
137TEST_SUITE_END() // U16
138
139TEST_SUITE(U8)
140using NEGEMMTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, NEGEMMTranspose1xW, uint8_t>;
141FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * framework::dataset::make("DataType", DataType::U8))
142{
143 // Validate output
144 validate(Accessor(_target), _reference);
145}
146TEST_SUITE_END() // U8
Pablo Tello088cc7f2017-12-07 15:20:55 +0000147
Pablo Tello088cc7f2017-12-07 15:20:55 +0000148TEST_SUITE_END() // TRANSPOSE_1XW
149
Pablo Tello2fdc4092017-11-23 15:50:08 +0000150TEST_SUITE(INTERLEAVE_4X4)
151using NEGEMMInterleave4x4 = NESynthetizeFunctionWithZeroConstantBorder<NEGEMMInterleave4x4Kernel, 4>;
152
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100153DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip(
154 framework::dataset::make("M", { 1, 23, 63, 101 }),
155 framework::dataset::make("K", { 1, 47, 29, 27 })),
156 m_value, k_value)
157{
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100158 bool status = validate_zero_padding<NEGEMMInterleave4x4Kernel>(m_value, k_value);
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100159 ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS);
160}
161
162TEST_SUITE(U32)
163using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, NEGEMMInterleave4x4, uint32_t>;
164FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * framework::dataset::make("DataType", DataType::U32))
Pablo Tello2fdc4092017-11-23 15:50:08 +0000165{
166 // Validate output
167 validate(Accessor(_target), _reference);
168}
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100169TEST_SUITE_END() // U32
170
171TEST_SUITE(U16)
172using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, NEGEMMInterleave4x4, uint16_t>;
173FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * framework::dataset::make("DataType", DataType::U16))
174{
175 // Validate output
176 validate(Accessor(_target), _reference);
177}
178TEST_SUITE_END() // U16
179
180TEST_SUITE(U8)
181using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, NEGEMMInterleave4x4, uint8_t>;
182FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * framework::dataset::make("DataType", DataType::QASYMM8))
183{
184 // Validate output
185 validate(Accessor(_target), _reference);
186}
187TEST_SUITE_END() // U8
Pablo Tello2fdc4092017-11-23 15:50:08 +0000188
Pablo Tello2fdc4092017-11-23 15:50:08 +0000189TEST_SUITE_END() // INTERLEAVE_4X4
190
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +0000191//TODO(COMPMID-415): Validate valid region
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100192
193template <typename T>
194using NEGEMMFixture = GEMMValidationFixture<Tensor, Accessor, NEGEMM, T>;
195
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000196template <typename T>
197using NEGEMMFixtureDisabledC = GEMMValidationFixture<Tensor, Accessor, NEGEMM, T, true>;
198
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100199TEST_SUITE(Float)
Michele Di Giorgiocf9e29e2020-10-08 11:54:42 +0100200DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip(framework::dataset::make("In0", { TensorShape(21U, 13U),
201 TensorShape(31U, 1U),
202 TensorShape(31U, 1U),
203 TensorShape(8U, 2U),
204 TensorShape(38U, 12U),
205 TensorShape(32U, 1U)
206 }),
207 framework::dataset::make("In1", { TensorShape(33U, 21U),
208 TensorShape(23U, 31U),
209 TensorShape(23U, 31U),
210 TensorShape(16U, 8U),
211 TensorShape(21U, 38U),
212 TensorShape(17U, 32U)
213 })),
214 shape0, shape1)
215{
216 bool status = validate_gemm_zero_padding(shape0, shape1);
217 ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS);
218}
219
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000220#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100221TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000222FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
223 framework::dataset::make("ReshapeWeights", { true, false })),
224 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100225{
226 // Validate output
Gian Marco Iodicefbf3ecc2018-08-23 17:26:21 +0100227 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100228}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000229FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
230 framework::dataset::make("ReshapeWeights", { true, false })),
231
232 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100233{
234 // Validate output
Gian Marco Iodicefbf3ecc2018-08-23 17:26:21 +0100235 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100236}
237TEST_SUITE_END()
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000238#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100239
240TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000241FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
242 framework::dataset::make("ReshapeWeights", { true, false })),
243
244 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100245{
246 // Validate output
247 validate(Accessor(_target), _reference, tolerance_f);
248}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000249FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
250 framework::dataset::make("ReshapeWeights", { true, false })),
251
252 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100253{
254 // Validate output
255 validate(Accessor(_target), _reference, tolerance_f);
256}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000257TEST_SUITE(DisabledC)
258FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixtureDisabledC<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
259 framework::dataset::make("ReshapeWeights", { true, false })),
260
261 framework::dataset::make("DataType", DataType::F32)))
262{
263 // Validate output
264 validate(Accessor(_target), _reference, tolerance_f);
265}
266TEST_SUITE_END()
267
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100268TEST_SUITE_END()
269TEST_SUITE_END()
270
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100271TEST_SUITE_END()
272TEST_SUITE_END()
273} // namespace validation
274} // namespace test
275} // namespace arm_compute