Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 1 | /* |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2019-2020 ARM Limited. |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 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 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | namespace cl_gemm |
| 37 | { |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame^] | 38 | CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::CLGEMMReshapedOnlyRHSKernelConfigurationBifrost(GPUTarget gpu) |
| 39 | : ICLGEMMKernelConfiguration(gpu) |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 40 | { |
| 41 | } |
| 42 | |
| 43 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure(unsigned int m, unsigned int n, unsigned int k, unsigned int b, DataType data_type) |
| 44 | { |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 45 | using ConfigurationFunctionExecutorPtr = std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> (CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::*)(unsigned int m, unsigned int n, unsigned int k, |
| 46 | unsigned int b); |
| 47 | |
Gian Marco Iodice | ee6454a | 2019-09-17 10:56:51 +0100 | [diff] [blame] | 48 | // Configurations for Mali-G51 |
| 49 | static std::map<DataType, ConfigurationFunctionExecutorPtr> gemm_configs_G51 = |
| 50 | { |
| 51 | { DataType::F32, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_f32 }, |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 52 | { DataType::F16, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_f16 }, |
Gian Marco Iodice | ee6454a | 2019-09-17 10:56:51 +0100 | [diff] [blame] | 53 | { DataType::QASYMM8, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_u8 } |
| 54 | }; |
| 55 | |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 56 | // Configurations for Mali-G76 |
| 57 | static std::map<DataType, ConfigurationFunctionExecutorPtr> gemm_configs_G76 = |
| 58 | { |
| 59 | { DataType::F32, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_f32 }, |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 60 | { DataType::F16, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_f16 }, |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 61 | { DataType::QASYMM8, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_u8 } |
| 62 | }; |
| 63 | |
| 64 | // Configurations for Mali-G7x |
| 65 | static std::map<DataType, ConfigurationFunctionExecutorPtr> gemm_configs_G7x = |
| 66 | { |
| 67 | { DataType::F32, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_f32 }, |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 68 | { DataType::F16, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_f16 }, |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 69 | { DataType::QASYMM8, &CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_u8 } |
| 70 | }; |
| 71 | |
| 72 | switch(_target) |
| 73 | { |
| 74 | case GPUTarget::G76: |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame^] | 75 | if(gemm_configs_G76.find(data_type) != gemm_configs_G76.end()) |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 76 | { |
| 77 | return (this->*gemm_configs_G76[data_type])(m, n, k, b); |
| 78 | } |
| 79 | else |
| 80 | { |
| 81 | ARM_COMPUTE_ERROR("Not supported data type"); |
| 82 | } |
Gian Marco Iodice | ee6454a | 2019-09-17 10:56:51 +0100 | [diff] [blame] | 83 | case GPUTarget::G51: |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame^] | 84 | if(gemm_configs_G51.find(data_type) != gemm_configs_G51.end()) |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 85 | { |
| 86 | return (this->*gemm_configs_G51[data_type])(m, n, k, b); |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | ARM_COMPUTE_ERROR("Not supported data type"); |
| 91 | } |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 92 | default: |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame^] | 93 | if(gemm_configs_G7x.find(data_type) != gemm_configs_G7x.end()) |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 94 | { |
| 95 | return (this->*gemm_configs_G7x[data_type])(m, n, k, b); |
| 96 | } |
| 97 | else |
| 98 | { |
| 99 | ARM_COMPUTE_ERROR("Not supported data type"); |
| 100 | } |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
| 104 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
| 105 | { |
| 106 | ARM_COMPUTE_UNUSED(k); |
| 107 | ARM_COMPUTE_UNUSED(b); |
| 108 | |
| 109 | if(m == 1) |
| 110 | { |
| 111 | if(n > 2048) |
| 112 | { |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 113 | const unsigned int h0 = std::max(n / 4, 1U); |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 114 | return configure_lhs_rhs_info(m, n, 1, 4, 4, 1, h0, false, true, false, true); |
| 115 | } |
| 116 | else |
| 117 | { |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 118 | const unsigned int h0 = std::max(n / 2, 1U); |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 119 | return configure_lhs_rhs_info(m, n, 1, 2, 8, 1, h0, false, true, false, true); |
| 120 | } |
| 121 | } |
| 122 | else |
| 123 | { |
| 124 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 4, false, true, false, true); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
| 129 | { |
| 130 | ARM_COMPUTE_UNUSED(k); |
| 131 | ARM_COMPUTE_UNUSED(b); |
| 132 | |
| 133 | if(m == 1) |
| 134 | { |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 135 | const unsigned int h0 = std::max(n / 2, 1U); |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 136 | return configure_lhs_rhs_info(m, n, 1, 2, 8, 1, h0, false, true, false, true); |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, true, false, true); |
| 141 | } |
| 142 | } |
| 143 | |
Gian Marco Iodice | ee6454a | 2019-09-17 10:56:51 +0100 | [diff] [blame] | 144 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
| 145 | { |
| 146 | ARM_COMPUTE_UNUSED(k); |
| 147 | ARM_COMPUTE_UNUSED(b); |
| 148 | |
| 149 | if(m == 1) |
| 150 | { |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame^] | 151 | const unsigned int n0 = n < 1280 ? 2 : 4; |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 152 | const unsigned int h0 = std::max(n / n0, 1U); |
Gian Marco Iodice | ee6454a | 2019-09-17 10:56:51 +0100 | [diff] [blame] | 153 | return configure_lhs_rhs_info(m, n, 1, n0, 4, 1, h0, false, true, false, true); |
| 154 | } |
| 155 | else |
| 156 | { |
| 157 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, true, false, true); |
| 158 | } |
| 159 | } |
| 160 | |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 161 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
| 162 | { |
| 163 | ARM_COMPUTE_UNUSED(k); |
| 164 | ARM_COMPUTE_UNUSED(b); |
| 165 | |
| 166 | if(m == 1) |
| 167 | { |
| 168 | if(n > 2048) |
| 169 | { |
| 170 | const unsigned int h0 = std::max(n / 4, 1U); |
| 171 | return configure_lhs_rhs_info(m, n, 1, 4, 4, 1, h0, false, true, false, true); |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | const unsigned int h0 = std::max(n / 2, 1U); |
| 176 | return configure_lhs_rhs_info(m, n, 1, 2, 8, 1, h0, false, true, false, true); |
| 177 | } |
| 178 | } |
| 179 | else |
| 180 | { |
| 181 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 4, false, true, false, true); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
| 186 | { |
| 187 | ARM_COMPUTE_UNUSED(k); |
| 188 | ARM_COMPUTE_UNUSED(b); |
| 189 | |
| 190 | if(m == 1) |
| 191 | { |
| 192 | const unsigned int h0 = std::max(n / 2, 1U); |
| 193 | return configure_lhs_rhs_info(m, n, 1, 2, 8, 1, h0, false, true, false, true); |
| 194 | } |
| 195 | else |
| 196 | { |
| 197 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, true, false, true); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
| 202 | { |
| 203 | ARM_COMPUTE_UNUSED(k); |
| 204 | ARM_COMPUTE_UNUSED(b); |
| 205 | |
| 206 | if(m == 1) |
| 207 | { |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame^] | 208 | const unsigned int n0 = n < 1280 ? 2 : 4; |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 209 | const unsigned int h0 = std::max(n / n0, 1U); |
| 210 | return configure_lhs_rhs_info(m, n, 1, n0, 8, 1, h0, false, true, false, true); |
| 211 | } |
| 212 | else |
| 213 | { |
| 214 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, true, false, true); |
| 215 | } |
| 216 | } |
| 217 | |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 218 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G7x_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
| 219 | { |
| 220 | ARM_COMPUTE_UNUSED(k); |
| 221 | ARM_COMPUTE_UNUSED(b); |
| 222 | |
| 223 | if(dot8_supported(CLKernelLibrary::get().get_device())) |
| 224 | { |
| 225 | if(m == 1) |
| 226 | { |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 227 | const unsigned int h0 = std::max(n / 2, 1U); |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 228 | return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, h0, false, true, false, true); |
| 229 | } |
| 230 | else |
| 231 | { |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 232 | const unsigned int h0 = std::max(n / 4, 1U); |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 233 | return configure_lhs_rhs_info(m, n, 4, 4, 16, 1, h0, false, true, false, true); |
| 234 | } |
| 235 | } |
| 236 | else |
| 237 | { |
| 238 | if(m == 1) |
| 239 | { |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 240 | const unsigned int h0 = std::max(n / 2, 1U); |
Gian Marco Iodice | 2ec6c1e | 2019-04-09 12:03:05 +0100 | [diff] [blame] | 241 | return configure_lhs_rhs_info(m, n, 1, 2, 4, 1, h0, false, true, false, true); |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 242 | } |
| 243 | else |
| 244 | { |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 245 | const unsigned int h0 = std::max(n / 4, 1U); |
Gian Marco Iodice | 2ec6c1e | 2019-04-09 12:03:05 +0100 | [diff] [blame] | 246 | return configure_lhs_rhs_info(m, n, 2, 2, 16, 1, h0, false, true, false, true); |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G76_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
| 252 | { |
| 253 | ARM_COMPUTE_UNUSED(k); |
| 254 | ARM_COMPUTE_UNUSED(b); |
| 255 | |
| 256 | if(m == 1) |
| 257 | { |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 258 | const unsigned int h0 = std::max(n / 2, 1U); |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 259 | return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, h0, false, true, false, true); |
| 260 | } |
| 261 | else |
| 262 | { |
| 263 | return configure_lhs_rhs_info(m, n, 4, 4, 16, 1, 2, false, true, false, true); |
| 264 | } |
| 265 | } |
Gian Marco Iodice | ee6454a | 2019-09-17 10:56:51 +0100 | [diff] [blame] | 266 | |
| 267 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedOnlyRHSKernelConfigurationBifrost::configure_G51_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
| 268 | { |
| 269 | ARM_COMPUTE_UNUSED(k); |
| 270 | ARM_COMPUTE_UNUSED(b); |
| 271 | |
| 272 | if(m == 1) |
| 273 | { |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 274 | const unsigned int h0 = std::max(n / 2, 1U); |
Gian Marco Iodice | ee6454a | 2019-09-17 10:56:51 +0100 | [diff] [blame] | 275 | return configure_lhs_rhs_info(m, n, 1, 4, 16, 1, h0, false, true, false, true); |
| 276 | } |
| 277 | else |
| 278 | { |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 279 | const unsigned int h0 = std::max(n / 2, 1U); |
Gian Marco Iodice | ee6454a | 2019-09-17 10:56:51 +0100 | [diff] [blame] | 280 | return configure_lhs_rhs_info(m, n, 4, 2, 16, 1, h0, false, true, false, true); |
| 281 | } |
| 282 | } |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame^] | 283 | |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 284 | } // namespace cl_gemm |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame^] | 285 | } // namespace arm_compute |