Elffuss BraidHub

kikocis/kleidiai public

main · 95.0 KiBRawPermalink
1//
2// SPDX-FileCopyrightText: Copyright 2024-2026 Arm Limited and/or its affiliates <open-source-office@arm.com>
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6
7#include "test/reference/matmul.hpp"
8
9#include <gtest/gtest.h>
10
11#include <array>
12#include <cstddef>
13#include <cstdint>
14#include <functional>
15#include <limits>
16#include <map>
17#include <string>
18#include <string_view>
19#include <tuple>
20#include <utility>
21#include <vector>
22
23#include "kai/kai_common.h"
24#include "test/common/abi_checker.hpp"
25#include "test/common/buffer.hpp"
26#include "test/common/compare.hpp"
27#include "test/common/cpu_info.hpp"
28#include "test/common/data_format.hpp"
29#include "test/common/data_type.hpp"
30#include "test/common/matmul_test_common.hpp"
31#include "test/common/matrix_portion.hpp"
32#include "test/common/seed.hpp"
33#include "test/common/sme.hpp"
34#include "test/common/sve.hpp"
35#include "test/reference/clamp.hpp"
36#include "test/reference/fill.hpp"
37#include "test/reference/generators.hpp"
38#include "test/reference/pack.hpp"
39#include "test/reference/transpose.hpp"
40
41// matmul_clamp_f16_f16_f16p
42#include "kai/ukernels/matmul/matmul_clamp_f16_f16_f16p/kai_matmul_clamp_f16_f16_f16p16x1biasf16_6x16x8_neon_mla.h"
43#include "kai/ukernels/matmul/matmul_clamp_f16_f16_f16p/kai_matmul_clamp_f16_f16_f16p2vlx2b_1x16vl_sme2_dot.h"
44#include "kai/ukernels/matmul/matmul_clamp_f16_f16_f16p/kai_matmul_clamp_f16_f16_f16p2vlx2b_1x8vl_sme_mla.h"
45#include "kai/ukernels/matmul/matmul_clamp_f16_f16_f16p/kai_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla.h"
46#include "kai/ukernels/matmul/matmul_clamp_f16_f16_f16p/kai_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla_cortexa55.h"
47#include "kai/ukernels/matmul/pack/kai_rhs_pack_kxn_f16p16x1biasf16_f16_f16_neon.h"
48#include "kai/ukernels/matmul/pack/kai_rhs_pack_kxn_x16p32x1b_x16_x16_neon.h"
49#include "kai/ukernels/matmul/pack/kai_rhs_pack_nxk_x16p32x1bx16_x16_x16_neon.h"
50
51// matmul_clamp_f16_f16p_f16p
52#include "kai/ukernels/matmul/matmul_clamp_f16_f16p_f16p/kai_matmul_clamp_f16_f16p2vlx2_f16p2vlx2_2vlx2vl_sme2_mopa.h"
53#include "kai/ukernels/matmul/matmul_clamp_f16_f16p_f16p/kai_matmul_clamp_f16_f16p2vlx2_f16p2vlx2b_2vlx2vl_sme_mopa.h"
54#include "kai/ukernels/matmul/pack/kai_lhs_pack_x16p2vlx2_x16_sme.h"
55#include "kai/ukernels/matmul/pack/kai_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme.h"
56#include "kai/ukernels/matmul/pack/kai_rhs_pack_nxk_x16p2vlx2b_x16_x16_sme.h"
57
58// matmul_clamp_f32_f32_f32p
59#include "kai/ukernels/matmul/matmul_clamp_f32_f32_f32p/kai_matmul_clamp_f32_f32_f32p16vlx1b_1x16vl_sme2_mla.h"
60#include "kai/ukernels/matmul/matmul_clamp_f32_f32_f32p/kai_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla.h"
61#include "kai/ukernels/matmul/matmul_clamp_f32_f32_f32p/kai_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla_cortexa55.h"
62#include "kai/ukernels/matmul/matmul_clamp_f32_f32_f32p/kai_matmul_clamp_f32_f32_f32p2vlx1b_1x16vl_sme2_mla.h"
63#include "kai/ukernels/matmul/matmul_clamp_f32_f32_f32p/kai_matmul_clamp_f32_f32_f32p2vlx1b_1x8vl_sme_mla.h"
64#include "kai/ukernels/matmul/matmul_clamp_f32_f32_f32p/kai_matmul_clamp_f32_f32_f32p4vlx1b_6x4vl_sve_mla.h"
65#include "kai/ukernels/matmul/matmul_clamp_f32_f32_f32p/kai_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla.h"
66#include "kai/ukernels/matmul/pack/kai_rhs_pack_kxn_f32p16vlx1b_f32_f32_sme.h"
67#include "kai/ukernels/matmul/pack/kai_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon.h"
68#include "kai/ukernels/matmul/pack/kai_rhs_pack_kxn_x32p16x1b_x32_x32_neon.h"
69#include "kai/ukernels/matmul/pack/kai_rhs_pack_kxn_x32p4vlx1b_x32_x32_sve.h"
70#include "kai/ukernels/matmul/pack/kai_rhs_pack_nxk_x32p16x1bx32_x32_x32_neon.h"
71
72// matmul_clamp_f32_f32p_f32p
73#include "kai/ukernels/matmul/matmul_clamp_f32_f32p_f32p/kai_matmul_clamp_f32_f32p2vlx1_f32p2vlx1b_2vlx2vl_sme_mopa.h"
74#include "kai/ukernels/matmul/matmul_clamp_f32_f32p_f32p/kai_matmul_clamp_f32_f32p2vlx1_f32p2vlx1biasf32_sme2_mopa.h"
75#include "kai/ukernels/matmul/pack/kai_lhs_pack_f32p2vlx1_f32_sme.h"
76#include "kai/ukernels/matmul/pack/kai_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme.h"
77#include "kai/ukernels/matmul/pack/kai_rhs_pack_nxk_f32p2vlx1biasf32_f32_f32_sme.h"
78
79namespace kai::test {
80
81static constexpr auto capabilities_pack_rhs_output =
82 MatMulMethodCapability::PACKED_RHS | MatMulMethodCapability::OUTPUT;
83static constexpr auto capabilities_all = MatMulMethodCapability::PACKED_LHS | MatMulMethodCapability::PACKED_RHS |
84 MatMulMethodCapability::PACKED_TRANSPOSED_RHS | MatMulMethodCapability::OUTPUT;
85static constexpr auto capabilities_pack_rhs_transposed_output =
86 MatMulMethodCapability::PACKED_RHS | MatMulMethodCapability::PACKED_TRANSPOSED_RHS | MatMulMethodCapability::OUTPUT;
87
88static const auto& get_matmul_methods() {
89 // List of supported matrix multiplication methods.
90 static std::array<MatMulMethod, 7> matmul_methods{};
91
92 matmul_methods[0].name = "matmul_clamp_f16_f16_f16p16x1biasf16_6x16x8_neon_mla";
93 matmul_methods[0].capabilities = capabilities_pack_rhs_output;
94 matmul_methods[0].m0 = 6;
95 matmul_methods[0].n0 = 16;
96 matmul_methods[0].dst_format = DataFormat(DataType::FP16);
97 matmul_methods[0].lhs_format = DataFormat(DataType::FP16);
98 matmul_methods[0].packed_lhs_format = DataFormat(DataType::UNKNOWN);
99 matmul_methods[0].rhs_format = DataFormat(DataType::FP16);
100 matmul_methods[0].packed_rhs_format = DataFormat(
101 DataType::FP16, 16, 0, DataFormat::PackFormat::BIAS_PER_ROW, DataType::FP16, DataType::UNKNOWN, 16, 1);
102 matmul_methods[0].bias_format = DataFormat(DataType::FP16);
103 matmul_methods[0].fn_generate_lhs = [](size_t rows, size_t cols, SeedFeed& feed) {
104 return NormalRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
105 };
106 matmul_methods[0].fn_generate_rhs = [](size_t rows, size_t cols, SeedFeed& feed) {
107 return NormalRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
108 };
109 matmul_methods[0].fn_generate_bias = [](size_t rows, size_t cols, SeedFeed& feed, bool null_bias_mode) {
110 KAI_UNUSED(null_bias_mode);
111 return NormalRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
112 };
113 matmul_methods[0].fn_is_supported = cpu_has_fp16;
114 matmul_methods[0].fn_get_nr = kai_get_nr_matmul_clamp_f16_f16_f16p16x1biasf16_6x16x8_neon_mla;
115 matmul_methods[0].fn_get_kr = kai_get_kr_matmul_clamp_f16_f16_f16p16x1biasf16_6x16x8_neon_mla;
116 matmul_methods[0].fn_get_sr = kai_get_sr_matmul_clamp_f16_f16_f16p16x1biasf16_6x16x8_neon_mla;
117 matmul_methods[0].fn_get_main_m_step = kai_get_m_step_matmul_clamp_f16_f16_f16p16x1biasf16_6x16x8_neon_mla;
118 matmul_methods[0].fn_get_pack_rhs_n_step = kai_get_n_step_rhs_pack_kxn_f16p16x1biasf16_f16_f16_neon;
119 matmul_methods[0].fn_get_main_n_step = kai_get_n_step_matmul_clamp_f16_f16_f16p16x1biasf16_6x16x8_neon_mla;
120 matmul_methods[0].fn_get_lhs_offset = kai_get_lhs_offset_matmul_clamp_f16_f16_f16p16x1biasf16_6x16x8_neon_mla;
121 matmul_methods[0].fn_get_rhs_offset = kai_get_rhs_offset_rhs_pack_kxn_f16p16x1biasf16_f16_f16_neon;
122 matmul_methods[0].fn_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_kxn_f16p16x1biasf16_f16_f16_neon;
123 matmul_methods[0].fn_get_pack_rhs_packed_rhs_offset =
124 kai_get_rhs_packed_offset_rhs_pack_kxn_f16p16x1biasf16_f16_f16_neon;
125 matmul_methods[0].fn_get_main_packed_rhs_offset =
126 kai_get_rhs_packed_offset_matmul_clamp_f16_f16_f16p16x1biasf16_6x16x8_neon_mla;
127 matmul_methods[0].fn_pack_rhs = kai_run_rhs_pack_kxn_f16p16x1biasf16_f16_f16_neon;
128 matmul_methods[0].fn_get_bias_offset = kai_get_bias_offset_rhs_pack_kxn_f16p16x1biasf16_f16_f16_neon;
129 matmul_methods[0].fn_get_dst_offset = kai_get_dst_offset_matmul_clamp_f16_f16_f16p16x1biasf16_6x16x8_neon_mla;
130 matmul_methods[0].fn_get_dst_size = kai_get_dst_size_matmul_clamp_f16_f16_f16p16x1biasf16_6x16x8_neon_mla;
131 matmul_methods[0].fn_matmul_f16_f16_f16p = kai_run_matmul_clamp_f16_f16_f16p16x1biasf16_6x16x8_neon_mla;
132
133 matmul_methods[1].name = "matmul_clamp_f16_f16p2vlx2_f16p2vlx2_2vlx2vl_sme2_mopa";
134 matmul_methods[1].capabilities = capabilities_all;
135 matmul_methods[1].m0 = 2 * get_sme_vector_length<float>();
136 matmul_methods[1].n0 = 2 * get_sme_vector_length<float>();
137 matmul_methods[1].dst_format = DataFormat(DataType::FP16);
138 matmul_methods[1].lhs_format = DataFormat(DataType::FP16);
139 matmul_methods[1].packed_lhs_format = DataFormat(DataType::FP16, 2 * get_sme_vector_length<float>(), 2);
140 matmul_methods[1].rhs_format = DataFormat(DataType::FP16);
141 matmul_methods[1].packed_rhs_format = DataFormat(
142 DataType::FP16, // Output type
143 2 * get_sme_vector_length<float>(), 2, // Block size
144 DataFormat::PackFormat::BIAS_PER_ROW, // Data layout
145 DataType::FP16, // Bias format
146 DataType::UNKNOWN, // Scaling type
147 2 * get_sme_vector_length<float>(), 2); // Sub-block
148 matmul_methods[1].bias_format = DataFormat(DataType::FP16);
149 matmul_methods[1].acc_dt = DataType::FP32;
150 matmul_methods[1].fn_generate_lhs = [](size_t rows, size_t cols, SeedFeed& feed) {
151 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
152 };
153 matmul_methods[1].fn_generate_rhs = [](size_t rows, size_t cols, SeedFeed& feed) {
154 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
155 };
156 matmul_methods[1].fn_generate_bias = [](size_t rows, size_t cols, SeedFeed& feed, bool null_bias_mode) {
157 KAI_UNUSED(null_bias_mode);
158 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
159 };
160 matmul_methods[1].fn_is_supported = cpu_has_sme2;
161 matmul_methods[1].fn_get_mr = kai_get_mr_matmul_clamp_f16_f16p2vlx2_f16p2vlx2_2vlx2vl_sme2_mopa;
162 matmul_methods[1].fn_get_nr = kai_get_nr_matmul_clamp_f16_f16p2vlx2_f16p2vlx2_2vlx2vl_sme2_mopa;
163 matmul_methods[1].fn_get_kr = kai_get_kr_matmul_clamp_f16_f16p2vlx2_f16p2vlx2_2vlx2vl_sme2_mopa;
164 matmul_methods[1].fn_get_sr = kai_get_sr_matmul_clamp_f16_f16p2vlx2_f16p2vlx2_2vlx2vl_sme2_mopa;
165 matmul_methods[1].fn_get_main_m_step = kai_get_m_step_matmul_clamp_f16_f16p2vlx2_f16p2vlx2_2vlx2vl_sme2_mopa;
166 matmul_methods[1].fn_get_pack_rhs_n_step = kai_get_n_step_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
167 matmul_methods[1].fn_get_main_n_step = kai_get_n_step_matmul_clamp_f16_f16p2vlx2_f16p2vlx2_2vlx2vl_sme2_mopa;
168 matmul_methods[1].fn_get_lhs_offset = kai_get_lhs_offset_lhs_pack_x16p2vlx2_x16_sme;
169 matmul_methods[1].fn_get_packed_lhs_size = kai_get_lhs_packed_size_lhs_pack_x16p2vlx2_x16_sme;
170 matmul_methods[1].fn_get_packed_lhs_offset =
171 kai_get_lhs_packed_offset_matmul_clamp_f16_f16p2vlx2_f16p2vlx2_2vlx2vl_sme2_mopa;
172 matmul_methods[1].fn_pack_lhs = kai_run_lhs_pack_x16p2vlx2_x16_sme;
173 matmul_methods[1].fn_get_rhs_offset = kai_get_rhs_offset_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
174 matmul_methods[1].fn_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
175 matmul_methods[1].fn_get_pack_rhs_packed_rhs_offset = kai_get_rhs_packed_offset_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
176 matmul_methods[1].fn_get_main_packed_rhs_offset =
177 kai_get_rhs_packed_offset_matmul_clamp_f16_f16p2vlx2_f16p2vlx2_2vlx2vl_sme2_mopa;
178 matmul_methods[1].fn_pack_rhs = kai_run_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
179 matmul_methods[1].fn_pack_rhs_nxk_get_n_step = kai_get_n_step_rhs_pack_nxk_x16p2vlx2b_x16_x16_sme;
180 matmul_methods[1].fn_pack_rhs_nxk_get_rhs_offset = kai_get_rhs_offset_rhs_pack_nxk_x16p2vlx2b_x16_x16_sme;
181 matmul_methods[1].fn_pack_rhs_nxk_get_bias_offset = kai_get_bias_offset_rhs_pack_nxk_x16p2vlx2b_x16_x16_sme;
182 matmul_methods[1].fn_pack_rhs_nxk_get_packed_rhs_offset =
183 kai_get_rhs_packed_offset_rhs_pack_nxk_x16p2vlx2b_x16_x16_sme;
184 matmul_methods[1].fn_pack_rhs_nxk_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_nxk_x16p2vlx2b_x16_x16_sme;
185 matmul_methods[1].fn_pack_rhs_nxk = kai_run_rhs_pack_nxk_x16p2vlx2b_x16_x16_sme;
186 matmul_methods[1].fn_get_bias_offset = kai_get_bias_offset_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
187 matmul_methods[1].fn_get_dst_offset = kai_get_dst_offset_matmul_clamp_f16_f16p2vlx2_f16p2vlx2_2vlx2vl_sme2_mopa;
188 matmul_methods[1].fn_get_dst_size = kai_get_dst_size_matmul_clamp_f16_f16p2vlx2_f16p2vlx2_2vlx2vl_sme2_mopa;
189 matmul_methods[1].fn_matmul_f16_f16p_f16p = kai_run_matmul_clamp_f16_f16p2vlx2_f16p2vlx2_2vlx2vl_sme2_mopa;
190
191 matmul_methods[2].name = "matmul_nt_nt_fp32_fp32_fp32_6x8_neon_mla";
192 matmul_methods[2].capabilities = capabilities_pack_rhs_output;
193 matmul_methods[2].m0 = 6;
194 matmul_methods[2].n0 = 8;
195 matmul_methods[2].dst_format = DataFormat(DataType::FP32);
196 matmul_methods[2].lhs_format = DataFormat(DataType::FP32);
197 matmul_methods[2].packed_lhs_format = DataFormat(DataType::UNKNOWN);
198 matmul_methods[2].rhs_format = DataFormat(DataType::FP32);
199 matmul_methods[2].packed_rhs_format =
200 DataFormat(DataType::FP32, 8, 0, DataFormat::PackFormat::BIAS_PER_ROW, DataType::FP32, DataType::UNKNOWN, 8, 1);
201 matmul_methods[2].bias_format = DataFormat(DataType::FP32);
202 matmul_methods[2].fn_generate_lhs = [](size_t rows, size_t cols, SeedFeed& feed) {
203 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
204 };
205 matmul_methods[2].fn_generate_rhs = [](size_t rows, size_t cols, SeedFeed& feed) {
206 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
207 };
208 matmul_methods[2].fn_generate_bias = [](size_t rows, size_t cols, SeedFeed& feed, bool null_bias_mode) {
209 KAI_UNUSED(null_bias_mode);
210 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
211 };
212 matmul_methods[2].fn_is_supported = cpu_has_advsimd;
213 matmul_methods[2].fn_get_nr = kai_get_nr_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla;
214 matmul_methods[2].fn_get_kr = kai_get_kr_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla;
215 matmul_methods[2].fn_get_sr = kai_get_sr_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla;
216 matmul_methods[2].fn_get_main_m_step = kai_get_m_step_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla;
217 matmul_methods[2].fn_get_pack_rhs_n_step = kai_get_n_step_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon;
218 matmul_methods[2].fn_get_main_n_step = kai_get_n_step_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla;
219 matmul_methods[2].fn_get_lhs_offset = kai_get_lhs_offset_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla;
220 matmul_methods[2].fn_get_rhs_offset = kai_get_rhs_offset_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon;
221 matmul_methods[2].fn_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon;
222 matmul_methods[2].fn_get_pack_rhs_packed_rhs_offset =
223 kai_get_rhs_packed_offset_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon;
224 matmul_methods[2].fn_get_main_packed_rhs_offset =
225 kai_get_rhs_packed_offset_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla;
226 matmul_methods[2].fn_pack_rhs = kai_run_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon;
227 matmul_methods[2].fn_get_bias_offset = kai_get_bias_offset_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon;
228 matmul_methods[2].fn_get_dst_offset = kai_get_dst_offset_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla;
229 matmul_methods[2].fn_get_dst_size = kai_get_dst_size_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla;
230 matmul_methods[2].fn_matmul_f32_f32_f32p = kai_run_matmul_clamp_f32_f32_f32p8x1biasf32_6x8x4_neon_mla;
231
232 matmul_methods[3].name = "matmul_clamp_f32_f32p2vlx1_f32p2vlx1biasf32_sme2_mopa";
233 matmul_methods[3].capabilities = capabilities_all;
234 matmul_methods[3].m0 = 2 * get_sme_vector_length<float>();
235 matmul_methods[3].n0 = 2 * get_sme_vector_length<float>();
236 matmul_methods[3].dst_format = DataFormat(DataType::FP32);
237 matmul_methods[3].lhs_format = DataFormat(DataType::FP32);
238 matmul_methods[3].packed_lhs_format = DataFormat(DataType::FP32, 2 * get_sme_vector_length<float>(), 1);
239 matmul_methods[3].rhs_format = DataFormat(DataType::FP32);
240 matmul_methods[3].packed_rhs_format = DataFormat(
241 DataType::FP32, 2 * get_sme_vector_length<float>(), 0, DataFormat::PackFormat::BIAS_PER_ROW, DataType::FP32,
242 DataType::UNKNOWN, 2 * get_sme_vector_length<float>(), 1);
243 matmul_methods[3].bias_format = DataFormat(DataType::FP32);
244 matmul_methods[3].fn_generate_lhs = [](size_t rows, size_t cols, SeedFeed& feed) {
245 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
246 };
247 matmul_methods[3].fn_generate_rhs = [](size_t rows, size_t cols, SeedFeed& feed) {
248 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
249 };
250 matmul_methods[3].fn_generate_bias = [](size_t rows, size_t cols, SeedFeed& feed, bool null_bias_mode) {
251 KAI_UNUSED(null_bias_mode);
252 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
253 };
254 matmul_methods[3].fn_is_supported = cpu_has_sme2;
255 matmul_methods[3].fn_get_mr = kai_get_mr_matmul_clamp_f32_f32p2vlx1_f32p2vlx1biasf32_sme2_mopa;
256 matmul_methods[3].fn_get_nr = kai_get_nr_matmul_clamp_f32_f32p2vlx1_f32p2vlx1biasf32_sme2_mopa;
257 matmul_methods[3].fn_get_kr = kai_get_kr_matmul_clamp_f32_f32p2vlx1_f32p2vlx1biasf32_sme2_mopa;
258 matmul_methods[3].fn_get_sr = kai_get_sr_matmul_clamp_f32_f32p2vlx1_f32p2vlx1biasf32_sme2_mopa;
259 matmul_methods[3].fn_get_main_m_step = kai_get_m_step_matmul_clamp_f32_f32p2vlx1_f32p2vlx1biasf32_sme2_mopa;
260 matmul_methods[3].fn_get_pack_rhs_n_step = kai_get_n_step_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
261 matmul_methods[3].fn_get_main_n_step = kai_get_n_step_matmul_clamp_f32_f32p2vlx1_f32p2vlx1biasf32_sme2_mopa;
262 matmul_methods[3].fn_get_lhs_offset = kai_get_lhs_offset_lhs_pack_f32p2vlx1_f32_sme;
263 matmul_methods[3].fn_get_packed_lhs_size = kai_get_lhs_packed_size_lhs_pack_f32p2vlx1_f32_sme;
264 matmul_methods[3].fn_get_packed_lhs_offset =
265 kai_get_lhs_packed_offset_matmul_clamp_f32_f32p2vlx1_f32p2vlx1biasf32_sme2_mopa;
266 matmul_methods[3].fn_pack_lhs = kai_run_lhs_pack_f32p2vlx1_f32_sme;
267 matmul_methods[3].fn_get_rhs_offset = kai_get_rhs_offset_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
268 matmul_methods[3].fn_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
269 matmul_methods[3].fn_get_pack_rhs_packed_rhs_offset =
270 kai_get_rhs_packed_offset_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
271 matmul_methods[3].fn_get_main_packed_rhs_offset =
272 kai_get_rhs_packed_offset_matmul_clamp_f32_f32p2vlx1_f32p2vlx1biasf32_sme2_mopa;
273 matmul_methods[3].fn_pack_rhs = kai_run_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
274 matmul_methods[3].fn_pack_rhs_nxk_get_n_step = kai_get_n_step_rhs_pack_nxk_f32p2vlx1biasf32_f32_f32_sme;
275 matmul_methods[3].fn_pack_rhs_nxk_get_rhs_offset = kai_get_rhs_offset_rhs_pack_nxk_f32p2vlx1biasf32_f32_f32_sme;
276 matmul_methods[3].fn_pack_rhs_nxk_get_bias_offset = kai_get_bias_offset_rhs_pack_nxk_f32p2vlx1biasf32_f32_f32_sme;
277 matmul_methods[3].fn_pack_rhs_nxk_get_packed_rhs_offset =
278 kai_get_rhs_packed_offset_rhs_pack_nxk_f32p2vlx1biasf32_f32_f32_sme;
279 matmul_methods[3].fn_pack_rhs_nxk_get_packed_rhs_size =
280 kai_get_rhs_packed_size_rhs_pack_nxk_f32p2vlx1biasf32_f32_f32_sme;
281 matmul_methods[3].fn_pack_rhs_nxk = kai_run_rhs_pack_nxk_f32p2vlx1biasf32_f32_f32_sme;
282 matmul_methods[3].fn_get_bias_offset = kai_get_bias_offset_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
283 matmul_methods[3].fn_get_dst_offset = kai_get_dst_offset_matmul_clamp_f32_f32p2vlx1_f32p2vlx1biasf32_sme2_mopa;
284 matmul_methods[3].fn_get_dst_size = kai_get_dst_size_matmul_clamp_f32_f32p2vlx1_f32p2vlx1biasf32_sme2_mopa;
285 matmul_methods[3].fn_matmul_f32_f32p_f32p = kai_run_matmul_clamp_f32_f32p2vlx1_f32p2vlx1biasf32_sme2_mopa;
286
287 matmul_methods[4].name = "matmul_clamp_f32_f32p2vlx1_f32p2vlx1b_2vlx2vl_sme_mopa";
288 matmul_methods[4].capabilities = capabilities_all;
289 matmul_methods[4].m0 = 2 * get_sme_vector_length<float>();
290 matmul_methods[4].n0 = 2 * get_sme_vector_length<float>();
291 matmul_methods[4].dst_format = DataFormat(DataType::FP32);
292 matmul_methods[4].lhs_format = DataFormat(DataType::FP32);
293 matmul_methods[4].packed_lhs_format = DataFormat(DataType::FP32, 2 * get_sme_vector_length<float>(), 1);
294 matmul_methods[4].rhs_format = DataFormat(DataType::FP32);
295 matmul_methods[4].packed_rhs_format = DataFormat(
296 DataType::FP32, 2 * get_sme_vector_length<float>(), 0, DataFormat::PackFormat::BIAS_PER_ROW, DataType::FP32,
297 DataType::UNKNOWN, 2 * get_sme_vector_length<float>(), 1);
298 matmul_methods[4].bias_format = DataFormat(DataType::FP32);
299 matmul_methods[4].fn_generate_lhs = [](size_t rows, size_t cols, SeedFeed& feed) {
300 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
301 };
302 matmul_methods[4].fn_generate_rhs = [](size_t rows, size_t cols, SeedFeed& feed) {
303 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
304 };
305 matmul_methods[4].fn_generate_bias = [](size_t rows, size_t cols, SeedFeed& feed, bool null_bias_mode) {
306 KAI_UNUSED(null_bias_mode);
307 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
308 };
309 matmul_methods[4].fn_is_supported = cpu_has_sme;
310 matmul_methods[4].fn_get_mr = kai_get_mr_matmul_clamp_f32_f32p2vlx1_f32p2vlx1b_2vlx2vl_sme_mopa;
311 matmul_methods[4].fn_get_nr = kai_get_nr_matmul_clamp_f32_f32p2vlx1_f32p2vlx1b_2vlx2vl_sme_mopa;
312 matmul_methods[4].fn_get_kr = kai_get_kr_matmul_clamp_f32_f32p2vlx1_f32p2vlx1b_2vlx2vl_sme_mopa;
313 matmul_methods[4].fn_get_sr = kai_get_sr_matmul_clamp_f32_f32p2vlx1_f32p2vlx1b_2vlx2vl_sme_mopa;
314 matmul_methods[4].fn_get_main_m_step = kai_get_m_step_matmul_clamp_f32_f32p2vlx1_f32p2vlx1b_2vlx2vl_sme_mopa;
315 matmul_methods[4].fn_get_pack_rhs_n_step = kai_get_n_step_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
316 matmul_methods[4].fn_get_main_n_step = kai_get_n_step_matmul_clamp_f32_f32p2vlx1_f32p2vlx1b_2vlx2vl_sme_mopa;
317 matmul_methods[4].fn_get_lhs_offset = kai_get_lhs_offset_lhs_pack_f32p2vlx1_f32_sme;
318 matmul_methods[4].fn_get_packed_lhs_size = kai_get_lhs_packed_size_lhs_pack_f32p2vlx1_f32_sme;
319 matmul_methods[4].fn_get_packed_lhs_offset =
320 kai_get_lhs_packed_offset_matmul_clamp_f32_f32p2vlx1_f32p2vlx1b_2vlx2vl_sme_mopa;
321 matmul_methods[4].fn_pack_lhs = kai_run_lhs_pack_f32p2vlx1_f32_sme;
322 matmul_methods[4].fn_get_rhs_offset = kai_get_rhs_offset_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
323 matmul_methods[4].fn_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
324 matmul_methods[4].fn_get_pack_rhs_packed_rhs_offset =
325 kai_get_rhs_packed_offset_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
326 matmul_methods[4].fn_get_main_packed_rhs_offset =
327 kai_get_rhs_packed_offset_matmul_clamp_f32_f32p2vlx1_f32p2vlx1b_2vlx2vl_sme_mopa;
328 matmul_methods[4].fn_pack_rhs = kai_run_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
329 matmul_methods[4].fn_pack_rhs_nxk_get_n_step = kai_get_n_step_rhs_pack_nxk_f32p2vlx1biasf32_f32_f32_sme;
330 matmul_methods[4].fn_pack_rhs_nxk_get_rhs_offset = kai_get_rhs_offset_rhs_pack_nxk_f32p2vlx1biasf32_f32_f32_sme;
331 matmul_methods[4].fn_pack_rhs_nxk_get_bias_offset = kai_get_bias_offset_rhs_pack_nxk_f32p2vlx1biasf32_f32_f32_sme;
332 matmul_methods[4].fn_pack_rhs_nxk_get_packed_rhs_offset =
333 kai_get_rhs_packed_offset_rhs_pack_nxk_f32p2vlx1biasf32_f32_f32_sme;
334 matmul_methods[4].fn_pack_rhs_nxk_get_packed_rhs_size =
335 kai_get_rhs_packed_size_rhs_pack_nxk_f32p2vlx1biasf32_f32_f32_sme;
336 matmul_methods[4].fn_pack_rhs_nxk = kai_run_rhs_pack_nxk_f32p2vlx1biasf32_f32_f32_sme;
337 matmul_methods[4].fn_get_bias_offset = kai_get_bias_offset_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
338 matmul_methods[4].fn_get_dst_offset = kai_get_dst_offset_matmul_clamp_f32_f32p2vlx1_f32p2vlx1b_2vlx2vl_sme_mopa;
339 matmul_methods[4].fn_get_dst_size = kai_get_dst_size_matmul_clamp_f32_f32p2vlx1_f32p2vlx1b_2vlx2vl_sme_mopa;
340 matmul_methods[4].fn_matmul_f32_f32p_f32p = kai_run_matmul_clamp_f32_f32p2vlx1_f32p2vlx1b_2vlx2vl_sme_mopa;
341
342 matmul_methods[5].name = "matmul_clamp_f16_f16p2vlx2_f16p2vlx2b_2vlx2vl_sme_mopa";
343 matmul_methods[5].capabilities = capabilities_all;
344 matmul_methods[5].m0 = 2 * get_sme_vector_length<float>();
345 matmul_methods[5].n0 = 2 * get_sme_vector_length<float>();
346 matmul_methods[5].dst_format = DataFormat(DataType::FP16);
347 matmul_methods[5].lhs_format = DataFormat(DataType::FP16);
348 matmul_methods[5].packed_lhs_format = DataFormat(DataType::FP16, 2 * get_sme_vector_length<float>(), 2);
349 matmul_methods[5].rhs_format = DataFormat(DataType::FP16);
350 matmul_methods[5].packed_rhs_format = DataFormat(
351 DataType::FP16, // Output type
352 2 * get_sme_vector_length<float>(), 2, // Block size
353 DataFormat::PackFormat::BIAS_PER_ROW, // Data layout
354 DataType::FP16, // Bias format
355 DataType::UNKNOWN, // Scaling type
356 2 * get_sme_vector_length<float>(), 2); // Sub-block
357 matmul_methods[5].bias_format = DataFormat(DataType::FP16);
358 matmul_methods[5].acc_dt = DataType::FP32;
359 matmul_methods[5].fn_generate_lhs = [](size_t rows, size_t cols, SeedFeed& feed) {
360 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
361 };
362 matmul_methods[5].fn_generate_rhs = [](size_t rows, size_t cols, SeedFeed& feed) {
363 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
364 };
365 matmul_methods[5].fn_generate_bias = [](size_t rows, size_t cols, SeedFeed& feed, bool null_bias_mode) {
366 KAI_UNUSED(null_bias_mode);
367 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
368 };
369 matmul_methods[5].fn_is_supported = cpu_has_sme;
370 matmul_methods[5].fn_get_mr = kai_get_mr_matmul_clamp_f16_f16p2vlx2_f16p2vlx2b_2vlx2vl_sme_mopa;
371 matmul_methods[5].fn_get_nr = kai_get_nr_matmul_clamp_f16_f16p2vlx2_f16p2vlx2b_2vlx2vl_sme_mopa;
372 matmul_methods[5].fn_get_kr = kai_get_kr_matmul_clamp_f16_f16p2vlx2_f16p2vlx2b_2vlx2vl_sme_mopa;
373 matmul_methods[5].fn_get_sr = kai_get_sr_matmul_clamp_f16_f16p2vlx2_f16p2vlx2b_2vlx2vl_sme_mopa;
374 matmul_methods[5].fn_get_main_m_step = kai_get_m_step_matmul_clamp_f16_f16p2vlx2_f16p2vlx2b_2vlx2vl_sme_mopa;
375 matmul_methods[5].fn_get_pack_rhs_n_step = kai_get_n_step_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
376 matmul_methods[5].fn_get_main_n_step = kai_get_n_step_matmul_clamp_f16_f16p2vlx2_f16p2vlx2b_2vlx2vl_sme_mopa;
377 matmul_methods[5].fn_get_lhs_offset = kai_get_lhs_offset_lhs_pack_x16p2vlx2_x16_sme;
378 matmul_methods[5].fn_get_packed_lhs_size = kai_get_lhs_packed_size_lhs_pack_x16p2vlx2_x16_sme;
379 matmul_methods[5].fn_get_packed_lhs_offset =
380 kai_get_lhs_packed_offset_matmul_clamp_f16_f16p2vlx2_f16p2vlx2b_2vlx2vl_sme_mopa;
381 matmul_methods[5].fn_pack_lhs = kai_run_lhs_pack_x16p2vlx2_x16_sme;
382 matmul_methods[5].fn_get_rhs_offset = kai_get_rhs_offset_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
383 matmul_methods[5].fn_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
384 matmul_methods[5].fn_get_pack_rhs_packed_rhs_offset = kai_get_rhs_packed_offset_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
385 matmul_methods[5].fn_get_main_packed_rhs_offset =
386 kai_get_rhs_packed_offset_matmul_clamp_f16_f16p2vlx2_f16p2vlx2b_2vlx2vl_sme_mopa;
387 matmul_methods[5].fn_pack_rhs = kai_run_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
388 matmul_methods[5].fn_pack_rhs_nxk_get_n_step = kai_get_n_step_rhs_pack_nxk_x16p2vlx2b_x16_x16_sme;
389 matmul_methods[5].fn_pack_rhs_nxk_get_rhs_offset = kai_get_rhs_offset_rhs_pack_nxk_x16p2vlx2b_x16_x16_sme;
390 matmul_methods[5].fn_pack_rhs_nxk_get_bias_offset = kai_get_bias_offset_rhs_pack_nxk_x16p2vlx2b_x16_x16_sme;
391 matmul_methods[5].fn_pack_rhs_nxk_get_packed_rhs_offset =
392 kai_get_rhs_packed_offset_rhs_pack_nxk_x16p2vlx2b_x16_x16_sme;
393 matmul_methods[5].fn_pack_rhs_nxk_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_nxk_x16p2vlx2b_x16_x16_sme;
394 matmul_methods[5].fn_pack_rhs_nxk = kai_run_rhs_pack_nxk_x16p2vlx2b_x16_x16_sme;
395 matmul_methods[5].fn_get_bias_offset = kai_get_bias_offset_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
396 matmul_methods[5].fn_get_dst_offset = kai_get_dst_offset_matmul_clamp_f16_f16p2vlx2_f16p2vlx2b_2vlx2vl_sme_mopa;
397 matmul_methods[5].fn_get_dst_size = kai_get_dst_size_matmul_clamp_f16_f16p2vlx2_f16p2vlx2b_2vlx2vl_sme_mopa;
398 matmul_methods[5].fn_matmul_f16_f16p_f16p = kai_run_matmul_clamp_f16_f16p2vlx2_f16p2vlx2b_2vlx2vl_sme_mopa;
399
400 matmul_methods[6].name = "matmul_clamp_f32_f32_f32p4vlx1b_6x4vl_sve_mla";
401 matmul_methods[6].capabilities = capabilities_pack_rhs_output;
402 matmul_methods[6].m0 = 1;
403 matmul_methods[6].n0 = 4 * get_sve_vector_length<float>();
404 matmul_methods[6].dst_format = DataFormat(DataType::FP32);
405 matmul_methods[6].lhs_format = DataFormat(DataType::FP32);
406 matmul_methods[6].packed_lhs_format = DataFormat(DataType::UNKNOWN);
407 matmul_methods[6].rhs_format = DataFormat(DataType::FP32);
408 matmul_methods[6].packed_rhs_format = DataFormat(
409 DataType::FP32, 4 * get_sve_vector_length<float>(), 0, DataFormat::PackFormat::BIAS_PER_ROW, DataType::FP32,
410 DataType::UNKNOWN, 4 * get_sve_vector_length<float>(), 1);
411 matmul_methods[6].bias_format = DataFormat(DataType::FP32);
412 matmul_methods[6].fn_generate_lhs = [](size_t rows, size_t cols, SeedFeed& feed) {
413 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
414 };
415 matmul_methods[6].fn_generate_rhs = [](size_t rows, size_t cols, SeedFeed& feed) {
416 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
417 };
418 matmul_methods[6].fn_generate_bias = [](size_t rows, size_t cols, SeedFeed& feed, bool null_bias_mode) {
419 KAI_UNUSED(null_bias_mode);
420 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
421 };
422 matmul_methods[6].fn_is_supported = cpu_has_sve;
423 matmul_methods[6].fn_get_nr = kai_get_nr_matmul_clamp_f32_f32_f32p4vlx1b_6x4vl_sve_mla;
424 matmul_methods[6].fn_get_kr = kai_get_kr_matmul_clamp_f32_f32_f32p4vlx1b_6x4vl_sve_mla;
425 matmul_methods[6].fn_get_sr = kai_get_sr_matmul_clamp_f32_f32_f32p4vlx1b_6x4vl_sve_mla;
426 matmul_methods[6].fn_get_main_m_step = kai_get_m_step_matmul_clamp_f32_f32_f32p4vlx1b_6x4vl_sve_mla;
427 matmul_methods[6].fn_get_pack_rhs_n_step = kai_get_n_step_rhs_pack_kxn_x32p4vlx1b_x32_x32_sve;
428 matmul_methods[6].fn_get_main_n_step = kai_get_n_step_matmul_clamp_f32_f32_f32p4vlx1b_6x4vl_sve_mla;
429 matmul_methods[6].fn_get_lhs_offset = kai_get_lhs_offset_matmul_clamp_f32_f32_f32p4vlx1b_6x4vl_sve_mla;
430 matmul_methods[6].fn_get_rhs_offset = kai_get_rhs_offset_rhs_pack_kxn_x32p4vlx1b_x32_x32_sve;
431 matmul_methods[6].fn_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_kxn_x32p4vlx1b_x32_x32_sve;
432 matmul_methods[6].fn_get_pack_rhs_packed_rhs_offset = kai_get_rhs_packed_offset_rhs_pack_kxn_x32p4vlx1b_x32_x32_sve;
433 matmul_methods[6].fn_get_main_packed_rhs_offset =
434 kai_get_rhs_packed_offset_matmul_clamp_f32_f32_f32p4vlx1b_6x4vl_sve_mla;
435 matmul_methods[6].fn_pack_rhs = kai_run_rhs_pack_kxn_x32p4vlx1b_x32_x32_sve;
436 matmul_methods[6].fn_get_bias_offset = kai_get_bias_offset_rhs_pack_kxn_x32p4vlx1b_x32_x32_sve;
437 matmul_methods[6].fn_get_dst_offset = kai_get_dst_offset_matmul_clamp_f32_f32_f32p4vlx1b_6x4vl_sve_mla;
438 matmul_methods[6].fn_get_dst_size = kai_get_dst_size_matmul_clamp_f32_f32_f32p4vlx1b_6x4vl_sve_mla;
439 matmul_methods[6].fn_matmul_f32_f32_f32p = kai_run_matmul_clamp_f32_f32_f32p4vlx1b_6x4vl_sve_mla;
440
441 return matmul_methods;
442}
443
444static const auto& get_vecmul_methods() {
445 // List of supported vector by matrix multiplication methods
446 static std::array<MatMulMethod, 5> vecmul_methods{};
447
448 vecmul_methods[0].name = "matmul_clamp_f16_f16_f16p2vlx2b_1x16vl_sme2_dot";
449 vecmul_methods[0].capabilities = capabilities_pack_rhs_output;
450 vecmul_methods[0].m0 = 1;
451 vecmul_methods[0].n0 = 16 * get_sme_vector_length<float>();
452 vecmul_methods[0].dst_format = DataFormat(DataType::FP16);
453 vecmul_methods[0].lhs_format = DataFormat(DataType::FP16);
454 vecmul_methods[0].packed_lhs_format = DataFormat(DataType::UNKNOWN);
455 vecmul_methods[0].rhs_format = DataFormat(DataType::FP16);
456 vecmul_methods[0].packed_rhs_format = DataFormat(
457 DataType::FP16, // Output type
458 2 * get_sme_vector_length<float>(), 2, // Block size
459 DataFormat::PackFormat::BIAS_PER_ROW, // Data layout
460 DataType::FP16, // Bias format
461 DataType::UNKNOWN, // Scaling type
462 2 * get_sme_vector_length<float>(), 2); // Sub-block
463 vecmul_methods[0].bias_format = DataFormat(DataType::FP16);
464 vecmul_methods[0].acc_dt = DataType::FP32;
465 vecmul_methods[0].fn_generate_lhs = [](size_t rows, size_t cols, SeedFeed& feed) {
466 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
467 };
468 vecmul_methods[0].fn_generate_rhs = [](size_t rows, size_t cols, SeedFeed& feed) {
469 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
470 };
471 vecmul_methods[0].fn_generate_bias = [](size_t rows, size_t cols, SeedFeed& feed, bool null_bias_mode) {
472 KAI_UNUSED(null_bias_mode);
473 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
474 };
475 vecmul_methods[0].fn_is_supported = cpu_has_sme2;
476 vecmul_methods[0].fn_get_nr = kai_get_nr_matmul_clamp_f16_f16_f16p2vlx2b_1x16vl_sme2_dot;
477 vecmul_methods[0].fn_get_kr = kai_get_kr_matmul_clamp_f16_f16_f16p2vlx2b_1x16vl_sme2_dot;
478 vecmul_methods[0].fn_get_sr = kai_get_sr_matmul_clamp_f16_f16_f16p2vlx2b_1x16vl_sme2_dot;
479 vecmul_methods[0].fn_get_main_m_step = kai_get_m_step_matmul_clamp_f16_f16_f16p2vlx2b_1x16vl_sme2_dot;
480 vecmul_methods[0].fn_get_pack_rhs_n_step = kai_get_n_step_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
481 vecmul_methods[0].fn_get_main_n_step = kai_get_n_step_matmul_clamp_f16_f16_f16p2vlx2b_1x16vl_sme2_dot;
482 vecmul_methods[0].fn_get_lhs_offset = kai_get_lhs_offset_lhs_pack_x16p2vlx2_x16_sme;
483 vecmul_methods[0].fn_get_rhs_offset = kai_get_rhs_offset_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
484 vecmul_methods[0].fn_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
485 vecmul_methods[0].fn_get_pack_rhs_packed_rhs_offset = kai_get_rhs_packed_offset_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
486 vecmul_methods[0].fn_get_main_packed_rhs_offset =
487 kai_get_rhs_packed_offset_matmul_clamp_f16_f16_f16p2vlx2b_1x16vl_sme2_dot;
488 vecmul_methods[0].fn_pack_rhs = kai_run_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
489 vecmul_methods[0].fn_get_bias_offset = kai_get_bias_offset_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
490 vecmul_methods[0].fn_get_dst_offset = kai_get_dst_offset_matmul_clamp_f16_f16_f16p2vlx2b_1x16vl_sme2_dot;
491 vecmul_methods[0].fn_get_dst_size = kai_get_dst_size_matmul_clamp_f16_f16_f16p2vlx2b_1x16vl_sme2_dot;
492 vecmul_methods[0].fn_matmul_f16_f16_f16p = kai_run_matmul_clamp_f16_f16_f16p2vlx2b_1x16vl_sme2_dot;
493
494 vecmul_methods[1].name = "matmul_clamp_f16_f16_f16p2vlx2b_1x8vl_sme_mla";
495 vecmul_methods[1].capabilities = capabilities_pack_rhs_output;
496 vecmul_methods[1].m0 = 1;
497 vecmul_methods[1].n0 = 8 * get_sme_vector_length<float>();
498 vecmul_methods[1].dst_format = DataFormat(DataType::FP16);
499 vecmul_methods[1].lhs_format = DataFormat(DataType::FP16);
500 vecmul_methods[1].packed_lhs_format = DataFormat(DataType::UNKNOWN);
501 vecmul_methods[1].rhs_format = DataFormat(DataType::FP16);
502 vecmul_methods[1].packed_rhs_format = DataFormat(
503 DataType::FP16, // Output type
504 2 * get_sme_vector_length<float>(), 2, // Block size
505 DataFormat::PackFormat::BIAS_PER_ROW, // Data layout
506 DataType::FP16, // Bias format
507 DataType::UNKNOWN, // Scaling type
508 2 * get_sme_vector_length<float>(), 2); // Sub-block
509 vecmul_methods[1].bias_format = DataFormat(DataType::FP16);
510 vecmul_methods[1].acc_dt = DataType::FP32;
511 vecmul_methods[1].fn_generate_lhs = [](size_t rows, size_t cols, SeedFeed& feed) {
512 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
513 };
514 vecmul_methods[1].fn_generate_rhs = [](size_t rows, size_t cols, SeedFeed& feed) {
515 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
516 };
517 vecmul_methods[1].fn_generate_bias = [](size_t rows, size_t cols, SeedFeed& feed, bool null_bias_mode) {
518 KAI_UNUSED(null_bias_mode);
519 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
520 };
521 vecmul_methods[1].fn_is_supported = cpu_has_sme;
522 vecmul_methods[1].fn_get_nr = kai_get_nr_matmul_clamp_f16_f16_f16p2vlx2b_1x8vl_sme_mla;
523 vecmul_methods[1].fn_get_kr = kai_get_kr_matmul_clamp_f16_f16_f16p2vlx2b_1x8vl_sme_mla;
524 vecmul_methods[1].fn_get_sr = kai_get_sr_matmul_clamp_f16_f16_f16p2vlx2b_1x8vl_sme_mla;
525 vecmul_methods[1].fn_get_main_m_step = kai_get_m_step_matmul_clamp_f16_f16_f16p2vlx2b_1x8vl_sme_mla;
526 vecmul_methods[1].fn_get_pack_rhs_n_step = kai_get_n_step_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
527 vecmul_methods[1].fn_get_main_n_step = kai_get_n_step_matmul_clamp_f16_f16_f16p2vlx2b_1x8vl_sme_mla;
528 vecmul_methods[1].fn_get_lhs_offset = kai_get_lhs_offset_lhs_pack_x16p2vlx2_x16_sme;
529 vecmul_methods[1].fn_get_rhs_offset = kai_get_rhs_offset_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
530 vecmul_methods[1].fn_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
531 vecmul_methods[1].fn_get_pack_rhs_packed_rhs_offset = kai_get_rhs_packed_offset_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
532 vecmul_methods[1].fn_get_main_packed_rhs_offset =
533 kai_get_rhs_packed_offset_matmul_clamp_f16_f16_f16p2vlx2b_1x8vl_sme_mla;
534 vecmul_methods[1].fn_pack_rhs = kai_run_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
535 vecmul_methods[1].fn_get_bias_offset = kai_get_bias_offset_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme;
536 vecmul_methods[1].fn_get_dst_offset = kai_get_dst_offset_matmul_clamp_f16_f16_f16p2vlx2b_1x8vl_sme_mla;
537 vecmul_methods[1].fn_get_dst_size = kai_get_dst_size_matmul_clamp_f16_f16_f16p2vlx2b_1x8vl_sme_mla;
538 vecmul_methods[1].fn_matmul_f16_f16_f16p = kai_run_matmul_clamp_f16_f16_f16p2vlx2b_1x8vl_sme_mla;
539
540 vecmul_methods[2].name = "matmul_clamp_f32_f32_f32p2vlx1b_1x8vl_sme_mla";
541 vecmul_methods[2].capabilities = capabilities_pack_rhs_output;
542 vecmul_methods[2].m0 = 1;
543 vecmul_methods[2].n0 = 8 * get_sme_vector_length<float>();
544 vecmul_methods[2].dst_format = DataFormat(DataType::FP32);
545 vecmul_methods[2].lhs_format = DataFormat(DataType::FP32);
546 vecmul_methods[2].packed_lhs_format = DataFormat(DataType::UNKNOWN);
547 vecmul_methods[2].rhs_format = DataFormat(DataType::FP32);
548 vecmul_methods[2].packed_rhs_format = DataFormat(
549 DataType::FP32, // Output type
550 2 * get_sme_vector_length<float>(), 1, // Block size
551 DataFormat::PackFormat::BIAS_PER_ROW, // Data layout
552 DataType::FP32, // Bias format
553 DataType::UNKNOWN, // Scaling type
554 2 * get_sme_vector_length<float>(), 1); // Sub-block
555 vecmul_methods[2].bias_format = DataFormat(DataType::FP32);
556 vecmul_methods[2].fn_generate_lhs = [](size_t rows, size_t cols, SeedFeed& feed) {
557 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
558 };
559 vecmul_methods[2].fn_generate_rhs = [](size_t rows, size_t cols, SeedFeed& feed) {
560 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
561 };
562 vecmul_methods[2].fn_generate_bias = [](size_t rows, size_t cols, SeedFeed& feed, bool null_bias_mode) {
563 KAI_UNUSED(null_bias_mode);
564 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
565 };
566 vecmul_methods[2].fn_is_supported = cpu_has_sme;
567 vecmul_methods[2].fn_get_nr = kai_get_nr_matmul_clamp_f32_f32_f32p2vlx1b_1x8vl_sme_mla;
568 vecmul_methods[2].fn_get_kr = kai_get_kr_matmul_clamp_f32_f32_f32p2vlx1b_1x8vl_sme_mla;
569 vecmul_methods[2].fn_get_sr = kai_get_sr_matmul_clamp_f32_f32_f32p2vlx1b_1x8vl_sme_mla;
570 vecmul_methods[2].fn_get_main_m_step = kai_get_m_step_matmul_clamp_f32_f32_f32p2vlx1b_1x8vl_sme_mla;
571 vecmul_methods[2].fn_get_main_n_step = kai_get_n_step_matmul_clamp_f32_f32_f32p2vlx1b_1x8vl_sme_mla;
572 vecmul_methods[2].fn_get_pack_rhs_n_step = kai_get_n_step_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
573 vecmul_methods[2].fn_get_lhs_offset = kai_get_lhs_offset_matmul_clamp_f32_f32_f32p2vlx1b_1x8vl_sme_mla;
574 vecmul_methods[2].fn_get_rhs_offset = kai_get_rhs_offset_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
575 vecmul_methods[2].fn_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
576 vecmul_methods[2].fn_get_pack_rhs_packed_rhs_offset =
577 kai_get_rhs_packed_offset_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
578 vecmul_methods[2].fn_get_main_packed_rhs_offset =
579 kai_get_rhs_packed_offset_matmul_clamp_f32_f32_f32p2vlx1b_1x8vl_sme_mla;
580 vecmul_methods[2].fn_pack_rhs = kai_run_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
581 vecmul_methods[2].fn_get_bias_offset = kai_get_bias_offset_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
582 vecmul_methods[2].fn_get_dst_offset = kai_get_dst_offset_matmul_clamp_f32_f32_f32p2vlx1b_1x8vl_sme_mla;
583 vecmul_methods[2].fn_get_dst_size = kai_get_dst_size_matmul_clamp_f32_f32_f32p2vlx1b_1x8vl_sme_mla;
584 vecmul_methods[2].fn_matmul_f32_f32_f32p = kai_run_matmul_clamp_f32_f32_f32p2vlx1b_1x8vl_sme_mla;
585
586 vecmul_methods[3].name = "matmul_clamp_f32_f32_f32p2vlx1b_1x16vl_sme2_mla";
587 vecmul_methods[3].capabilities = capabilities_pack_rhs_output;
588 vecmul_methods[3].m0 = 1;
589 vecmul_methods[3].n0 = 16 * get_sme_vector_length<float>();
590 vecmul_methods[3].dst_format = DataFormat(DataType::FP32);
591 vecmul_methods[3].lhs_format = DataFormat(DataType::FP32);
592 vecmul_methods[3].packed_lhs_format = DataFormat(DataType::UNKNOWN);
593 vecmul_methods[3].rhs_format = DataFormat(DataType::FP32);
594 vecmul_methods[3].packed_rhs_format = DataFormat(
595 DataType::FP32, // Output type
596 2 * get_sme_vector_length<float>(), 1, // Block size
597 DataFormat::PackFormat::BIAS_PER_ROW, // Data layout
598 DataType::FP32, // Bias format
599 DataType::UNKNOWN, // Scaling type
600 2 * get_sme_vector_length<float>(), 1); // Sub-block
601 vecmul_methods[3].bias_format = DataFormat(DataType::FP32);
602 vecmul_methods[3].fn_generate_lhs = [](size_t rows, size_t cols, SeedFeed& feed) {
603 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
604 };
605 vecmul_methods[3].fn_generate_rhs = [](size_t rows, size_t cols, SeedFeed& feed) {
606 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
607 };
608 vecmul_methods[3].fn_generate_bias = [](size_t rows, size_t cols, SeedFeed& feed, bool null_bias_mode) {
609 KAI_UNUSED(null_bias_mode);
610 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
611 };
612 vecmul_methods[3].fn_is_supported = cpu_has_sme2;
613 vecmul_methods[3].fn_get_nr = kai_get_nr_matmul_clamp_f32_f32_f32p2vlx1b_1x16vl_sme2_mla;
614 vecmul_methods[3].fn_get_kr = kai_get_kr_matmul_clamp_f32_f32_f32p2vlx1b_1x16vl_sme2_mla;
615 vecmul_methods[3].fn_get_sr = kai_get_sr_matmul_clamp_f32_f32_f32p2vlx1b_1x16vl_sme2_mla;
616 vecmul_methods[3].fn_get_main_m_step = kai_get_m_step_matmul_clamp_f32_f32_f32p2vlx1b_1x16vl_sme2_mla;
617 vecmul_methods[3].fn_get_main_n_step = kai_get_n_step_matmul_clamp_f32_f32_f32p2vlx1b_1x16vl_sme2_mla;
618 vecmul_methods[3].fn_get_pack_rhs_n_step = kai_get_n_step_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
619 vecmul_methods[3].fn_get_lhs_offset = kai_get_lhs_offset_matmul_clamp_f32_f32_f32p2vlx1b_1x16vl_sme2_mla;
620 vecmul_methods[3].fn_get_rhs_offset = kai_get_rhs_offset_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
621 vecmul_methods[3].fn_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
622 vecmul_methods[3].fn_get_pack_rhs_packed_rhs_offset =
623 kai_get_rhs_packed_offset_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
624 vecmul_methods[3].fn_get_main_packed_rhs_offset =
625 kai_get_rhs_packed_offset_matmul_clamp_f32_f32_f32p2vlx1b_1x16vl_sme2_mla;
626 vecmul_methods[3].fn_pack_rhs = kai_run_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
627 vecmul_methods[3].fn_get_bias_offset = kai_get_bias_offset_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme;
628 vecmul_methods[3].fn_get_dst_offset = kai_get_dst_offset_matmul_clamp_f32_f32_f32p2vlx1b_1x16vl_sme2_mla;
629 vecmul_methods[3].fn_get_dst_size = kai_get_dst_size_matmul_clamp_f32_f32_f32p2vlx1b_1x16vl_sme2_mla;
630 vecmul_methods[3].fn_matmul_f32_f32_f32p = kai_run_matmul_clamp_f32_f32_f32p2vlx1b_1x16vl_sme2_mla;
631
632 vecmul_methods[4].name = "matmul_clamp_f32_f32_f32p16vlx1b_1x16vl_sme2_mla";
633 vecmul_methods[4].capabilities = capabilities_pack_rhs_output;
634 vecmul_methods[4].m0 = 1;
635 vecmul_methods[4].n0 = 16 * get_sme_vector_length<float>();
636 vecmul_methods[4].dst_format = DataFormat(DataType::FP32);
637 vecmul_methods[4].lhs_format = DataFormat(DataType::FP32);
638 vecmul_methods[4].packed_lhs_format = DataFormat(DataType::UNKNOWN);
639 vecmul_methods[4].rhs_format = DataFormat(DataType::FP32);
640 vecmul_methods[4].packed_rhs_format = DataFormat(
641 DataType::FP32, // Output type
642 16 * get_sme_vector_length<float>(), 1, // Block size
643 DataFormat::PackFormat::BIAS_PER_ROW, // Data layout
644 DataType::FP32, // Bias format
645 DataType::UNKNOWN, // Scaling type
646 16 * get_sme_vector_length<float>(), 1); // Sub-block
647 vecmul_methods[4].bias_format = DataFormat(DataType::FP32);
648 vecmul_methods[4].fn_generate_lhs = [](size_t rows, size_t cols, SeedFeed& feed) {
649 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
650 };
651 vecmul_methods[4].fn_generate_rhs = [](size_t rows, size_t cols, SeedFeed& feed) {
652 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
653 };
654 vecmul_methods[4].fn_generate_bias = [](size_t rows, size_t cols, SeedFeed& feed, bool null_bias_mode) {
655 KAI_UNUSED(null_bias_mode);
656 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
657 };
658 vecmul_methods[4].fn_is_supported = cpu_has_sme2;
659 vecmul_methods[4].fn_get_nr = kai_get_nr_matmul_clamp_f32_f32_f32p16vlx1b_1x16vl_sme2_mla;
660 vecmul_methods[4].fn_get_kr = kai_get_kr_matmul_clamp_f32_f32_f32p16vlx1b_1x16vl_sme2_mla;
661 vecmul_methods[4].fn_get_sr = kai_get_sr_matmul_clamp_f32_f32_f32p16vlx1b_1x16vl_sme2_mla;
662 vecmul_methods[4].fn_get_main_m_step = kai_get_m_step_matmul_clamp_f32_f32_f32p16vlx1b_1x16vl_sme2_mla;
663 vecmul_methods[4].fn_get_main_n_step = kai_get_n_step_matmul_clamp_f32_f32_f32p16vlx1b_1x16vl_sme2_mla;
664 vecmul_methods[4].fn_get_pack_rhs_n_step = kai_get_n_step_rhs_pack_kxn_f32p16vlx1b_f32_f32_sme;
665 vecmul_methods[4].fn_get_lhs_offset = kai_get_lhs_offset_matmul_clamp_f32_f32_f32p16vlx1b_1x16vl_sme2_mla;
666 vecmul_methods[4].fn_get_rhs_offset = kai_get_rhs_offset_rhs_pack_kxn_f32p16vlx1b_f32_f32_sme;
667 vecmul_methods[4].fn_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_kxn_f32p16vlx1b_f32_f32_sme;
668 vecmul_methods[4].fn_get_pack_rhs_packed_rhs_offset =
669 kai_get_rhs_packed_offset_rhs_pack_kxn_f32p16vlx1b_f32_f32_sme;
670 vecmul_methods[4].fn_get_main_packed_rhs_offset =
671 kai_get_rhs_packed_offset_matmul_clamp_f32_f32_f32p16vlx1b_1x16vl_sme2_mla;
672 vecmul_methods[4].fn_pack_rhs = kai_run_rhs_pack_kxn_f32p16vlx1b_f32_f32_sme;
673 vecmul_methods[4].fn_get_bias_offset = kai_get_bias_offset_rhs_pack_kxn_f32p16vlx1b_f32_f32_sme;
674 vecmul_methods[4].fn_get_dst_offset = kai_get_dst_offset_matmul_clamp_f32_f32_f32p16vlx1b_1x16vl_sme2_mla;
675 vecmul_methods[4].fn_get_dst_size = kai_get_dst_size_matmul_clamp_f32_f32_f32p16vlx1b_1x16vl_sme2_mla;
676 vecmul_methods[4].fn_matmul_f32_f32_f32p = kai_run_matmul_clamp_f32_f32_f32p16vlx1b_1x16vl_sme2_mla;
677
678 return vecmul_methods;
679}
680
681static const auto& get_nullbias_matmul_methods() {
682 // List of supported vector by matrix multiplication methods
683 static std::array<MatMulMethod, 4> nullbias_matmul_methods{};
684
685 nullbias_matmul_methods[0].name = "matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla";
686 nullbias_matmul_methods[0].capabilities = capabilities_pack_rhs_transposed_output;
687 nullbias_matmul_methods[0].m0 = 6;
688 nullbias_matmul_methods[0].n0 = 16;
689 nullbias_matmul_methods[0].dst_format = DataFormat(DataType::FP32);
690 nullbias_matmul_methods[0].lhs_format = DataFormat(DataType::FP32);
691 nullbias_matmul_methods[0].packed_lhs_format = DataFormat(DataType::UNKNOWN);
692 nullbias_matmul_methods[0].rhs_format = DataFormat(DataType::FP32);
693 nullbias_matmul_methods[0].packed_rhs_format = DataFormat(
694 DataType::FP32, 16, 0, DataFormat::PackFormat::BIAS_PER_ROW, DataType::FP32, DataType::UNKNOWN, 16, 1);
695 nullbias_matmul_methods[0].bias_format = DataFormat(DataType::FP32);
696 nullbias_matmul_methods[0].fn_generate_lhs = [](size_t rows, size_t cols, SeedFeed& feed) {
697 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
698 };
699 nullbias_matmul_methods[0].fn_generate_rhs = [](size_t rows, size_t cols, SeedFeed& feed) {
700 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
701 };
702 nullbias_matmul_methods[0].fn_generate_bias = [](size_t rows, size_t cols, SeedFeed& feed, bool null_bias_mode) {
703 if (null_bias_mode) {
704 return ConstantGenerator<float>(0.0)(rows, cols);
705 } else {
706 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
707 }
708 };
709 nullbias_matmul_methods[0].fn_is_supported = cpu_has_advsimd;
710 nullbias_matmul_methods[0].fn_get_nr = kai_get_nr_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla;
711 nullbias_matmul_methods[0].fn_get_kr = kai_get_kr_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla;
712 nullbias_matmul_methods[0].fn_get_sr = kai_get_sr_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla;
713 nullbias_matmul_methods[0].fn_get_main_m_step = kai_get_m_step_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla;
714 nullbias_matmul_methods[0].fn_get_pack_rhs_n_step = kai_get_n_step_rhs_pack_kxn_x32p16x1b_x32_x32_neon;
715 nullbias_matmul_methods[0].fn_get_main_n_step = kai_get_n_step_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla;
716 nullbias_matmul_methods[0].fn_get_lhs_offset = kai_get_lhs_offset_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla;
717 nullbias_matmul_methods[0].fn_get_rhs_offset = kai_get_rhs_offset_rhs_pack_kxn_x32p16x1b_x32_x32_neon;
718 nullbias_matmul_methods[0].fn_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_kxn_x32p16x1b_x32_x32_neon;
719 nullbias_matmul_methods[0].fn_get_pack_rhs_packed_rhs_offset =
720 kai_get_rhs_packed_offset_rhs_pack_kxn_x32p16x1b_x32_x32_neon;
721 nullbias_matmul_methods[0].fn_get_main_packed_rhs_offset =
722 kai_get_rhs_packed_offset_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla;
723 nullbias_matmul_methods[0].fn_pack_rhs = kai_run_rhs_pack_kxn_x32p16x1b_x32_x32_neon;
724 nullbias_matmul_methods[0].fn_pack_rhs_nxk_get_n_step = kai_get_n_step_rhs_pack_nxk_x32p16x1bx32_x32_x32_neon;
725 nullbias_matmul_methods[0].fn_pack_rhs_nxk_get_rhs_offset =
726 kai_get_rhs_offset_rhs_pack_nxk_x32p16x1bx32_x32_x32_neon;
727 nullbias_matmul_methods[0].fn_pack_rhs_nxk_get_bias_offset =
728 kai_get_bias_offset_rhs_pack_nxk_x32p16x1bx32_x32_x32_neon;
729 nullbias_matmul_methods[0].fn_pack_rhs_nxk_get_packed_rhs_offset =
730 kai_get_rhs_packed_offset_rhs_pack_nxk_x32p16x1bx32_x32_x32_neon;
731 nullbias_matmul_methods[0].fn_pack_rhs_nxk_get_packed_rhs_size =
732 kai_get_rhs_packed_size_rhs_pack_nxk_x32p16x1bx32_x32_x32_neon;
733 nullbias_matmul_methods[0].fn_pack_rhs_nxk = kai_run_rhs_pack_nxk_x32p16x1bx32_x32_x32_neon;
734 nullbias_matmul_methods[0].fn_get_bias_offset = kai_get_bias_offset_rhs_pack_kxn_x32p16x1b_x32_x32_neon;
735 nullbias_matmul_methods[0].fn_get_dst_offset = kai_get_dst_offset_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla;
736 nullbias_matmul_methods[0].fn_get_dst_size = kai_get_dst_size_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla;
737 nullbias_matmul_methods[0].fn_matmul_f32_f32_f32p = kai_run_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla;
738
739 nullbias_matmul_methods[1].name = "matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla_cortexa55";
740 nullbias_matmul_methods[1].capabilities = capabilities_pack_rhs_transposed_output;
741 nullbias_matmul_methods[1].m0 = 6;
742 nullbias_matmul_methods[1].n0 = 16;
743 nullbias_matmul_methods[1].dst_format = DataFormat(DataType::FP32);
744 nullbias_matmul_methods[1].lhs_format = DataFormat(DataType::FP32);
745 nullbias_matmul_methods[1].packed_lhs_format = DataFormat(DataType::UNKNOWN);
746 nullbias_matmul_methods[1].rhs_format = DataFormat(DataType::FP32);
747 nullbias_matmul_methods[1].packed_rhs_format = DataFormat(
748 DataType::FP32, 16, 0, DataFormat::PackFormat::BIAS_PER_ROW, DataType::FP32, DataType::UNKNOWN, 16, 1);
749 nullbias_matmul_methods[1].bias_format = DataFormat(DataType::FP32);
750 nullbias_matmul_methods[1].fn_generate_lhs = [](size_t rows, size_t cols, SeedFeed& feed) {
751 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
752 };
753 nullbias_matmul_methods[1].fn_generate_rhs = [](size_t rows, size_t cols, SeedFeed& feed) {
754 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
755 };
756 nullbias_matmul_methods[1].fn_generate_bias = [](size_t rows, size_t cols, SeedFeed& feed, bool null_bias_mode) {
757 if (null_bias_mode) {
758 return ConstantGenerator<float>(0.0)(rows, cols);
759 } else {
760 return UniformRandomGenerator<float>(-1.0, 1.0, feed())(rows, cols);
761 }
762 };
763 nullbias_matmul_methods[1].fn_is_supported = cpu_has_advsimd;
764 nullbias_matmul_methods[1].fn_get_nr = kai_get_nr_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla_cortexa55;
765 nullbias_matmul_methods[1].fn_get_kr = kai_get_kr_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla_cortexa55;
766 nullbias_matmul_methods[1].fn_get_sr = kai_get_sr_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla_cortexa55;
767 nullbias_matmul_methods[1].fn_get_main_m_step =
768 kai_get_m_step_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla_cortexa55;
769 nullbias_matmul_methods[1].fn_get_pack_rhs_n_step = kai_get_n_step_rhs_pack_kxn_x32p16x1b_x32_x32_neon;
770 nullbias_matmul_methods[1].fn_get_main_n_step =
771 kai_get_n_step_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla_cortexa55;
772 nullbias_matmul_methods[1].fn_get_lhs_offset =
773 kai_get_lhs_offset_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla_cortexa55;
774 nullbias_matmul_methods[1].fn_get_rhs_offset = kai_get_rhs_offset_rhs_pack_kxn_x32p16x1b_x32_x32_neon;
775 nullbias_matmul_methods[1].fn_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_kxn_x32p16x1b_x32_x32_neon;
776 nullbias_matmul_methods[1].fn_get_pack_rhs_packed_rhs_offset =
777 kai_get_rhs_packed_offset_rhs_pack_kxn_x32p16x1b_x32_x32_neon;
778 nullbias_matmul_methods[1].fn_get_main_packed_rhs_offset =
779 kai_get_rhs_packed_offset_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla_cortexa55;
780 nullbias_matmul_methods[1].fn_pack_rhs = kai_run_rhs_pack_kxn_x32p16x1b_x32_x32_neon;
781 nullbias_matmul_methods[1].fn_pack_rhs_nxk_get_n_step = kai_get_n_step_rhs_pack_nxk_x32p16x1bx32_x32_x32_neon;
782 nullbias_matmul_methods[1].fn_pack_rhs_nxk_get_rhs_offset =
783 kai_get_rhs_offset_rhs_pack_nxk_x32p16x1bx32_x32_x32_neon;
784 nullbias_matmul_methods[1].fn_pack_rhs_nxk_get_bias_offset =
785 kai_get_bias_offset_rhs_pack_nxk_x32p16x1bx32_x32_x32_neon;
786 nullbias_matmul_methods[1].fn_pack_rhs_nxk_get_packed_rhs_offset =
787 kai_get_rhs_packed_offset_rhs_pack_nxk_x32p16x1bx32_x32_x32_neon;
788 nullbias_matmul_methods[1].fn_pack_rhs_nxk_get_packed_rhs_size =
789 kai_get_rhs_packed_size_rhs_pack_nxk_x32p16x1bx32_x32_x32_neon;
790 nullbias_matmul_methods[1].fn_pack_rhs_nxk = kai_run_rhs_pack_nxk_x32p16x1bx32_x32_x32_neon;
791 nullbias_matmul_methods[1].fn_get_bias_offset = kai_get_bias_offset_rhs_pack_kxn_x32p16x1b_x32_x32_neon;
792 nullbias_matmul_methods[1].fn_get_dst_offset =
793 kai_get_dst_offset_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla_cortexa55;
794 nullbias_matmul_methods[1].fn_get_dst_size =
795 kai_get_dst_size_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla_cortexa55;
796 nullbias_matmul_methods[1].fn_matmul_f32_f32_f32p = kai_run_matmul_clamp_f32_f32_f32p16x1b_6x16_neon_mla_cortexa55;
797
798 nullbias_matmul_methods[2].name = "matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla";
799 nullbias_matmul_methods[2].capabilities = capabilities_pack_rhs_transposed_output;
800 nullbias_matmul_methods[2].m0 = 6;
801 nullbias_matmul_methods[2].n0 = 32;
802 nullbias_matmul_methods[2].dst_format = DataFormat(DataType::FP16);
803 nullbias_matmul_methods[2].lhs_format = DataFormat(DataType::FP16);
804 nullbias_matmul_methods[2].packed_lhs_format = DataFormat(DataType::UNKNOWN);
805 nullbias_matmul_methods[2].rhs_format = DataFormat(DataType::FP16);
806 nullbias_matmul_methods[2].packed_rhs_format = DataFormat(
807 DataType::FP16, 32, 0, DataFormat::PackFormat::BIAS_PER_ROW, DataType::FP16, DataType::UNKNOWN, 32, 1);
808 nullbias_matmul_methods[2].bias_format = DataFormat(DataType::FP16);
809 nullbias_matmul_methods[2].fn_generate_lhs = [](size_t rows, size_t cols, SeedFeed& feed) {
810 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
811 };
812 nullbias_matmul_methods[2].fn_generate_rhs = [](size_t rows, size_t cols, SeedFeed& feed) {
813 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
814 };
815 nullbias_matmul_methods[2].fn_generate_bias = [](size_t rows, size_t cols, SeedFeed& feed, bool null_bias_mode) {
816 if (null_bias_mode) {
817 return ConstantGenerator<Float16>(0.0)(rows, cols);
818 } else {
819 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
820 }
821 };
822 nullbias_matmul_methods[2].fn_is_supported = cpu_has_fp16;
823 nullbias_matmul_methods[2].fn_get_nr = kai_get_nr_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla;
824 nullbias_matmul_methods[2].fn_get_kr = kai_get_kr_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla;
825 nullbias_matmul_methods[2].fn_get_sr = kai_get_sr_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla;
826 nullbias_matmul_methods[2].fn_get_main_m_step = kai_get_m_step_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla;
827 nullbias_matmul_methods[2].fn_get_pack_rhs_n_step = kai_get_n_step_rhs_pack_kxn_x16p32x1b_x16_x16_neon;
828 nullbias_matmul_methods[2].fn_get_main_n_step = kai_get_n_step_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla;
829 nullbias_matmul_methods[2].fn_get_lhs_offset = kai_get_lhs_offset_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla;
830 nullbias_matmul_methods[2].fn_get_rhs_offset = kai_get_rhs_offset_rhs_pack_kxn_x16p32x1b_x16_x16_neon;
831 nullbias_matmul_methods[2].fn_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_kxn_x16p32x1b_x16_x16_neon;
832 nullbias_matmul_methods[2].fn_get_pack_rhs_packed_rhs_offset =
833 kai_get_rhs_packed_offset_rhs_pack_kxn_x16p32x1b_x16_x16_neon;
834 nullbias_matmul_methods[2].fn_get_main_packed_rhs_offset =
835 kai_get_rhs_packed_offset_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla;
836 nullbias_matmul_methods[2].fn_pack_rhs = kai_run_rhs_pack_kxn_x16p32x1b_x16_x16_neon;
837 nullbias_matmul_methods[2].fn_pack_rhs_nxk_get_n_step = kai_get_n_step_rhs_pack_nxk_x16p32x1bx16_x16_x16_neon;
838 nullbias_matmul_methods[2].fn_pack_rhs_nxk_get_rhs_offset =
839 kai_get_rhs_offset_rhs_pack_nxk_x16p32x1bx16_x16_x16_neon;
840 nullbias_matmul_methods[2].fn_pack_rhs_nxk_get_bias_offset =
841 kai_get_bias_offset_rhs_pack_nxk_x16p32x1bx16_x16_x16_neon;
842 nullbias_matmul_methods[2].fn_pack_rhs_nxk_get_packed_rhs_offset =
843 kai_get_rhs_packed_offset_rhs_pack_nxk_x16p32x1bx16_x16_x16_neon;
844 nullbias_matmul_methods[2].fn_pack_rhs_nxk_get_packed_rhs_size =
845 kai_get_rhs_packed_size_rhs_pack_nxk_x16p32x1bx16_x16_x16_neon;
846 nullbias_matmul_methods[2].fn_pack_rhs_nxk = kai_run_rhs_pack_nxk_x16p32x1bx16_x16_x16_neon;
847 nullbias_matmul_methods[2].fn_get_bias_offset = kai_get_bias_offset_rhs_pack_kxn_x16p32x1b_x16_x16_neon;
848 nullbias_matmul_methods[2].fn_get_dst_offset = kai_get_dst_offset_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla;
849 nullbias_matmul_methods[2].fn_get_dst_size = kai_get_dst_size_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla;
850 nullbias_matmul_methods[2].fn_matmul_f16_f16_f16p = kai_run_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla;
851
852 nullbias_matmul_methods[3].name = "matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla_cortexa55";
853 nullbias_matmul_methods[3].capabilities = capabilities_pack_rhs_transposed_output;
854 nullbias_matmul_methods[3].m0 = 6;
855 nullbias_matmul_methods[3].n0 = 32;
856 nullbias_matmul_methods[3].dst_format = DataFormat(DataType::FP16);
857 nullbias_matmul_methods[3].lhs_format = DataFormat(DataType::FP16);
858 nullbias_matmul_methods[3].packed_lhs_format = DataFormat(DataType::UNKNOWN);
859 nullbias_matmul_methods[3].rhs_format = DataFormat(DataType::FP16);
860 nullbias_matmul_methods[3].packed_rhs_format = DataFormat(
861 DataType::FP16, 32, 0, DataFormat::PackFormat::BIAS_PER_ROW, DataType::FP16, DataType::UNKNOWN, 32, 1);
862 nullbias_matmul_methods[3].bias_format = DataFormat(DataType::FP16);
863 nullbias_matmul_methods[3].fn_generate_lhs = [](size_t rows, size_t cols, SeedFeed& feed) {
864 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
865 };
866 nullbias_matmul_methods[3].fn_generate_rhs = [](size_t rows, size_t cols, SeedFeed& feed) {
867 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
868 };
869 nullbias_matmul_methods[3].fn_generate_bias = [](size_t rows, size_t cols, SeedFeed& feed, bool null_bias_mode) {
870 if (null_bias_mode) {
871 return ConstantGenerator<Float16>(0.0)(rows, cols);
872 } else {
873 return UniformRandomGenerator<Float16>(-1.0, 1.0, feed())(rows, cols);
874 }
875 };
876 nullbias_matmul_methods[3].fn_is_supported = cpu_has_fp16;
877 nullbias_matmul_methods[3].fn_get_nr = kai_get_nr_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla_cortexa55;
878 nullbias_matmul_methods[3].fn_get_kr = kai_get_kr_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla_cortexa55;
879 nullbias_matmul_methods[3].fn_get_sr = kai_get_sr_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla_cortexa55;
880 nullbias_matmul_methods[3].fn_get_main_m_step =
881 kai_get_m_step_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla_cortexa55;
882 nullbias_matmul_methods[3].fn_get_pack_rhs_n_step = kai_get_n_step_rhs_pack_kxn_x16p32x1b_x16_x16_neon;
883 nullbias_matmul_methods[3].fn_get_main_n_step =
884 kai_get_n_step_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla_cortexa55;
885 nullbias_matmul_methods[3].fn_get_lhs_offset =
886 kai_get_lhs_offset_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla_cortexa55;
887 nullbias_matmul_methods[3].fn_get_rhs_offset = kai_get_rhs_offset_rhs_pack_kxn_x16p32x1b_x16_x16_neon;
888 nullbias_matmul_methods[3].fn_get_packed_rhs_size = kai_get_rhs_packed_size_rhs_pack_kxn_x16p32x1b_x16_x16_neon;
889 nullbias_matmul_methods[3].fn_get_pack_rhs_packed_rhs_offset =
890 kai_get_rhs_packed_offset_rhs_pack_kxn_x16p32x1b_x16_x16_neon;
891 nullbias_matmul_methods[3].fn_get_main_packed_rhs_offset =
892 kai_get_rhs_packed_offset_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla_cortexa55;
893 nullbias_matmul_methods[3].fn_pack_rhs = kai_run_rhs_pack_kxn_x16p32x1b_x16_x16_neon;
894 nullbias_matmul_methods[3].fn_pack_rhs_nxk_get_n_step = kai_get_n_step_rhs_pack_nxk_x16p32x1bx16_x16_x16_neon;
895 nullbias_matmul_methods[3].fn_pack_rhs_nxk_get_rhs_offset =
896 kai_get_rhs_offset_rhs_pack_nxk_x16p32x1bx16_x16_x16_neon;
897 nullbias_matmul_methods[3].fn_pack_rhs_nxk_get_bias_offset =
898 kai_get_bias_offset_rhs_pack_nxk_x16p32x1bx16_x16_x16_neon;
899 nullbias_matmul_methods[3].fn_pack_rhs_nxk_get_packed_rhs_offset =
900 kai_get_rhs_packed_offset_rhs_pack_nxk_x16p32x1bx16_x16_x16_neon;
901 nullbias_matmul_methods[3].fn_pack_rhs_nxk_get_packed_rhs_size =
902 kai_get_rhs_packed_size_rhs_pack_nxk_x16p32x1bx16_x16_x16_neon;
903 nullbias_matmul_methods[3].fn_pack_rhs_nxk = kai_run_rhs_pack_nxk_x16p32x1bx16_x16_x16_neon;
904 nullbias_matmul_methods[3].fn_get_bias_offset = kai_get_bias_offset_rhs_pack_kxn_x16p32x1b_x16_x16_neon;
905 nullbias_matmul_methods[3].fn_get_dst_offset =
906 kai_get_dst_offset_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla_cortexa55;
907 nullbias_matmul_methods[3].fn_get_dst_size =
908 kai_get_dst_size_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla_cortexa55;
909 nullbias_matmul_methods[3].fn_matmul_f16_f16_f16p = kai_run_matmul_clamp_f16_f16_f16p32x1b_6x32_neon_mla_cortexa55;
910
911 return nullbias_matmul_methods;
912}
913
914using MatMulClampTestParams = std::tuple<MatMulMethod, MatMulShape, MatrixPortion, BiasMode, std::optional<float>>;
915
916template <typename Methods>
917static std::vector<MatMulMethod> methods_with_capability(
918 const Methods& methods, const MatMulMethodCapability capability) {
919 std::vector<MatMulMethod> filtered_methods;
920 for (const auto& method : methods) {
921 if (method.has_capability(capability)) {
922 filtered_methods.emplace_back(method);
923 }
924 }
925 return filtered_methods;
926}
927
928template <typename Methods>
929static void expect_method_metadata_is_consistent(const Methods& methods) {
930 for (const auto& method : methods) {
931 SCOPED_TRACE(std::string(method.name));
932
933 EXPECT_FALSE(method.name.empty());
934 EXPECT_TRUE(static_cast<bool>(method.fn_generate_lhs));
935 EXPECT_TRUE(static_cast<bool>(method.fn_generate_rhs));
936 EXPECT_TRUE(static_cast<bool>(method.fn_generate_bias));
937 EXPECT_TRUE(static_cast<bool>(method.fn_is_supported));
938
939 EXPECT_EQ(method.has_capability(MatMulMethodCapability::PACKED_LHS), method.is_pack_lhs_needed());
940 EXPECT_EQ(method.has_capability(MatMulMethodCapability::PACKED_RHS), method.is_pack_rhs_needed());
941 EXPECT_EQ(
942 method.has_capability(MatMulMethodCapability::PACKED_TRANSPOSED_RHS), method.is_pack_rhs_nxk_needed());
943 EXPECT_EQ(method.has_capability(MatMulMethodCapability::OUTPUT), method.has_main_kernel());
944
945 if (method.has_capability(MatMulMethodCapability::PACKED_LHS)) {
946 EXPECT_TRUE(static_cast<bool>(method.fn_pack_lhs));
947 EXPECT_TRUE(static_cast<bool>(method.fn_get_mr));
948 EXPECT_TRUE(static_cast<bool>(method.fn_get_kr));
949 EXPECT_TRUE(static_cast<bool>(method.fn_get_sr));
950 EXPECT_TRUE(static_cast<bool>(method.fn_get_lhs_offset));
951 EXPECT_TRUE(static_cast<bool>(method.fn_get_packed_lhs_size));
952 EXPECT_TRUE(static_cast<bool>(method.fn_get_packed_lhs_offset));
953 }
954
955 if (method.has_capability(MatMulMethodCapability::PACKED_RHS)) {
956 EXPECT_TRUE(static_cast<bool>(method.fn_pack_rhs));
957 EXPECT_TRUE(static_cast<bool>(method.fn_get_nr));
958 EXPECT_TRUE(static_cast<bool>(method.fn_get_kr));
959 EXPECT_TRUE(static_cast<bool>(method.fn_get_sr));
960 EXPECT_TRUE(static_cast<bool>(method.fn_get_pack_rhs_n_step));
961 EXPECT_TRUE(static_cast<bool>(method.fn_get_rhs_offset));
962 EXPECT_TRUE(static_cast<bool>(method.fn_get_packed_rhs_size));
963 EXPECT_TRUE(static_cast<bool>(method.fn_get_pack_rhs_packed_rhs_offset));
964 EXPECT_TRUE(static_cast<bool>(method.fn_get_bias_offset));
965 }
966
967 if (method.has_capability(MatMulMethodCapability::PACKED_TRANSPOSED_RHS)) {
968 EXPECT_TRUE(static_cast<bool>(method.fn_pack_rhs_nxk));
969 EXPECT_TRUE(static_cast<bool>(method.fn_get_nr));
970 EXPECT_TRUE(static_cast<bool>(method.fn_get_kr));
971 EXPECT_TRUE(static_cast<bool>(method.fn_get_sr));
972 EXPECT_TRUE(static_cast<bool>(method.fn_pack_rhs_nxk_get_n_step));
973 EXPECT_TRUE(static_cast<bool>(method.fn_pack_rhs_nxk_get_rhs_offset));
974 EXPECT_TRUE(static_cast<bool>(method.fn_pack_rhs_nxk_get_bias_offset));
975 EXPECT_TRUE(static_cast<bool>(method.fn_pack_rhs_nxk_get_packed_rhs_offset));
976 EXPECT_TRUE(static_cast<bool>(method.fn_pack_rhs_nxk_get_packed_rhs_size));
977 }
978
979 if (method.has_capability(MatMulMethodCapability::OUTPUT)) {
980 EXPECT_TRUE(method.has_main_kernel());
981 EXPECT_TRUE(static_cast<bool>(method.fn_get_main_m_step));
982 EXPECT_TRUE(static_cast<bool>(method.fn_get_main_n_step));
983 EXPECT_TRUE(static_cast<bool>(method.fn_get_dst_offset));
984 EXPECT_TRUE(static_cast<bool>(method.fn_get_dst_size));
985 if (method.has_capability(MatMulMethodCapability::PACKED_RHS)) {
986 EXPECT_TRUE(static_cast<bool>(method.fn_get_main_packed_rhs_offset));
987 }
988 }
989 }
990}
991
992/// Matrix multiplication test fixture.
993class MatMulTestBase : public testing::TestWithParam<MatMulClampTestParams> {
994private:
995 /// Unique ID: m, n, k, method_id.
996 using TestDataId = std::tuple<size_t, size_t, size_t, std::string_view, BiasMode, std::optional<float>, DataType>;
997
998protected:
999 /// Cached test data that is shared between multiple test case.
1000 struct TestData {
1001 Buffer lhs{}; ///< LHS operand.
1002 Buffer ref_packed_lhs{}; ///< Reference packed LHS.
1003 Buffer rhs{}; ///< RHS operand.
1004 Buffer rhs_scales{}; ///< RHS per-row quantization scales.
1005 Buffer bias{}; ///< Bias.
1006 Buffer rhs_t{}; ///< Transposed RHS matrix.
1007 Buffer ref_packed_rhs{}; ///< Reference packed RHS.
1008 Buffer ref_dst{}; ///< Reference output.
1009 float clamp_min{}; ///< Minimum output value.
1010 float clamp_max{}; ///< Maximum output value.
1011 };
1012
1013 /// Gets the test data for the current test case.
1014 static const TestData& test_data() {
1015 const auto& [method, info, portion, bias_mode, clamp_keep_ratio] = GetParam();
1016 const TestDataId data_id{info.m, info.n, info.k, method.name, bias_mode, clamp_keep_ratio, method.acc_dt};
1017
1018 // Creates a unique seed for the test data.
1019 const auto key = std::string(method.name) + "_" + std::to_string(info.m) + "x" + std::to_string(info.n) + "x" +
1020 std::to_string(info.k) + "_" + (bias_mode == BiasMode::INTERNAL ? "internal" : "provided") + "_" +
1021 (clamp_keep_ratio.has_value() ? std::to_string(clamp_keep_ratio.value()) : "noclamp") + "_" +
1022 to_cstring(method.acc_dt);
1023 auto& feed = seed_stream(key);
1024
1025 // If the test data is already available, returns it.
1026 const auto data_it = _data.find(data_id);
1027
1028 if (data_it != _data.end()) {
1029 return data_it->second;
1030 }
1031
1032 // Generates the test data.
1033 const auto has_lhs_pack = method.packed_lhs_format.data_type() != DataType::UNKNOWN;
1034 const auto has_rhs_pack = method.packed_rhs_format.data_type() != DataType::UNKNOWN;
1035 const auto has_bias = method.bias_format.data_type() != DataType::UNKNOWN;
1036 const bool null_bias_mode = bias_mode == BiasMode::INTERNAL;
1037
1038 const auto lhs_h = info.m;
1039 const auto lhs_w = info.k;
1040 auto lhs = method.fn_generate_lhs(lhs_h, lhs_w, feed);
1041
1042 Buffer ref_packed_lhs;
1043 if (has_lhs_pack) {
1044 ref_packed_lhs =
1045 pack(method.packed_lhs_format, lhs.data(), nullptr, nullptr, method.lhs_format, lhs_h, lhs_w);
1046 }
1047
1048 const auto rhs_h = info.k;
1049 const auto rhs_w = info.n;
1050 auto rhs = method.fn_generate_rhs(rhs_h, rhs_w, feed);
1051
1052 KAI_ASSUME_ALWAYS(method.rhs_format.is_raw());
1053 auto rhs_t = transpose(rhs.data(), method.rhs_format.data_type(), rhs_h, rhs_w);
1054
1055 Buffer rhs_scales;
1056 if (data_type_is_quantized(method.rhs_format.data_type()) &&
1057 method.rhs_format.pack_format() == DataFormat::PackFormat::NONE) {
1058 rhs_scales = fill_matrix_random(rhs_h, 1, DataFormat(DataType::FP32), feed());
1059 }
1060
1061 const auto bias_h = 1;
1062 const auto bias_w = info.n;
1063 Buffer bias;
1064
1065 if (has_bias) {
1066 bias = method.fn_generate_bias(bias_h, bias_w, feed, null_bias_mode);
1067 }
1068
1069 Buffer packed_rhs;
1070 if (has_rhs_pack) {
1071 packed_rhs = matmul_pack_rhs(
1072 rhs.data(), rhs_scales.data(), bias.data(), method.rhs_format, method.packed_rhs_format, info.n, info.k,
1073 true);
1074 }
1075
1076 KAI_ASSUME_ALWAYS(method.lhs_format.is_raw());
1077 KAI_ASSUME_ALWAYS(method.rhs_format.is_raw());
1078 KAI_ASSUME_ALWAYS(method.dst_format.is_raw());
1079 auto ref_dst = matmul(
1080 lhs.data(), nullptr, nullptr, method.lhs_format.data_type(), //
1081 rhs.data(), rhs_scales.data(), nullptr, method.rhs_format.data_type(), //
1082 bias.data(), nullptr, nullptr, method.bias_format.data_type(), //
1083 method.dst_format.data_type(), //
1084 info.m, info.n, info.k, false, false, method.acc_dt);
1085
1086 const auto [clamp_min, clamp_max] =
1087 find_clamp_range(method.dst_format.data_type(), ref_dst.data(), info.m * info.n, clamp_keep_ratio);
1088 ref_dst = clamp(method.dst_format.data_type(), ref_dst.data(), info.m * info.n, clamp_min, clamp_max);
1089
1090 auto& data = _data[data_id] = {};
1091 data.lhs = std::move(lhs);
1092 data.ref_packed_lhs = std::move(ref_packed_lhs);
1093 data.rhs = std::move(rhs);
1094 data.rhs_scales = std::move(rhs_scales);
1095 data.bias = std::move(bias);
1096 data.rhs_t = std::move(rhs_t);
1097 data.ref_packed_rhs = std::move(packed_rhs);
1098 data.ref_dst = std::move(ref_dst);
1099 data.clamp_min = clamp_min;
1100 data.clamp_max = clamp_max;
1101
1102 return data;
1103 }
1104
1105private:
1106 // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
1107 static std::map<TestDataId, TestData> _data;
1108 // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
1109};
1110
1111// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
1112std::map<MatMulTestBase::TestDataId, MatMulTestBase::TestData> MatMulTestBase::_data;
1113// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
1114
1115class MatMulPackedLhsTest : public MatMulTestBase {};
1116class MatMulPackedRhsTest : public MatMulTestBase {};
1117class MatMulPackedTransposedRhsTest : public MatMulTestBase {};
1118class MatMulOutputTest : public MatMulTestBase {};
1119
1120// Capability filtering happens during parameter generation, so inconsistent
1121// method metadata can silently omit tests. Keep this guard automatic rather
1122// than pinning exact method lists.
1123TEST(MatMulMethodMetadataTest, MethodCapabilityMetadataIsConsistent) {
1124 expect_method_metadata_is_consistent(get_matmul_methods());
1125 expect_method_metadata_is_consistent(get_nullbias_matmul_methods());
1126 expect_method_metadata_is_consistent(get_vecmul_methods());
1127}
1128
1129/// Tests the LHS packing micro-kernel.
1130TEST_P(MatMulPackedLhsTest, PackedLhs) {
1131 const auto& [method, info, portion, bias_mode, clamp_keep_ratio] = GetParam();
1132
1133 if (method.fn_is_supported && !method.fn_is_supported()) {
1134 GTEST_SKIP() << "Unsupported CPU feature";
1135 }
1136
1137 ASSERT_TRUE(method.is_pack_lhs_needed());
1138
1139 const auto& data = test_data();
1140 const auto lhs_h = info.m;
1141 const auto lhs_w = info.k;
1142
1143 const auto rect = portion.compute_portion(
1144 lhs_h, lhs_w, method.packed_lhs_format.scheduler_block_height(lhs_h),
1145 lhs_w); // LHS packing micro-kernel API doesn't support scheduling over K dimension.
1146
1147 if (rect.height() == 0 || rect.width() == 0) {
1148 GTEST_SKIP() << "Empty dimension of matrix(" << rect.width() << "," << rect.height() << ")";
1149 }
1150
1151 const auto mr = method.fn_get_mr();
1152 const auto kr = method.fn_get_kr();
1153 const auto sr = method.fn_get_sr();
1154 const auto ref_lhs_row_stride = method.lhs_format.default_row_stride(lhs_w);
1155
1156 const auto packed_lhs_size = method.fn_get_packed_lhs_size(info.m, info.k, mr, kr, sr);
1157 const auto ref_packed_lhs_size = method.packed_lhs_format.default_size_in_bytes(lhs_h, lhs_w);
1158 ASSERT_EQ(packed_lhs_size, ref_packed_lhs_size);
1159
1160 const auto lhs_offset = method.fn_get_lhs_offset(rect.start_row(), ref_lhs_row_stride);
1161 const auto ref_lhs_offset = method.lhs_format.default_offset_in_bytes(rect.start_row(), rect.start_col(), lhs_w);
1162 ASSERT_EQ(lhs_offset, ref_lhs_offset);
1163
1164 const auto packed_lhs_offset = method.fn_get_packed_lhs_offset(rect.start_row(), info.k);
1165 const auto ref_packed_lhs_offset = method.packed_lhs_format.default_offset_in_bytes(rect.start_row(), 0, lhs_w);
1166 ASSERT_EQ(packed_lhs_offset, ref_packed_lhs_offset);
1167
1168 Buffer packed_lhs(packed_lhs_size, 0);
1169 abi_check(
1170 method.fn_pack_lhs, rect.height(), rect.width(), mr, kr, sr, 0, data.lhs.data() + lhs_offset,
1171 ref_lhs_row_stride, packed_lhs.data() + packed_lhs_offset);
1172
1173 DefaultMismatchHandler handler(0, 0.0001, 0, 0.001);
1174 const auto success =
1175 compare(packed_lhs.data(), data.ref_packed_lhs.data(), method.packed_lhs_format, lhs_h, lhs_w, rect, handler);
1176 ASSERT_TRUE(success);
1177}
1178
1179/// Tests the RHS packing micro-kernel.
1180TEST_P(MatMulPackedRhsTest, PackedRhs) {
1181 const auto& [method, info, portion, bias_mode, clamp_keep_ratio] = GetParam();
1182
1183 if (method.fn_is_supported && !method.fn_is_supported()) {
1184 GTEST_SKIP() << "Unsupported CPU feature";
1185 }
1186
1187 ASSERT_TRUE(method.is_pack_rhs_needed());
1188
1189 const auto& data = test_data();
1190 const auto rhs_full_width = info.n;
1191 const auto rhs_full_height = info.k;
1192
1193 const auto block_height = method.packed_rhs_format.scheduler_block_height(rhs_full_width);
1194 const auto block_width = method.packed_rhs_format.scheduler_block_width(rhs_full_height);
1195
1196 const auto null_bias_mode = bias_mode == BiasMode::INTERNAL;
1197
1198 const Rect rect = portion.compute_portion(rhs_full_width, rhs_full_height, block_height, block_width);
1199
1200 if (rect.height() == 0 || rect.width() == 0) {
1201 GTEST_SKIP() << "Empty dimension of matrix(" << rect.width() << "," << rect.height() << ")";
1202 }
1203
1204 const auto rhs_start_row = rect.start_row();
1205 const auto rhs_start_col = rect.start_col();
1206 const auto width = rect.width();
1207 const auto height = rect.height();
1208 const auto rhs_row_stride = method.rhs_format.default_row_stride(rhs_full_width);
1209
1210 /** Ensure that all relevant parameters are sane **/
1211 const auto n_step = method.fn_get_pack_rhs_n_step();
1212 const auto ref_n_step = block_height;
1213 ASSERT_EQ(n_step, ref_n_step);
1214
1215 const auto rhs_offset = method.fn_get_rhs_offset(rhs_start_row);
1216 const auto ref_rhs_offset =
1217 method.rhs_format.default_offset_in_bytes(rhs_start_col, rhs_start_row, rhs_full_height);
1218 ASSERT_EQ(rhs_offset, ref_rhs_offset);
1219
1220 const auto packed_rhs_size = method.fn_get_packed_rhs_size(rhs_full_width, rhs_full_height);
1221 const auto ref_packed_rhs_size = method.packed_rhs_format.default_size_in_bytes(rhs_full_width, rhs_full_height);
1222 ASSERT_EQ(packed_rhs_size, ref_packed_rhs_size);
1223
1224 const auto packed_rhs_offset = method.fn_get_pack_rhs_packed_rhs_offset(rhs_start_row, rhs_full_height);
1225 const auto ref_packed_rhs_offset =
1226 method.packed_rhs_format.default_offset_in_bytes(rhs_start_row, rhs_start_col, rhs_full_height);
1227 ASSERT_EQ(packed_rhs_offset, ref_packed_rhs_offset);
1228
1229 size_t ref_rhs_scales_offset = 0;
1230 if (data.rhs_scales.size() != 0) {
1231 const auto scale_type = method.packed_rhs_format.scale_data_type();
1232 ref_rhs_scales_offset = rhs_start_row * data_type_size_in_bits(scale_type) / 8;
1233 }
1234
1235 const auto bias_offset = method.fn_get_bias_offset(rhs_start_row);
1236 const auto ref_bias_offset =
1237 !null_bias_mode ? method.bias_format.default_offset_in_bytes(0, rhs_start_row, rhs_full_height) : bias_offset;
1238 ASSERT_EQ(bias_offset, ref_bias_offset);
1239
1240 /** Perform RHS packing, and compare with reference result **/
1241 Buffer packed_rhs(packed_rhs_size, 0);
1242 abi_check(
1243 &MatMulMethod::pack_rhs, method, height, width, data.rhs.data() + rhs_offset, rhs_row_stride,
1244 !null_bias_mode ? data.bias.data() + bias_offset : nullptr,
1245 data.rhs_scales.data() != nullptr ? data.rhs_scales.data() + ref_rhs_scales_offset : nullptr,
1246 packed_rhs.data() + packed_rhs_offset);
1247
1248 const bool exact = method.packed_rhs_format.pack_format() != DataFormat::PackFormat::QUANTIZE_PER_ROW;
1249 DefaultMismatchHandler handler(0, exact ? 0 : 0.0001, 0, exact ? 0 : 0.001);
1250 const auto success = compare(
1251 packed_rhs.data(), data.ref_packed_rhs.data(), method.packed_rhs_format, rhs_full_width, rhs_full_height, rect,
1252 handler);
1253 ASSERT_TRUE(success);
1254}
1255
1256/// Tests the transposed RHS packing micro-kernel.
1257TEST_P(MatMulPackedTransposedRhsTest, PackedTransposedRhs) {
1258 const auto& [method, info, portion, bias_mode, clamp_keep_ratio] = GetParam();
1259
1260 if (method.fn_is_supported && !method.fn_is_supported()) {
1261 GTEST_SKIP() << "Unsupported CPU feature";
1262 }
1263
1264 ASSERT_TRUE(method.is_pack_rhs_nxk_needed());
1265
1266 const auto& data = test_data();
1267 const bool null_bias_mode = bias_mode == BiasMode::INTERNAL;
1268
1269 const auto n_step = method.fn_pack_rhs_nxk_get_n_step();
1270 const auto ref_n_step = method.packed_rhs_format.scheduler_block_height(info.n);
1271 ASSERT_EQ(n_step, ref_n_step);
1272
1273 const auto rect = portion.compute_portion(
1274 info.n, info.k, method.packed_rhs_format.scheduler_block_height(info.n),
1275 method.packed_rhs_format.scheduler_block_width(info.k));
1276
1277 if (rect.height() == 0 || rect.width() == 0) {
1278 GTEST_SKIP() << "Empty dimension of matrix(" << rect.width() << "," << rect.height() << ")";
1279 }
1280
1281 const auto ref_rhs_row_stride = method.rhs_format.default_row_stride(info.k);
1282
1283 const auto rhs_offset = method.fn_pack_rhs_nxk_get_rhs_offset(rect.start_row(), ref_rhs_row_stride);
1284 const auto ref_rhs_offset = method.rhs_format.default_offset_in_bytes(rect.start_row(), rect.start_col(), info.k);
1285 ASSERT_EQ(rhs_offset, ref_rhs_offset);
1286
1287 const auto packed_rhs_size = method.fn_pack_rhs_nxk_get_packed_rhs_size(info.n, info.k);
1288 const auto ref_packed_rhs_size = method.packed_rhs_format.default_size_in_bytes(info.n, info.k);
1289 ASSERT_EQ(packed_rhs_size, ref_packed_rhs_size);
1290
1291 const auto packed_rhs_offset = method.fn_pack_rhs_nxk_get_packed_rhs_offset(rect.start_row(), info.k);
1292 const auto ref_packed_rhs_offset =
1293 method.packed_rhs_format.default_offset_in_bytes(rect.start_row(), rect.start_col(), info.k);
1294 ASSERT_EQ(packed_rhs_offset, ref_packed_rhs_offset);
1295
1296 size_t ref_rhs_scales_offset = 0;
1297 if (data.rhs_scales.size() != 0) {
1298 ref_rhs_scales_offset =
1299 rect.start_row() * data_type_size_in_bits(method.packed_rhs_format.scale_data_type()) / 8;
1300 }
1301
1302 const auto bias_offset = method.fn_get_bias_offset(rect.start_row());
1303 const auto ref_bias_offset =
1304 !null_bias_mode ? method.bias_format.default_offset_in_bytes(0, rect.start_row(), info.n) : bias_offset;
1305 ASSERT_EQ(bias_offset, ref_bias_offset);
1306
1307 Buffer packed_rhs(packed_rhs_size, 0);
1308
1309 abi_check(
1310 &MatMulMethod::pack_rhs_nxk, method, rect.height(), rect.width(), data.rhs_t.data() + rhs_offset,
1311 ref_rhs_row_stride, null_bias_mode ? nullptr : data.bias.data() + bias_offset,
1312 data.rhs_scales.data() != nullptr ? data.rhs_scales.data() + ref_rhs_scales_offset : nullptr,
1313 packed_rhs.data() + packed_rhs_offset);
1314
1315 const auto exact = method.packed_rhs_format.pack_format() != DataFormat::PackFormat::QUANTIZE_PER_ROW;
1316 DefaultMismatchHandler handler(0, exact ? 0 : 0.0001, 0, exact ? 0 : 0.001);
1317 const auto success =
1318 compare(packed_rhs.data(), data.ref_packed_rhs.data(), method.packed_rhs_format, info.n, info.k, rect, handler);
1319 ASSERT_TRUE(success);
1320}
1321
1322/// Tests the output.
1323TEST_P(MatMulOutputTest, Output) {
1324 const auto& [method, info, portion, bias_mode, clamp_keep_ratio] = GetParam();
1325
1326 if (method.fn_is_supported && !method.fn_is_supported()) {
1327 GTEST_SKIP() << "Unsupported CPU feature";
1328 }
1329
1330 ASSERT_TRUE(method.has_main_kernel());
1331
1332 const auto& data = test_data();
1333 const auto m_step = method.fn_get_main_m_step();
1334 ASSERT_EQ(m_step, method.m0);
1335
1336 const auto n_step = method.fn_get_main_n_step();
1337 ASSERT_EQ(n_step, method.n0);
1338
1339 const auto rect = portion.compute_portion(info.m, info.n, method.m0, method.n0);
1340
1341 if (rect.height() == 0 || rect.width() == 0) {
1342 GTEST_SKIP() << "Empty dimension of matrix(" << rect.width() << "," << rect.height() << ")";
1343 }
1344
1345 const auto lhs_w = info.k;
1346 const auto rhs_w = info.n;
1347 const auto bias_w = info.n;
1348 const auto dst_w = info.n;
1349
1350 const bool null_bias_mode = bias_mode == BiasMode::INTERNAL;
1351
1352 const auto lhs_start_row = rect.start_row();
1353 const auto lhs_start_col = 0;
1354 const auto lhs_stride = method.lhs_format.default_row_stride(lhs_w);
1355
1356 const std::byte* lhs_data = nullptr;
1357 uintptr_t lhs_offset = 0;
1358
1359 if (method.is_pack_lhs_needed()) {
1360 lhs_data = data.ref_packed_lhs.data();
1361
1362 const auto ref_packed_lhs_offset =
1363 method.packed_lhs_format.default_offset_in_bytes(lhs_start_row, lhs_start_col, info.k);
1364 lhs_offset = method.fn_get_packed_lhs_offset(lhs_start_row, info.k);
1365 ASSERT_EQ(lhs_offset, ref_packed_lhs_offset);
1366 } else {
1367 lhs_data = data.lhs.data();
1368
1369 lhs_offset = method.fn_get_lhs_offset(lhs_start_row, lhs_stride);
1370 const auto ref_lhs_offset = method.lhs_format.default_offset_in_bytes(lhs_start_row, lhs_start_col, lhs_w);
1371 ASSERT_EQ(lhs_offset, ref_lhs_offset);
1372 }
1373
1374 const auto rhs_stride = method.rhs_format.default_row_stride(rhs_w);
1375
1376 const std::byte* rhs_data = nullptr;
1377 uintptr_t rhs_offset = 0;
1378
1379 if (method.is_pack_rhs_needed()) {
1380 const auto packed_rhs_start_row = rect.start_col();
1381 const auto packed_rhs_start_col = 0;
1382
1383 rhs_data = data.ref_packed_rhs.data();
1384
1385 rhs_offset = method.fn_get_main_packed_rhs_offset(packed_rhs_start_row, info.k);
1386 const auto ref_rhs_offset =
1387 method.packed_rhs_format.default_offset_in_bytes(packed_rhs_start_row, packed_rhs_start_col, info.k);
1388 ASSERT_EQ(rhs_offset, ref_rhs_offset);
1389 } else {
1390 const auto rhs_start_row = 0;
1391 const auto rhs_start_col = rect.start_col();
1392
1393 rhs_data = data.rhs.data();
1394 rhs_offset = method.rhs_format.default_offset_in_bytes(rhs_start_row, rhs_start_col, rhs_w);
1395 }
1396
1397 const std::byte* bias_data = nullptr;
1398 if (!null_bias_mode) {
1399 const auto bias_offset = method.bias_format.default_offset_in_bytes(0, rect.start_row(), bias_w);
1400 bias_data = data.bias.data() + bias_offset;
1401 }
1402
1403 const auto dst_stride = method.dst_format.default_row_stride(dst_w);
1404 const auto dst_offset = method.fn_get_dst_offset(rect.start_row(), rect.start_col(), dst_stride);
1405 const auto ref_dst_offset = method.dst_format.default_offset_in_bytes(rect.start_row(), rect.start_col(), dst_w);
1406 ASSERT_EQ(dst_offset, ref_dst_offset);
1407
1408 const auto dst_size = method.fn_get_dst_size(info.m, info.n);
1409 const auto ref_dst_size = method.dst_format.default_size_in_bytes(info.m, info.n);
1410 ASSERT_EQ(dst_size, ref_dst_size);
1411
1412 Buffer dst(dst_size, 0);
1413
1414 abi_check(
1415 &MatMulMethod::main_kernel, method, rect.height(), rect.width(), info.k, lhs_data + lhs_offset,
1416 rhs_data + rhs_offset, bias_data, dst.data() + dst_offset, lhs_stride, rhs_stride, dst_stride, data.clamp_min,
1417 data.clamp_max);
1418
1419 DefaultMismatchHandler handler(0, 0.1, 0, 0.1);
1420 const auto success = compare(dst.data(), data.ref_dst.data(), method.dst_format, info.m, info.n, rect, handler);
1421 ASSERT_TRUE(success);
1422}
1423
1424const std::vector<MatrixPortion> MatrixPortions = {
1425 {0, 0, 1, 1},
1426 {0, 0, 0.25, 0.25},
1427 {0.75, 0.75, 1, 1},
1428};
1429const std::vector<MatMulShape> MatMulShapes = {
1430 {1, 16, 16}, //
1431 {20, 1, 20}, //
1432 {6, 16, 32}, //
1433 {12, 32, 17}, //
1434 {13, 33, 23}, //
1435 {87, 93, 56}, //
1436};
1437
1438const std::vector<MatMulShape> VecMulShapes = {
1439 {1, 16, 16}, //
1440 {1, 1, 20}, //
1441 {1, 16, 32}, //
1442 {1, 32, 17}, //
1443 {1, 33, 23}, //
1444 {1, 1500, 20}, //
1445 {1, 93, 56}, //
1446 {1, 1, 1}, //
1447 {1, 16, 1}, //
1448 {1, 32, 64}, //
1449 {1, 7, 74}, //
1450 {1, 800, 64}, //
1451 {1, 512, 130} //
1452};
1453
1454const std::vector<MatrixPortion> VecMulPortions = {
1455 {0, 0, 1, 1}, // Full row.
1456 {0, 0, 1, 0.5}, // First half
1457 {0, .4, 1, 0.3}, // mid row-section.
1458 {0, 0.75, 1, .25} // right row section
1459};
1460
1461INSTANTIATE_TEST_SUITE_P(
1462 MatMul, MatMulPackedLhsTest,
1463 testing::Combine(
1464 testing::ValuesIn(methods_with_capability(get_matmul_methods(), MatMulMethodCapability::PACKED_LHS)),
1465 testing::ValuesIn(MatMulShapes), testing::ValuesIn(MatrixPortions), testing::Values(BiasMode::PROVIDED),
1466 testing::ValuesIn(std::initializer_list<std::optional<float>>{
1467 std::nullopt, // Disable clamping
1468 1.0f, // Clamp to full range
1469 0.9f, // Clamp to 90% range
1470 0.5f})), // Clamp to 50% range
1471 testing::PrintToStringParamName());
1472
1473INSTANTIATE_TEST_SUITE_P(
1474 NullBiasMatMul, MatMulPackedLhsTest,
1475 testing::Combine(
1476 testing::ValuesIn(methods_with_capability(get_nullbias_matmul_methods(), MatMulMethodCapability::PACKED_LHS)),
1477 testing::ValuesIn(MatMulShapes), testing::ValuesIn(MatrixPortions),
1478 testing::Values(BiasMode::INTERNAL, BiasMode::PROVIDED),
1479 testing::ValuesIn(std::initializer_list<std::optional<float>>{
1480 std::nullopt, // Disable clamping
1481 1.0f, // Clamp to full range
1482 0.9f, // Clamp to 90% range
1483 0.5f})), // Clamp to 50% range
1484 testing::PrintToStringParamName());
1485
1486INSTANTIATE_TEST_SUITE_P(
1487 VecMul, MatMulPackedLhsTest,
1488 testing::Combine(
1489 testing::ValuesIn(methods_with_capability(get_vecmul_methods(), MatMulMethodCapability::PACKED_LHS)),
1490 testing::ValuesIn(VecMulShapes), testing::ValuesIn(VecMulPortions), testing::Values(BiasMode::PROVIDED),
1491 testing::ValuesIn(std::initializer_list<std::optional<float>>{
1492 std::nullopt, // Disable clamping
1493 1.0f, // Clamp to full range
1494 0.9f, // Clamp to 90% range
1495 0.5f})), // Clamp to 50% range
1496 testing::PrintToStringParamName());
1497
1498INSTANTIATE_TEST_SUITE_P(
1499 MatMul, MatMulPackedRhsTest,
1500 testing::Combine(
1501 testing::ValuesIn(methods_with_capability(get_matmul_methods(), MatMulMethodCapability::PACKED_RHS)),
1502 testing::ValuesIn(MatMulShapes), testing::ValuesIn(MatrixPortions), testing::Values(BiasMode::PROVIDED),
1503 testing::ValuesIn(std::initializer_list<std::optional<float>>{
1504 std::nullopt, // Disable clamping
1505 1.0f, // Clamp to full range
1506 0.9f, // Clamp to 90% range
1507 0.5f})), // Clamp to 50% range
1508 testing::PrintToStringParamName());
1509
1510INSTANTIATE_TEST_SUITE_P(
1511 NullBiasMatMul, MatMulPackedRhsTest,
1512 testing::Combine(
1513 testing::ValuesIn(methods_with_capability(get_nullbias_matmul_methods(), MatMulMethodCapability::PACKED_RHS)),
1514 testing::ValuesIn(MatMulShapes), testing::ValuesIn(MatrixPortions),
1515 testing::Values(BiasMode::INTERNAL, BiasMode::PROVIDED),
1516 testing::ValuesIn(std::initializer_list<std::optional<float>>{
1517 std::nullopt, // Disable clamping
1518 1.0f, // Clamp to full range
1519 0.9f, // Clamp to 90% range
1520 0.5f})), // Clamp to 50% range
1521 testing::PrintToStringParamName());
1522
1523INSTANTIATE_TEST_SUITE_P(
1524 VecMul, MatMulPackedRhsTest,
1525 testing::Combine(
1526 testing::ValuesIn(methods_with_capability(get_vecmul_methods(), MatMulMethodCapability::PACKED_RHS)),
1527 testing::ValuesIn(VecMulShapes), testing::ValuesIn(VecMulPortions), testing::Values(BiasMode::PROVIDED),
1528 testing::ValuesIn(std::initializer_list<std::optional<float>>{
1529 std::nullopt, // Disable clamping
1530 1.0f, // Clamp to full range
1531 0.9f, // Clamp to 90% range
1532 0.5f})), // Clamp to 50% range
1533 testing::PrintToStringParamName());
1534
1535INSTANTIATE_TEST_SUITE_P(
1536 MatMul, MatMulPackedTransposedRhsTest,
1537 testing::Combine(
1538 testing::ValuesIn(methods_with_capability(get_matmul_methods(), MatMulMethodCapability::PACKED_TRANSPOSED_RHS)),
1539 testing::ValuesIn(MatMulShapes), testing::ValuesIn(MatrixPortions), testing::Values(BiasMode::PROVIDED),
1540 testing::ValuesIn(std::initializer_list<std::optional<float>>{
1541 std::nullopt, // Disable clamping
1542 1.0f, // Clamp to full range
1543 0.9f, // Clamp to 90% range
1544 0.5f})), // Clamp to 50% range
1545 testing::PrintToStringParamName());
1546
1547INSTANTIATE_TEST_SUITE_P(
1548 NullBiasMatMul, MatMulPackedTransposedRhsTest,
1549 testing::Combine(
1550 testing::ValuesIn(
1551 methods_with_capability(get_nullbias_matmul_methods(), MatMulMethodCapability::PACKED_TRANSPOSED_RHS)),
1552 testing::ValuesIn(MatMulShapes), testing::ValuesIn(MatrixPortions),
1553 testing::Values(BiasMode::INTERNAL, BiasMode::PROVIDED),
1554 testing::ValuesIn(std::initializer_list<std::optional<float>>{
1555 std::nullopt, // Disable clamping
1556 1.0f, // Clamp to full range
1557 0.9f, // Clamp to 90% range
1558 0.5f})), // Clamp to 50% range
1559 testing::PrintToStringParamName());
1560
1561INSTANTIATE_TEST_SUITE_P(
1562 VecMul, MatMulPackedTransposedRhsTest,
1563 testing::Combine(
1564 testing::ValuesIn(methods_with_capability(get_vecmul_methods(), MatMulMethodCapability::PACKED_TRANSPOSED_RHS)),
1565 testing::ValuesIn(VecMulShapes), testing::ValuesIn(VecMulPortions), testing::Values(BiasMode::PROVIDED),
1566 testing::ValuesIn(std::initializer_list<std::optional<float>>{
1567 std::nullopt, // Disable clamping
1568 1.0f, // Clamp to full range
1569 0.9f, // Clamp to 90% range
1570 0.5f})), // Clamp to 50% range
1571 testing::PrintToStringParamName());
1572
1573INSTANTIATE_TEST_SUITE_P(
1574 MatMul, MatMulOutputTest,
1575 testing::Combine(
1576 testing::ValuesIn(methods_with_capability(get_matmul_methods(), MatMulMethodCapability::OUTPUT)),
1577 testing::ValuesIn(MatMulShapes), testing::ValuesIn(MatrixPortions), testing::Values(BiasMode::PROVIDED),
1578 testing::ValuesIn(std::initializer_list<std::optional<float>>{
1579 std::nullopt, // Disable clamping
1580 1.0f, // Clamp to full range
1581 0.9f, // Clamp to 90% range
1582 0.5f})), // Clamp to 50% range
1583 testing::PrintToStringParamName());
1584
1585INSTANTIATE_TEST_SUITE_P(
1586 NullBiasMatMul, MatMulOutputTest,
1587 testing::Combine(
1588 testing::ValuesIn(methods_with_capability(get_nullbias_matmul_methods(), MatMulMethodCapability::OUTPUT)),
1589 testing::ValuesIn(MatMulShapes), testing::ValuesIn(MatrixPortions),
1590 testing::Values(BiasMode::INTERNAL, BiasMode::PROVIDED),
1591 testing::ValuesIn(std::initializer_list<std::optional<float>>{
1592 std::nullopt, // Disable clamping
1593 1.0f, // Clamp to full range
1594 0.9f, // Clamp to 90% range
1595 0.5f})), // Clamp to 50% range
1596 testing::PrintToStringParamName());
1597
1598INSTANTIATE_TEST_SUITE_P(
1599 VecMul, MatMulOutputTest,
1600 testing::Combine(
1601 testing::ValuesIn(methods_with_capability(get_vecmul_methods(), MatMulMethodCapability::OUTPUT)),
1602 testing::ValuesIn(VecMulShapes), testing::ValuesIn(VecMulPortions), testing::Values(BiasMode::PROVIDED),
1603 testing::ValuesIn(std::initializer_list<std::optional<float>>{
1604 std::nullopt, // Disable clamping
1605 1.0f, // Clamp to full range
1606 0.9f, // Clamp to 90% range
1607 0.5f})), // Clamp to 50% range
1608 testing::PrintToStringParamName());
1609
1610} // namespace kai::test