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