blob: 57e8ce7ea9c1fd34f95dcd289d6c3678e4fdd063 [file] [log] [blame]
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +01001/*
2 * Copyright (c) 2017 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 */
Pablo Tello2fdc4092017-11-23 15:50:08 +000024#include "arm_compute/core/NEON/kernels/NEGEMMInterleave4x4Kernel.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010025#include "arm_compute/core/Types.h"
26#include "arm_compute/runtime/NEON/functions/NEGEMM.h"
27#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010029#include "tests/NEON/Accessor.h"
Pablo Tello2fdc4092017-11-23 15:50:08 +000030#include "tests/NEON/Helper.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010031#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010032#include "tests/datasets/LargeGEMMDataset.h"
33#include "tests/datasets/SmallGEMMDataset.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"
Pablo Tello2fdc4092017-11-23 15:50:08 +000039#include "tests/validation/fixtures/GEMMInterleave4x4Fixture.h"
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010040
41namespace arm_compute
42{
43namespace test
44{
45namespace validation
46{
47namespace
48{
49constexpr AbsoluteTolerance<float> tolerance_f(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for floating point data types */
50constexpr AbsoluteTolerance<float> tolerance_q(1.0f); /**< Tolerance value for comparing reference's output against implementation's output for fixed point data types */
51
52/** CNN data types */
53const auto CNNDataTypes = framework::dataset::make("DataType",
54{
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000055#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010056 DataType::F16,
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000057#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010058 DataType::F32,
59 DataType::QS8,
60 DataType::QS16,
61});
Pablo Tello2fdc4092017-11-23 15:50:08 +000062
63const auto data_interleave = framework::dataset::make("M", 8, 12) * framework::dataset::make("N", 8, 12);
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +010064} // namespace
65
66TEST_SUITE(NEON)
67TEST_SUITE(GEMM)
68
Pablo Tello2fdc4092017-11-23 15:50:08 +000069TEST_SUITE(INTERLEAVE_4X4)
70using NEGEMMInterleave4x4 = NESynthetizeFunctionWithZeroConstantBorder<NEGEMMInterleave4x4Kernel, 4>;
71
72TEST_SUITE(FP32)
73using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, NEGEMMInterleave4x4, float>;
74FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * framework::dataset::make("DataType", DataType::F32))
75{
76 // Validate output
77 validate(Accessor(_target), _reference);
78}
79TEST_SUITE_END() // FP32
80
81TEST_SUITE(Quantized)
82TEST_SUITE(QS8)
83using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixedPointFixture<Tensor, Accessor, NEGEMMInterleave4x4, int8_t>;
84FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave *
85 framework::dataset::make("DataType", DataType::QS8)
86 * framework::dataset::make("FractionalBits", 1, 7))
87{
88 // Validate output
89 validate(Accessor(_target), _reference);
90}
91TEST_SUITE_END()
92
93TEST_SUITE(QS16)
94using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixedPointFixture<Tensor, Accessor, NEGEMMInterleave4x4, int16_t>;
95FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave *
96 framework::dataset::make("DataType", DataType::QS16)
97 * framework::dataset::make("FractionalBits", 1, 14))
98{
99 // Validate output
100 validate(Accessor(_target), _reference);
101}
102TEST_SUITE_END()
103
104TEST_SUITE_END()
105
106TEST_SUITE_END() // INTERLEAVE_4X4
107
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100108DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallGEMMDataset(), datasets::LargeGEMMDataset()), CNNDataTypes),
109 shape_a, shape_b, shape_c, output_shape, alpha, beta, data_type)
110{
111 // Set fixed point position data type allowed
112 const int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0;
113
114 // Create tensors
115 Tensor a = create_tensor<Tensor>(shape_a, data_type, 1, fixed_point_position);
116 Tensor b = create_tensor<Tensor>(shape_b, data_type, 1, fixed_point_position);
117 Tensor c = create_tensor<Tensor>(shape_c, data_type, 1, fixed_point_position);
118 Tensor dst = create_tensor<Tensor>(output_shape, data_type, 1, fixed_point_position);
119
120 ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS);
121 ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS);
122 ARM_COMPUTE_EXPECT(c.info()->is_resizable(), framework::LogLevel::ERRORS);
123 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
124
125 // Create and configure function
126 NEGEMM gemm;
127 gemm.configure(&a, &b, &c, &dst, alpha, beta);
128
129 //TODO(COMPMID-415): Validate valid region
130}
131
132template <typename T>
133using NEGEMMFixture = GEMMValidationFixture<Tensor, Accessor, NEGEMM, T>;
134
135TEST_SUITE(Float)
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000136#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100137TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100138FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallGEMMDataset(), framework::dataset::make("DataType", DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100139{
140 // Validate output
141 validate(Accessor(_target), _reference, tolerance_f);
142}
Georgios Pinitas583137c2017-08-31 18:12:42 +0100143FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMDataset(), framework::dataset::make("DataType",
144 DataType::F16)))
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100145{
146 // Validate output
147 validate(Accessor(_target), _reference, tolerance_f);
148}
149TEST_SUITE_END()
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000150#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer4dfc2352017-08-02 14:51:36 +0100151
152TEST_SUITE(FP32)
153FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallGEMMDataset(), framework::dataset::make("DataType", DataType::F32)))
154{
155 // Validate output
156 validate(Accessor(_target), _reference, tolerance_f);
157}
158FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMDataset(), framework::dataset::make("DataType", DataType::F32)))
159{
160 // Validate output
161 validate(Accessor(_target), _reference, tolerance_f);
162}
163TEST_SUITE_END()
164TEST_SUITE_END()
165
166template <typename T>
167using NEGEMMFixedPointFixture = GEMMValidationFixedPointFixture<Tensor, Accessor, NEGEMM, T>;
168
169TEST_SUITE(Quantized)
170TEST_SUITE(QS8)
171FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
172 framework::dataset::make("DataType",
173 DataType::QS8)),
174 framework::dataset::make("FractionalBits", 1, 7)))
175{
176 // Validate output
177 validate(Accessor(_target), _reference, tolerance_q);
178}
179FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
180 framework::dataset::make("DataType",
181 DataType::QS8)),
182 framework::dataset::make("FractionalBits", 1, 7)))
183{
184 // Validate output
185 validate(Accessor(_target), _reference, tolerance_q);
186}
187TEST_SUITE_END()
188
189TEST_SUITE(QS16)
190FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(),
191 framework::dataset::make("DataType",
192 DataType::QS16)),
193 framework::dataset::make("FractionalBits", 1, 14)))
194{
195 // Validate output
196 validate(Accessor(_target), _reference, tolerance_q);
197}
198FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(),
199 framework::dataset::make("DataType",
200 DataType::QS16)),
201 framework::dataset::make("FractionalBits", 1, 14)))
202{
203 // Validate output
204 validate(Accessor(_target), _reference, tolerance_q);
205}
206TEST_SUITE_END()
207TEST_SUITE_END()
208
209TEST_SUITE_END()
210TEST_SUITE_END()
211} // namespace validation
212} // namespace test
213} // namespace arm_compute