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