blob: 5526616001b337be04630bf5db4f11c39bdb1cd1 [file] [log] [blame]
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +00001/*
2 * Copyright (c) 2020 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/CLGEMMReshapedOnlyRHSKernelConfigurationValhall.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{
38CLGEMMReshapedOnlyRHSKernelConfigurationValhall::CLGEMMReshapedOnlyRHSKernelConfigurationValhall(GPUTarget gpu)
39 : ICLGEMMKernelConfiguration(gpu)
40{
41}
42
43std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationValhall::configure(unsigned int m, unsigned int n, unsigned int k, unsigned int b, DataType data_type)
44{
45 using ConfigurationFunctionExecutorPtr = std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> (CLGEMMReshapedOnlyRHSKernelConfigurationValhall::*)(unsigned int m, unsigned int n, unsigned int k,
46 unsigned int b);
47
48 // Configurations for Mali-G77
49 static std::map<DataType, ConfigurationFunctionExecutorPtr> gemm_configs_G77 =
50 {
51 { DataType::F32, &CLGEMMReshapedOnlyRHSKernelConfigurationValhall::configure_G77_f32 },
52 { DataType::F16, &CLGEMMReshapedOnlyRHSKernelConfigurationValhall::configure_G77_f16 },
Gian Marco Iodiceeb65f6d2020-04-15 11:42:15 +010053 { DataType::QASYMM8, &CLGEMMReshapedOnlyRHSKernelConfigurationValhall::configure_G77_u8 },
54 { DataType::QSYMM8, &CLGEMMReshapedOnlyRHSKernelConfigurationValhall::configure_G77_u8 },
55 { DataType::QASYMM8_SIGNED, &CLGEMMReshapedOnlyRHSKernelConfigurationValhall::configure_G77_u8 },
56 { DataType::QSYMM8_PER_CHANNEL, &CLGEMMReshapedOnlyRHSKernelConfigurationValhall::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> CLGEMMReshapedOnlyRHSKernelConfigurationValhall::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 {
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000081 if(n > 2048)
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +000082 {
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000083 return configure_lhs_rhs_info(m, n, 1, 8, 2, 1, 256, false, true, false, true);
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +000084 }
85 else
86 {
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000087 return configure_lhs_rhs_info(m, n, 1, 2, 2, 1, 256, false, true, false, true);
88 }
89 }
90 else
91 {
92 if(m > 300)
93 {
94 const int v0 = std::max(std::min(static_cast<int>(n / 4), static_cast<int>(256)), static_cast<int>(1));
95 return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, v0, false, true, false, true);
96 }
97 else
98 {
99 const int v0 = std::max(std::min(static_cast<int>(n / 4), static_cast<int>(256)), static_cast<int>(1));
100 return configure_lhs_rhs_info(m, n, 2, 4, 4, 1, v0, false, true, false, true);
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +0000101 }
102 }
103}
104
105std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationValhall::configure_G77_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
106{
107 ARM_COMPUTE_UNUSED(k);
108 ARM_COMPUTE_UNUSED(b);
109
110 if(m == 1)
111 {
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +0000112 const int h0 = std::max(std::min(static_cast<int>(n / 4), static_cast<int>(256)), static_cast<int>(1));
113 return configure_lhs_rhs_info(m, n, 1, 4, 4, 1, h0, false, true, false, true);
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +0000114 }
Gian Marco Iodice939586e2020-05-05 15:10:21 +0100115 else if (m < 128)
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +0000116 {
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +0000117 const int h0 = std::max(std::min(static_cast<int>(n / 4), static_cast<int>(256)), static_cast<int>(1));
118 if(k > 512)
119 {
120 return configure_lhs_rhs_info(m, n, 2, 4, 16, 1, h0, false, true, false, false);
121 }
122 else
123 {
124 return configure_lhs_rhs_info(m, n, 2, 4, 8, 1, h0, false, true, false, false);
125 }
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +0000126 }
Gian Marco Iodice939586e2020-05-05 15:10:21 +0100127 else
128 {
129 const int h0 = std::max(std::min(static_cast<int>(n / 4), static_cast<int>(256)), static_cast<int>(1));
130 return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, h0, false, true, false, false);
131 }
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +0000132}
133
134std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationValhall::configure_G77_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b)
135{
136 ARM_COMPUTE_UNUSED(k);
137 ARM_COMPUTE_UNUSED(b);
138
139 if(m == 1)
140 {
141 const unsigned int h0 = std::max(n / 2, 1U);
142 return configure_lhs_rhs_info(m, n, 1, 4, 16, 1, h0, false, true, false, true);
143 }
144 else
145 {
Gian Marco Iodiceeb65f6d2020-04-15 11:42:15 +0100146 const int h0 = std::max(std::min(static_cast<int>(n / 4), static_cast<int>(256)), static_cast<int>(1));
147 if(m >= 28)
148 {
149 return configure_lhs_rhs_info(m, n, 4, 4, 16, 1, h0, false, true, false, true);
150 }
151 else
152 {
153 return configure_lhs_rhs_info(m, n, 2, 4, 16, 1, h0, false, true, false, true);
154 }
Gian Marco Iodice12f2b8c2020-02-13 12:27:37 +0000155 }
156}
157} // namespace cl_gemm
158} // namespace arm_compute