blob: 25e8f28dc343269439c32c906ffeac38bca5aed9 [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 */
Pablo Tello2fdc4092017-11-23 15:50:08 +000024#include "arm_compute/core/NEON/kernels/NEGEMMInterleave4x4Kernel.h"
Pablo Tello088cc7f2017-12-07 15:20:55 +000025#include "arm_compute/core/NEON/kernels/NEGEMMTranspose1xWKernel.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010026#include "arm_compute/core/Types.h"
27#include "arm_compute/runtime/NEON/functions/NEGEMM.h"
28#include "arm_compute/runtime/Tensor.h"
29#include "arm_compute/runtime/TensorAllocator.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010030#include "tests/NEON/Accessor.h"
Pablo Tello2fdc4092017-11-23 15:50:08 +000031#include "tests/NEON/Helper.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010032#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010033#include "tests/datasets/LargeGEMMDataset.h"
34#include "tests/datasets/SmallGEMMDataset.h"
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +000035#include "tests/datasets/TinyGEMMDataset.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010036#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"
Pablo Tello2fdc4092017-11-23 15:50:08 +000041#include "tests/validation/fixtures/GEMMInterleave4x4Fixture.h"
Pablo Tello088cc7f2017-12-07 15:20:55 +000042#include "tests/validation/fixtures/GEMMTranspose1xWFixture.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010043
44namespace arm_compute
45{
46namespace test
47{
48namespace validation
49{
50namespace
51{
Gian Marco Iodicefbf3ecc2018-08-23 17:26:21 +010052constexpr AbsoluteTolerance<float> tolerance_f(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for FP32 data types */
53#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
54RelativeTolerance<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 */
55const AbsoluteTolerance<float> abs_tolerance_f16(0.2f); /**< Absolute tolerance value for comparing reference's output against implementation's output for FP16 data types */
56constexpr float tolerance_num = 0.07f; /**< Tolerance number for FP16 data types */
57#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010058/** CNN data types */
59const auto CNNDataTypes = framework::dataset::make("DataType",
60{
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000061#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010062 DataType::F16,
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000063#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010064 DataType::F32,
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010065});
Pablo Tello2fdc4092017-11-23 15:50:08 +000066
67const auto data_interleave = framework::dataset::make("M", 8, 12) * framework::dataset::make("N", 8, 12);
Pablo Tello088cc7f2017-12-07 15:20:55 +000068const auto data_transpose = framework::dataset::make("M", 8, 14) * framework::dataset::make("N", 7, 14);
69
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010070/** Zero padding test */
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +010071template <typename FunctionType>
72bool validate_zero_padding(unsigned int dim0_value, unsigned int dim1_value)
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010073{
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +010074 const TensorShape in_shape(dim0_value, dim1_value);
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010075
76 // Create tensors
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +010077 Tensor in = create_tensor<Tensor>(in_shape, DataType::U32);
78 Tensor dst;
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010079
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +010080 ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS);
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010081
82 // Validate zero-padding
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +010083 FunctionType func;
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010084
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +010085 func.configure(&in, &dst);
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010086
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +010087 return in.info()->padding().empty();
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010088}
89
Michele Di Giorgiocf9e29e2020-10-08 11:54:42 +010090/* Zero padding test for GEMM kernels */
91bool validate_gemm_zero_padding(const TensorShape shape0, const TensorShape shape1)
92{
93 // Create tensors
94 Tensor in0 = create_tensor<Tensor>(shape0, DataType::F32);
95 Tensor in1 = create_tensor<Tensor>(shape1, DataType::F32);
96 Tensor dst;
97
98 // Validate zero-padding
99 NEGEMMMatrixMultiplyKernel gemm;
100 gemm.configure(&in0, &in1, &dst, 1.0, false);
101
102 return in0.info()->padding().empty() && in1.info()->padding().empty() && dst.info()->padding().empty();
103}
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100104} // namespace
105
106TEST_SUITE(NEON)
107TEST_SUITE(GEMM)
108
Pablo Tello088cc7f2017-12-07 15:20:55 +0000109TEST_SUITE(TRANSPOSE_1XW)
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100110using NEGEMMTranspose1xW = NESynthetizeFunctionWithZeroConstantBorder<NEGEMMTranspose1xWKernel, 4>;
111DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip(
112 framework::dataset::make("N", { 1, 23, 63, 101 }),
113 framework::dataset::make("K", { 1, 47, 29, 27 })),
114 n_value, k_value)
115{
116 bool status = validate_zero_padding<NEGEMMTranspose1xWKernel>(n_value, k_value);
117 ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS);
118}
119
120TEST_SUITE(U32)
121using NEGEMMTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, NEGEMMTranspose1xW, uint32_t>;
122FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * framework::dataset::make("DataType", DataType::U32))
Pablo Tello088cc7f2017-12-07 15:20:55 +0000123{
124 // Validate output
125 validate(Accessor(_target), _reference);
126}
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100127TEST_SUITE_END() // U32
128
129TEST_SUITE(U16)
130using NEGEMMTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, NEGEMMTranspose1xW, uint16_t>;
131FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * framework::dataset::make("DataType", DataType::U16))
132{
133 // Validate output
134 validate(Accessor(_target), _reference);
135}
136TEST_SUITE_END() // U16
137
138TEST_SUITE(U8)
139using NEGEMMTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, NEGEMMTranspose1xW, uint8_t>;
140FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * framework::dataset::make("DataType", DataType::U8))
141{
142 // Validate output
143 validate(Accessor(_target), _reference);
144}
145TEST_SUITE_END() // U8
Pablo Tello088cc7f2017-12-07 15:20:55 +0000146
Pablo Tello088cc7f2017-12-07 15:20:55 +0000147TEST_SUITE_END() // TRANSPOSE_1XW
148
Pablo Tello2fdc4092017-11-23 15:50:08 +0000149TEST_SUITE(INTERLEAVE_4X4)
150using NEGEMMInterleave4x4 = NESynthetizeFunctionWithZeroConstantBorder<NEGEMMInterleave4x4Kernel, 4>;
151
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100152DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip(
153 framework::dataset::make("M", { 1, 23, 63, 101 }),
154 framework::dataset::make("K", { 1, 47, 29, 27 })),
155 m_value, k_value)
156{
Gian Marco Iodiceb3182b12020-09-04 08:44:52 +0100157 bool status = validate_zero_padding<NEGEMMInterleave4x4Kernel>(m_value, k_value);
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100158 ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS);
159}
160
161TEST_SUITE(U32)
162using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, NEGEMMInterleave4x4, uint32_t>;
163FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * framework::dataset::make("DataType", DataType::U32))
Pablo Tello2fdc4092017-11-23 15:50:08 +0000164{
165 // Validate output
166 validate(Accessor(_target), _reference);
167}
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100168TEST_SUITE_END() // U32
169
170TEST_SUITE(U16)
171using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, NEGEMMInterleave4x4, uint16_t>;
172FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * framework::dataset::make("DataType", DataType::U16))
173{
174 // Validate output
175 validate(Accessor(_target), _reference);
176}
177TEST_SUITE_END() // U16
178
179TEST_SUITE(U8)
180using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, NEGEMMInterleave4x4, uint8_t>;
181FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * framework::dataset::make("DataType", DataType::QASYMM8))
182{
183 // Validate output
184 validate(Accessor(_target), _reference);
185}
186TEST_SUITE_END() // U8
Pablo Tello2fdc4092017-11-23 15:50:08 +0000187
Pablo Tello2fdc4092017-11-23 15:50:08 +0000188TEST_SUITE_END() // INTERLEAVE_4X4
189
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +0000190//TODO(COMPMID-415): Validate valid region
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100191
192template <typename T>
193using NEGEMMFixture = GEMMValidationFixture<Tensor, Accessor, NEGEMM, T>;
194
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000195template <typename T>
196using NEGEMMFixtureDisabledC = GEMMValidationFixture<Tensor, Accessor, NEGEMM, T, true>;
197
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100198TEST_SUITE(Float)
Michele Di Giorgiocf9e29e2020-10-08 11:54:42 +0100199DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip(framework::dataset::make("In0", { TensorShape(21U, 13U),
200 TensorShape(31U, 1U),
201 TensorShape(31U, 1U),
202 TensorShape(8U, 2U),
203 TensorShape(38U, 12U),
204 TensorShape(32U, 1U)
205 }),
206 framework::dataset::make("In1", { TensorShape(33U, 21U),
207 TensorShape(23U, 31U),
208 TensorShape(23U, 31U),
209 TensorShape(16U, 8U),
210 TensorShape(21U, 38U),
211 TensorShape(17U, 32U)
212 })),
213 shape0, shape1)
214{
215 bool status = validate_gemm_zero_padding(shape0, shape1);
216 ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS);
217}
218
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000219#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100220TEST_SUITE(FP16)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000221FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
222 framework::dataset::make("ReshapeWeights", { true, false })),
223 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100224{
225 // Validate output
Gian Marco Iodicefbf3ecc2018-08-23 17:26:21 +0100226 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100227}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000228FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
229 framework::dataset::make("ReshapeWeights", { true, false })),
230
231 framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100232{
233 // Validate output
Gian Marco Iodicefbf3ecc2018-08-23 17:26:21 +0100234 validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100235}
236TEST_SUITE_END()
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000237#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100238
239TEST_SUITE(FP32)
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000240FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
241 framework::dataset::make("ReshapeWeights", { true, false })),
242
243 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100244{
245 // Validate output
246 validate(Accessor(_target), _reference, tolerance_f);
247}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000248FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
249 framework::dataset::make("ReshapeWeights", { true, false })),
250
251 framework::dataset::make("DataType", DataType::F32)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100252{
253 // Validate output
254 validate(Accessor(_target), _reference, tolerance_f);
255}
Pablo Tello0e37b5c2018-10-30 11:18:37 +0000256TEST_SUITE(DisabledC)
257FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixtureDisabledC<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
258 framework::dataset::make("ReshapeWeights", { true, false })),
259
260 framework::dataset::make("DataType", DataType::F32)))
261{
262 // Validate output
263 validate(Accessor(_target), _reference, tolerance_f);
264}
265TEST_SUITE_END()
266
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100267TEST_SUITE_END()
268TEST_SUITE_END()
269
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100270TEST_SUITE_END()
271TEST_SUITE_END()
272} // namespace validation
273} // namespace test
274} // namespace arm_compute