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