Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 1 | /* |
Gian Marco Iodice | 2344189 | 2021-01-21 12:23:22 +0000 | [diff] [blame] | 2 | * Copyright (c) 2019-2021 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 | */ |
SiCong Li | a085a0c | 2020-12-02 14:54:34 +0000 | [diff] [blame] | 24 | #include "src/core/CL/gemm/reshaped_only_rhs/CLGEMMDefaultConfigReshapedRHSOnlyBifrost.h" |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 25 | |
| 26 | #include "arm_compute/core/CL/CLHelpers.h" |
| 27 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/GPUTarget.h" |
Gian Marco Iodice | ed5fe69 | 2020-07-09 08:41:10 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/TensorInfo.h" |
| 30 | #include "arm_compute/core/TensorShape.h" |
| 31 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 32 | #include "src/core/CL/gemm/CLGEMMHelpers.h" |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 33 | |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 34 | #include <utility> |
| 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | namespace cl_gemm |
| 39 | { |
Gian Marco Iodice | ed5fe69 | 2020-07-09 08:41:10 +0100 | [diff] [blame] | 40 | using namespace arm_compute::misc::shape_calculator; |
| 41 | |
SiCong Li | a085a0c | 2020-12-02 14:54:34 +0000 | [diff] [blame] | 42 | CLGEMMDefaultConfigReshapedRHSOnlyBifrost::CLGEMMDefaultConfigReshapedRHSOnlyBifrost(GPUTarget gpu) |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame] | 43 | : ICLGEMMKernelConfiguration(gpu) |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 44 | { |
| 45 | } |
| 46 | |
SiCong Li | a085a0c | 2020-12-02 14:54:34 +0000 | [diff] [blame] | 47 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure(unsigned int m, unsigned int n, unsigned int k, unsigned int b, DataType data_type) |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 48 | { |
SiCong Li | a085a0c | 2020-12-02 14:54:34 +0000 | [diff] [blame] | 49 | using ConfigurationFunctionExecutorPtr = std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> (CLGEMMDefaultConfigReshapedRHSOnlyBifrost::*)(unsigned int m, unsigned int n, unsigned int k, |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 50 | unsigned int b); |
| 51 | |
Gian Marco Iodice | 3795491 | 2021-04-12 17:34:33 +0100 | [diff] [blame^] | 52 | CLGEMMConfigArray<ConfigurationFunctionExecutorPtr> configs_G51(&CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G51_f32, |
| 53 | &CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G51_f16, |
| 54 | &CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G51_u8); |
Gian Marco Iodice | ee6454a | 2019-09-17 10:56:51 +0100 | [diff] [blame] | 55 | |
Gian Marco Iodice | 3795491 | 2021-04-12 17:34:33 +0100 | [diff] [blame^] | 56 | CLGEMMConfigArray<ConfigurationFunctionExecutorPtr> configs_G52(&CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G52_f32, |
| 57 | &CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G52_f16, |
| 58 | &CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G7x_u8); |
Gian Marco Iodice | eaca67a | 2020-11-10 10:41:37 +0000 | [diff] [blame] | 59 | |
Gian Marco Iodice | 3795491 | 2021-04-12 17:34:33 +0100 | [diff] [blame^] | 60 | CLGEMMConfigArray<ConfigurationFunctionExecutorPtr> configs_G76(&CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G76_f32, |
| 61 | &CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G76_f16, |
| 62 | &CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G76_u8); |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 63 | |
Gian Marco Iodice | 3795491 | 2021-04-12 17:34:33 +0100 | [diff] [blame^] | 64 | CLGEMMConfigArray<ConfigurationFunctionExecutorPtr> configs_G7x(&CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G7x_f32, |
| 65 | &CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G7x_f16, |
| 66 | &CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G7x_u8); |
| 67 | |
| 68 | ConfigurationFunctionExecutorPtr func = nullptr; |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 69 | |
| 70 | switch(_target) |
| 71 | { |
| 72 | case GPUTarget::G76: |
Gian Marco Iodice | 3795491 | 2021-04-12 17:34:33 +0100 | [diff] [blame^] | 73 | func = configs_G76.get_function(data_type); |
| 74 | break; |
Gian Marco Iodice | ee6454a | 2019-09-17 10:56:51 +0100 | [diff] [blame] | 75 | case GPUTarget::G51: |
Gian Marco Iodice | 3795491 | 2021-04-12 17:34:33 +0100 | [diff] [blame^] | 76 | func = configs_G51.get_function(data_type); |
| 77 | break; |
| 78 | case GPUTarget::G52: |
| 79 | func = configs_G52.get_function(data_type); |
| 80 | break; |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 81 | default: |
Gian Marco Iodice | 3795491 | 2021-04-12 17:34:33 +0100 | [diff] [blame^] | 82 | func = configs_G7x.get_function(data_type); |
| 83 | break; |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 84 | } |
Gian Marco Iodice | 3795491 | 2021-04-12 17:34:33 +0100 | [diff] [blame^] | 85 | |
| 86 | ARM_COMPUTE_ERROR_ON_MSG(func == nullptr, "Data type not support for GEMM"); |
| 87 | return (this->*func)(m, n, k, b); |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 88 | } |
| 89 | |
SiCong Li | a085a0c | 2020-12-02 14:54:34 +0000 | [diff] [blame] | 90 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G7x_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 91 | { |
| 92 | ARM_COMPUTE_UNUSED(k); |
| 93 | ARM_COMPUTE_UNUSED(b); |
| 94 | |
| 95 | if(m == 1) |
| 96 | { |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 97 | if(n <= 2548) |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 98 | { |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 99 | return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, 4, false, true, false, true, false); |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 100 | } |
| 101 | else |
| 102 | { |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 103 | return configure_lhs_rhs_info(m, n, 1, 4, 16, 1, 8, false, true, false, true, false); |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 4, false, true, false, true); |
| 109 | } |
| 110 | } |
| 111 | |
SiCong Li | a085a0c | 2020-12-02 14:54:34 +0000 | [diff] [blame] | 112 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G76_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 113 | { |
| 114 | ARM_COMPUTE_UNUSED(k); |
| 115 | ARM_COMPUTE_UNUSED(b); |
| 116 | |
Gian Marco Iodice | ed5fe69 | 2020-07-09 08:41:10 +0100 | [diff] [blame] | 117 | GEMMLHSMatrixInfo lhs_info_buf; |
| 118 | GEMMRHSMatrixInfo rhs_info_buf; |
| 119 | GEMMLHSMatrixInfo lhs_info_img; |
| 120 | GEMMRHSMatrixInfo rhs_info_img; |
| 121 | |
Gian Marco Iodice | 4aed4aa | 2020-08-07 15:36:30 +0100 | [diff] [blame] | 122 | const bool is_workload_big = ((m * n * b) / 16) >= 2048; |
Gian Marco Iodice | 229757b | 2020-11-15 16:06:10 +0000 | [diff] [blame] | 123 | |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 124 | if(m == 1) |
| 125 | { |
Gian Marco Iodice | 229757b | 2020-11-15 16:06:10 +0000 | [diff] [blame] | 126 | if(n >= 8192) |
Gian Marco Iodice | 4aed4aa | 2020-08-07 15:36:30 +0100 | [diff] [blame] | 127 | { |
Gian Marco Iodice | 229757b | 2020-11-15 16:06:10 +0000 | [diff] [blame] | 128 | const unsigned int h0 = std::max(n / 4, 1U); |
| 129 | return configure_lhs_rhs_info(m, n, 1, 4, 8, 1, h0, false, true, false, true, false); |
Gian Marco Iodice | 4aed4aa | 2020-08-07 15:36:30 +0100 | [diff] [blame] | 130 | } |
| 131 | else |
| 132 | { |
Gian Marco Iodice | 229757b | 2020-11-15 16:06:10 +0000 | [diff] [blame] | 133 | const unsigned int h0 = std::max(n / 2, 1U); |
| 134 | if(n <= 204) |
| 135 | { |
| 136 | return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, h0, false, true, false, true, false); |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | return configure_lhs_rhs_info(m, n, 1, 2, 8, 1, h0, false, true, false, true, false); |
| 141 | } |
Gian Marco Iodice | 4aed4aa | 2020-08-07 15:36:30 +0100 | [diff] [blame] | 142 | } |
Gian Marco Iodice | ed5fe69 | 2020-07-09 08:41:10 +0100 | [diff] [blame] | 143 | } |
| 144 | else |
| 145 | { |
| 146 | const int h0 = std::max(std::min(static_cast<int>(n / 4), static_cast<int>(16)), static_cast<int>(1)); |
Gian Marco Iodice | 4aed4aa | 2020-08-07 15:36:30 +0100 | [diff] [blame] | 147 | if(is_workload_big) |
| 148 | { |
| 149 | std::tie(lhs_info_buf, rhs_info_buf) = configure_lhs_rhs_info(m, n, 4, 4, 4, 1, h0, false, true, false, true); |
| 150 | } |
| 151 | else |
| 152 | { |
| 153 | std::tie(lhs_info_buf, rhs_info_buf) = configure_lhs_rhs_info(m, n, 2, 4, 8, 1, h0, false, true, false, true); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // Get lhs_info/rhs_info in case of OpenCL image |
| 158 | const int h0 = std::max(std::min(static_cast<int>(n / 4), static_cast<int>(16)), static_cast<int>(1)); |
| 159 | if(is_workload_big) |
| 160 | { |
Gian Marco Iodice | ed5fe69 | 2020-07-09 08:41:10 +0100 | [diff] [blame] | 161 | std::tie(lhs_info_img, rhs_info_img) = configure_lhs_rhs_info(m, n, 4, 4, 4, 1, h0, false, true, false, false, true); |
| 162 | } |
Gian Marco Iodice | 4aed4aa | 2020-08-07 15:36:30 +0100 | [diff] [blame] | 163 | else |
| 164 | { |
| 165 | std::tie(lhs_info_img, rhs_info_img) = configure_lhs_rhs_info(m, n, 2, 4, 8, 1, h0, false, true, false, true, true); |
| 166 | } |
Gian Marco Iodice | ed5fe69 | 2020-07-09 08:41:10 +0100 | [diff] [blame] | 167 | |
| 168 | const TensorInfo tensor_rhs_info(TensorShape(n, k, b), 1, DataType::F32); |
| 169 | const TensorShape shape = compute_rhs_reshaped_shape(tensor_rhs_info, rhs_info_img); |
| 170 | const TensorInfo tensor_reshaped_info(shape, 1, DataType::F32); |
| 171 | |
Gian Marco Iodice | 4aed4aa | 2020-08-07 15:36:30 +0100 | [diff] [blame] | 172 | // In case of vector by matrix or small workloads, we use the OpenCL buffer rather than the OpenCL image2d |
| 173 | const bool use_cl_image2d = ((m == 1) || ((((m * n * b) / 16) < 2048) && n < 128)) ? false : true; |
Gian Marco Iodice | ed5fe69 | 2020-07-09 08:41:10 +0100 | [diff] [blame] | 174 | |
| 175 | if(bool(validate_image2d_support_on_rhs(tensor_reshaped_info, rhs_info_img)) && use_cl_image2d) |
| 176 | { |
| 177 | return std::make_pair(lhs_info_img, rhs_info_img); |
| 178 | } |
| 179 | else |
| 180 | { |
| 181 | return std::make_pair(lhs_info_buf, rhs_info_buf); |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
SiCong Li | a085a0c | 2020-12-02 14:54:34 +0000 | [diff] [blame] | 185 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G52_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
Gian Marco Iodice | eaca67a | 2020-11-10 10:41:37 +0000 | [diff] [blame] | 186 | { |
| 187 | const float workload = (static_cast<float>(m) * static_cast<float>(n) * static_cast<float>(b)) / 20.0f; |
| 188 | const float r_nk = static_cast<float>(n) / static_cast<float>(k); |
| 189 | |
| 190 | GEMMLHSMatrixInfo lhs_info_buf; |
| 191 | GEMMRHSMatrixInfo rhs_info_buf; |
| 192 | GEMMLHSMatrixInfo lhs_info_img; |
| 193 | GEMMRHSMatrixInfo rhs_info_img; |
| 194 | |
| 195 | if(m == 1) |
| 196 | { |
| 197 | if(r_nk <= 0.4664f) |
| 198 | { |
| 199 | return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, 16, false, true, false, true, false); |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | std::tie(lhs_info_img, rhs_info_img) = configure_lhs_rhs_info(m, n, 1, 4, 8, 1, 16, false, true, false, true, true); |
| 204 | std::tie(lhs_info_buf, rhs_info_buf) = configure_lhs_rhs_info(m, n, 1, 4, 8, 1, 16, false, true, false, true, false); |
| 205 | |
| 206 | return select_lhs_rhs_info(std::make_pair(lhs_info_img, rhs_info_img), |
| 207 | std::make_pair(lhs_info_buf, rhs_info_buf), |
| 208 | n, k, b, DataType::F32); |
| 209 | } |
| 210 | } |
| 211 | else |
| 212 | { |
| 213 | if(workload <= 274.4000f) |
| 214 | { |
| 215 | return configure_lhs_rhs_info(m, n, 2, 2, 4, 1, 16, false, false, false, true, false); |
| 216 | } |
| 217 | else |
| 218 | { |
| 219 | std::tie(lhs_info_img, rhs_info_img) = configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, false, false, true, true); |
| 220 | std::tie(lhs_info_buf, rhs_info_buf) = configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, false, false, true, false); |
| 221 | |
| 222 | return select_lhs_rhs_info(std::make_pair(lhs_info_img, rhs_info_img), |
| 223 | std::make_pair(lhs_info_buf, rhs_info_buf), |
| 224 | n, k, b, DataType::F32); |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
SiCong Li | a085a0c | 2020-12-02 14:54:34 +0000 | [diff] [blame] | 229 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G51_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
Gian Marco Iodice | ee6454a | 2019-09-17 10:56:51 +0100 | [diff] [blame] | 230 | { |
| 231 | ARM_COMPUTE_UNUSED(k); |
| 232 | ARM_COMPUTE_UNUSED(b); |
| 233 | |
| 234 | if(m == 1) |
| 235 | { |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame] | 236 | const unsigned int n0 = n < 1280 ? 2 : 4; |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 237 | const unsigned int h0 = std::max(n / n0, 1U); |
Gian Marco Iodice | ee6454a | 2019-09-17 10:56:51 +0100 | [diff] [blame] | 238 | return configure_lhs_rhs_info(m, n, 1, n0, 4, 1, h0, false, true, false, true); |
| 239 | } |
| 240 | else |
| 241 | { |
| 242 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, true, false, true); |
| 243 | } |
| 244 | } |
| 245 | |
SiCong Li | a085a0c | 2020-12-02 14:54:34 +0000 | [diff] [blame] | 246 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G7x_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 247 | { |
| 248 | ARM_COMPUTE_UNUSED(k); |
| 249 | ARM_COMPUTE_UNUSED(b); |
| 250 | |
| 251 | if(m == 1) |
| 252 | { |
| 253 | if(n > 2048) |
| 254 | { |
| 255 | const unsigned int h0 = std::max(n / 4, 1U); |
| 256 | return configure_lhs_rhs_info(m, n, 1, 4, 4, 1, h0, false, true, false, true); |
| 257 | } |
| 258 | else |
| 259 | { |
| 260 | const unsigned int h0 = std::max(n / 2, 1U); |
| 261 | return configure_lhs_rhs_info(m, n, 1, 2, 8, 1, h0, false, true, false, true); |
| 262 | } |
| 263 | } |
| 264 | else |
| 265 | { |
| 266 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 4, false, true, false, true); |
| 267 | } |
| 268 | } |
| 269 | |
SiCong Li | a085a0c | 2020-12-02 14:54:34 +0000 | [diff] [blame] | 270 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G52_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
Gian Marco Iodice | 229757b | 2020-11-15 16:06:10 +0000 | [diff] [blame] | 271 | { |
| 272 | const float r_mn = static_cast<float>(m) / static_cast<float>(n); |
| 273 | const float workload = (static_cast<float>(m) * static_cast<float>(n) * static_cast<float>(b)) / 20.0f; |
SiCong Li | a085a0c | 2020-12-02 14:54:34 +0000 | [diff] [blame] | 274 | const float r_mk = static_cast<float>(m) / static_cast<float>(k); |
| 275 | const float r_nk = static_cast<float>(n) / static_cast<float>(k); |
Gian Marco Iodice | 229757b | 2020-11-15 16:06:10 +0000 | [diff] [blame] | 276 | |
Gian Marco Iodice | 8919a1a | 2020-11-23 16:10:27 +0000 | [diff] [blame] | 277 | GEMMLHSMatrixInfo lhs_info_buf; |
| 278 | GEMMRHSMatrixInfo rhs_info_buf; |
| 279 | GEMMLHSMatrixInfo lhs_info_img; |
| 280 | GEMMRHSMatrixInfo rhs_info_img; |
| 281 | |
Gian Marco Iodice | 229757b | 2020-11-15 16:06:10 +0000 | [diff] [blame] | 282 | if(m == 1) |
| 283 | { |
Gian Marco Iodice | 8919a1a | 2020-11-23 16:10:27 +0000 | [diff] [blame] | 284 | std::tie(lhs_info_buf, rhs_info_buf) = configure_lhs_rhs_info(m, n, 1, 4, 16, 1, 16, false, true, false, false, false); |
| 285 | |
Gian Marco Iodice | 229757b | 2020-11-15 16:06:10 +0000 | [diff] [blame] | 286 | if(r_mk <= 0.0026f) |
| 287 | { |
| 288 | if(r_nk <= 0.4664f) |
| 289 | { |
| 290 | return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, 32, false, true, false, true, false); |
| 291 | } |
| 292 | else |
| 293 | { |
Gian Marco Iodice | 8919a1a | 2020-11-23 16:10:27 +0000 | [diff] [blame] | 294 | std::tie(lhs_info_img, rhs_info_img) = configure_lhs_rhs_info(m, n, 1, 4, 16, 1, 16, false, true, false, false, true); |
| 295 | return select_lhs_rhs_info(std::make_pair(lhs_info_img, rhs_info_img), |
| 296 | std::make_pair(lhs_info_buf, rhs_info_buf), |
| 297 | n, k, b, DataType::F16); |
Gian Marco Iodice | 229757b | 2020-11-15 16:06:10 +0000 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | else |
| 301 | { |
| 302 | if(r_mk <= 0.0148f) |
| 303 | { |
| 304 | return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, 32, false, true, false, true, false); |
| 305 | } |
| 306 | else |
| 307 | { |
Gian Marco Iodice | 8919a1a | 2020-11-23 16:10:27 +0000 | [diff] [blame] | 308 | std::tie(lhs_info_img, rhs_info_img) = configure_lhs_rhs_info(m, n, 1, 4, 16, 1, 16, false, true, false, false, true); |
| 309 | return select_lhs_rhs_info(std::make_pair(lhs_info_img, rhs_info_img), |
| 310 | std::make_pair(lhs_info_buf, rhs_info_buf), |
| 311 | n, k, b, DataType::F16); |
Gian Marco Iodice | 229757b | 2020-11-15 16:06:10 +0000 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | } |
| 315 | else |
| 316 | { |
Gian Marco Iodice | 8919a1a | 2020-11-23 16:10:27 +0000 | [diff] [blame] | 317 | std::tie(lhs_info_buf, rhs_info_buf) = configure_lhs_rhs_info(m, n, 5, 8, 4, 1, 2, false, false, false, false, false); |
| 318 | |
Gian Marco Iodice | 229757b | 2020-11-15 16:06:10 +0000 | [diff] [blame] | 319 | if(workload <= 362.6000f) |
| 320 | { |
| 321 | return configure_lhs_rhs_info(m, n, 2, 2, 8, 1, 16, false, false, false, true, false); |
| 322 | } |
| 323 | else |
| 324 | { |
| 325 | if(r_mn <= 22.6067f) |
| 326 | { |
| 327 | if(workload <= 708.8000f) |
| 328 | { |
Gian Marco Iodice | 8919a1a | 2020-11-23 16:10:27 +0000 | [diff] [blame] | 329 | std::tie(lhs_info_img, rhs_info_img) = configure_lhs_rhs_info(m, n, 5, 4, 4, 1, 2, false, false, false, false, true); |
| 330 | return select_lhs_rhs_info(std::make_pair(lhs_info_img, rhs_info_img), |
| 331 | std::make_pair(lhs_info_buf, rhs_info_buf), |
| 332 | n, k, b, DataType::F16); |
Gian Marco Iodice | 229757b | 2020-11-15 16:06:10 +0000 | [diff] [blame] | 333 | } |
| 334 | else |
| 335 | { |
| 336 | return configure_lhs_rhs_info(m, n, 5, 8, 2, 1, 16, false, false, false, false, false); |
| 337 | } |
| 338 | } |
| 339 | else |
| 340 | { |
| 341 | if(r_nk <= 0.0917f) |
| 342 | { |
| 343 | return configure_lhs_rhs_info(m, n, 2, 2, 8, 1, 16, false, false, false, true, false); |
| 344 | } |
| 345 | else |
| 346 | { |
Gian Marco Iodice | 8919a1a | 2020-11-23 16:10:27 +0000 | [diff] [blame] | 347 | std::tie(lhs_info_img, rhs_info_img) = configure_lhs_rhs_info(m, n, 5, 4, 4, 1, 2, false, false, false, false, true); |
| 348 | return select_lhs_rhs_info(std::make_pair(lhs_info_img, rhs_info_img), |
| 349 | std::make_pair(lhs_info_buf, rhs_info_buf), |
| 350 | n, k, b, DataType::F16); |
Gian Marco Iodice | 229757b | 2020-11-15 16:06:10 +0000 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | |
SiCong Li | a085a0c | 2020-12-02 14:54:34 +0000 | [diff] [blame] | 357 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G76_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 358 | { |
| 359 | ARM_COMPUTE_UNUSED(k); |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 360 | |
| 361 | if(m == 1) |
| 362 | { |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 363 | return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, 32, false, true, false, true, false); |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 364 | } |
| 365 | else |
| 366 | { |
Gian Marco Iodice | 839e198 | 2020-10-29 13:36:50 +0000 | [diff] [blame] | 367 | const float r_mn = static_cast<float>(m) / static_cast<float>(n); |
| 368 | const float workload = (static_cast<float>(m) * static_cast<float>(n) * static_cast<float>(b)) / 20.0f; |
| 369 | |
| 370 | if(workload <= 7449.60f) |
| 371 | { |
| 372 | if(workload <= 691.60f) |
| 373 | { |
| 374 | return configure_lhs_rhs_info(m, n, 2, 2, 8, 1, 8, false, false, false, false, false); |
| 375 | } |
| 376 | else |
| 377 | { |
| 378 | if(workload <= 4155.20f) |
| 379 | { |
| 380 | return configure_lhs_rhs_info(m, n, 5, 2, 8, 1, 16, false, false, false, false, false); |
| 381 | } |
| 382 | else |
| 383 | { |
| 384 | return configure_lhs_rhs_info(m, n, 5, 8, 2, 1, 32, false, false, false, false, false); |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | else |
| 389 | { |
| 390 | if(workload <= 16300.80f) |
| 391 | { |
| 392 | if(r_mn <= 44.56f) |
| 393 | { |
| 394 | GEMMLHSMatrixInfo lhs_info_buf; |
| 395 | GEMMRHSMatrixInfo rhs_info_buf; |
| 396 | GEMMLHSMatrixInfo lhs_info_img; |
| 397 | GEMMRHSMatrixInfo rhs_info_img; |
| 398 | |
Gian Marco Iodice | 2344189 | 2021-01-21 12:23:22 +0000 | [diff] [blame] | 399 | std::tie(lhs_info_img, rhs_info_img) = configure_lhs_rhs_info(m, n, 8, 4, 4, 1, 1, false, true, false, false, true); |
Gian Marco Iodice | 839e198 | 2020-10-29 13:36:50 +0000 | [diff] [blame] | 400 | std::tie(lhs_info_buf, rhs_info_buf) = configure_lhs_rhs_info(m, n, 5, 2, 8, 1, 16, false, false, false, false, false); |
| 401 | |
| 402 | return select_lhs_rhs_info(std::make_pair(lhs_info_img, rhs_info_img), |
| 403 | std::make_pair(lhs_info_buf, rhs_info_buf), |
| 404 | n, k, b, DataType::F16); |
| 405 | } |
| 406 | else |
| 407 | { |
| 408 | return configure_lhs_rhs_info(m, n, 5, 2, 8, 1, 16, false, false, false, false, false); |
| 409 | } |
| 410 | } |
| 411 | else |
| 412 | { |
| 413 | GEMMLHSMatrixInfo lhs_info_buf; |
| 414 | GEMMRHSMatrixInfo rhs_info_buf; |
| 415 | GEMMLHSMatrixInfo lhs_info_img; |
| 416 | GEMMRHSMatrixInfo rhs_info_img; |
| 417 | |
| 418 | std::tie(lhs_info_img, rhs_info_img) = configure_lhs_rhs_info(m, n, 5, 4, 4, 1, 2, false, true, false, false, true); |
| 419 | std::tie(lhs_info_buf, rhs_info_buf) = configure_lhs_rhs_info(m, n, 5, 2, 8, 1, 16, false, false, false, false, false); |
| 420 | |
| 421 | return select_lhs_rhs_info(std::make_pair(lhs_info_img, rhs_info_img), |
| 422 | std::make_pair(lhs_info_buf, rhs_info_buf), |
| 423 | n, k, b, DataType::F16); |
| 424 | } |
| 425 | } |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
SiCong Li | a085a0c | 2020-12-02 14:54:34 +0000 | [diff] [blame] | 429 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G51_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 430 | { |
| 431 | ARM_COMPUTE_UNUSED(k); |
| 432 | ARM_COMPUTE_UNUSED(b); |
| 433 | |
| 434 | if(m == 1) |
| 435 | { |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame] | 436 | const unsigned int n0 = n < 1280 ? 2 : 4; |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 437 | const unsigned int h0 = std::max(n / n0, 1U); |
| 438 | return configure_lhs_rhs_info(m, n, 1, n0, 8, 1, h0, false, true, false, true); |
| 439 | } |
| 440 | else |
| 441 | { |
| 442 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 1, 2, false, true, false, true); |
| 443 | } |
| 444 | } |
| 445 | |
SiCong Li | a085a0c | 2020-12-02 14:54:34 +0000 | [diff] [blame] | 446 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G7x_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 447 | { |
| 448 | ARM_COMPUTE_UNUSED(k); |
| 449 | ARM_COMPUTE_UNUSED(b); |
| 450 | |
| 451 | if(dot8_supported(CLKernelLibrary::get().get_device())) |
| 452 | { |
| 453 | if(m == 1) |
| 454 | { |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 455 | const unsigned int h0 = std::max(n / 2, 1U); |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 456 | return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, h0, false, true, false, true); |
| 457 | } |
| 458 | else |
| 459 | { |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 460 | const unsigned int h0 = std::max(n / 4, 1U); |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 461 | return configure_lhs_rhs_info(m, n, 4, 4, 16, 1, h0, false, true, false, true); |
| 462 | } |
| 463 | } |
| 464 | else |
| 465 | { |
Gian Marco Iodice | eb65f6d | 2020-04-15 11:42:15 +0100 | [diff] [blame] | 466 | 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] | 467 | if(m == 1) |
| 468 | { |
Gian Marco Iodice | 2ec6c1e | 2019-04-09 12:03:05 +0100 | [diff] [blame] | 469 | 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] | 470 | } |
| 471 | else |
| 472 | { |
Gian Marco Iodice | eb65f6d | 2020-04-15 11:42:15 +0100 | [diff] [blame] | 473 | 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] | 474 | } |
| 475 | } |
| 476 | } |
| 477 | |
SiCong Li | a085a0c | 2020-12-02 14:54:34 +0000 | [diff] [blame] | 478 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G76_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 479 | { |
| 480 | ARM_COMPUTE_UNUSED(k); |
| 481 | ARM_COMPUTE_UNUSED(b); |
| 482 | |
| 483 | if(m == 1) |
| 484 | { |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 485 | const unsigned int h0 = std::max(n / 2, 1U); |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 486 | return configure_lhs_rhs_info(m, n, 1, 2, 16, 1, h0, false, true, false, true); |
| 487 | } |
| 488 | else |
| 489 | { |
| 490 | return configure_lhs_rhs_info(m, n, 4, 4, 16, 1, 2, false, true, false, true); |
| 491 | } |
| 492 | } |
Gian Marco Iodice | ee6454a | 2019-09-17 10:56:51 +0100 | [diff] [blame] | 493 | |
SiCong Li | a085a0c | 2020-12-02 14:54:34 +0000 | [diff] [blame] | 494 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMDefaultConfigReshapedRHSOnlyBifrost::configure_G51_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
Gian Marco Iodice | ee6454a | 2019-09-17 10:56:51 +0100 | [diff] [blame] | 495 | { |
| 496 | ARM_COMPUTE_UNUSED(k); |
| 497 | ARM_COMPUTE_UNUSED(b); |
| 498 | |
| 499 | if(m == 1) |
| 500 | { |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 501 | const unsigned int h0 = std::max(n / 2, 1U); |
Gian Marco Iodice | ee6454a | 2019-09-17 10:56:51 +0100 | [diff] [blame] | 502 | return configure_lhs_rhs_info(m, n, 1, 4, 16, 1, h0, false, true, false, true); |
| 503 | } |
| 504 | else |
| 505 | { |
Gian Marco Iodice | 0d54804 | 2019-10-03 15:12:09 +0100 | [diff] [blame] | 506 | const unsigned int h0 = std::max(n / 2, 1U); |
Gian Marco Iodice | ee6454a | 2019-09-17 10:56:51 +0100 | [diff] [blame] | 507 | return configure_lhs_rhs_info(m, n, 4, 2, 16, 1, h0, false, true, false, true); |
| 508 | } |
| 509 | } |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame] | 510 | |
Gian Marco Iodice | 926afe1 | 2019-03-19 11:44:13 +0000 | [diff] [blame] | 511 | } // namespace cl_gemm |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame] | 512 | } // namespace arm_compute |