blob: 0a20d1849006f8594b5f6db457621bbf9d4565d4 [file] [log] [blame]
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +00001/*
2 * Copyright (c) 2023 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 */
24#include "arm_compute/core/Types.h"
25#include "arm_compute/runtime/NEON/functions/NEMatMul.h"
26
27#include "tests/NEON/Accessor.h"
28#include "tests/framework/Asserts.h"
29#include "tests/framework/Macros.h"
30#include "tests/framework/datasets/Datasets.h"
31#include "tests/validation/Validation.h"
32
33#include "tests/datasets/LargeMatMulDataset.h"
34#include "tests/datasets/SmallMatMulDataset.h"
35#include "tests/validation/fixtures/MatMulFixture.h"
36
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43TEST_SUITE(NEON)
44TEST_SUITE(MatMul)
45
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +010046constexpr AbsoluteTolerance<float> tolerance_fp32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for FP32 data types */
47const AbsoluteTolerance<half> tolerance_fp16(half(0.1f));
Ramy Elgammalaf150762023-04-25 17:19:27 +010048#ifdef __aarch64__
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +010049constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(0);
50constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8_signed(0);
Ramy Elgammalaf150762023-04-25 17:19:27 +010051#endif // __aarch64__
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000052
53// clang-format off
54// *INDENT-OFF*
55// Validation Tests
56DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
57 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(9U, 6U), 1, DataType::F32), // Mismatching datatype
58 TensorInfo(TensorShape(9U, 6U), 1, DataType::S32), // Unsupported datatypes
59 TensorInfo(TensorShape(9U, 6U, 2U), 1, DataType::F32), // Broadcasting in batch dimension not supported
60 TensorInfo(TensorShape(9U, 6U), 1, DataType::F32), // Invalid shape for multiplication
61 TensorInfo(TensorShape(9U, 6U), 1, DataType::F32),
62 TensorInfo(TensorShape(9U, 6U , 12U) , 1 , DataType::F32),
63 TensorInfo(TensorShape(9U, 6U , 12U) , 1 , DataType::F32), // Tensors are not dynamic
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +010064 TensorInfo(TensorShape(9U, 6U), 1, DataType::QASYMM8),
65 TensorInfo(TensorShape(9U, 6U), 1, DataType::QASYMM8_SIGNED),
66 TensorInfo(TensorShape(9U, 6U), 1, DataType::QASYMM8_SIGNED), // Mismatching data type
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000067 }),
68 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(5U, 9U), 1, DataType::QASYMM8),
69 TensorInfo(TensorShape(5U, 9U), 1, DataType::S32),
70 TensorInfo(TensorShape(5U, 9U, 1U), 1, DataType::F32),
71 TensorInfo(TensorShape(5U, 12U), 1, DataType::F32),
72 TensorInfo(TensorShape(5U, 9U), 1, DataType::F32),
73 TensorInfo(TensorShape(5U, 9U, 12U), 1, DataType::F32),
74 TensorInfo(TensorShape(5U, 9U, 12U), 1, DataType::F32),
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +010075 TensorInfo(TensorShape(5U, 9U), 1, DataType::QASYMM8),
76 TensorInfo(TensorShape(5U, 9U), 1, DataType::QASYMM8_SIGNED),
77 TensorInfo(TensorShape(5U, 9U), 1, DataType::QASYMM8_SIGNED),
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000078 })),
79 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(5U, 6U), 1, DataType::F32),
80 TensorInfo(TensorShape(5U, 6U), 1, DataType::S32),
81 TensorInfo(TensorShape(5U, 6U, 2U), 1, DataType::F32),
82 TensorInfo(TensorShape(5U, 6U), 1, DataType::F32),
83 TensorInfo(TensorShape(5U, 6U), 1, DataType::F32),
84 TensorInfo(TensorShape(5U, 6U, 12U) , 1, DataType::F32),
85 TensorInfo(TensorShape(5U, 6U, 12U) , 1, DataType::F32),
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +010086 TensorInfo(TensorShape(5U, 6U), 1, DataType::QASYMM8),
87 TensorInfo(TensorShape(5U, 6U), 1, DataType::QASYMM8_SIGNED),
88 TensorInfo(TensorShape(5U, 6U), 1, DataType::QASYMM8),
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000089 })),
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +010090 framework::dataset::make( "TensorIsConst", {false, false, false, false, false , false, true, false, false, false} )),
91 framework::dataset::make("Expected", { false, false, false, false, true, true, false, true, true, false })),
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000092 a_info, b_info, output_info, are_tensors_const, expected)
93{
94 TensorInfo a{a_info};
95 TensorInfo b{b_info};
96 a.set_are_values_constant(are_tensors_const);
97 b.set_are_values_constant(are_tensors_const);
98 Status status = NEMatMul::validate(&a,
99 &b,
100 &output_info,
101 MatMulInfo(),
102 CpuMatMulSettings());
103 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
104}
105// *INDENT-ON*
106// clang-format on
107
108// Generic Template
109template <typename T>
110using NEMatMulFixture = MatMulValidationWithActivationFixture<Tensor, Accessor, NEMatMul, CpuMatMulSettings, T>;
111
112// Fast math Template
113template <typename T>
114using NEMatMulFastMathFixture = MatMulGenericValidationFixture<Tensor, Accessor, NEMatMul, CpuMatMulSettings, T>;
115
116template <typename T>
117using NEMatMulDynamicTensorsFixture = MatMulValidationWithDynamicTensorsFixture<Tensor, Accessor, NEMatMul, CpuMatMulSettings, T>;
118
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100119template <typename T>
120using NEQuantizedMatMulFixture = QuantizedMatMulValidationFixture<Tensor, Accessor, NEMatMul, CpuMatMulSettings, T>;
121
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +0000122TEST_SUITE(Float)
123TEST_SUITE(FP32)
124FIXTURE_DATA_TEST_CASE(RunSmall, NEMatMulFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallMatMulDataset(),
125 framework::dataset::make("TransposeA", { false, true })),
126 framework::dataset::make("TransposeB", { false, true })),
127 framework::dataset::make("DataType", DataType::F32)),
128 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })))
129{
130 // Validate output
131 validate(Accessor(_target), _reference, tolerance_fp32);
132}
133FIXTURE_DATA_TEST_CASE(RunLarge, NEMatMulFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeMatMulDataset(),
134 framework::dataset::make("TransposeA", { false, true })),
135 framework::dataset::make("TransposeB", { false, true })),
136 framework::dataset::make("DataType", DataType::F32)),
137 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })))
138{
139 // Validate output
140 validate(Accessor(_target), _reference, tolerance_fp32);
141}
142FIXTURE_DATA_TEST_CASE(RunHighDimensions, NEMatMulFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::HighDimensionalMatMulDataset(),
143 framework::dataset::make("TransposeA", { false, true })),
144 framework::dataset::make("TransposeB", { false, true })),
145 framework::dataset::make("DataType", DataType::F32)),
146 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })))
147{
148 // Validate output
149 validate(Accessor(_target), _reference, tolerance_fp32);
150}
151
152FIXTURE_DATA_TEST_CASE(RunStressDynamicTensors, NEMatMulDynamicTensorsFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallMatMulDataset(),
153 framework::dataset::make("TransposeA", { false, true })),
154 framework::dataset::make("TransposeB", { false, true })),
155 framework::dataset::make("DataType", DataType::F32)),
156 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })),
157 framework::dataset::make("NumberOfRuns", 5)))
158{
159 // Validate output
160 validate(Accessor(_target), _reference, tolerance_fp32);
161}
162TEST_SUITE_END() // FP32
163
164#ifdef ARM_COMPUTE_ENABLE_BF16
165/* Note : MatMul BF16 is enabled by specifying FP32 datatype and enabling the fast math setting */
166constexpr AbsoluteTolerance<float> tolerance_bf16(0.001f);
167TEST_SUITE(BF16)
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100168FIXTURE_DATA_TEST_CASE(RunSmall, NEMatMulFastMathFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(combine(combine(
169 datasets::SmallMatMulDataset(),
170 framework::dataset::make("TransposeA", { false, true })),
171 framework::dataset::make("TransposeB", { false, true })),
172 framework::dataset::make("DataType", DataType::F32)),
173 framework::dataset::make("ActivationInfo", { ActivationLayerInfo() })),
174 framework::dataset::make("RunTimes", { 0 })),
175 framework::dataset::make("Settings", { CpuMatMulSettings().fast_math(true) })),
176 framework::dataset::make("LhsQInfo", { QuantizationInfo() })),
177 framework::dataset::make("RhsQInfo", { QuantizationInfo() })),
178 framework::dataset::make("OutQInfo", { QuantizationInfo() }))
179)
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +0000180{
181 // Validate output
182 validate(Accessor(_target), _reference, tolerance_bf16);
183}
184TEST_SUITE_END() // BF16
185#endif /* ARM_COMPUTE_ENABLE_BF16 */
186
187#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
188TEST_SUITE(FP16)
189FIXTURE_DATA_TEST_CASE(RunSmall, NEMatMulFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallMatMulDataset(),
190 framework::dataset::make("TransposeA", { false, true })),
191 framework::dataset::make("TransposeB", { false, true })),
192 framework::dataset::make("DataType", DataType::F16)),
193 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })))
194{
195 // Validate output
196 validate(Accessor(_target), _reference, tolerance_fp16);
197}
198FIXTURE_DATA_TEST_CASE(RunLarge, NEMatMulFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeMatMulDataset(),
199 framework::dataset::make("TransposeA", { false, true })),
200 framework::dataset::make("TransposeB", { false, true })),
201 framework::dataset::make("DataType", DataType::F16)),
202 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })))
203{
204 // Validate output
205 validate(Accessor(_target), _reference, tolerance_fp16);
206}
207FIXTURE_DATA_TEST_CASE(RunStressDynamicTensors, NEMatMulDynamicTensorsFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallMatMulDataset(),
208 framework::dataset::make("TransposeA", { false, true })),
209 framework::dataset::make("TransposeB", { false, true })),
210 framework::dataset::make("DataType", DataType::F16)),
211 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })),
212 framework::dataset::make("NumberOfRuns", 5)))
213{
214 // Validate output
215 validate(Accessor(_target), _reference, tolerance_fp16);
216}
217TEST_SUITE_END() // FP16
218#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
219
220TEST_SUITE_END() // Float
221
Ramy Elgammal05a65e32023-04-24 01:58:21 +0100222#ifdef __aarch64__ // All the GeMM CPU assembly kernels for integer datatypes require aarch64
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100223TEST_SUITE(Quantized)
224
225TEST_SUITE(QASYMM8)
226
227FIXTURE_DATA_TEST_CASE(RunSmall, NEQuantizedMatMulFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(combine(
228 datasets::SmallMatMulDataset(),
229 framework::dataset::make("TransposeA", { false, true })),
230 framework::dataset::make("TransposeB", { false, true })),
231 framework::dataset::make("DataType", DataType::QASYMM8)),
232 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })),
233 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
234 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 50, 1) })),
235 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 30, -1) })),
236 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f, 2) }))
237)
238{
239 // Validate output
240 validate(Accessor(_target), _reference, tolerance_qasymm8);
241}
242
243FIXTURE_DATA_TEST_CASE(RunSmallExtraActivation, NEQuantizedMatMulFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(
244 datasets::SmallerMatMulDataset(),
245 framework::dataset::make("TransposeA", { false, true })),
246 framework::dataset::make("TransposeB", { false, true })),
247 framework::dataset::make("DataType", DataType::QASYMM8)),
248 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU) })),
249 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
250 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 50, 1) })),
251 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 30, -1) })),
252 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f, 2) }))
253)
254{
255 // Validate output
256 validate(Accessor(_target), _reference, tolerance_qasymm8);
257}
258
259FIXTURE_DATA_TEST_CASE(RunLarge, NEQuantizedMatMulFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(
260 datasets::LargeMatMulDataset(),
261 framework::dataset::make("TransposeA", { false, true })),
262 framework::dataset::make("TransposeB", { false, true })),
263 framework::dataset::make("DataType", DataType::QASYMM8)),
264 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })),
265 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
266 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 100, 1) })),
267 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 200, -1) })),
268 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f, 2) }))
269)
270{
271 // Validate output
272 validate(Accessor(_target), _reference, tolerance_qasymm8);
273}
274
275TEST_SUITE_END() // QASYMM8
276
277TEST_SUITE(QASYMM8_SIGNED)
278
279FIXTURE_DATA_TEST_CASE(RunSmall, NEQuantizedMatMulFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(combine(
280 datasets::SmallMatMulDataset(),
281 framework::dataset::make("TransposeA", { false, true })),
282 framework::dataset::make("TransposeB", { false, true })),
283 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
284 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })),
285 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
286 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 40, -2) })),
287 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 50, 1) })),
288 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f, 1) }))
289)
290{
291 // Validate output
292 validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
293}
294
295FIXTURE_DATA_TEST_CASE(RunSmallExtraActivation, NEQuantizedMatMulFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(
296 datasets::SmallerMatMulDataset(),
297 framework::dataset::make("TransposeA", { false, true })),
298 framework::dataset::make("TransposeB", { false, true })),
299 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
300 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU) })),
301 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
302 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 40, -2) })),
303 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 50, 1) })),
304 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f, 1) }))
305)
306{
307 // Validate output
308 validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
309}
310
311FIXTURE_DATA_TEST_CASE(RunLarge, NEQuantizedMatMulFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(
312 datasets::LargeMatMulDataset(),
313 framework::dataset::make("TransposeA", { false, true })),
314 framework::dataset::make("TransposeB", { false, true })),
315 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
316 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })),
317 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
318 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 150, -2) })),
319 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 250, 1) })),
320 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f, 1) }))
321)
322{
323 // Validate output
324 validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
325}
326
327TEST_SUITE_END() // QASYMM8_SIGNED
328
329TEST_SUITE_END() // Quantized
Ramy Elgammal05a65e32023-04-24 01:58:21 +0100330#endif // __aarch64__
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100331
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +0000332TEST_SUITE_END() // MatMul
333TEST_SUITE_END() // NEON
334} // namespace validation
335} // namespace test
336} // namespace arm_compute