blob: 844597f3e982faf4577ba1283ba481fba46a1afd [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
Mohammed Suhail Munshic9eeee52023-06-30 15:43:29 +010072/* The main act functions matmul (float) is expected to support */
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010073const 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),
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010079});
80
Mohammed Suhail Munshic9eeee52023-06-30 15:43:29 +010081/* (Float datatype only) Larger activation functions dataset, used during some nightly tests. */
82const auto AllActivationsDataset = combine(datasets::ActivationFunctions(), framework::dataset::make("AlphaBeta", { 0.5f, 1.f }));
83
84// Alpha beta values should be integer values
85// This is for testing purposes with quantized datatypes and is not a limitation of the kernel.
86// To properly remove this restriction, dst_qinfo should be auto-initialised with consideration for alpha beta values
87// The main act functions quantized matmul kernels are expected to support
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010088const auto ActivationFunctionsQuantizedDataset = concat(concat(concat(
89 framework::dataset::make("ActivationInfo", ActivationLayerInfo()),
90 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))),
Mohammed Suhail Munshic9eeee52023-06-30 15:43:29 +010091 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 1.f))),
92 framework::dataset::make("ActivationInfo", ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 2.f, 1.f)));
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +010093
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000094TEST_SUITE(CL)
95TEST_SUITE(MatMul)
Jakub Sujake9b3ee22023-04-17 12:08:48 +010096
97TEST_SUITE(Float)
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000098TEST_SUITE(FP32)
Jakub Sujake9b3ee22023-04-17 12:08:48 +010099
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +0100100FIXTURE_DATA_TEST_CASE(RunSmall, CLMatMulActivationFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallMatMulDataset(),
101 framework::dataset::make("TransposeA", { false, true })),
102 framework::dataset::make("TransposeB", { false, true })),
103 framework::dataset::make("DataType", DataType::F32)),
104 ActivationFunctionsDataset))
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100105{
106 // Validate output
107 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
108}
109
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +0100110FIXTURE_DATA_TEST_CASE(RunLarge, CLMatMulActivationFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeMatMulDataset(),
111 framework::dataset::make("TransposeA", { false, true })),
112 framework::dataset::make("TransposeB", { false, true })),
113 framework::dataset::make("DataType", DataType::F32)),
114 ActivationFunctionsDataset))
115{
116 // Validate output
117 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
118}
119
120FIXTURE_DATA_TEST_CASE(RunAllActivations, CLMatMulActivationAlphaBetaFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::SmallerMatMulDataset(),
121 framework::dataset::make("TransposeA", { false })),
122 framework::dataset::make("TransposeB", { true })),
123 framework::dataset::make("DataType", DataType::F32)),
124 AllActivationsDataset))
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000125{
126 // Validate output
Ramy Elgammaldcab9ca2023-04-04 14:41:10 +0100127 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000128}
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100129
130TEST_SUITE_END() // FP32
131
132TEST_SUITE(FP16)
133
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +0100134FIXTURE_DATA_TEST_CASE(RunSmall, CLMatMulActivationFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallMatMulDataset(),
135 framework::dataset::make("TransposeA", { false, true })),
136 framework::dataset::make("TransposeB", { false, true })),
137 framework::dataset::make("DataType", DataType::F16)),
138 ActivationFunctionsDataset))
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000139{
140 // Validate output
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100141 validate(CLAccessor(_target), _reference, tolerance_f16, 0.f, abs_tolerance_f16);
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000142}
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100143
Mohammed Suhail Munshi94abde42023-05-25 16:48:43 +0100144FIXTURE_DATA_TEST_CASE(RunLarge, CLMatMulActivationFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeMatMulDataset(),
145 framework::dataset::make("TransposeA", { false, true })),
146 framework::dataset::make("TransposeB", { false, true })),
147 framework::dataset::make("DataType", DataType::F16)),
148 ActivationFunctionsDataset))
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000149{
150 // Validate output
Ramy Elgammaldcab9ca2023-04-04 14:41:10 +0100151 validate(CLAccessor(_target), _reference, tolerance_f16, 0.f, abs_tolerance_f16);
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000152}
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100153
154TEST_SUITE_END() // FP16
155TEST_SUITE_END() // Float
156
157TEST_SUITE(Quantized)
158TEST_SUITE(QASYMM8)
159
160FIXTURE_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 +0100161 datasets::SmallMatMulDataset(),
162 framework::dataset::make("TransposeA", { false, true })),
163 framework::dataset::make("TransposeB", { false, true })),
164 framework::dataset::make("DataType", DataType::QASYMM8)),
165 ActivationFunctionsQuantizedDataset),
166 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
167 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 50, 1) })),
168 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 30, -1) })),
169 framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) })))
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000170{
171 // Validate output
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100172 validate(CLAccessor(_target), _reference, tolerance_quant);
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000173}
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100174
175FIXTURE_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 +0100176 datasets::LargeMatMulDataset(),
177 framework::dataset::make("TransposeA", { false, true })),
178 framework::dataset::make("TransposeB", { false, true })),
179 framework::dataset::make("DataType", DataType::QASYMM8)),
180 ActivationFunctionsQuantizedDataset),
181 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
182 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 100, 1) })),
183 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 200, -1) })),
184 framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) })))
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100185{
186 // Validate output
187 validate(CLAccessor(_target), _reference, tolerance_quant);
188}
189
190TEST_SUITE_END() // QASYMM8
191
192TEST_SUITE(QASYMM8_SIGNED)
193
194FIXTURE_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 +0100195 datasets::SmallMatMulDataset(),
196 framework::dataset::make("TransposeA", { false, true })),
197 framework::dataset::make("TransposeB", { false, true })),
198 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
199 ActivationFunctionsQuantizedDataset),
200 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
201 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 50, 1) })),
202 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 30, -1) })),
203 framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) })))
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100204{
205 // Validate output
206 validate(CLAccessor(_target), _reference, tolerance_quant);
207}
208
209FIXTURE_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 +0100210 datasets::LargeMatMulDataset(),
211 framework::dataset::make("TransposeA", { false, true })),
212 framework::dataset::make("TransposeB", { false, true })),
213 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
214 ActivationFunctionsQuantizedDataset),
215 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
216 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 100, 1) })),
217 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 200, -1) })),
Mohammed Suhail Munshic9eeee52023-06-30 15:43:29 +0100218 framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 50) })))
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100219{
220 // Validate output
221 validate(CLAccessor(_target), _reference, tolerance_quant);
222}
223
224TEST_SUITE_END() // QASYMM8_SIGNED
225
226TEST_SUITE_END() // Quantized
227
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000228TEST_SUITE_END() // MatMul
229TEST_SUITE_END() // CL
230} // namespace validation
231} // namespace test
232} // namespace arm_compute