Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2020 Arm Limited. |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +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 | */ |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 24 | #include "src/core/CL/gemm/reshaped/CLGEMMReshapedKernelConfigurationValhall.h" |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame] | 25 | |
| 26 | #include "arm_compute/core/CL/CLHelpers.h" |
| 27 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/GPUTarget.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 29 | #include "src/core/CL/gemm/CLGEMMHelpers.h" |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame] | 30 | |
| 31 | #include <map> |
| 32 | #include <utility> |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | namespace cl_gemm |
| 37 | { |
| 38 | CLGEMMReshapedKernelConfigurationValhall::CLGEMMReshapedKernelConfigurationValhall(GPUTarget gpu) |
| 39 | : ICLGEMMKernelConfiguration(gpu) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedKernelConfigurationValhall::configure(unsigned int m, unsigned int n, unsigned int k, unsigned int b, DataType data_type) |
| 44 | { |
| 45 | using ConfigurationFunctionExecutorPtr = std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> (CLGEMMReshapedKernelConfigurationValhall::*)(unsigned int m, unsigned int n, unsigned int k, unsigned int b); |
| 46 | |
| 47 | // Configurations for Mali-G77 |
| 48 | static std::map<DataType, ConfigurationFunctionExecutorPtr> gemm_configs_G77 = |
| 49 | { |
| 50 | { DataType::F32, &CLGEMMReshapedKernelConfigurationValhall::configure_G77_f32 }, |
| 51 | { DataType::F16, &CLGEMMReshapedKernelConfigurationValhall::configure_G77_f16 }, |
Gian Marco Iodice | eb65f6d | 2020-04-15 11:42:15 +0100 | [diff] [blame] | 52 | { DataType::QASYMM8, &CLGEMMReshapedKernelConfigurationValhall::configure_G77_u8 }, |
| 53 | { DataType::QSYMM8, &CLGEMMReshapedKernelConfigurationValhall::configure_G77_u8 }, |
| 54 | { DataType::QASYMM8_SIGNED, &CLGEMMReshapedKernelConfigurationValhall::configure_G77_u8 }, |
| 55 | { DataType::QSYMM8_PER_CHANNEL, &CLGEMMReshapedKernelConfigurationValhall::configure_G77_u8 } |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | switch(_target) |
| 59 | { |
| 60 | case GPUTarget::G77: |
| 61 | default: |
| 62 | if(gemm_configs_G77.find(data_type) != gemm_configs_G77.end()) |
| 63 | { |
| 64 | return (this->*gemm_configs_G77[data_type])(m, n, k, b); |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | ARM_COMPUTE_ERROR("Not supported data type"); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedKernelConfigurationValhall::configure_G77_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
| 74 | { |
| 75 | ARM_COMPUTE_UNUSED(k); |
| 76 | ARM_COMPUTE_UNUSED(b); |
| 77 | |
| 78 | if(n <= 4) |
| 79 | { |
| 80 | return configure_lhs_rhs_info(m, n, 4, 2, 8, 16, 16, true, false, false, true); |
| 81 | } |
| 82 | else |
| 83 | { |
| 84 | return configure_lhs_rhs_info(m, n, 5, 4, 4, 2, 16, false, true, false, true); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedKernelConfigurationValhall::configure_G77_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
| 89 | { |
| 90 | ARM_COMPUTE_UNUSED(k); |
| 91 | ARM_COMPUTE_UNUSED(b); |
| 92 | |
Gian Marco Iodice | 491f30c | 2020-11-02 15:43:57 +0000 | [diff] [blame^] | 93 | const float r_mn = static_cast<float>(m) / static_cast<float>(n); |
| 94 | const float workload = (static_cast<float>(m) * static_cast<float>(n) * static_cast<float>(b)) / 20.0f; |
| 95 | const float r_mk = static_cast<float>(m) / static_cast<float>(k); |
| 96 | const float r_nk = static_cast<float>(n) / static_cast<float>(k); |
| 97 | |
| 98 | if(r_mk <= 0.11824845522642136) |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame] | 99 | { |
Gian Marco Iodice | 491f30c | 2020-11-02 15:43:57 +0000 | [diff] [blame^] | 100 | if(workload <= 880.0) |
| 101 | { |
| 102 | return configure_lhs_rhs_info(m, n, 2, 4, 4, 1, 4, false, false, true, false, false); |
| 103 | } |
| 104 | else |
| 105 | { |
| 106 | if(r_nk <= 0.42521367967128754) |
| 107 | { |
| 108 | if(workload <= 1726.4000244140625) |
| 109 | { |
| 110 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 2, 2, false, false, true, false, false); |
| 111 | } |
| 112 | else |
| 113 | { |
| 114 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 2, 1, false, true, true, false, true); |
| 115 | } |
| 116 | } |
| 117 | else |
| 118 | { |
| 119 | if(workload <= 1241.6000366210938) |
| 120 | { |
| 121 | return configure_lhs_rhs_info(m, n, 2, 4, 4, 1, 4, false, false, true, false, false); |
| 122 | } |
| 123 | else |
| 124 | { |
| 125 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 4, 4, false, false, true, false, false); |
| 126 | } |
| 127 | } |
| 128 | } |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame] | 129 | } |
| 130 | else |
| 131 | { |
Gian Marco Iodice | 491f30c | 2020-11-02 15:43:57 +0000 | [diff] [blame^] | 132 | if(workload <= 11404.7998046875) |
| 133 | { |
| 134 | if(r_mk <= 1.0126488208770752) |
| 135 | { |
| 136 | if(r_mn <= 2.545312523841858) |
| 137 | { |
| 138 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 2, 1, false, true, true, false, true); |
| 139 | } |
| 140 | else |
| 141 | { |
| 142 | return configure_lhs_rhs_info(m, n, 2, 4, 4, 1, 4, false, false, true, false, false); |
| 143 | } |
| 144 | } |
| 145 | else |
| 146 | { |
| 147 | if(workload <= 2881.199951171875) |
| 148 | { |
| 149 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 4, 2, false, false, true, false, true); |
| 150 | } |
| 151 | else |
| 152 | { |
| 153 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 2, 1, false, true, true, false, true); |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | else |
| 158 | { |
| 159 | if(r_nk <= 0.5765306055545807) |
| 160 | { |
| 161 | if(r_mn <= 6.010416746139526) |
| 162 | { |
| 163 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 2, 1, false, true, true, false, true); |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 2, 1, true, false, true, false, true); |
| 168 | } |
| 169 | } |
| 170 | else |
| 171 | { |
| 172 | return configure_lhs_rhs_info(m, n, 4, 4, 4, 2, 1, true, false, true, false, true); |
| 173 | } |
| 174 | } |
Gian Marco Iodice | 12f2b8c | 2020-02-13 12:27:37 +0000 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
| 178 | std::pair<GEMMLHSMatrixInfo, GEMMRHSMatrixInfo> CLGEMMReshapedKernelConfigurationValhall::configure_G77_u8(unsigned int m, unsigned int n, unsigned int k, unsigned int b) |
| 179 | { |
| 180 | ARM_COMPUTE_UNUSED(k); |
| 181 | ARM_COMPUTE_UNUSED(b); |
| 182 | |
| 183 | if(n <= 4) |
| 184 | { |
| 185 | return configure_lhs_rhs_info(m, n, 4, 2, 16, 4, 1, false, false, false, true); |
| 186 | } |
| 187 | else |
| 188 | { |
| 189 | return configure_lhs_rhs_info(m, n, 4, 4, 16, 2, 2, false, true, false, true); |
| 190 | } |
| 191 | } |
| 192 | } // namespace cl_gemm |
| 193 | } // namespace arm_compute |