blob: 2c82340eefc653127be1b2abbd8526661e243b5c [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/native/CLGEMMNativeKernelConfigurationValhall.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{
38CLGEMMNativeKernelConfigurationValhall::CLGEMMNativeKernelConfigurationValhall(GPUTarget gpu)
39 : ICLGEMMKernelConfiguration(gpu)
40{
41}
42
43std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMNativeKernelConfigurationValhall::configure(unsigned int m, unsigned int n, unsigned int k, unsigned int b, DataType data_type)
44{
45 using ConfigurationFunctionExecutorPtr = std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> (CLGEMMNativeKernelConfigurationValhall::*)(unsigned int m, unsigned int n, unsigned int k,
46 unsigned int b);
47
Gian Marco Iodiceeb65f6d2020-04-15 11:42:15 +010048 // Configurations for Mali-G77
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +000049 static std::map<DataType, ConfigurationFunctionExecutorPtr> gemm_configs_G77 =
50 {
51 { DataType::F32, &CLGEMMNativeKernelConfigurationValhall::configure_G77_f32 },
52 { DataType::F16, &CLGEMMNativeKernelConfigurationValhall::configure_G77_f16 },
Gian Marco Iodiceeb65f6d2020-04-15 11:42:15 +010053 { DataType::QASYMM8, &CLGEMMNativeKernelConfigurationValhall::configure_G77_u8 },
54 { DataType::QSYMM8, &CLGEMMNativeKernelConfigurationValhall::configure_G77_u8 },
55 { DataType::QASYMM8_SIGNED, &CLGEMMNativeKernelConfigurationValhall::configure_G77_u8 },
56 { DataType::QSYMM8_PER_CHANNEL, &CLGEMMNativeKernelConfigurationValhall::configure_G77_u8 }
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +000057 };
58
59 switch(_target)
60 {
61 case GPUTarget::G77:
62 default:
63 if(gemm_configs_G77.find(data_type) != gemm_configs_G77.end())
64 {
65 return (this->*gemm_configs_G77[data_type])(m, n, k, b);
66 }
67 else
68 {
69 ARM_COMPUTE_ERROR("Not supported data type");
70 }
71 }
72}
73
74std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMNativeKernelConfigurationValhall::configure_G77_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
75{
76 ARM_COMPUTE_UNUSED(k);
77 ARM_COMPUTE_UNUSED(b);
78
79 if(m == 1)
80 {
81 if(n < 2048)
82 {
83 return configure_lhs_rhs_info(m, n, 1, 2, 4, 1, 1, false, false, false, false);
84 }
85 else if(n >= 2048 && n < 8192)
86 {
87 return configure_lhs_rhs_info(m, n, 1, 4, 4, 1, 1, false, false, false, false);
88 }
89 else
90 {
91 return configure_lhs_rhs_info(m, n, 1, 8, 4, 1, 1, false, false, false, false);
92 }
93 }
94 else
95 {
96 return configure_lhs_rhs_info(m, n, 5, 4, 2, 1, 1, false, false, false, false);
97 }
98}
99
100std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMNativeKernelConfigurationValhall::configure_G77_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
101{
102 ARM_COMPUTE_UNUSED(k);
103 ARM_COMPUTE_UNUSED(b);
104
105 if(m == 1)
106 {
107 if(n < 2048)
108 {
109 return configure_lhs_rhs_info(m, n, 1, 2, 4, 1, 1, false, false, false, false);
110 }
111 else if(n >= 2048 && n < 8192)
112 {
113 return configure_lhs_rhs_info(m, n, 1, 4, 4, 1, 1, false, false, false, false);
114 }
115 else
116 {
117 return configure_lhs_rhs_info(m, n, 1, 8, 4, 1, 1, false, false, false, false);
118 }
119 }
120 else
121 {
122 return configure_lhs_rhs_info(m, n, 4, 8, 2, 1, 1, false, false, false, false);
123 }
124}
125
126std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMNativeKernelConfigurationValhall::configure_G77_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
127{
128 ARM_COMPUTE_UNUSED(k);
129 ARM_COMPUTE_UNUSED(b);
130
131 if(dot8_supported(CLKernelLibrary::get().get_device()))
132 {
133 if(m == 1)
134 {
135 if(n < 2048)
136 {
137 return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, 1, false, false, false, false);
138 }
139 else if(n >= 2048 && n < 16384)
140 {
141 return configure_lhs_rhs_info(m, n, 1, 4, 16, 1, 1, false, false, false, false);
142 }
143 else
144 {
145 return configure_lhs_rhs_info(m, n, 1, 8, 16, 1, 1, false, false, false, false);
146 }
147 }
148 else
149 {
150 if(m < 64)
151 {
152 return configure_lhs_rhs_info(m, n, 2, 2, 16, 1, 1, false, false, false, false);
153 }
154 else
155 {
156 return configure_lhs_rhs_info(m, n, 5, 2, 16, 1, 1, false, false, false, false);
157 }
158 }
159 }
160 else
161 {
162 if(m == 1)
163 {
164 if(n < 8192)
165 {
166 return configure_lhs_rhs_info(m, n, 1, 4, 16, 1, 1, false, false, false, false);
167 }
168 else
169 {
170 return configure_lhs_rhs_info(m, n, 1, 8, 16, 1, 1, false, false, false, false);
171 }
172 }
173 else
174 {
175 return configure_lhs_rhs_info(m, n, 2, 8, 16, 1, 1, false, false, false, false);
176 }
177 }
178}
179} // namespace cl_gemm
180} // namespace arm_compute