blob: 0ffbe78449af128b18e21f8d497999c2e0a15df0 [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/CLGEMMReshapedKernelConfigurationBifrost.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{
38CLGEMMReshapedKernelConfigurationBifrost::CLGEMMReshapedKernelConfigurationBifrost(GPUTarget arch)
39 : ICLGEMMKernelConfiguration(arch)
40{
41}
42
43std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedKernelConfigurationBifrost::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> (CLGEMMReshapedKernelConfigurationBifrost::*)(unsigned int m, unsigned int n, unsigned int k, unsigned int b);
46
47 // Configurations for Mali-G76
48 static std::map<DataType, ConfigurationFunctionExecutorPtr> gemm_configs_G76 =
49 {
50 { DataType::F32, &CLGEMMReshapedKernelConfigurationBifrost::configure_G76_f32 },
Gian Marco Iodice05639f62019-09-24 12:05:06 +010051 { DataType::F16, &CLGEMMReshapedKernelConfigurationBifrost::configure_G76_f16 },
Gian Marco Iodice926afe12019-03-19 11:44:13 +000052 { DataType::QASYMM8, &CLGEMMReshapedKernelConfigurationBifrost::configure_G76_u8 }
53 };
54
55 // Configurations for Mali-G7x
56 static std::map<DataType, ConfigurationFunctionExecutorPtr> gemm_configs_G7x =
57 {
58 { DataType::F32, &CLGEMMReshapedKernelConfigurationBifrost::configure_G7x_f32 },
Gian Marco Iodice05639f62019-09-24 12:05:06 +010059 { DataType::F16, &CLGEMMReshapedKernelConfigurationBifrost::configure_G7x_f16 },
Gian Marco Iodice926afe12019-03-19 11:44:13 +000060 { DataType::QASYMM8, &CLGEMMReshapedKernelConfigurationBifrost::configure_G7x_u8 }
61 };
62
63 switch(_target)
64 {
65 case GPUTarget::G76:
Gian Marco Iodice0c17aa22019-09-27 09:23:15 +010066 if (gemm_configs_G76.find(data_type) != gemm_configs_G76.end())
67 {
68 return (this->*gemm_configs_G76[data_type])(m, n, k, b);
69 }
70 else
71 {
72 ARM_COMPUTE_ERROR("Not supported data type");
73 }
Gian Marco Iodice926afe12019-03-19 11:44:13 +000074 default:
Gian Marco Iodice0c17aa22019-09-27 09:23:15 +010075 if (gemm_configs_G7x.find(data_type) != gemm_configs_G7x.end())
76 {
77 return (this->*gemm_configs_G7x[data_type])(m, n, k, b);
78 }
79 else
80 {
81 ARM_COMPUTE_ERROR("Not supported data type");
82 }
Gian Marco Iodice926afe12019-03-19 11:44:13 +000083 }
84}
85
86std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedKernelConfigurationBifrost::configure_G7x_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
87{
88 ARM_COMPUTE_UNUSED(k);
89 ARM_COMPUTE_UNUSED(b);
90
91 if(n <= 4)
92 {
93 return configure_lhs_rhs_info(m, n, 4, 2, 8, 16, 16, true, false, false, true);
94 }
95 else
96 {
97 return configure_lhs_rhs_info(m, n, 5, 4, 4, 2, 16, false, true, false, true);
98 }
99}
100
Gian Marco Iodice05639f62019-09-24 12:05:06 +0100101std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedKernelConfigurationBifrost::configure_G7x_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
102{
103 ARM_COMPUTE_UNUSED(k);
104 ARM_COMPUTE_UNUSED(b);
105
106 if(n <= 4)
107 {
108 return configure_lhs_rhs_info(m, n, 4, 2, 8, 8, 2, true, true, true, false);
109 }
110 else
111 {
112 return configure_lhs_rhs_info(m, n, 4, 8, 4, 4, 2, true, true, true, false);
113 }
114}
115
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000116std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedKernelConfigurationBifrost::configure_G7x_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
117{
118 ARM_COMPUTE_UNUSED(k);
119 ARM_COMPUTE_UNUSED(b);
120
121 if(dot8_supported(CLKernelLibrary::get().get_device()))
122 {
123 if(n <= 4)
124 {
125 return configure_lhs_rhs_info(m, n, 4, 2, 16, 2, 2, true, false, false, true);
126 }
127 else
128 {
129 return configure_lhs_rhs_info(m, n, 4, 4, 16, 2, 2, true, false, false, true);
130 }
131 }
132 else
133 {
134 if(n <= 4)
135 {
136 return configure_lhs_rhs_info(m, n, 4, 2, 8, 2, 2, true, false, false, true);
137 }
138 else
139 {
140 return configure_lhs_rhs_info(m, n, 6, 4, 4, 2, 2, true, true, false, true);
141 }
142 }
143}
144
145std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedKernelConfigurationBifrost::configure_G76_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
146{
147 ARM_COMPUTE_UNUSED(k);
148 ARM_COMPUTE_UNUSED(b);
149
150 if(n <= 4)
151 {
152 return configure_lhs_rhs_info(m, n, 4, 2, 8, 16, 16, true, false, false, true);
153 }
154 else
155 {
156 return configure_lhs_rhs_info(m, n, 4, 4, 2, 8, 16, false, false, false, true);
157 }
158}
159
Gian Marco Iodice05639f62019-09-24 12:05:06 +0100160std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedKernelConfigurationBifrost::configure_G76_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
161{
162 ARM_COMPUTE_UNUSED(k);
163 ARM_COMPUTE_UNUSED(b);
164
165 if(n <= 4)
166 {
167 return configure_lhs_rhs_info(m, n, 4, 4, 4, 8, 2, true, true, true, false);
168 }
169 else
170 {
171 return configure_lhs_rhs_info(m, n, 4, 4, 4, 4, 8, true, true, true, false);
172 }
173}
174
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000175std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedKernelConfigurationBifrost::configure_G76_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
176{
177 ARM_COMPUTE_UNUSED(k);
178 ARM_COMPUTE_UNUSED(b);
179
180 if(n <= 4)
181 {
182 return configure_lhs_rhs_info(m, n, 4, 2, 16, 4, 1, false, false, false, true);
183 }
184 else
185 {
186 return configure_lhs_rhs_info(m, n, 4, 4, 16, 2, 2, false, true, false, true);
187 }
188}
189} // namespace cl_gemm
190} // namespace arm_compute