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