Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | a967611 | 2018-02-22 18:07:43 +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 | #ifndef __ARM_COMPUTE_CLHELPERS_H__ |
| 25 | #define __ARM_COMPUTE_CLHELPERS_H__ |
| 26 | |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/CL/CLTypes.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/CL/OpenCL.h" |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/GPUTarget.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/Helpers.h" |
Moritz Pflanzer | d0ae8b8 | 2017-06-29 14:51:57 +0100 | [diff] [blame] | 31 | #include "support/ToolchainSupport.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | |
| 33 | #include <string> |
| 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | enum class DataType; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 38 | |
| 39 | /** Max vector width of an OpenCL vector */ |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 40 | static constexpr unsigned int max_cl_vector_width = 16; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 41 | |
| 42 | /** Translates a tensor data type to the appropriate OpenCL type. |
| 43 | * |
| 44 | * @param[in] dt @ref DataType to be translated to OpenCL type. |
| 45 | * |
| 46 | * @return The string specifying the OpenCL type to be used. |
| 47 | */ |
| 48 | std::string get_cl_type_from_data_type(const DataType &dt); |
| 49 | |
Giorgio Arena | 7302302 | 2018-09-04 14:55:55 +0100 | [diff] [blame] | 50 | /** Translates a tensor data type to the appropriate OpenCL select type. |
| 51 | * |
| 52 | * @param[in] dt @ref DataType to be translated to OpenCL select type. |
| 53 | * |
| 54 | * @return The string specifying the OpenCL select type to be used. |
| 55 | */ |
| 56 | std::string get_cl_select_type_from_data_type(const DataType &dt); |
| 57 | |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 58 | /** Get the size of a data type in number of bits. |
| 59 | * |
| 60 | * @param[in] dt @ref DataType. |
| 61 | * |
| 62 | * @return Number of bits in the data type specified. |
| 63 | */ |
| 64 | std::string get_data_size_from_data_type(const DataType &dt); |
| 65 | |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 66 | /** Translates fixed point tensor data type to the underlying OpenCL type. |
| 67 | * |
| 68 | * @param[in] dt @ref DataType to be translated to OpenCL type. |
| 69 | * |
| 70 | * @return The string specifying the underlying OpenCL type to be used. |
| 71 | */ |
| 72 | std::string get_underlying_cl_type_from_data_type(const DataType &dt); |
| 73 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 74 | /** Helper function to get the GPU target from CL device |
| 75 | * |
| 76 | * @param[in] device A CL device |
| 77 | * |
| 78 | * @return the GPU target |
| 79 | */ |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 80 | GPUTarget get_target_from_device(const cl::Device &device); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 81 | |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 82 | /** Helper function to get the highest OpenCL version supported |
| 83 | * |
| 84 | * @param[in] device A CL device |
| 85 | * |
| 86 | * @return the highest OpenCL version supported |
| 87 | */ |
| 88 | CLVersion get_cl_version(const cl::Device &device); |
Vidhya Sudhan Loganathan | eb8a399 | 2018-04-10 12:23:22 +0100 | [diff] [blame] | 89 | |
| 90 | /** Helper function to check whether a given extension is supported |
| 91 | * |
| 92 | * @param[in] device A CL device |
| 93 | * @param[in] extension_name Name of the extension to be checked |
| 94 | * |
| 95 | * @return True if the extension is supported |
| 96 | */ |
| 97 | bool device_supports_extension(const cl::Device &device, const char *extension_name); |
| 98 | |
Matthew Bentham | 6f31f8c | 2017-10-27 11:50:06 +0100 | [diff] [blame] | 99 | /** Helper function to check whether the cl_khr_fp16 extension is supported |
| 100 | * |
| 101 | * @param[in] device A CL device |
| 102 | * |
| 103 | * @return True if the extension is supported |
| 104 | */ |
Anthony Barbier | d727e85 | 2018-04-20 11:05:29 +0100 | [diff] [blame] | 105 | bool fp16_supported(const cl::Device &device); |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 106 | /** Helper function to check whether the arm_non_uniform_work_group_size extension is supported |
| 107 | * |
| 108 | * @param[in] device A CL device |
| 109 | * |
| 110 | * @return True if the extension is supported |
| 111 | */ |
Anthony Barbier | d727e85 | 2018-04-20 11:05:29 +0100 | [diff] [blame] | 112 | bool arm_non_uniform_workgroup_supported(const cl::Device &device); |
Michalis Spyrou | e03342e | 2018-01-15 14:39:13 +0000 | [diff] [blame] | 113 | /** Helper function to check whether the cl_arm_integer_dot_product_int8 extension is supported |
| 114 | * |
| 115 | * @param[in] device A CL device |
| 116 | * |
| 117 | * @return True if the extension is supported |
| 118 | */ |
| 119 | bool dot8_supported(const cl::Device &device); |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 120 | |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 121 | /** Helper function to check whether the cl_arm_integer_dot_product_accumulate_int8 extension is supported |
| 122 | * |
| 123 | * @param[in] device A CL device |
| 124 | * |
| 125 | * @return True if the extension is supported |
| 126 | */ |
| 127 | bool dot8_acc_supported(const cl::Device &device); |
| 128 | |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 129 | /** This function checks if the Winograd configuration (defined through the output tile, kernel size and the data layout) is supported on OpenCL |
| 130 | * |
| 131 | * @param[in] output_tile Output tile for the Winograd filtering algorithm |
| 132 | * @param[in] kernel_size Kernel size for the Winograd filtering algorithm |
| 133 | * @param[in] data_layout Data layout of the input tensor |
| 134 | * |
| 135 | * @return True if the configuration is supported |
| 136 | */ |
| 137 | bool cl_winograd_convolution_layer_supported(const Size2D &output_tile, const Size2D &kernel_size, DataLayout data_layout); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 138 | } |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 139 | #endif /* __ARM_COMPUTE_CLHELPERS_H__ */ |