Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Anthony Barbier | 30a6342 | 2018-02-28 18:18:24 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2018 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" |
| 29 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | #include <vector> |
| 31 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | namespace arm_compute |
| 33 | { |
| 34 | std::string get_cl_type_from_data_type(const DataType &dt) |
| 35 | { |
| 36 | switch(dt) |
| 37 | { |
| 38 | case DataType::U8: |
| 39 | return "uchar"; |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 40 | case DataType::QS8: |
| 41 | return "qs8"; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 42 | case DataType::S8: |
| 43 | return "char"; |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 44 | case DataType::QASYMM8: |
| 45 | return "uchar"; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 46 | case DataType::U16: |
| 47 | return "ushort"; |
| 48 | case DataType::S16: |
| 49 | return "short"; |
Gian Marco Iodice | 5cb4c42 | 2017-06-23 10:38:25 +0100 | [diff] [blame] | 50 | case DataType::QS16: |
| 51 | return "qs16"; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 52 | case DataType::U32: |
| 53 | return "uint"; |
| 54 | case DataType::S32: |
| 55 | return "int"; |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 56 | case DataType::QS32: |
| 57 | return "qs32"; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 58 | case DataType::U64: |
| 59 | return "ulong"; |
| 60 | case DataType::S64: |
| 61 | return "long"; |
| 62 | case DataType::F16: |
| 63 | return "half"; |
| 64 | case DataType::F32: |
| 65 | return "float"; |
| 66 | default: |
| 67 | ARM_COMPUTE_ERROR("Unsupported input data type."); |
| 68 | return ""; |
| 69 | } |
| 70 | } |
| 71 | |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 72 | std::string get_data_size_from_data_type(const DataType &dt) |
| 73 | { |
| 74 | switch(dt) |
| 75 | { |
| 76 | case DataType::U8: |
| 77 | case DataType::QS8: |
| 78 | case DataType::S8: |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 79 | case DataType::QASYMM8: |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 80 | return "8"; |
| 81 | case DataType::U16: |
| 82 | case DataType::S16: |
| 83 | case DataType::QS16: |
| 84 | case DataType::F16: |
| 85 | return "16"; |
| 86 | case DataType::U32: |
| 87 | case DataType::S32: |
| 88 | case DataType::F32: |
| 89 | return "32"; |
| 90 | case DataType::U64: |
| 91 | case DataType::S64: |
| 92 | return "64"; |
| 93 | default: |
| 94 | ARM_COMPUTE_ERROR("Unsupported input data type."); |
| 95 | return "0"; |
| 96 | } |
| 97 | } |
| 98 | |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 99 | std::string get_underlying_cl_type_from_data_type(const DataType &dt) |
| 100 | { |
| 101 | switch(dt) |
| 102 | { |
| 103 | case DataType::QS8: |
| 104 | return "char"; |
| 105 | case DataType::QS16: |
| 106 | return "short"; |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 107 | case DataType::QS32: |
| 108 | return "int"; |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 109 | default: |
| 110 | return get_cl_type_from_data_type(dt); |
| 111 | } |
| 112 | } |
| 113 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 114 | GPUTarget get_target_from_device(cl::Device &device) |
| 115 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 116 | // Query device name size |
Anthony Barbier | 30a6342 | 2018-02-28 18:18:24 +0000 | [diff] [blame] | 117 | std::string device_name = device.getInfo<CL_DEVICE_NAME>(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 118 | |
Michalis Spyrou | a967611 | 2018-02-22 18:07:43 +0000 | [diff] [blame] | 119 | return get_target_from_name(device_name); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 120 | } |
| 121 | |
Anthony Barbier | d727e85 | 2018-04-20 11:05:29 +0100 | [diff] [blame] | 122 | bool arm_non_uniform_workgroup_supported(const cl::Device &device) |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 123 | { |
Vidhya Sudhan Loganathan | eb8a399 | 2018-04-10 12:23:22 +0100 | [diff] [blame] | 124 | return device_supports_extension(device, "cl_arm_non_uniform_work_group_size"); |
Matthew Bentham | 6f31f8c | 2017-10-27 11:50:06 +0100 | [diff] [blame] | 125 | } |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 126 | |
Anthony Barbier | d727e85 | 2018-04-20 11:05:29 +0100 | [diff] [blame] | 127 | bool fp16_supported(const cl::Device &device) |
Matthew Bentham | 6f31f8c | 2017-10-27 11:50:06 +0100 | [diff] [blame] | 128 | { |
Vidhya Sudhan Loganathan | eb8a399 | 2018-04-10 12:23:22 +0100 | [diff] [blame] | 129 | return device_supports_extension(device, "cl_khr_fp16"); |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 130 | } |
| 131 | |
Michalis Spyrou | e03342e | 2018-01-15 14:39:13 +0000 | [diff] [blame] | 132 | bool dot8_supported(const cl::Device &device) |
| 133 | { |
| 134 | return device_supports_extension(device, "cl_arm_integer_dot_product_int8"); |
| 135 | } |
| 136 | |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 137 | CLVersion get_cl_version(const cl::Device &device) |
| 138 | { |
Anthony Barbier | 30a6342 | 2018-02-28 18:18:24 +0000 | [diff] [blame] | 139 | std::string version_str = device.getInfo<CL_DEVICE_VERSION>(); |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 140 | if(version_str.find("OpenCL 2") != std::string::npos) |
| 141 | { |
| 142 | return CLVersion::CL20; |
| 143 | } |
| 144 | else if(version_str.find("OpenCL 1.2") != std::string::npos) |
| 145 | { |
| 146 | return CLVersion::CL12; |
| 147 | } |
| 148 | else if(version_str.find("OpenCL 1.1") != std::string::npos) |
| 149 | { |
| 150 | return CLVersion::CL11; |
| 151 | } |
| 152 | else if(version_str.find("OpenCL 1.0") != std::string::npos) |
| 153 | { |
| 154 | return CLVersion::CL10; |
| 155 | } |
| 156 | |
| 157 | return CLVersion::UNKNOWN; |
| 158 | } |
| 159 | |
Vidhya Sudhan Loganathan | eb8a399 | 2018-04-10 12:23:22 +0100 | [diff] [blame] | 160 | bool device_supports_extension(const cl::Device &device, const char *extension_name) |
| 161 | { |
| 162 | std::string extensions = device.getInfo<CL_DEVICE_EXTENSIONS>(); |
| 163 | auto pos = extensions.find(extension_name); |
| 164 | return (pos != std::string::npos); |
| 165 | } |
| 166 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 167 | } // namespace arm_compute |