blob: 6364b1620067220a834c0240470c760c9b98b780 [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"
Jakub Sujake9b3ee22023-04-17 12:08:48 +010029#include "tests/framework/DatasetModes.h"
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000030#include "tests/framework/Macros.h"
Jakub Sujake9b3ee22023-04-17 12:08:48 +010031#include "tests/framework/TestCase.h"
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000032#include "tests/framework/datasets/Datasets.h"
33#include "tests/validation/Validation.h"
Jakub Sujake9b3ee22023-04-17 12:08:48 +010034
35#include "tests/datasets/LargeMatMulDataset.h"
36#include "tests/datasets/SmallMatMulDataset.h"
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000037#include "tests/validation/fixtures/MatMulFixture.h"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45namespace
46{
Jakub Sujake9b3ee22023-04-17 12:08:48 +010047RelativeTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for fp32 data type */
48constexpr float abs_tolerance_f32(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 */
49constexpr float abs_tolerance_f16(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 */
50RelativeTolerance<half_float::half> tolerance_f16(half(0.01)); /**< Tolerance value for comparing reference's output against implementation's output for fp16 data type */
51constexpr 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 +000052} // namespace
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000053
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000054template <typename T>
Jakub Sujake9b3ee22023-04-17 12:08:48 +010055using CLMatMulFixture = MatMulValidationFixture<CLTensor, CLAccessor, CLMatMul, GpuMatMulSettings, T>;
56
57template <typename T>
58using CLQuantizedMatMulFixture = QuantizedMatMulValidationFixture<CLTensor, CLAccessor, CLMatMul, GpuMatMulSettings, T>;
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000059
60TEST_SUITE(CL)
61TEST_SUITE(MatMul)
Jakub Sujake9b3ee22023-04-17 12:08:48 +010062
63TEST_SUITE(Float)
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000064TEST_SUITE(FP32)
Jakub Sujake9b3ee22023-04-17 12:08:48 +010065
66FIXTURE_DATA_TEST_CASE(RunSmall, CLMatMulFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallMatMulDataset(),
67 framework::dataset::make("TransposeA", { false, true })),
68 framework::dataset::make("TransposeB", { false, true })),
69 framework::dataset::make("DataType", DataType::F32)))
70{
71 // Validate output
72 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
73}
74
75FIXTURE_DATA_TEST_CASE(RunLarge, CLMatMulFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeMatMulDataset(),
76 framework::dataset::make("TransposeA", { false, true })),
77 framework::dataset::make("TransposeB", { false, true })),
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000078 framework::dataset::make("DataType", DataType::F32)))
79{
80 // Validate output
Ramy Elgammaldcab9ca2023-04-04 14:41:10 +010081 validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32);
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000082}
Jakub Sujake9b3ee22023-04-17 12:08:48 +010083
84TEST_SUITE_END() // FP32
85
86TEST_SUITE(FP16)
87
88FIXTURE_DATA_TEST_CASE(RunSmall, CLMatMulFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallMatMulDataset(),
89 framework::dataset::make("TransposeA", { false, true })),
90 framework::dataset::make("TransposeB", { false, true })),
91 framework::dataset::make("DataType", DataType::F16)))
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000092{
93 // Validate output
Jakub Sujake9b3ee22023-04-17 12:08:48 +010094 validate(CLAccessor(_target), _reference, tolerance_f16, 0.f, abs_tolerance_f16);
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +000095}
Jakub Sujake9b3ee22023-04-17 12:08:48 +010096
97FIXTURE_DATA_TEST_CASE(RunLarge, CLMatMulFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeMatMulDataset(),
98 framework::dataset::make("TransposeA", { false, true })),
99 framework::dataset::make("TransposeB", { false, true })),
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000100 framework::dataset::make("DataType", DataType::F16)))
101{
102 // Validate output
Ramy Elgammaldcab9ca2023-04-04 14:41:10 +0100103 validate(CLAccessor(_target), _reference, tolerance_f16, 0.f, abs_tolerance_f16);
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000104}
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100105
106TEST_SUITE_END() // FP16
107TEST_SUITE_END() // Float
108
109TEST_SUITE(Quantized)
110TEST_SUITE(QASYMM8)
111
112FIXTURE_DATA_TEST_CASE(RunSmall, CLQuantizedMatMulFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine(
113 datasets::SmallMatMulDataset(),
114 framework::dataset::make("TransposeA", { false, true })),
115 framework::dataset::make("TransposeB", { false, true })),
116 framework::dataset::make("DataType", DataType::QASYMM8)),
117 framework::dataset::make("ActivationInfo", { ActivationLayerInfo() })),
118 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
119 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 50, 1) })),
120 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 30, -1) })),
121 framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) }))
122)
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000123{
124 // Validate output
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100125 validate(CLAccessor(_target), _reference, tolerance_quant);
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000126}
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100127
128FIXTURE_DATA_TEST_CASE(RunLarge, CLQuantizedMatMulFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(
129 datasets::LargeMatMulDataset(),
130 framework::dataset::make("TransposeA", { false, true })),
131 framework::dataset::make("TransposeB", { false, true })),
132 framework::dataset::make("DataType", DataType::QASYMM8)),
133 framework::dataset::make("ActivationInfo", { ActivationLayerInfo() })),
134 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
135 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 100, 1) })),
136 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 200, -1) })),
137 framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) }))
138)
139{
140 // Validate output
141 validate(CLAccessor(_target), _reference, tolerance_quant);
142}
143
144TEST_SUITE_END() // QASYMM8
145
146TEST_SUITE(QASYMM8_SIGNED)
147
148FIXTURE_DATA_TEST_CASE(RunSmall, CLQuantizedMatMulFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine(
149 datasets::SmallMatMulDataset(),
150 framework::dataset::make("TransposeA", { false, true })),
151 framework::dataset::make("TransposeB", { false, true })),
152 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
153 framework::dataset::make("ActivationInfo", { ActivationLayerInfo() })),
154 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
155 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 50, 1) })),
156 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 30, -1) })),
157 framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) }))
158)
159{
160 // Validate output
161 validate(CLAccessor(_target), _reference, tolerance_quant);
162}
163
164FIXTURE_DATA_TEST_CASE(RunLarge, CLQuantizedMatMulFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(combine(
165 datasets::LargeMatMulDataset(),
166 framework::dataset::make("TransposeA", { false, true })),
167 framework::dataset::make("TransposeB", { false, true })),
168 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
169 framework::dataset::make("ActivationInfo", { ActivationLayerInfo() })),
170 framework::dataset::make("NumberOfExtraRuns", { 0, 1 })),
171 framework::dataset::make("LhsQInfo", { QuantizationInfo(1.f / 100, 1) })),
172 framework::dataset::make("RhsQInfo", { QuantizationInfo(1.f / 200, -1) })),
173 framework::dataset::make("DstQInfo", { QuantizationInfo(1.f, 2) }))
174)
175{
176 // Validate output
177 validate(CLAccessor(_target), _reference, tolerance_quant);
178}
179
180TEST_SUITE_END() // QASYMM8_SIGNED
181
182TEST_SUITE_END() // Quantized
183
Ramy Elgammalf26ea2f2023-03-24 11:42:03 +0000184TEST_SUITE_END() // MatMul
185TEST_SUITE_END() // CL
186} // namespace validation
187} // namespace test
188} // namespace arm_compute