blob: fd7a4cb156a4fe5e223c3cbce118cb49b63cef6b [file] [log] [blame]
Gunes Bayir9d0c4de2023-04-13 18:22:58 +01001/*
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
25#include "arm_compute/runtime/CL/CLTensor.h"
26
27#include "src/gpu/cl/kernels/ClMatMulLowpNativeKernel.h"
28
29#include "tests/datasets/LargeMatMulDataset.h"
30#include "tests/datasets/SmallMatMulDataset.h"
31#include "tests/framework/Macros.h"
32#include "tests/framework/datasets/Datasets.h"
33#include "tests/validation/Validation.h"
34#include "tests/validation/fixtures/MatMulKernelFixture.h"
35#include "tests/validation/reference/Permute.h"
36
37#include <tuple>
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45namespace
46{
47constexpr AbsoluteTolerance<float> tolerance_quant(1); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
48}
49template <typename T>
50using CLMatMulLowpNativeKernelFixture = MatMulKernelValidationFixture<T, ClMatMulLowpNativeKernel>;
51
52/** M0 values to test --precommit*/
53const auto m0_values_precommit = framework::dataset::make("M0", { 1, 3 });
54
55/** N0 values to test --precommit*/
56const auto n0_values_precommit = framework::dataset::make("N0", { 2, 4 });
57
58/** K0 values to test --precommit*/
59const auto k0_values_precommit = framework::dataset::make("K0", { 2, 3 });
60
61/** M0 values to test --nightly*/
62const auto m0_values_nightly_lhs_nt = framework::dataset::make("M0", { 1, 2, 3, 4, 5, 6, 7, 8 });
63const auto m0_values_nightly_lhs_t = framework::dataset::make("M0", { 1, 2, 3, 4, 8 });
64
65/** N0 values to test --nightly*/
66const auto n0_values_nightly_rhs_nt = framework::dataset::make("N0", { 1, 2, 3, 4, 8, 16 });
Omar Al Khatib467daef2023-04-13 14:56:23 +010067const auto n0_values_nightly_rhs_t = framework::dataset::make("N0", { 1, 2, 3, 4, 8 });
Gunes Bayir9d0c4de2023-04-13 18:22:58 +010068
69/** K0 values to test --nightly*/
70const auto k0_values_nightly_lhs_nt_rhs_nt = framework::dataset::make("K0", { 1, 2, 3, 4, 8, 16 });
Omar Al Khatib467daef2023-04-13 14:56:23 +010071const auto k0_values_nightly_rhs_t = framework::dataset::make("K0", { 1, 2, 3, 4, 8 });
72const auto k0_values_nightly_lhs_t_rhs_nt = framework::dataset::make("K0", { 1, 2, 3, 4, 5, 6, 7, 8 });
Gunes Bayir9d0c4de2023-04-13 18:22:58 +010073
74TEST_SUITE(CL)
75TEST_SUITE(MatMulLowpNativeKernel)
76TEST_SUITE(Validate)
77
78TEST_CASE(SupportedKernelConfigurations, framework::DatasetMode::ALL)
79{
80 using MatMulConfigurationPair = std::pair<MatMulKernelInfo, bool>;
81
82 const std::vector<MatMulConfigurationPair> supported_block_sizes =
83 {
84 // MatMulKernelInfo(adj_lhs, adj_rhs, M0, N0, K0, export_rhs_to_cl_image = false)
85 // Lhs not-transposed, Rhs-not-transposed
86 { MatMulKernelInfo(false, false, 0, 1, 1), false }, // M0 should be > 0
87 { MatMulKernelInfo(false, false, 3, 5, 1), false }, // N0 not in {1, 2, 3, 4, 8, 16}
88 { MatMulKernelInfo(false, false, 3, 6, 1), false }, // N0 not in {1, 2, 3, 4, 8, 16}
89 { MatMulKernelInfo(false, false, 3, 3, 17), false }, // K0 not in {1, 2, 3, 4, 8, 16}
90 { MatMulKernelInfo(false, false, 3, 3, 7), false }, // K0 not in {1, 2, 3, 4, 8, 16}
91 { MatMulKernelInfo(false, false, 9, 1, 2), true },
92 { MatMulKernelInfo(false, false, 3, 16, 3), true },
93 { MatMulKernelInfo(false, false, 7, 3, 4), true },
94 { MatMulKernelInfo(false, false, 7, 3, 4, true), true }, // export to CLImage is unsupported for quantized types
95 };
96
97 // Set big enough shapes so that block sizes are not truncated. Also, set all dimensions equal
98 // so that it doesn't fail for different NT/T configurations. We aim to test the block sizes here,
99 // not the shapes themselves.
100 const TensorInfo lhs_info = TensorInfo(TensorShape(100U, 100U), 1, DataType::QASYMM8_SIGNED);
101 const TensorInfo rhs_info = TensorInfo(TensorShape(100U, 100U), 1, DataType::QASYMM8_SIGNED);
102
103 for(auto &pair : supported_block_sizes)
104 {
105 TensorInfo output_info;
106 Status status = ClMatMulLowpNativeKernel::validate(&lhs_info, &rhs_info, &output_info, pair.first);
107
108 ARM_COMPUTE_EXPECT(bool(status) == pair.second, framework::LogLevel::ERRORS);
109 }
110}
111
112TEST_CASE(ValidateInputShapes, framework::DatasetMode::ALL)
113{
114 // Configurations are assumed to be Nt/Nt, but will be transposed inside the test to test other configurations
115 using ShapeConfigurationTuple = std::tuple<TensorShape, TensorShape, bool>;
116 const std::vector<ShapeConfigurationTuple> shape_configurations =
117 {
118 { TensorShape(5U, 1U), TensorShape(3U, 5U), true },
119 { TensorShape(10U, 12U), TensorShape(3U, 10U), true },
120 { TensorShape(8U, 4U), TensorShape(2U, 8U), true },
121 { TensorShape(8U, 4U), TensorShape(2U, 5U), false }, // Mismatch in the K dimension
122 { TensorShape(5U, 0U), TensorShape(2U, 5U), false }, // Invalid dimension
123 { TensorShape(5U, 4U, 3U, 4U, 5U, 6U), TensorShape(2U, 5U, 3U, 4U, 5U, 6U), true },
124 { TensorShape(5U, 4U, 3U, 4U, 5U, 1U), TensorShape(2U, 5U, 3U, 4U, 5U, 6U), false }, // no batch broadcasting
125 { TensorShape(5U, 4U, 3U, 4U, 9U, 6U), TensorShape(2U, 5U, 3U, 4U, 5U, 6U), false }, // mismatch in batch dimension
126 };
127
128 for(auto &tuple : shape_configurations)
129 {
130 const bool expected = std::get<2>(tuple);
131
132 for(bool adj_lhs :
133 {
134 false, true
135 })
136 {
137 for(bool adj_rhs :
138 {
139 false, true
140 })
141 {
142 TensorShape lhs_shape = std::get<0>(tuple);
143 TensorShape rhs_shape = std::get<1>(tuple);
144
145 if(adj_lhs)
146 {
147 permute(lhs_shape, PermutationVector(1U, 0U));
148 }
149
150 if(adj_rhs)
151 {
152 permute(rhs_shape, PermutationVector(1U, 0U));
153 }
154
155 const TensorInfo lhs_info = TensorInfo(lhs_shape, 1, DataType::QASYMM8_SIGNED);
156 const TensorInfo rhs_info = TensorInfo(rhs_shape, 1, DataType::QASYMM8_SIGNED);
157 TensorInfo output_info;
158
159 MatMulKernelInfo matmul_kernel_info{ adj_lhs, adj_rhs, 1, 1, 1, false /* export_rhs_to_cl_image */ };
160
161 Status status = ClMatMulLowpNativeKernel::validate(&lhs_info, &rhs_info, &output_info, matmul_kernel_info);
162 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
163 }
164 }
165 }
166}
167
168TEST_CASE(ValidateDataTypes, framework::DatasetMode::ALL)
169{
170 using DataTypeConfigurationTuple = std::tuple<DataType, DataType, DataType, bool>;
171 const std::vector<DataTypeConfigurationTuple> data_type_configurations =
172 {
173 { DataType::F32, DataType::F32, DataType::F32, false }, // no floating point types
174 { DataType::F16, DataType::F16, DataType::F16, false }, // no floating point types
175 { DataType::F64, DataType::F64, DataType::F64, false }, // no double precision
176 { DataType::QASYMM8, DataType::QASYMM8, DataType::QASYMM8, true },
177 { DataType::QASYMM8_SIGNED, DataType::QASYMM8_SIGNED, DataType::QASYMM8_SIGNED, true },
178 { DataType::QSYMM8_PER_CHANNEL, DataType::QSYMM8_PER_CHANNEL, DataType::QSYMM8_PER_CHANNEL, false }, // only qasymm8/qasymm8_signed is supported
179 { DataType::QASYMM16, DataType::QASYMM16, DataType::QASYMM16, false }, // only qasymm8/qasymm8_signed is supported
180 { DataType::QSYMM16, DataType::QSYMM16, DataType::QSYMM16, false }, // only qasymm8/qasymm8_signed is supported
181 { DataType::QSYMM8, DataType::QSYMM8, DataType::QSYMM8, false }, // only qasymm8/qasymm8_signed is supported
182 { DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::QASYMM8, false }, // no mixed data types
183 { DataType::S64, DataType::S64, DataType::S64, false }, // no integral types
184 { DataType::S32, DataType::S32, DataType::S32, false }, // no integral types
185 { DataType::S16, DataType::S16, DataType::S16, false }, // no integral types
186 { DataType::S8, DataType::S8, DataType::S8, false }, // no integral types
187 { DataType::U64, DataType::U64, DataType::U64, false }, // no integral types
188 { DataType::U32, DataType::U32, DataType::U32, false }, // no integral types
189 { DataType::U16, DataType::U16, DataType::U16, false }, // no integral types
190 { DataType::U8, DataType::U8, DataType::U8, false }, // no integral types
191 };
192
193 // It's enough to test a single shape and block size configuration while checking data types
194 const TensorShape shape = TensorShape(10U, 10U);
195 const MatMulKernelInfo matmul_kernel_info{ false, false, 1, 1, 1, false };
196 for(auto &tuple : data_type_configurations)
197 {
198 const bool expected = std::get<3>(tuple);
199
200 const TensorInfo lhs_info(shape, 1, std::get<0>(tuple));
201 const TensorInfo rhs_info(shape, 1, std::get<1>(tuple));
202 TensorInfo output_info(shape, 1, std::get<2>(tuple));
203
204 Status status = ClMatMulLowpNativeKernel::validate(&lhs_info, &rhs_info, &output_info, matmul_kernel_info);
205 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
206 }
207}
208
209TEST_SUITE_END() // Validate
210
211TEST_SUITE(Quantized)
212TEST_SUITE(QASYMM8_SIGNED)
213FIXTURE_DATA_TEST_CASE(RunTiny, CLMatMulLowpNativeKernelFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(datasets::TinyMatMulDataset(),
214 framework::dataset::make("TransposeA", { true, false })),
Jakub Sujak5e99a3e2023-04-18 08:33:56 +0100215 framework::dataset::make("TransposeB", { true, false })),
Gunes Bayir9d0c4de2023-04-13 18:22:58 +0100216 m0_values_precommit),
217 n0_values_precommit),
218 k0_values_precommit),
219 framework::dataset::make("ExportRhsToCLImage", { false })),
220 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)))
221{
222 // Validate output
223 validate(CLAccessor(_target), _reference, tolerance_quant);
224}
225FIXTURE_DATA_TEST_CASE(RunSmall, CLMatMulLowpNativeKernelFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(datasets::SmallMatMulDataset(),
226 framework::dataset::make("TransposeA", { true, false })),
Jakub Sujak5e99a3e2023-04-18 08:33:56 +0100227 framework::dataset::make("TransposeB", { true, false })),
Gunes Bayir9d0c4de2023-04-13 18:22:58 +0100228 m0_values_precommit),
229 n0_values_precommit),
230 k0_values_precommit),
231 framework::dataset::make("ExportRhsToCLImage", { false })),
232 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)))
233{
234 // Validate output
235 validate(CLAccessor(_target), _reference, tolerance_quant);
236}
237FIXTURE_DATA_TEST_CASE(RunLargeNoTranspose, CLMatMulLowpNativeKernelFixture<int8_t>, framework::DatasetMode::NIGHTLY,
238 combine(combine(combine(combine(combine(combine(combine(datasets::LargeMatMulDataset(),
239 framework::dataset::make("TransposeA", { false })),
240 framework::dataset::make("TransposeB", { false })),
241 m0_values_nightly_lhs_nt),
242 n0_values_nightly_rhs_nt),
243 k0_values_nightly_lhs_nt_rhs_nt),
244 framework::dataset::make("ExportRhsToCLImage", { false })),
245 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)))
246{
247 // Validate output
248 validate(CLAccessor(_target), _reference, tolerance_quant);
249}
Jakub Sujak5e99a3e2023-04-18 08:33:56 +0100250FIXTURE_DATA_TEST_CASE(RunLargeRhsTransposed, CLMatMulLowpNativeKernelFixture<int8_t>, framework::DatasetMode::NIGHTLY,
251 combine(combine(combine(combine(combine(combine(combine(datasets::LargeMatMulDataset(),
252 framework::dataset::make("TransposeA", { false })),
253 framework::dataset::make("TransposeB", { true })),
254 m0_values_nightly_lhs_nt),
255 n0_values_nightly_rhs_t),
256 k0_values_nightly_rhs_t),
257 framework::dataset::make("ExportRhsToCLImage", { false })),
258 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)))
259{
260 // Validate output
261 validate(CLAccessor(_target), _reference, tolerance_quant);
262}
Gunes Bayir9d0c4de2023-04-13 18:22:58 +0100263FIXTURE_DATA_TEST_CASE(RunLargeLhsTransposed, CLMatMulLowpNativeKernelFixture<int8_t>, framework::DatasetMode::NIGHTLY,
264 combine(combine(combine(combine(combine(combine(combine(datasets::LargeMatMulDataset(),
265 framework::dataset::make("TransposeA", { true })),
266 framework::dataset::make("TransposeB", { false })),
267 m0_values_nightly_lhs_t),
268 n0_values_nightly_rhs_nt),
269 k0_values_nightly_lhs_t_rhs_nt),
270 framework::dataset::make("ExportRhsToCLImage", { false })),
271 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)))
272{
273 // Validate output
274 validate(CLAccessor(_target), _reference, tolerance_quant);
275}
Omar Al Khatib467daef2023-04-13 14:56:23 +0100276FIXTURE_DATA_TEST_CASE(RunLargeLhsTransposedRhsTransposed, CLMatMulLowpNativeKernelFixture<int8_t>, framework::DatasetMode::NIGHTLY,
277 combine(combine(combine(combine(combine(combine(combine(datasets::LargeMatMulDataset(),
278 framework::dataset::make("TransposeA", { true })),
279 framework::dataset::make("TransposeB", { true })),
280 m0_values_nightly_lhs_t),
281 n0_values_nightly_rhs_t),
282 k0_values_nightly_rhs_t),
283 framework::dataset::make("ExportRhsToCLImage", { false })),
284 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)))
285{
286 // Validate output
287 validate(CLAccessor(_target), _reference, tolerance_quant);
288}
Gunes Bayir9d0c4de2023-04-13 18:22:58 +0100289// Running High Dimensional test is enough for qasymm8_signed, because we're stressing the number of dimensions, not data type or M0/N0/K0
290// It's a good idea to test for each Lhs/Rhs T/NT combinations because they're different CL kernels
291FIXTURE_DATA_TEST_CASE(RunHighDimensional, CLMatMulLowpNativeKernelFixture<int8_t>, framework::DatasetMode::ALL,
292 combine(combine(combine(combine(combine(combine(combine(datasets::HighDimensionalMatMulDataset(),
293 framework::dataset::make("TransposeA", { true, false })),
Jakub Sujak5e99a3e2023-04-18 08:33:56 +0100294 framework::dataset::make("TransposeB", { true, false })),
Omar Al Khatib467daef2023-04-13 14:56:23 +0100295 framework::dataset::make("M0", { 2 })),
296 framework::dataset::make("N0", { 2 })),
297 framework::dataset::make("K0", { 2 })),
298 framework::dataset::make("ExportRhsToCLImage", { false })),
299 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)))
300{
301 // Validate output
302 validate(CLAccessor(_target), _reference, tolerance_quant);
303}
Gunes Bayir9d0c4de2023-04-13 18:22:58 +0100304TEST_SUITE_END() // QASYMM8_SIGNED
305
306TEST_SUITE(QASYMM8)
307FIXTURE_DATA_TEST_CASE(RunTiny, CLMatMulLowpNativeKernelFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(datasets::TinyMatMulDataset(),
308 framework::dataset::make("TransposeA", { true, false })),
Jakub Sujak5e99a3e2023-04-18 08:33:56 +0100309 framework::dataset::make("TransposeB", { true, false })),
Gunes Bayir9d0c4de2023-04-13 18:22:58 +0100310 m0_values_precommit),
311 n0_values_precommit),
312 k0_values_precommit),
313 framework::dataset::make("ExportRhsToCLImage", { false })),
314 framework::dataset::make("DataType", DataType::QASYMM8)))
315{
316 // Validate output
317 validate(CLAccessor(_target), _reference, tolerance_quant);
318}
319FIXTURE_DATA_TEST_CASE(RunSmall, CLMatMulLowpNativeKernelFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(datasets::SmallMatMulDataset(),
320 framework::dataset::make("TransposeA", { true, false })),
Jakub Sujak5e99a3e2023-04-18 08:33:56 +0100321 framework::dataset::make("TransposeB", { true, false })),
Gunes Bayir9d0c4de2023-04-13 18:22:58 +0100322 m0_values_precommit),
323 n0_values_precommit),
324 k0_values_precommit),
325 framework::dataset::make("ExportRhsToCLImage", { false })),
326 framework::dataset::make("DataType", DataType::QASYMM8)))
327{
328 // Validate output
329 validate(CLAccessor(_target), _reference, tolerance_quant);
330}
331FIXTURE_DATA_TEST_CASE(RunLargeNoTranspose, CLMatMulLowpNativeKernelFixture<uint8_t>, framework::DatasetMode::NIGHTLY,
332 combine(combine(combine(combine(combine(combine(combine(datasets::LargeMatMulDataset(),
333 framework::dataset::make("TransposeA", { false })),
334 framework::dataset::make("TransposeB", { false })),
335 m0_values_nightly_lhs_nt),
336 n0_values_nightly_rhs_nt),
337 k0_values_nightly_lhs_nt_rhs_nt),
338 framework::dataset::make("ExportRhsToCLImage", { false })),
339 framework::dataset::make("DataType", DataType::QASYMM8)))
340{
341 // Validate output
342 validate(CLAccessor(_target), _reference, tolerance_quant);
343}
Jakub Sujak5e99a3e2023-04-18 08:33:56 +0100344FIXTURE_DATA_TEST_CASE(RunLargeRhsTransposed, CLMatMulLowpNativeKernelFixture<uint8_t>, framework::DatasetMode::NIGHTLY,
345 combine(combine(combine(combine(combine(combine(combine(datasets::LargeMatMulDataset(),
346 framework::dataset::make("TransposeA", { false })),
347 framework::dataset::make("TransposeB", { true })),
348 m0_values_nightly_lhs_nt),
349 n0_values_nightly_rhs_t),
350 k0_values_nightly_rhs_t),
351 framework::dataset::make("ExportRhsToCLImage", { false })),
352 framework::dataset::make("DataType", DataType::QASYMM8)))
353{
354 // Validate output
355 validate(CLAccessor(_target), _reference, tolerance_quant);
356}
Gunes Bayir9d0c4de2023-04-13 18:22:58 +0100357FIXTURE_DATA_TEST_CASE(RunLargeLhsTransposed, CLMatMulLowpNativeKernelFixture<uint8_t>, framework::DatasetMode::NIGHTLY,
358 combine(combine(combine(combine(combine(combine(combine(datasets::LargeMatMulDataset(),
359 framework::dataset::make("TransposeA", { true })),
360 framework::dataset::make("TransposeB", { false })),
361 m0_values_nightly_lhs_t),
362 n0_values_nightly_rhs_nt),
363 k0_values_nightly_lhs_t_rhs_nt),
364 framework::dataset::make("ExportRhsToCLImage", { false })),
365 framework::dataset::make("DataType", DataType::QASYMM8)))
366{
367 // Validate output
368 validate(CLAccessor(_target), _reference, tolerance_quant);
369}
Omar Al Khatib467daef2023-04-13 14:56:23 +0100370FIXTURE_DATA_TEST_CASE(RunLargeLhsTransposedRhsTransposed, CLMatMulLowpNativeKernelFixture<uint8_t>, framework::DatasetMode::NIGHTLY,
371 combine(combine(combine(combine(combine(combine(combine(datasets::LargeMatMulDataset(),
372 framework::dataset::make("TransposeA", { true })),
373 framework::dataset::make("TransposeB", { true })),
374 m0_values_nightly_lhs_t),
375 n0_values_nightly_rhs_t),
376 k0_values_nightly_rhs_t),
377 framework::dataset::make("ExportRhsToCLImage", { false })),
378 framework::dataset::make("DataType", DataType::QASYMM8)))
379{
380 // Validate output
381 validate(CLAccessor(_target), _reference, tolerance_quant);
382}
Gunes Bayir9d0c4de2023-04-13 18:22:58 +0100383TEST_SUITE_END() // QASYMM8
384TEST_SUITE_END() // Quantized
385TEST_SUITE_END() // MatMulLowpNativeKernel
386TEST_SUITE_END() // CL
387} // namespace validation
388} // namespace test
389} // namespace arm_compute