blob: f696f0b253d79693bee2baf50eff5ddff0616028 [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{
45 ARM_COMPUTE_ERROR_ON(data_type != DataType::F32 && data_type != DataType::QASYMM8);
46 ARM_COMPUTE_UNUSED(data_type);
47
48 using ConfigurationFunctionExecutorPtr = std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> (CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::*)(unsigned int m, unsigned int n, unsigned int k,
49 unsigned int b);
50
51 // Configurations for Mali-G76
52 static std::map<DataType, ConfigurationFunctionExecutorPtr> gemm_configs_G76 =
53 {
54 { DataType::F32, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_f32 },
55 { DataType::QASYMM8, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_u8 }
56 };
57
58 // Configurations for Mali-G7x
59 static std::map<DataType, ConfigurationFunctionExecutorPtr> gemm_configs_G7x =
60 {
61 { DataType::F32, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_f32 },
62 { DataType::QASYMM8, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_u8 }
63 };
64
65 switch(_target)
66 {
67 case GPUTarget::G76:
68 return (this->*gemm_configs_G76[data_type])(m, n, k, b);
69 default:
70 return (this->*gemm_configs_G7x[data_type])(m, n, k, b);
71 }
72}
73
74std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_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 const unsigned int h0 = std::max(n / 4, static_cast<unsigned int>(1));
84 return configure_lhs_rhs_info(m, n, 1, 4, 4, 1, h0, false, true, false, true);
85 }
86 else
87 {
88 const unsigned int h0 = std::max(n / 2, static_cast<unsigned int>(1));
89 return configure_lhs_rhs_info(m, n, 1, 2, 8, 1, h0, false, true, false, true);
90 }
91 }
92 else
93 {
94 return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 4, false, true, false, true);
95 }
96}
97
98std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
99{
100 ARM_COMPUTE_UNUSED(k);
101 ARM_COMPUTE_UNUSED(b);
102
103 if(m == 1)
104 {
105 const unsigned int h0 = std::max(n / 2, static_cast<unsigned int>(1));
106 return configure_lhs_rhs_info(m, n, 1, 2, 8, 1, h0, false, true, false, true);
107 }
108 else
109 {
110 return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, true, false, true);
111 }
112}
113
114std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
115{
116 ARM_COMPUTE_UNUSED(k);
117 ARM_COMPUTE_UNUSED(b);
118
119 if(dot8_supported(CLKernelLibrary::get().get_device()))
120 {
121 if(m == 1)
122 {
123 const unsigned int h0 = std::max(n / 2, static_cast<unsigned int>(1));
124 return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, h0, false, true, false, true);
125 }
126 else
127 {
128 const unsigned int h0 = std::max(n / 4, static_cast<unsigned int>(1));
129 return configure_lhs_rhs_info(m, n, 4, 4, 16, 1, h0, false, true, false, true);
130 }
131 }
132 else
133 {
134 if(m == 1)
135 {
136 if(n > 2048)
137 {
138 const unsigned int h0 = std::max(n / 4, static_cast<unsigned int>(1));
139 return configure_lhs_rhs_info(m, n, 1, 4, 16, 1, h0, false, true, false, true);
140 }
141 else
142 {
143 const unsigned int h0 = std::max(n / 2, static_cast<unsigned int>(1));
144 return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, h0, false, true, false, true);
145 }
146 }
147 else
148 {
149 const unsigned int h0 = std::max(n / 4, static_cast<unsigned int>(1));
150 return configure_lhs_rhs_info(m, n, 4, 1, 16, 1, h0, false, true, false, true);
151 }
152 }
153}
154
155std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
156{
157 ARM_COMPUTE_UNUSED(k);
158 ARM_COMPUTE_UNUSED(b);
159
160 if(m == 1)
161 {
162 const unsigned int h0 = std::max(n / 2, static_cast<unsigned int>(1));
163 return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, h0, false, true, false, true);
164 }
165 else
166 {
167 return configure_lhs_rhs_info(m, n, 4, 4, 16, 1, 2, false, true, false, true);
168 }
169}
170} // namespace cl_gemm
171} // namespace arm_compute