blob: 3f82dcab00ba6af286b699169f545c23bad8ec56 [file] [log] [blame]
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2020 Arm Limited.
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +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 */
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010024#include "src/core/CL/gemm/reshaped/CLGEMMReshapedKernelConfigurationValhall.h"
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +000025
26#include "arm_compute/core/CL/CLHelpers.h"
27#include "arm_compute/core/CL/CLKernelLibrary.h"
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +000028#include "arm_compute/core/GPUTarget.h"
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010029#include "src/core/CL/gemm/CLGEMMHelpers.h"
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +000030
31#include <map>
32#include <utility>
33
34namespace arm_compute
35{
36namespace cl_gemm
37{
38CLGEMMReshapedKernelConfigurationValhall::CLGEMMReshapedKernelConfigurationValhall(GPUTarget gpu)
39 : ICLGEMMKernelConfiguration(gpu)
40{
41}
42
43std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedKernelConfigurationValhall::configure(unsigned int m, unsigned int n, unsigned int k, unsigned int b, DataType data_type)
44{
45 using ConfigurationFunctionExecutorPtr = std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> (CLGEMMReshapedKernelConfigurationValhall::*)(unsigned int m, unsigned int n, unsigned int k, unsigned int b);
46
47 // Configurations for Mali-G77
48 static std::map<DataType, ConfigurationFunctionExecutorPtr> gemm_configs_G77 =
49 {
50 { DataType::F32, &CLGEMMReshapedKernelConfigurationValhall::configure_G77_f32 },
51 { DataType::F16, &CLGEMMReshapedKernelConfigurationValhall::configure_G77_f16 },
Gian Marco Iodiceeb65f6d2020-04-15 11:42:15 +010052 { DataType::QASYMM8, &CLGEMMReshapedKernelConfigurationValhall::configure_G77_u8 },
53 { DataType::QSYMM8, &CLGEMMReshapedKernelConfigurationValhall::configure_G77_u8 },
54 { DataType::QASYMM8_SIGNED, &CLGEMMReshapedKernelConfigurationValhall::configure_G77_u8 },
55 { DataType::QSYMM8_PER_CHANNEL, &CLGEMMReshapedKernelConfigurationValhall::configure_G77_u8 }
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +000056 };
57
58 switch(_target)
59 {
60 case GPUTarget::G77:
61 default:
62 if(gemm_configs_G77.find(data_type) != gemm_configs_G77.end())
63 {
64 return (this->*gemm_configs_G77[data_type])(m, n, k, b);
65 }
66 else
67 {
68 ARM_COMPUTE_ERROR("Not supported data type");
69 }
70 }
71}
72
73std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedKernelConfigurationValhall::configure_G77_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
74{
75 ARM_COMPUTE_UNUSED(k);
76 ARM_COMPUTE_UNUSED(b);
77
78 if(n <= 4)
79 {
80 return configure_lhs_rhs_info(m, n, 4, 2, 8, 16, 16, true, false, false, true);
81 }
82 else
83 {
84 return configure_lhs_rhs_info(m, n, 5, 4, 4, 2, 16, false, true, false, true);
85 }
86}
87
88std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedKernelConfigurationValhall::configure_G77_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
89{
90 ARM_COMPUTE_UNUSED(k);
91 ARM_COMPUTE_UNUSED(b);
92
Gian Marco Iodice491f30c2020-11-02 15:43:57 +000093 const float r_mn = static_cast<float>(m) / static_cast<float>(n);
94 const float workload = (static_cast<float>(m) * static_cast<float>(n) * static_cast<float>(b)) / 20.0f;
95 const float r_mk = static_cast<float>(m) / static_cast<float>(k);
96 const float r_nk = static_cast<float>(n) / static_cast<float>(k);
97
98 if(r_mk <= 0.11824845522642136)
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +000099 {
Gian Marco Iodice491f30c2020-11-02 15:43:57 +0000100 if(workload <= 880.0)
101 {
102 return configure_lhs_rhs_info(m, n, 2, 4, 4, 1, 4, false, false, true, false, false);
103 }
104 else
105 {
106 if(r_nk <= 0.42521367967128754)
107 {
108 if(workload <= 1726.4000244140625)
109 {
110 return configure_lhs_rhs_info(m, n, 4, 4, 4, 2, 2, false, false, true, false, false);
111 }
112 else
113 {
114 return configure_lhs_rhs_info(m, n, 4, 4, 4, 2, 1, false, true, true, false, true);
115 }
116 }
117 else
118 {
119 if(workload <= 1241.6000366210938)
120 {
121 return configure_lhs_rhs_info(m, n, 2, 4, 4, 1, 4, false, false, true, false, false);
122 }
123 else
124 {
125 return configure_lhs_rhs_info(m, n, 4, 4, 4, 4, 4, false, false, true, false, false);
126 }
127 }
128 }
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +0000129 }
130 else
131 {
Gian Marco Iodice491f30c2020-11-02 15:43:57 +0000132 if(workload <= 11404.7998046875)
133 {
134 if(r_mk <= 1.0126488208770752)
135 {
136 if(r_mn <= 2.545312523841858)
137 {
138 return configure_lhs_rhs_info(m, n, 4, 4, 4, 2, 1, false, true, true, false, true);
139 }
140 else
141 {
142 return configure_lhs_rhs_info(m, n, 2, 4, 4, 1, 4, false, false, true, false, false);
143 }
144 }
145 else
146 {
147 if(workload <= 2881.199951171875)
148 {
149 return configure_lhs_rhs_info(m, n, 4, 4, 4, 4, 2, false, false, true, false, true);
150 }
151 else
152 {
153 return configure_lhs_rhs_info(m, n, 4, 4, 4, 2, 1, false, true, true, false, true);
154 }
155 }
156 }
157 else
158 {
159 if(r_nk <= 0.5765306055545807)
160 {
161 if(r_mn <= 6.010416746139526)
162 {
163 return configure_lhs_rhs_info(m, n, 4, 4, 4, 2, 1, false, true, true, false, true);
164 }
165 else
166 {
167 return configure_lhs_rhs_info(m, n, 4, 4, 4, 2, 1, true, false, true, false, true);
168 }
169 }
170 else
171 {
172 return configure_lhs_rhs_info(m, n, 4, 4, 4, 2, 1, true, false, true, false, true);
173 }
174 }
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +0000175 }
176}
177
178std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedKernelConfigurationValhall::configure_G77_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
179{
180 ARM_COMPUTE_UNUSED(k);
181 ARM_COMPUTE_UNUSED(b);
182
183 if(n <= 4)
184 {
185 return configure_lhs_rhs_info(m, n, 4, 2, 16, 4, 1, false, false, false, true);
186 }
187 else
188 {
189 return configure_lhs_rhs_info(m, n, 4, 4, 16, 2, 2, false, true, false, true);
190 }
191}
192} // namespace cl_gemm
193} // namespace arm_compute