blob: 0f97dcf9c4953c39f047d062aa1ce4ca4e6bc3e8 [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));
48constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(0);
49constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8_signed(0);
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000050
51// clang-format off
52// *INDENT-OFF*
53// Validation Tests
54DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
55 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(9U, 6U), 1, DataType::F32), // Mismatching datatype
56 TensorInfo(TensorShape(9U, 6U), 1, DataType::S32), // Unsupported datatypes
57 TensorInfo(TensorShape(9U, 6U, 2U), 1, DataType::F32), // Broadcasting in batch dimension not supported
58 TensorInfo(TensorShape(9U, 6U), 1, DataType::F32), // Invalid shape for multiplication
59 TensorInfo(TensorShape(9U, 6U), 1, DataType::F32),
60 TensorInfo(TensorShape(9U, 6U , 12U) , 1 , DataType::F32),
61 TensorInfo(TensorShape(9U, 6U , 12U) , 1 , DataType::F32), // Tensors are not dynamic
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +010062 TensorInfo(TensorShape(9U, 6U), 1, DataType::QASYMM8),
63 TensorInfo(TensorShape(9U, 6U), 1, DataType::QASYMM8_SIGNED),
64 TensorInfo(TensorShape(9U, 6U), 1, DataType::QASYMM8_SIGNED), // Mismatching data type
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000065 }),
66 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(5U, 9U), 1, DataType::QASYMM8),
67 TensorInfo(TensorShape(5U, 9U), 1, DataType::S32),
68 TensorInfo(TensorShape(5U, 9U, 1U), 1, DataType::F32),
69 TensorInfo(TensorShape(5U, 12U), 1, DataType::F32),
70 TensorInfo(TensorShape(5U, 9U), 1, DataType::F32),
71 TensorInfo(TensorShape(5U, 9U, 12U), 1, DataType::F32),
72 TensorInfo(TensorShape(5U, 9U, 12U), 1, DataType::F32),
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +010073 TensorInfo(TensorShape(5U, 9U), 1, DataType::QASYMM8),
74 TensorInfo(TensorShape(5U, 9U), 1, DataType::QASYMM8_SIGNED),
75 TensorInfo(TensorShape(5U, 9U), 1, DataType::QASYMM8_SIGNED),
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000076 })),
77 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(5U, 6U), 1, DataType::F32),
78 TensorInfo(TensorShape(5U, 6U), 1, DataType::S32),
79 TensorInfo(TensorShape(5U, 6U, 2U), 1, DataType::F32),
80 TensorInfo(TensorShape(5U, 6U), 1, DataType::F32),
81 TensorInfo(TensorShape(5U, 6U), 1, DataType::F32),
82 TensorInfo(TensorShape(5U, 6U, 12U) , 1, DataType::F32),
83 TensorInfo(TensorShape(5U, 6U, 12U) , 1, DataType::F32),
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +010084 TensorInfo(TensorShape(5U, 6U), 1, DataType::QASYMM8),
85 TensorInfo(TensorShape(5U, 6U), 1, DataType::QASYMM8_SIGNED),
86 TensorInfo(TensorShape(5U, 6U), 1, DataType::QASYMM8),
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000087 })),
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +010088 framework::dataset::make( "TensorIsConst", {false, false, false, false, false , false, true, false, false, false} )),
89 framework::dataset::make("Expected", { false, false, false, false, true, true, false, true, true, false })),
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000090 a_info, b_info, output_info, are_tensors_const, expected)
91{
92 TensorInfo a{a_info};
93 TensorInfo b{b_info};
94 a.set_are_values_constant(are_tensors_const);
95 b.set_are_values_constant(are_tensors_const);
96 Status status = NEMatMul::validate(&a,
97 &b,
98 &output_info,
99 MatMulInfo(),
100 CpuMatMulSettings());
101 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
102}
103// *INDENT-ON*
104// clang-format on
105
106// Generic Template
107template <typename T>
108using NEMatMulFixture = MatMulValidationWithActivationFixture<Tensor, Accessor, NEMatMul, CpuMatMulSettings, T>;
109
110// Fast math Template
111template <typename T>
112using NEMatMulFastMathFixture = MatMulGenericValidationFixture<Tensor, Accessor, NEMatMul, CpuMatMulSettings, T>;
113
114template <typename T>
115using NEMatMulDynamicTensorsFixture = MatMulValidationWithDynamicTensorsFixture<Tensor, Accessor, NEMatMul, CpuMatMulSettings, T>;
116
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100117template <typename T>
118using NEQuantizedMatMulFixture = QuantizedMatMulValidationFixture<Tensor, Accessor, NEMatMul, CpuMatMulSettings, T>;
119
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +0000120TEST_SUITE(Float)
121TEST_SUITE(FP32)
122FIXTURE_DATA_TEST_CASE(RunSmall, NEMatMulFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallMatMulDataset(),
123 framework::dataset::make("TransposeA", { false, true })),
124 framework::dataset::make("TransposeB", { false, true })),
125 framework::dataset::make("DataType", DataType::F32)),
126 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })))
127{
128 // Validate output
129 validate(Accessor(_target), _reference, tolerance_fp32);
130}
131FIXTURE_DATA_TEST_CASE(RunLarge, NEMatMulFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeMatMulDataset(),
132 framework::dataset::make("TransposeA", { false, true })),
133 framework::dataset::make("TransposeB", { false, true })),
134 framework::dataset::make("DataType", DataType::F32)),
135 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })))
136{
137 // Validate output
138 validate(Accessor(_target), _reference, tolerance_fp32);
139}
140FIXTURE_DATA_TEST_CASE(RunHighDimensions, NEMatMulFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::HighDimensionalMatMulDataset(),
141 framework::dataset::make("TransposeA", { false, true })),
142 framework::dataset::make("TransposeB", { false, true })),
143 framework::dataset::make("DataType", DataType::F32)),
144 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })))
145{
146 // Validate output
147 validate(Accessor(_target), _reference, tolerance_fp32);
148}
149
150FIXTURE_DATA_TEST_CASE(RunStressDynamicTensors, NEMatMulDynamicTensorsFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallMatMulDataset(),
151 framework::dataset::make("TransposeA", { false, true })),
152 framework::dataset::make("TransposeB", { false, true })),
153 framework::dataset::make("DataType", DataType::F32)),
154 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })),
155 framework::dataset::make("NumberOfRuns", 5)))
156{
157 // Validate output
158 validate(Accessor(_target), _reference, tolerance_fp32);
159}
160TEST_SUITE_END() // FP32
161
162#ifdef ARM_COMPUTE_ENABLE_BF16
163/* Note : MatMul BF16 is enabled by specifying FP32 datatype and enabling the fast math setting */
164constexpr AbsoluteTolerance<float> tolerance_bf16(0.001f);
165TEST_SUITE(BF16)
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100166FIXTURE_DATA_TEST_CASE(RunSmall, NEMatMulFastMathFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(combine(combine(
167 datasets::SmallMatMulDataset(),
168 framework::dataset::make("TransposeA", { false, true })),
169 framework::dataset::make("TransposeB", { false, true })),
170 framework::dataset::make("DataType", DataType::F32)),
171 framework::dataset::make("ActivationInfo", { ActivationLayerInfo() })),
172 framework::dataset::make("RunTimes", { 0 })),
173 framework::dataset::make("Settings", { CpuMatMulSettings().fast_math(true) })),
174 framework::dataset::make("LhsQInfo", { QuantizationInfo() })),
175 framework::dataset::make("RhsQInfo", { QuantizationInfo() })),
176 framework::dataset::make("OutQInfo", { QuantizationInfo() }))
177)
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +0000178{
179 // Validate output
180 validate(Accessor(_target), _reference, tolerance_bf16);
181}
182TEST_SUITE_END() // BF16
183#endif /* ARM_COMPUTE_ENABLE_BF16 */
184
185#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
186TEST_SUITE(FP16)
187FIXTURE_DATA_TEST_CASE(RunSmall, NEMatMulFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallMatMulDataset(),
188 framework::dataset::make("TransposeA", { false, true })),
189 framework::dataset::make("TransposeB", { false, true })),
190 framework::dataset::make("DataType", DataType::F16)),
191 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })))
192{
193 // Validate output
194 validate(Accessor(_target), _reference, tolerance_fp16);
195}
196FIXTURE_DATA_TEST_CASE(RunLarge, NEMatMulFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeMatMulDataset(),
197 framework::dataset::make("TransposeA", { false, true })),
198 framework::dataset::make("TransposeB", { false, true })),
199 framework::dataset::make("DataType", DataType::F16)),
200 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })))
201{
202 // Validate output
203 validate(Accessor(_target), _reference, tolerance_fp16);
204}
205FIXTURE_DATA_TEST_CASE(RunStressDynamicTensors, NEMatMulDynamicTensorsFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallMatMulDataset(),
206 framework::dataset::make("TransposeA", { false, true })),
207 framework::dataset::make("TransposeB", { false, true })),
208 framework::dataset::make("DataType", DataType::F16)),
209 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })),
210 framework::dataset::make("NumberOfRuns", 5)))
211{
212 // Validate output
213 validate(Accessor(_target), _reference, tolerance_fp16);
214}
215TEST_SUITE_END() // FP16
216#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
217
218TEST_SUITE_END() // Float
219
Ramy Elgammal05a65e32023-04-24 01:58:21 +0100220#ifdef __aarch64__ // All the GeMM CPU assembly kernels for integer datatypes require aarch64
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100221TEST_SUITE(Quantized)
222
223TEST_SUITE(QASYMM8)
224
225FIXTURE_DATA_TEST_CASE(RunSmall, NEQuantizedMatMulFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(combine(
226 datasets::SmallMatMulDataset(),
227 framework::dataset::make("TransposeA", { false, true })),
228 framework::dataset::make("TransposeB", { false, true })),
229 framework::dataset::make("DataType", DataType::QASYMM8)),
230 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })),
231 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
232 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 50, 1) })),
233 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 30, -1) })),
234 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f, 2) }))
235)
236{
237 // Validate output
238 validate(Accessor(_target), _reference, tolerance_qasymm8);
239}
240
241FIXTURE_DATA_TEST_CASE(RunSmallExtraActivation, NEQuantizedMatMulFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(
242 datasets::SmallerMatMulDataset(),
243 framework::dataset::make("TransposeA", { false, true })),
244 framework::dataset::make("TransposeB", { false, true })),
245 framework::dataset::make("DataType", DataType::QASYMM8)),
246 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU) })),
247 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
248 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 50, 1) })),
249 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 30, -1) })),
250 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f, 2) }))
251)
252{
253 // Validate output
254 validate(Accessor(_target), _reference, tolerance_qasymm8);
255}
256
257FIXTURE_DATA_TEST_CASE(RunLarge, NEQuantizedMatMulFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(
258 datasets::LargeMatMulDataset(),
259 framework::dataset::make("TransposeA", { false, true })),
260 framework::dataset::make("TransposeB", { false, true })),
261 framework::dataset::make("DataType", DataType::QASYMM8)),
262 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })),
263 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
264 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 100, 1) })),
265 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 200, -1) })),
266 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f, 2) }))
267)
268{
269 // Validate output
270 validate(Accessor(_target), _reference, tolerance_qasymm8);
271}
272
273TEST_SUITE_END() // QASYMM8
274
275TEST_SUITE(QASYMM8_SIGNED)
276
277FIXTURE_DATA_TEST_CASE(RunSmall, NEQuantizedMatMulFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(combine(
278 datasets::SmallMatMulDataset(),
279 framework::dataset::make("TransposeA", { false, true })),
280 framework::dataset::make("TransposeB", { false, true })),
281 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
282 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })),
283 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
284 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 40, -2) })),
285 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 50, 1) })),
286 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f, 1) }))
287)
288{
289 // Validate output
290 validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
291}
292
293FIXTURE_DATA_TEST_CASE(RunSmallExtraActivation, NEQuantizedMatMulFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(
294 datasets::SmallerMatMulDataset(),
295 framework::dataset::make("TransposeA", { false, true })),
296 framework::dataset::make("TransposeB", { false, true })),
297 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
298 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU) })),
299 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
300 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 40, -2) })),
301 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 50, 1) })),
302 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f, 1) }))
303)
304{
305 // Validate output
306 validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
307}
308
309FIXTURE_DATA_TEST_CASE(RunLarge, NEQuantizedMatMulFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(
310 datasets::LargeMatMulDataset(),
311 framework::dataset::make("TransposeA", { false, true })),
312 framework::dataset::make("TransposeB", { false, true })),
313 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
314 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) })),
315 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
316 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 150, -2) })),
317 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 250, 1) })),
318 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f, 1) }))
319)
320{
321 // Validate output
322 validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
323}
324
325TEST_SUITE_END() // QASYMM8_SIGNED
326
327TEST_SUITE_END() // Quantized
Ramy Elgammal05a65e32023-04-24 01:58:21 +0100328#endif // __aarch64__
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100329
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +0000330TEST_SUITE_END() // MatMul
331TEST_SUITE_END() // NEON
332} // namespace validation
333} // namespace test
334} // namespace arm_compute