Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2023 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [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/CLHelpers.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 25 | |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/CL/CLTypes.h" |
| 28 | #include "arm_compute/core/Error.h" |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 29 | #include "arm_compute/core/Log.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/Types.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 31 | #include "arm_compute/core/utils/DataTypeUtils.h" |
Georgios Pinitas | 908f616 | 2021-05-04 10:11:09 +0100 | [diff] [blame] | 32 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 33 | #include "src/gpu/cl/ClCompileContext.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 34 | #include "src/gpu/cl/ClKernelLibrary.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 35 | |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 36 | #include <utility> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 37 | #include <vector> |
| 38 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 39 | namespace arm_compute |
| 40 | { |
| 41 | std::string get_cl_type_from_data_type(const DataType &dt) |
| 42 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 43 | switch (dt) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 44 | { |
| 45 | case DataType::U8: |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 46 | case DataType::QASYMM8: |
| 47 | return "uchar"; |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 48 | case DataType::S8: |
Michele Di Giorgio | f9179d3 | 2019-11-27 16:17:30 +0000 | [diff] [blame] | 49 | case DataType::QASYMM8_SIGNED: |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 50 | case DataType::QSYMM8: |
Michalis Spyrou | 3f632f3 | 2019-08-22 16:52:00 +0100 | [diff] [blame] | 51 | case DataType::QSYMM8_PER_CHANNEL: |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 52 | return "char"; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 53 | case DataType::U16: |
Michele Di Giorgio | 4aff98f | 2019-08-28 16:27:26 +0100 | [diff] [blame] | 54 | case DataType::QASYMM16: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 55 | return "ushort"; |
| 56 | case DataType::S16: |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 57 | case DataType::QSYMM16: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 58 | return "short"; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 59 | case DataType::U32: |
| 60 | return "uint"; |
| 61 | case DataType::S32: |
| 62 | return "int"; |
| 63 | case DataType::U64: |
| 64 | return "ulong"; |
| 65 | case DataType::S64: |
| 66 | return "long"; |
| 67 | case DataType::F16: |
| 68 | return "half"; |
| 69 | case DataType::F32: |
| 70 | return "float"; |
| 71 | default: |
| 72 | ARM_COMPUTE_ERROR("Unsupported input data type."); |
| 73 | return ""; |
| 74 | } |
| 75 | } |
| 76 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 77 | std::string get_cl_promoted_type_from_data_type(const DataType &dt) |
| 78 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 79 | switch (dt) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 80 | { |
| 81 | case DataType::U8: |
| 82 | case DataType::QASYMM8: |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 83 | return "ushort"; |
| 84 | case DataType::S8: |
Michele Di Giorgio | f9179d3 | 2019-11-27 16:17:30 +0000 | [diff] [blame] | 85 | case DataType::QASYMM8_SIGNED: |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 86 | case DataType::QSYMM8: |
| 87 | case DataType::QSYMM8_PER_CHANNEL: |
| 88 | return "short"; |
| 89 | case DataType::U16: |
| 90 | case DataType::QASYMM16: |
| 91 | return "uint"; |
| 92 | case DataType::S16: |
| 93 | case DataType::QSYMM16: |
| 94 | return "int"; |
| 95 | case DataType::U32: |
| 96 | return "ulong"; |
| 97 | case DataType::S32: |
| 98 | return "long"; |
| 99 | case DataType::F16: |
| 100 | return "float"; |
| 101 | default: |
| 102 | ARM_COMPUTE_ERROR("Cannot get promoted OpenCL type for the input data type."); |
| 103 | return ""; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | std::string get_cl_unsigned_type_from_element_size(size_t element_size) |
| 108 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 109 | switch (element_size) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 110 | { |
| 111 | case 1: |
| 112 | return "uchar"; |
| 113 | case 2: |
| 114 | return "ushort"; |
| 115 | case 4: |
| 116 | return "uint"; |
| 117 | case 8: |
| 118 | return "ulong"; |
| 119 | default: |
| 120 | ARM_COMPUTE_ERROR("Data type not supported"); |
| 121 | return ""; |
| 122 | } |
| 123 | } |
| 124 | |
Michalis Spyrou | 7317e39 | 2020-01-17 11:27:49 +0000 | [diff] [blame] | 125 | std::string get_cl_signed_type_from_element_size(size_t element_size) |
| 126 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 127 | switch (element_size) |
Michalis Spyrou | 7317e39 | 2020-01-17 11:27:49 +0000 | [diff] [blame] | 128 | { |
| 129 | case 1: |
| 130 | return "char"; |
| 131 | case 2: |
| 132 | return "short"; |
| 133 | case 4: |
| 134 | return "int"; |
| 135 | case 8: |
| 136 | return "long"; |
| 137 | default: |
| 138 | ARM_COMPUTE_ERROR("Data type not supported"); |
| 139 | return ""; |
| 140 | } |
| 141 | } |
| 142 | |
Giorgio Arena | 7302302 | 2018-09-04 14:55:55 +0100 | [diff] [blame] | 143 | std::string get_cl_select_type_from_data_type(const DataType &dt) |
| 144 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 145 | switch (dt) |
Giorgio Arena | 7302302 | 2018-09-04 14:55:55 +0100 | [diff] [blame] | 146 | { |
| 147 | case DataType::U8: |
Giorgio Arena | 7302302 | 2018-09-04 14:55:55 +0100 | [diff] [blame] | 148 | case DataType::QASYMM8: |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 149 | case DataType::S8: |
Michele Di Giorgio | f9179d3 | 2019-11-27 16:17:30 +0000 | [diff] [blame] | 150 | case DataType::QASYMM8_SIGNED: |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 151 | case DataType::QSYMM8: |
Michalis Spyrou | 3f632f3 | 2019-08-22 16:52:00 +0100 | [diff] [blame] | 152 | case DataType::QSYMM8_PER_CHANNEL: |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 153 | return "char"; |
Giorgio Arena | 7302302 | 2018-09-04 14:55:55 +0100 | [diff] [blame] | 154 | case DataType::U16: |
Michele Di Giorgio | 4aff98f | 2019-08-28 16:27:26 +0100 | [diff] [blame] | 155 | case DataType::QASYMM16: |
Giorgio Arena | 7302302 | 2018-09-04 14:55:55 +0100 | [diff] [blame] | 156 | return "ushort"; |
| 157 | case DataType::F16: |
| 158 | case DataType::S16: |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 159 | case DataType::QSYMM16: |
Giorgio Arena | 7302302 | 2018-09-04 14:55:55 +0100 | [diff] [blame] | 160 | return "short"; |
| 161 | case DataType::U32: |
| 162 | return "uint"; |
| 163 | case DataType::F32: |
| 164 | case DataType::S32: |
| 165 | return "int"; |
| 166 | case DataType::U64: |
| 167 | return "ulong"; |
| 168 | case DataType::S64: |
| 169 | return "long"; |
| 170 | default: |
| 171 | ARM_COMPUTE_ERROR("Unsupported input data type."); |
| 172 | return ""; |
| 173 | } |
| 174 | } |
| 175 | |
Michele Di Giorgio | f9179d3 | 2019-11-27 16:17:30 +0000 | [diff] [blame] | 176 | std::string get_cl_dot8_acc_type_from_data_type(const DataType &dt) |
| 177 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 178 | switch (dt) |
Michele Di Giorgio | f9179d3 | 2019-11-27 16:17:30 +0000 | [diff] [blame] | 179 | { |
| 180 | case DataType::U8: |
| 181 | case DataType::QASYMM8: |
| 182 | return "uint"; |
| 183 | case DataType::S8: |
| 184 | case DataType::QASYMM8_SIGNED: |
| 185 | case DataType::QSYMM8: |
| 186 | case DataType::QSYMM8_PER_CHANNEL: |
| 187 | return "int"; |
| 188 | default: |
| 189 | ARM_COMPUTE_ERROR("Unsupported data type."); |
| 190 | return ""; |
| 191 | } |
| 192 | } |
| 193 | |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 194 | std::string get_data_size_from_data_type(const DataType &dt) |
| 195 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 196 | switch (dt) |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 197 | { |
| 198 | case DataType::U8: |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 199 | case DataType::S8: |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 200 | case DataType::QSYMM8: |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 201 | case DataType::QASYMM8: |
Michele Di Giorgio | f9179d3 | 2019-11-27 16:17:30 +0000 | [diff] [blame] | 202 | case DataType::QASYMM8_SIGNED: |
Michalis Spyrou | 3f632f3 | 2019-08-22 16:52:00 +0100 | [diff] [blame] | 203 | case DataType::QSYMM8_PER_CHANNEL: |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 204 | return "8"; |
| 205 | case DataType::U16: |
| 206 | case DataType::S16: |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 207 | case DataType::QSYMM16: |
Michele Di Giorgio | 4aff98f | 2019-08-28 16:27:26 +0100 | [diff] [blame] | 208 | case DataType::QASYMM16: |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 209 | case DataType::F16: |
| 210 | return "16"; |
| 211 | case DataType::U32: |
| 212 | case DataType::S32: |
| 213 | case DataType::F32: |
| 214 | return "32"; |
| 215 | case DataType::U64: |
| 216 | case DataType::S64: |
| 217 | return "64"; |
| 218 | default: |
| 219 | ARM_COMPUTE_ERROR("Unsupported input data type."); |
| 220 | return "0"; |
| 221 | } |
| 222 | } |
| 223 | |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 224 | GPUTarget get_target_from_device(const cl::Device &device) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 225 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 226 | // Query device name size |
Anthony Barbier | 30a6342 | 2018-02-28 18:18:24 +0000 | [diff] [blame] | 227 | std::string device_name = device.getInfo<CL_DEVICE_NAME>(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 228 | |
Michalis Spyrou | a967611 | 2018-02-22 18:07:43 +0000 | [diff] [blame] | 229 | return get_target_from_name(device_name); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 230 | } |
| 231 | |
Anthony Barbier | d727e85 | 2018-04-20 11:05:29 +0100 | [diff] [blame] | 232 | bool arm_non_uniform_workgroup_supported(const cl::Device &device) |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 233 | { |
Vidhya Sudhan Loganathan | eb8a399 | 2018-04-10 12:23:22 +0100 | [diff] [blame] | 234 | return device_supports_extension(device, "cl_arm_non_uniform_work_group_size"); |
Matthew Bentham | 6f31f8c | 2017-10-27 11:50:06 +0100 | [diff] [blame] | 235 | } |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 236 | |
Anthony Barbier | d727e85 | 2018-04-20 11:05:29 +0100 | [diff] [blame] | 237 | bool fp16_supported(const cl::Device &device) |
Matthew Bentham | 6f31f8c | 2017-10-27 11:50:06 +0100 | [diff] [blame] | 238 | { |
Vidhya Sudhan Loganathan | eb8a399 | 2018-04-10 12:23:22 +0100 | [diff] [blame] | 239 | return device_supports_extension(device, "cl_khr_fp16"); |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 240 | } |
| 241 | |
Michalis Spyrou | e03342e | 2018-01-15 14:39:13 +0000 | [diff] [blame] | 242 | bool dot8_supported(const cl::Device &device) |
| 243 | { |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 244 | std::string device_name = device.getInfo<CL_DEVICE_NAME>(); |
| 245 | const GPUTarget gpu_target = get_target_from_name(device_name); |
| 246 | |
| 247 | // SW_WORKAROUND: Workaround for DDK revision r14p0.to enable cl_arm_integer_dot_product_int8 |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 248 | std::set<GPUTarget> sw_workaround_issue = {GPUTarget::G76}; |
| 249 | return (device_supports_extension(device, "cl_arm_integer_dot_product_int8") || |
| 250 | sw_workaround_issue.count(gpu_target) != 0); |
Michalis Spyrou | e03342e | 2018-01-15 14:39:13 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 253 | bool dot8_acc_supported(const cl::Device &device) |
| 254 | { |
| 255 | return device_supports_extension(device, "cl_arm_integer_dot_product_accumulate_int8"); |
| 256 | } |
| 257 | |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 258 | CLVersion get_cl_version(const cl::Device &device) |
| 259 | { |
Anthony Barbier | 30a6342 | 2018-02-28 18:18:24 +0000 | [diff] [blame] | 260 | std::string version_str = device.getInfo<CL_DEVICE_VERSION>(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 261 | if (version_str.find("OpenCL 3") != std::string::npos) |
Viet-Hoa Do | f8bb092 | 2022-05-30 15:15:15 +0100 | [diff] [blame] | 262 | { |
| 263 | return CLVersion::CL30; |
| 264 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 265 | else if (version_str.find("OpenCL 2") != std::string::npos) |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 266 | { |
| 267 | return CLVersion::CL20; |
| 268 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 269 | else if (version_str.find("OpenCL 1.2") != std::string::npos) |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 270 | { |
| 271 | return CLVersion::CL12; |
| 272 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 273 | else if (version_str.find("OpenCL 1.1") != std::string::npos) |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 274 | { |
| 275 | return CLVersion::CL11; |
| 276 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 277 | else if (version_str.find("OpenCL 1.0") != std::string::npos) |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 278 | { |
| 279 | return CLVersion::CL10; |
| 280 | } |
| 281 | |
| 282 | return CLVersion::UNKNOWN; |
| 283 | } |
| 284 | |
Vidhya Sudhan Loganathan | eb8a399 | 2018-04-10 12:23:22 +0100 | [diff] [blame] | 285 | bool device_supports_extension(const cl::Device &device, const char *extension_name) |
| 286 | { |
| 287 | std::string extensions = device.getInfo<CL_DEVICE_EXTENSIONS>(); |
| 288 | auto pos = extensions.find(extension_name); |
| 289 | return (pos != std::string::npos); |
| 290 | } |
| 291 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 292 | bool cl_winograd_convolution_layer_supported(const Size2D &output_tile, |
| 293 | const Size2D &kernel_size, |
| 294 | DataLayout data_layout) |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 295 | { |
| 296 | ARM_COMPUTE_ERROR_ON(data_layout == DataLayout::UNKNOWN); |
| 297 | |
| 298 | using WinogradConfiguration = std::pair<std::pair<int, int>, std::pair<int, int>>; |
| 299 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 300 | std::vector<WinogradConfiguration> winograd_configs_nchw = { |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 301 | WinogradConfiguration(std::pair<int, int>(1, 2), std::pair<int, int>(1, 3)), |
| 302 | WinogradConfiguration(std::pair<int, int>(1, 4), std::pair<int, int>(1, 3)), |
| 303 | WinogradConfiguration(std::pair<int, int>(2, 1), std::pair<int, int>(3, 1)), |
| 304 | WinogradConfiguration(std::pair<int, int>(4, 1), std::pair<int, int>(3, 1)), |
| 305 | WinogradConfiguration(std::pair<int, int>(2, 2), std::pair<int, int>(3, 3)), |
| 306 | WinogradConfiguration(std::pair<int, int>(4, 4), std::pair<int, int>(3, 3)), |
Gian Marco Iodice | 876be2a | 2018-07-03 12:22:09 +0100 | [diff] [blame] | 307 | WinogradConfiguration(std::pair<int, int>(4, 4), std::pair<int, int>(5, 5)), |
| 308 | WinogradConfiguration(std::pair<int, int>(4, 1), std::pair<int, int>(5, 1)), |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 309 | WinogradConfiguration(std::pair<int, int>(1, 4), std::pair<int, int>(1, 5))}; |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 310 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 311 | std::vector<WinogradConfiguration> winograd_configs_nhwc = { |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 312 | WinogradConfiguration(std::pair<int, int>(2, 2), std::pair<int, int>(3, 3)), |
Giorgio Arena | 149fdf3 | 2018-07-04 17:03:33 +0100 | [diff] [blame] | 313 | WinogradConfiguration(std::pair<int, int>(1, 4), std::pair<int, int>(1, 3)), |
| 314 | WinogradConfiguration(std::pair<int, int>(4, 1), std::pair<int, int>(3, 1)), |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 315 | WinogradConfiguration(std::pair<int, int>(4, 4), std::pair<int, int>(3, 3)), |
Gian Marco Iodice | d28b751 | 2018-07-06 12:59:28 +0100 | [diff] [blame] | 316 | WinogradConfiguration(std::pair<int, int>(4, 4), std::pair<int, int>(5, 5)), |
| 317 | WinogradConfiguration(std::pair<int, int>(4, 1), std::pair<int, int>(5, 1)), |
Michele Di Giorgio | f955d51 | 2019-02-27 14:26:51 +0000 | [diff] [blame] | 318 | WinogradConfiguration(std::pair<int, int>(1, 4), std::pair<int, int>(1, 5)), |
| 319 | WinogradConfiguration(std::pair<int, int>(1, 2), std::pair<int, int>(1, 7)), |
| 320 | WinogradConfiguration(std::pair<int, int>(2, 1), std::pair<int, int>(7, 1)), |
| 321 | WinogradConfiguration(std::pair<int, int>(2, 2), std::pair<int, int>(7, 7)), |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 322 | }; |
| 323 | |
| 324 | auto p = std::make_pair(std::pair<int, int>(output_tile.width, output_tile.height), |
| 325 | std::pair<int, int>(kernel_size.width, kernel_size.height)); |
| 326 | |
| 327 | // Return true if supported |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 328 | if (data_layout == DataLayout::NCHW) |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 329 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 330 | return (std::find(winograd_configs_nchw.begin(), winograd_configs_nchw.end(), p) != |
| 331 | winograd_configs_nchw.end()); |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 332 | } |
| 333 | else |
| 334 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 335 | return (std::find(winograd_configs_nhwc.begin(), winograd_configs_nhwc.end(), p) != |
| 336 | winograd_configs_nhwc.end()); |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 337 | } |
| 338 | } |
Vidhya Sudhan Loganathan | 5e96be7 | 2018-12-18 14:17:00 +0000 | [diff] [blame] | 339 | |
| 340 | size_t preferred_vector_width(const cl::Device &device, const DataType dt) |
| 341 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 342 | switch (dt) |
Vidhya Sudhan Loganathan | 5e96be7 | 2018-12-18 14:17:00 +0000 | [diff] [blame] | 343 | { |
| 344 | case DataType::U8: |
| 345 | case DataType::S8: |
| 346 | case DataType::QASYMM8: |
Michele Di Giorgio | f9179d3 | 2019-11-27 16:17:30 +0000 | [diff] [blame] | 347 | case DataType::QASYMM8_SIGNED: |
Georgios Pinitas | 3d13af8 | 2019-06-04 13:04:16 +0100 | [diff] [blame] | 348 | case DataType::QSYMM8: |
Michalis Spyrou | 3f632f3 | 2019-08-22 16:52:00 +0100 | [diff] [blame] | 349 | case DataType::QSYMM8_PER_CHANNEL: |
Vidhya Sudhan Loganathan | 5e96be7 | 2018-12-18 14:17:00 +0000 | [diff] [blame] | 350 | return device.getInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR>(); |
| 351 | case DataType::U16: |
| 352 | case DataType::S16: |
Michele Di Giorgio | 6997fc9 | 2019-06-18 10:23:22 +0100 | [diff] [blame] | 353 | case DataType::QSYMM16: |
Michele Di Giorgio | 4aff98f | 2019-08-28 16:27:26 +0100 | [diff] [blame] | 354 | case DataType::QASYMM16: |
Vidhya Sudhan Loganathan | 5e96be7 | 2018-12-18 14:17:00 +0000 | [diff] [blame] | 355 | return device.getInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT>(); |
| 356 | case DataType::U32: |
| 357 | case DataType::S32: |
| 358 | return device.getInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT>(); |
| 359 | case DataType::F16: |
| 360 | case DataType::F32: |
| 361 | return device.getInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT>(); |
| 362 | case DataType::U64: |
| 363 | case DataType::S64: |
| 364 | return device.getInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG>(); |
| 365 | default: |
| 366 | return 1; |
| 367 | } |
| 368 | } |
Gian Marco Iodice | b0c5037 | 2019-03-15 10:13:05 +0000 | [diff] [blame] | 369 | |
| 370 | bool preferred_dummy_work_items_support(const cl::Device &device) |
| 371 | { |
| 372 | ARM_COMPUTE_UNUSED(device); |
| 373 | // TODO (COMPMID-2044) |
| 374 | return true; |
| 375 | } |
Pablo Tello | db8485a | 2019-09-24 11:03:47 +0100 | [diff] [blame] | 376 | |
Gian Marco Iodice | a98dee2 | 2020-06-02 12:12:35 +0100 | [diff] [blame] | 377 | bool image2d_from_buffer_supported(const cl::Device &device) |
| 378 | { |
| 379 | return device_supports_extension(device, "cl_khr_image2d_from_buffer"); |
| 380 | } |
| 381 | |
| 382 | size_t get_cl_image_pitch_alignment(const cl::Device &device) |
| 383 | { |
| 384 | cl_uint pixel_aligment = 0; |
| 385 | |
| 386 | cl_int err = clGetDeviceInfo(device(), CL_DEVICE_IMAGE_PITCH_ALIGNMENT, sizeof(cl_uint), &pixel_aligment, nullptr); |
| 387 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 388 | if (err == CL_SUCCESS) |
Gian Marco Iodice | a98dee2 | 2020-06-02 12:12:35 +0100 | [diff] [blame] | 389 | { |
| 390 | return pixel_aligment; |
| 391 | } |
| 392 | else |
| 393 | { |
| 394 | return 0; |
| 395 | } |
| 396 | } |
| 397 | |
Viet-Hoa Do | f8bb092 | 2022-05-30 15:15:15 +0100 | [diff] [blame] | 398 | bool get_cl_non_uniform_work_group_supported(const cl::Device &device) |
| 399 | { |
| 400 | cl_bool supported = CL_FALSE; |
| 401 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 402 | cl_int err = |
| 403 | clGetDeviceInfo(device(), CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT, sizeof(cl_bool), &supported, nullptr); |
Viet-Hoa Do | f8bb092 | 2022-05-30 15:15:15 +0100 | [diff] [blame] | 404 | |
| 405 | return (err == CL_SUCCESS && supported == CL_TRUE); |
| 406 | } |
| 407 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 408 | cl::Kernel |
| 409 | create_kernel(const CLCompileContext &ctx, const std::string &kernel_name, const std::set<std::string> &build_opts) |
Michalis Spyrou | 11d4918 | 2020-03-26 10:31:32 +0000 | [diff] [blame] | 410 | { |
Georgios Pinitas | 908f616 | 2021-05-04 10:11:09 +0100 | [diff] [blame] | 411 | opencl::ClKernelLibrary &klib = opencl::ClKernelLibrary::get(); |
| 412 | |
| 413 | const std::string program_name = klib.program_name(kernel_name); |
| 414 | auto kernel_src = klib.program(program_name); |
| 415 | const std::string kernel_path = klib.kernel_path(); |
| 416 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 417 | return static_cast<cl::Kernel>(ctx.create_kernel(kernel_name, program_name, kernel_src.program, kernel_path, |
| 418 | build_opts, kernel_src.is_binary)); |
Michalis Spyrou | 11d4918 | 2020-03-26 10:31:32 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 421 | cl::NDRange create_lws_hint_parallel_implementations(unsigned int input_dimension, unsigned int vector_size) |
| 422 | { |
| 423 | const unsigned int width_leftover = input_dimension % vector_size; |
| 424 | const unsigned int border_width = (width_leftover != 0) ? vector_size - width_leftover : 0; |
| 425 | const unsigned int num_of_threads = ((input_dimension + border_width) / 16); |
| 426 | return cl::NDRange(std::min(8U, num_of_threads)); |
| 427 | } |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 428 | |
| 429 | bool get_wbsm_support_info(const cl::Device &device) |
| 430 | { |
| 431 | cl_bitfield capabilities = 0; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 432 | cl_int err = clGetDeviceInfo(device.get(), CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM, sizeof(cl_bitfield), |
| 433 | &capabilities, nullptr); |
| 434 | if ((err == CL_SUCCESS) && (capabilities & CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM)) |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 435 | { |
| 436 | return true; |
| 437 | } |
| 438 | return false; |
| 439 | } |
| 440 | |
| 441 | void set_wbsm(cl::Kernel &kernel, cl_int wbsm_hint) |
| 442 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 443 | cl_int err = clSetKernelExecInfo(kernel.get(), CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM, |
| 444 | sizeof(cl_int), &wbsm_hint); |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 445 | ARM_COMPUTE_UNUSED(err); |
| 446 | ARM_COMPUTE_ERROR_ON(err != CL_SUCCESS); |
| 447 | } |
| 448 | |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 449 | bool export_to_cl_image(const ITensorInfo *tensor) |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 450 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 451 | if (tensor->tensor_shape()[0] % 4 != 0) |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 452 | { |
| 453 | return false; |
| 454 | } |
| 455 | |
| 456 | // If not floating point |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 457 | if (!is_data_type_float(tensor->data_type())) |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 458 | { |
| 459 | return false; |
| 460 | } |
| 461 | |
| 462 | // Check if the cl_khr_image2d_from_buffer extension is supported on the target platform |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 463 | if (!image2d_from_buffer_supported(CLKernelLibrary::get().get_device())) |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 464 | { |
| 465 | return false; |
| 466 | } |
| 467 | |
| 468 | // Check cl image pitch alignment |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 469 | if (get_cl_image_pitch_alignment(CLKernelLibrary::get().get_device()) == 0) |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 470 | { |
| 471 | return false; |
| 472 | } |
| 473 | |
| 474 | const size_t image_w = tensor->tensor_shape()[0] / 4; |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 475 | const size_t image_h = tensor->tensor_shape().total_size() / tensor->tensor_shape()[0]; |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 476 | const size_t max_image_w = CLKernelLibrary::get().get_device().getInfo<CL_DEVICE_IMAGE2D_MAX_WIDTH>(); |
| 477 | const size_t max_image_h = CLKernelLibrary::get().get_device().getInfo<CL_DEVICE_IMAGE2D_MAX_HEIGHT>(); |
| 478 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 479 | if (image_w > max_image_w || image_h > max_image_h) |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 480 | { |
| 481 | return false; |
| 482 | } |
| 483 | |
| 484 | return true; |
| 485 | } |
| 486 | |
Gian Marco Iodice | 5e28181 | 2021-07-06 13:19:41 +0100 | [diff] [blame] | 487 | void set_unroll_with_pragma(CLBuildOptions &built_opts, std::initializer_list<int> values) |
| 488 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 489 | for (const int value : values) |
Gian Marco Iodice | 5e28181 | 2021-07-06 13:19:41 +0100 | [diff] [blame] | 490 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 491 | if (value > max_manual_loop_unrolling) |
Gian Marco Iodice | 5e28181 | 2021-07-06 13:19:41 +0100 | [diff] [blame] | 492 | { |
| 493 | built_opts.add_option("-DUNROLL_WITH_PRAGMA"); |
| 494 | return; |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
Gunes Bayir | 4bfc70e | 2021-12-10 16:17:56 +0000 | [diff] [blame] | 499 | bool arm_matrix_multiply_supported(const cl::Device &device) |
| 500 | { |
| 501 | return device_supports_extension(device, "cl_arm_matrix_multiply"); |
| 502 | } |
Viet-Hoa Do | 48b6d17 | 2023-08-11 17:48:54 +0100 | [diff] [blame] | 503 | |
| 504 | bool command_buffer_supported(const cl::Device &device) |
| 505 | { |
| 506 | return device_supports_extension(device, "cl_khr_command_buffer"); |
| 507 | } |
| 508 | |
| 509 | bool command_buffer_mutable_dispatch_supported(const cl::Device &device) |
| 510 | { |
| 511 | return device_supports_extension(device, "cl_khr_command_buffer_mutable_dispatch"); |
| 512 | } |
| 513 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 514 | } // namespace arm_compute |