blob: 5a262a8e78147c4033042c6382ef55aab60398c8 [file] [log] [blame]
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +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 */
Jakub Sujake9b3ee22023-04-17 12:08:48 +010024#include "arm_compute/core/Types.h"
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000025#include "arm_compute/runtime/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/functions/CLMatMul.h"
Jakub Sujake9b3ee22023-04-17 12:08:48 +010027
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000028#include "tests/CL/CLAccessor.h"
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010029#include "tests/datasets/ActivationFunctionsDataset.h"
Jakub Sujake9b3ee22023-04-17 12:08:48 +010030#include "tests/framework/DatasetModes.h"
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000031#include "tests/framework/Macros.h"
Jakub Sujake9b3ee22023-04-17 12:08:48 +010032#include "tests/framework/TestCase.h"
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000033#include "tests/framework/datasets/Datasets.h"
34#include "tests/validation/Validation.h"
Jakub Sujake9b3ee22023-04-17 12:08:48 +010035
36#include "tests/datasets/LargeMatMulDataset.h"
37#include "tests/datasets/SmallMatMulDataset.h"
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000038#include "tests/validation/fixtures/MatMulFixture.h"
39
40namespace arm_compute
41{
42namespace test
43{
44namespace validation
45{
46namespace
47{
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010048RelativeTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for fp32 data type */
49constexpr float abs_tolerance_f32(
50 0.0001f); /**< Absolute tolerance value for comparing reference's output against implementation's output for fp32 data type in case using relative tolerance fails because of small values */
51constexpr float abs_tolerance_f16(
52 0.001f); /**< Absolute tolerance value for comparing reference's output against implementation's output for fp16 data type in case using relative tolerance fails because of small values */
53RelativeTolerance<half_float::half> tolerance_f16(half(0.01)); /**< Tolerance value for comparing reference's output against implementation's output for fp16 data type */
54constexpr AbsoluteTolerance<uint8_t> tolerance_quant(1); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000055} // namespace
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000056
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000057template <typename T>
Jakub Sujake9b3ee22023-04-17 12:08:48 +010058using CLMatMulFixture = MatMulValidationFixture<CLTensor, CLAccessor, CLMatMul, GpuMatMulSettings, T>;
59
60template <typename T>
61using CLQuantizedMatMulFixture = QuantizedMatMulValidationFixture<CLTensor, CLAccessor, CLMatMul, GpuMatMulSettings, T>;
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000062
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010063template <typename T>
64using CLMatMulActivationFixture = MatMulValidationWithActivationFixture<CLTensor, CLAccessor, CLMatMul, GpuMatMulSettings, T>;
65
66template <typename T>
67using CLMatMulActivationAlphaBetaFixture = MatMulValidationWithActivationAlphaBetaFixture<CLTensor, CLAccessor, CLMatMul, GpuMatMulSettings, T>;
68
69template <typename T>
70using CLQuantizedMatMulActivationFixture = QuantizedMatMulValidationWithActivationFixture<CLTensor, CLAccessor, CLMatMul, GpuMatMulSettings, T>;
71
72/* The main act functions matmul is expected to support */
73const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
74{
75 ActivationLayerInfo(),
76 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
77 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.5f),
78 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 0.75f, 0.25f),
79 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH)
80});
81
82const auto ActivationFunctionsQuantizedDataset = concat(concat(concat(
83 framework::dataset::make("ActivationInfo", ActivationLayerInfo()),
84 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))),
85 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.5f))),
86 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 0.75f, 0.25f)));
87
88/* Larger activation functions dataset, used during some nightly tests. */
89const auto AllActivationsDataset = combine(datasets::ActivationFunctions(), framework::dataset::make("AlphaBeta", { 0.5f, 1.f }));
90
91const auto AllQuantizedActivationsDataset = combine(concat(datasets::ActivationFunctionsQuantized(),
92 framework::dataset::make("ActivationFunction", { ActivationLayerInfo::ActivationFunction::HARD_SWISH,
93 ActivationLayerInfo::ActivationFunction::LEAKY_RELU
94 })),
95 framework::dataset::make("AlphaBeta", { 0.5f, 1.f }));
96
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000097TEST_SUITE(CL)
98TEST_SUITE(MatMul)
Jakub Sujake9b3ee22023-04-17 12:08:48 +010099
100TEST_SUITE(Float)
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000101TEST_SUITE(FP32)
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100102
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +0100103FIXTURE_DATA_TEST_CASE(RunSmall, CLMatMulActivationFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallMatMulDataset(),
104 framework::dataset::make("TransposeA", { false, true })),
105 framework::dataset::make("TransposeB", { false, true })),
106 framework::dataset::make("DataType", DataType::F32)),
107 ActivationFunctionsDataset))
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100108{
109 // Validate output
110 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
111}
112
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +0100113FIXTURE_DATA_TEST_CASE(RunLarge, CLMatMulActivationFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeMatMulDataset(),
114 framework::dataset::make("TransposeA", { false, true })),
115 framework::dataset::make("TransposeB", { false, true })),
116 framework::dataset::make("DataType", DataType::F32)),
117 ActivationFunctionsDataset))
118{
119 // Validate output
120 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
121}
122
123FIXTURE_DATA_TEST_CASE(RunAllActivations, CLMatMulActivationAlphaBetaFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::SmallerMatMulDataset(),
124 framework::dataset::make("TransposeA", { false })),
125 framework::dataset::make("TransposeB", { true })),
126 framework::dataset::make("DataType", DataType::F32)),
127 AllActivationsDataset))
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000128{
129 // Validate output
Ramy Elgammaldcab9ca2023-04-04 14:41:10 +0100130 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000131}
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100132
133TEST_SUITE_END() // FP32
134
135TEST_SUITE(FP16)
136
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +0100137FIXTURE_DATA_TEST_CASE(RunSmall, CLMatMulActivationFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallMatMulDataset(),
138 framework::dataset::make("TransposeA", { false, true })),
139 framework::dataset::make("TransposeB", { false, true })),
140 framework::dataset::make("DataType", DataType::F16)),
141 ActivationFunctionsDataset))
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000142{
143 // Validate output
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100144 validate(CLAccessor(_target), _reference, tolerance_f16, 0.f, abs_tolerance_f16);
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000145}
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100146
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +0100147FIXTURE_DATA_TEST_CASE(RunLarge, CLMatMulActivationFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeMatMulDataset(),
148 framework::dataset::make("TransposeA", { false, true })),
149 framework::dataset::make("TransposeB", { false, true })),
150 framework::dataset::make("DataType", DataType::F16)),
151 ActivationFunctionsDataset))
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000152{
153 // Validate output
Ramy Elgammaldcab9ca2023-04-04 14:41:10 +0100154 validate(CLAccessor(_target), _reference, tolerance_f16, 0.f, abs_tolerance_f16);
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000155}
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100156
157TEST_SUITE_END() // FP16
158TEST_SUITE_END() // Float
159
160TEST_SUITE(Quantized)
161TEST_SUITE(QASYMM8)
162
163FIXTURE_DATA_TEST_CASE(RunSmall, CLQuantizedMatMulFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine(
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +0100164 datasets::SmallMatMulDataset(),
165 framework::dataset::make("TransposeA", { false, true })),
166 framework::dataset::make("TransposeB", { false, true })),
167 framework::dataset::make("DataType", DataType::QASYMM8)),
168 ActivationFunctionsQuantizedDataset),
169 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
170 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 50, 1) })),
171 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 30, -1) })),
172 framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) })))
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000173{
174 // Validate output
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100175 validate(CLAccessor(_target), _reference, tolerance_quant);
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000176}
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100177
178FIXTURE_DATA_TEST_CASE(RunLarge, CLQuantizedMatMulFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +0100179 datasets::LargeMatMulDataset(),
180 framework::dataset::make("TransposeA", { false, true })),
181 framework::dataset::make("TransposeB", { false, true })),
182 framework::dataset::make("DataType", DataType::QASYMM8)),
183 ActivationFunctionsQuantizedDataset),
184 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
185 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 100, 1) })),
186 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 200, -1) })),
187 framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) })))
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100188{
189 // Validate output
190 validate(CLAccessor(_target), _reference, tolerance_quant);
191}
192
193TEST_SUITE_END() // QASYMM8
194
195TEST_SUITE(QASYMM8_SIGNED)
196
197FIXTURE_DATA_TEST_CASE(RunSmall, CLQuantizedMatMulFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine(
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +0100198 datasets::SmallMatMulDataset(),
199 framework::dataset::make("TransposeA", { false, true })),
200 framework::dataset::make("TransposeB", { false, true })),
201 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
202 ActivationFunctionsQuantizedDataset),
203 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
204 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 50, 1) })),
205 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 30, -1) })),
206 framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) })))
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100207{
208 // Validate output
209 validate(CLAccessor(_target), _reference, tolerance_quant);
210}
211
212FIXTURE_DATA_TEST_CASE(RunLarge, CLQuantizedMatMulFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +0100213 datasets::LargeMatMulDataset(),
214 framework::dataset::make("TransposeA", { false, true })),
215 framework::dataset::make("TransposeB", { false, true })),
216 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
217 ActivationFunctionsQuantizedDataset),
218 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
219 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 100, 1) })),
220 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 200, -1) })),
221 framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) })))
222{
223 // Validate output
224 validate(CLAccessor(_target), _reference, tolerance_quant);
225}
226
227FIXTURE_DATA_TEST_CASE(RunAllActivations, CLQuantizedMatMulActivationFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(
228 datasets::LargeMatMulDataset(),
229 framework::dataset::make("TransposeA", { false })),
230 framework::dataset::make("TransposeB", { true })),
231 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
232 AllQuantizedActivationsDataset),
233 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
234 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 100, 1) })),
235 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 200, -1) })),
236 framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) })))
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100237{
238 // Validate output
239 validate(CLAccessor(_target), _reference, tolerance_quant);
240}
241
242TEST_SUITE_END() // QASYMM8_SIGNED
243
244TEST_SUITE_END() // Quantized
245
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000246TEST_SUITE_END() // MatMul
247TEST_SUITE_END() // CL
248} // namespace validation
249} // namespace test
250} // namespace arm_compute