blob: f662089c779e06e6776c50e938a66c97e8b9c32d [file] [log] [blame]
Gian Marco Iodice926afe12019-03-19 11:44:13 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 Arm Limited.
Gian Marco Iodice926afe12019-03-19 11:44:13 +00003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/core/CL/gemm/reshaped_only_rhs/CLGEMMReshapedOnlyRHSKernelConfigurationBifrost.h"
25
26#include "arm_compute/core/CL/CLHelpers.h"
27#include "arm_compute/core/CL/CLKernelLibrary.h"
28#include "arm_compute/core/CL/gemm/CLGEMMHelpers.h"
29#include "arm_compute/core/GPUTarget.h"
30
31#include <map>
32#include <utility>
33
34namespace arm_compute
35{
36namespace cl_gemm
37{
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +000038CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::CLGEMMReshapedOnlyRHSKernelConfigurationBifrost(GPUTarget gpu)
39 : ICLGEMMKernelConfiguration(gpu)
Gian Marco Iodice926afe12019-03-19 11:44:13 +000040{
41}
42
43std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure(unsigned int m, unsigned int n, unsigned int k, unsigned int b, DataType data_type)
44{
Gian Marco Iodice926afe12019-03-19 11:44:13 +000045 using ConfigurationFunctionExecutorPtr = std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> (CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::*)(unsigned int m, unsigned int n, unsigned int k,
46 unsigned int b);
47
Gian Marco Iodiceee6454a2019-09-17 10:56:51 +010048 // Configurations for Mali-G51
49 static std::map<DataType, ConfigurationFunctionExecutorPtr> gemm_configs_G51 =
50 {
51 { DataType::F32, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_f32 },
Gian Marco Iodice0d548042019-10-03 15:12:09 +010052 { DataType::F16, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_f16 },
Gian Marco Iodiceeb65f6d2020-04-15 11:42:15 +010053 { DataType::QASYMM8, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_u8 },
54 { DataType::QSYMM8, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_u8 },
55 { DataType::QASYMM8_SIGNED, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_u8 },
56 { DataType::QSYMM8_PER_CHANNEL, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_u8 }
Gian Marco Iodiceee6454a2019-09-17 10:56:51 +010057 };
58
Gian Marco Iodice926afe12019-03-19 11:44:13 +000059 // Configurations for Mali-G76
60 static std::map<DataType, ConfigurationFunctionExecutorPtr> gemm_configs_G76 =
61 {
62 { DataType::F32, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_f32 },
Gian Marco Iodice0d548042019-10-03 15:12:09 +010063 { DataType::F16, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_f16 },
Gian Marco Iodiceeb65f6d2020-04-15 11:42:15 +010064 { DataType::QASYMM8, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_u8 },
65 { DataType::QSYMM8, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_u8 },
66 { DataType::QASYMM8_SIGNED, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_u8 },
67 { DataType::QSYMM8_PER_CHANNEL, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_u8 }
Gian Marco Iodice926afe12019-03-19 11:44:13 +000068 };
69
70 // Configurations for Mali-G7x
71 static std::map<DataType, ConfigurationFunctionExecutorPtr> gemm_configs_G7x =
72 {
73 { DataType::F32, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_f32 },
Gian Marco Iodice0d548042019-10-03 15:12:09 +010074 { DataType::F16, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_f16 },
Gian Marco Iodiceeb65f6d2020-04-15 11:42:15 +010075 { DataType::QASYMM8, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_u8 },
76 { DataType::QSYMM8, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_u8 },
77 { DataType::QASYMM8_SIGNED, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_u8 },
78 { DataType::QSYMM8_PER_CHANNEL, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_u8 }
Gian Marco Iodice926afe12019-03-19 11:44:13 +000079 };
80
81 switch(_target)
82 {
83 case GPUTarget::G76:
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +000084 if(gemm_configs_G76.find(data_type) != gemm_configs_G76.end())
Gian Marco Iodice0d548042019-10-03 15:12:09 +010085 {
86 return (this->*gemm_configs_G76[data_type])(m, n, k, b);
87 }
88 else
89 {
90 ARM_COMPUTE_ERROR("Not supported data type");
91 }
Gian Marco Iodiceee6454a2019-09-17 10:56:51 +010092 case GPUTarget::G51:
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +000093 if(gemm_configs_G51.find(data_type) != gemm_configs_G51.end())
Gian Marco Iodice0d548042019-10-03 15:12:09 +010094 {
95 return (this->*gemm_configs_G51[data_type])(m, n, k, b);
96 }
97 else
98 {
99 ARM_COMPUTE_ERROR("Not supported data type");
100 }
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000101 default:
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +0000102 if(gemm_configs_G7x.find(data_type) != gemm_configs_G7x.end())
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100103 {
104 return (this->*gemm_configs_G7x[data_type])(m, n, k, b);
105 }
106 else
107 {
108 ARM_COMPUTE_ERROR("Not supported data type");
109 }
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000110 }
111}
112
113std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
114{
115 ARM_COMPUTE_UNUSED(k);
116 ARM_COMPUTE_UNUSED(b);
117
118 if(m == 1)
119 {
120 if(n > 2048)
121 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100122 const unsigned int h0 = std::max(n / 4, 1U);
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000123 return configure_lhs_rhs_info(m, n, 1, 4, 4, 1, h0, false, true, false, true);
124 }
125 else
126 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100127 const unsigned int h0 = std::max(n / 2, 1U);
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000128 return configure_lhs_rhs_info(m, n, 1, 2, 8, 1, h0, false, true, false, true);
129 }
130 }
131 else
132 {
133 return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 4, false, true, false, true);
134 }
135}
136
137std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
138{
139 ARM_COMPUTE_UNUSED(k);
140 ARM_COMPUTE_UNUSED(b);
141
142 if(m == 1)
143 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100144 const unsigned int h0 = std::max(n / 2, 1U);
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000145 return configure_lhs_rhs_info(m, n, 1, 2, 8, 1, h0, false, true, false, true);
146 }
147 else
148 {
149 return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, true, false, true);
150 }
151}
152
Gian Marco Iodiceee6454a2019-09-17 10:56:51 +0100153std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
154{
155 ARM_COMPUTE_UNUSED(k);
156 ARM_COMPUTE_UNUSED(b);
157
158 if(m == 1)
159 {
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +0000160 const unsigned int n0 = n < 1280 ? 2 : 4;
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100161 const unsigned int h0 = std::max(n / n0, 1U);
Gian Marco Iodiceee6454a2019-09-17 10:56:51 +0100162 return configure_lhs_rhs_info(m, n, 1, n0, 4, 1, h0, false, true, false, true);
163 }
164 else
165 {
166 return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, true, false, true);
167 }
168}
169
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100170std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
171{
172 ARM_COMPUTE_UNUSED(k);
173 ARM_COMPUTE_UNUSED(b);
174
175 if(m == 1)
176 {
177 if(n > 2048)
178 {
179 const unsigned int h0 = std::max(n / 4, 1U);
180 return configure_lhs_rhs_info(m, n, 1, 4, 4, 1, h0, false, true, false, true);
181 }
182 else
183 {
184 const unsigned int h0 = std::max(n / 2, 1U);
185 return configure_lhs_rhs_info(m, n, 1, 2, 8, 1, h0, false, true, false, true);
186 }
187 }
188 else
189 {
190 return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 4, false, true, false, true);
191 }
192}
193
194std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
195{
196 ARM_COMPUTE_UNUSED(k);
197 ARM_COMPUTE_UNUSED(b);
198
199 if(m == 1)
200 {
201 const unsigned int h0 = std::max(n / 2, 1U);
202 return configure_lhs_rhs_info(m, n, 1, 2, 8, 1, h0, false, true, false, true);
203 }
204 else
205 {
206 return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, true, false, true);
207 }
208}
209
210std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
211{
212 ARM_COMPUTE_UNUSED(k);
213 ARM_COMPUTE_UNUSED(b);
214
215 if(m == 1)
216 {
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +0000217 const unsigned int n0 = n < 1280 ? 2 : 4;
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100218 const unsigned int h0 = std::max(n / n0, 1U);
219 return configure_lhs_rhs_info(m, n, 1, n0, 8, 1, h0, false, true, false, true);
220 }
221 else
222 {
223 return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, true, false, true);
224 }
225}
226
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000227std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
228{
229 ARM_COMPUTE_UNUSED(k);
230 ARM_COMPUTE_UNUSED(b);
231
232 if(dot8_supported(CLKernelLibrary::get().get_device()))
233 {
234 if(m == 1)
235 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100236 const unsigned int h0 = std::max(n / 2, 1U);
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000237 return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, h0, false, true, false, true);
238 }
239 else
240 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100241 const unsigned int h0 = std::max(n / 4, 1U);
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000242 return configure_lhs_rhs_info(m, n, 4, 4, 16, 1, h0, false, true, false, true);
243 }
244 }
245 else
246 {
Gian Marco Iodiceeb65f6d2020-04-15 11:42:15 +0100247 const int h0 = std::max(std::min(static_cast<int>(n / 2), static_cast<int>(128)), static_cast<int>(1));
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000248 if(m == 1)
249 {
Gian Marco Iodice2ec6c1e2019-04-09 12:03:05 +0100250 return configure_lhs_rhs_info(m, n, 1, 2, 4, 1, h0, false, true, false, true);
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000251 }
252 else
253 {
Gian Marco Iodiceeb65f6d2020-04-15 11:42:15 +0100254 return configure_lhs_rhs_info(m, n, 4, 2, 16, 1, h0, false, true, false, true);
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000255 }
256 }
257}
258
259std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
260{
261 ARM_COMPUTE_UNUSED(k);
262 ARM_COMPUTE_UNUSED(b);
263
264 if(m == 1)
265 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100266 const unsigned int h0 = std::max(n / 2, 1U);
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000267 return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, h0, false, true, false, true);
268 }
269 else
270 {
271 return configure_lhs_rhs_info(m, n, 4, 4, 16, 1, 2, false, true, false, true);
272 }
273}
Gian Marco Iodiceee6454a2019-09-17 10:56:51 +0100274
275std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
276{
277 ARM_COMPUTE_UNUSED(k);
278 ARM_COMPUTE_UNUSED(b);
279
280 if(m == 1)
281 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100282 const unsigned int h0 = std::max(n / 2, 1U);
Gian Marco Iodiceee6454a2019-09-17 10:56:51 +0100283 return configure_lhs_rhs_info(m, n, 1, 4, 16, 1, h0, false, true, false, true);
284 }
285 else
286 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100287 const unsigned int h0 = std::max(n / 2, 1U);
Gian Marco Iodiceee6454a2019-09-17 10:56:51 +0100288 return configure_lhs_rhs_info(m, n, 4, 2, 16, 1, h0, false, true, false, true);
289 }
290}
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +0000291
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000292} // namespace cl_gemm
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +0000293} // namespace arm_compute