blob: 5955bac384a5a1f0d929ebfc43594bb8541f7219 [file] [log] [blame]
Gian Marco Iodice926afe12019-03-19 11:44:13 +00001/*
2 * Copyright (c) 2019 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#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{
38CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::CLGEMMReshapedOnlyRHSKernelConfigurationBifrost(GPUTarget arch)
39 : ICLGEMMKernelConfiguration(arch)
40{
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 Iodiceee6454a2019-09-17 10:56:51 +010053 { DataType::QASYMM8, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_u8 }
54 };
55
Gian Marco Iodice926afe12019-03-19 11:44:13 +000056 // Configurations for Mali-G76
57 static std::map<DataType, ConfigurationFunctionExecutorPtr> gemm_configs_G76 =
58 {
59 { DataType::F32, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_f32 },
Gian Marco Iodice0d548042019-10-03 15:12:09 +010060 { DataType::F16, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_f16 },
Gian Marco Iodice926afe12019-03-19 11:44:13 +000061 { DataType::QASYMM8, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_u8 }
62 };
63
64 // Configurations for Mali-G7x
65 static std::map<DataType, ConfigurationFunctionExecutorPtr> gemm_configs_G7x =
66 {
67 { DataType::F32, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_f32 },
Gian Marco Iodice0d548042019-10-03 15:12:09 +010068 { DataType::F16, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_f16 },
Gian Marco Iodice926afe12019-03-19 11:44:13 +000069 { DataType::QASYMM8, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_u8 }
70 };
71
72 switch(_target)
73 {
74 case GPUTarget::G76:
Gian Marco Iodice0d548042019-10-03 15:12:09 +010075 if (gemm_configs_G76.find(data_type) != gemm_configs_G76.end())
76 {
77 return (this->*gemm_configs_G76[data_type])(m, n, k, b);
78 }
79 else
80 {
81 ARM_COMPUTE_ERROR("Not supported data type");
82 }
Gian Marco Iodiceee6454a2019-09-17 10:56:51 +010083 case GPUTarget::G51:
Gian Marco Iodice0d548042019-10-03 15:12:09 +010084 if (gemm_configs_G51.find(data_type) != gemm_configs_G51.end())
85 {
86 return (this->*gemm_configs_G51[data_type])(m, n, k, b);
87 }
88 else
89 {
90 ARM_COMPUTE_ERROR("Not supported data type");
91 }
Gian Marco Iodice926afe12019-03-19 11:44:13 +000092 default:
Gian Marco Iodice0d548042019-10-03 15:12:09 +010093 if (gemm_configs_G7x.find(data_type) != gemm_configs_G7x.end())
94 {
95 return (this->*gemm_configs_G7x[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 }
102}
103
104std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
105{
106 ARM_COMPUTE_UNUSED(k);
107 ARM_COMPUTE_UNUSED(b);
108
109 if(m == 1)
110 {
111 if(n > 2048)
112 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100113 const unsigned int h0 = std::max(n / 4, 1U);
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000114 return configure_lhs_rhs_info(m, n, 1, 4, 4, 1, h0, false, true, false, true);
115 }
116 else
117 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100118 const unsigned int h0 = std::max(n / 2, 1U);
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000119 return configure_lhs_rhs_info(m, n, 1, 2, 8, 1, h0, false, true, false, true);
120 }
121 }
122 else
123 {
124 return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 4, false, true, false, true);
125 }
126}
127
128std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
129{
130 ARM_COMPUTE_UNUSED(k);
131 ARM_COMPUTE_UNUSED(b);
132
133 if(m == 1)
134 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100135 const unsigned int h0 = std::max(n / 2, 1U);
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000136 return configure_lhs_rhs_info(m, n, 1, 2, 8, 1, h0, false, true, false, true);
137 }
138 else
139 {
140 return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, true, false, true);
141 }
142}
143
Gian Marco Iodiceee6454a2019-09-17 10:56:51 +0100144std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
145{
146 ARM_COMPUTE_UNUSED(k);
147 ARM_COMPUTE_UNUSED(b);
148
149 if(m == 1)
150 {
151 const unsigned int n0 = n < 1280? 2 : 4;
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100152 const unsigned int h0 = std::max(n / n0, 1U);
Gian Marco Iodiceee6454a2019-09-17 10:56:51 +0100153 return configure_lhs_rhs_info(m, n, 1, n0, 4, 1, h0, false, true, false, true);
154 }
155 else
156 {
157 return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, true, false, true);
158 }
159}
160
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100161std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
162{
163 ARM_COMPUTE_UNUSED(k);
164 ARM_COMPUTE_UNUSED(b);
165
166 if(m == 1)
167 {
168 if(n > 2048)
169 {
170 const unsigned int h0 = std::max(n / 4, 1U);
171 return configure_lhs_rhs_info(m, n, 1, 4, 4, 1, h0, false, true, false, true);
172 }
173 else
174 {
175 const unsigned int h0 = std::max(n / 2, 1U);
176 return configure_lhs_rhs_info(m, n, 1, 2, 8, 1, h0, false, true, false, true);
177 }
178 }
179 else
180 {
181 return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 4, false, true, false, true);
182 }
183}
184
185std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
186{
187 ARM_COMPUTE_UNUSED(k);
188 ARM_COMPUTE_UNUSED(b);
189
190 if(m == 1)
191 {
192 const unsigned int h0 = std::max(n / 2, 1U);
193 return configure_lhs_rhs_info(m, n, 1, 2, 8, 1, h0, false, true, false, true);
194 }
195 else
196 {
197 return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, true, false, true);
198 }
199}
200
201std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
202{
203 ARM_COMPUTE_UNUSED(k);
204 ARM_COMPUTE_UNUSED(b);
205
206 if(m == 1)
207 {
208 const unsigned int n0 = n < 1280? 2 : 4;
209 const unsigned int h0 = std::max(n / n0, 1U);
210 return configure_lhs_rhs_info(m, n, 1, n0, 8, 1, h0, false, true, false, true);
211 }
212 else
213 {
214 return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, true, false, true);
215 }
216}
217
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000218std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
219{
220 ARM_COMPUTE_UNUSED(k);
221 ARM_COMPUTE_UNUSED(b);
222
223 if(dot8_supported(CLKernelLibrary::get().get_device()))
224 {
225 if(m == 1)
226 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100227 const unsigned int h0 = std::max(n / 2, 1U);
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000228 return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, h0, false, true, false, true);
229 }
230 else
231 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100232 const unsigned int h0 = std::max(n / 4, 1U);
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000233 return configure_lhs_rhs_info(m, n, 4, 4, 16, 1, h0, false, true, false, true);
234 }
235 }
236 else
237 {
238 if(m == 1)
239 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100240 const unsigned int h0 = std::max(n / 2, 1U);
Gian Marco Iodice2ec6c1e2019-04-09 12:03:05 +0100241 return configure_lhs_rhs_info(m, n, 1, 2, 4, 1, h0, false, true, false, true);
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000242 }
243 else
244 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100245 const unsigned int h0 = std::max(n / 4, 1U);
Gian Marco Iodice2ec6c1e2019-04-09 12:03:05 +0100246 return configure_lhs_rhs_info(m, n, 2, 2, 16, 1, h0, false, true, false, true);
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000247 }
248 }
249}
250
251std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
252{
253 ARM_COMPUTE_UNUSED(k);
254 ARM_COMPUTE_UNUSED(b);
255
256 if(m == 1)
257 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100258 const unsigned int h0 = std::max(n / 2, 1U);
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000259 return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, h0, false, true, false, true);
260 }
261 else
262 {
263 return configure_lhs_rhs_info(m, n, 4, 4, 16, 1, 2, false, true, false, true);
264 }
265}
Gian Marco Iodiceee6454a2019-09-17 10:56:51 +0100266
267std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
268{
269 ARM_COMPUTE_UNUSED(k);
270 ARM_COMPUTE_UNUSED(b);
271
272 if(m == 1)
273 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100274 const unsigned int h0 = std::max(n / 2, 1U);
Gian Marco Iodiceee6454a2019-09-17 10:56:51 +0100275 return configure_lhs_rhs_info(m, n, 1, 4, 16, 1, h0, false, true, false, true);
276 }
277 else
278 {
Gian Marco Iodice0d548042019-10-03 15:12:09 +0100279 const unsigned int h0 = std::max(n / 2, 1U);
Gian Marco Iodiceee6454a2019-09-17 10:56:51 +0100280 return configure_lhs_rhs_info(m, n, 4, 2, 16, 1, h0, false, true, false, true);
281 }
282}
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000283} // namespace cl_gemm
284} // namespace arm_compute