Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, 2017 ARM Limited. |
| 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 | |
| 27 | #include "arm_compute/core/CL/OpenCL.h" |
| 28 | #include "arm_compute/core/Helpers.h" |
Moritz Pflanzer | d0ae8b8 | 2017-06-29 14:51:57 +0100 | [diff] [blame] | 29 | #include "support/ToolchainSupport.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | |
| 31 | #include <string> |
| 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | enum class DataType; |
| 36 | enum class GPUTarget; |
| 37 | |
| 38 | /** Enable operation operations on GPUTarget enumerations */ |
| 39 | template <> |
| 40 | struct enable_bitwise_ops<arm_compute::GPUTarget> |
| 41 | { |
| 42 | static constexpr bool value = true; |
| 43 | }; |
| 44 | |
| 45 | /** Max vector width of an OpenCL vector */ |
| 46 | static constexpr const unsigned int max_cl_vector_width = 16; |
| 47 | |
| 48 | /** Translates a tensor data type to the appropriate OpenCL type. |
| 49 | * |
| 50 | * @param[in] dt @ref DataType to be translated to OpenCL type. |
| 51 | * |
| 52 | * @return The string specifying the OpenCL type to be used. |
| 53 | */ |
| 54 | std::string get_cl_type_from_data_type(const DataType &dt); |
| 55 | |
| 56 | /** Translates a given gpu device target to string. |
| 57 | * |
| 58 | * @param[in] target Given gpu target. |
| 59 | * |
| 60 | * @return The string describing the target. |
| 61 | */ |
| 62 | const std::string &string_from_target(GPUTarget target); |
| 63 | |
| 64 | /** Helper function to create and return a unique_ptr pointed to a CL kernel object |
| 65 | * It also calls the kernel's configuration. |
| 66 | * |
| 67 | * @param[in] args All the arguments that need pass to kernel's configuration. |
| 68 | * |
| 69 | * @return A unique pointer pointed to a CL kernel object |
| 70 | */ |
| 71 | template <typename Kernel, typename... T> |
| 72 | std::unique_ptr<Kernel> create_configure_kernel(T &&... args) |
| 73 | { |
Moritz Pflanzer | d0ae8b8 | 2017-06-29 14:51:57 +0100 | [diff] [blame] | 74 | std::unique_ptr<Kernel> k = arm_compute::support::cpp14::make_unique<Kernel>(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 75 | k->configure(std::forward<T>(args)...); |
| 76 | return k; |
| 77 | } |
| 78 | |
| 79 | /** Helper function to create and return a unique_ptr pointed to a CL kernel object |
| 80 | * |
| 81 | * @return A unique pointer pointed to a CL kernel object |
| 82 | */ |
| 83 | template <typename Kernel> |
| 84 | std::unique_ptr<Kernel> create_kernel() |
| 85 | { |
Moritz Pflanzer | d0ae8b8 | 2017-06-29 14:51:57 +0100 | [diff] [blame] | 86 | std::unique_ptr<Kernel> k = arm_compute::support::cpp14::make_unique<Kernel>(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 87 | return k; |
| 88 | } |
| 89 | |
| 90 | /** Helper function to get the GPU target from CL device |
| 91 | * |
| 92 | * @param[in] device A CL device |
| 93 | * |
| 94 | * @return the GPU target |
| 95 | */ |
| 96 | GPUTarget get_target_from_device(cl::Device &device); |
| 97 | |
| 98 | /** Helper function to get the GPU arch |
| 99 | * |
| 100 | * @param[in] target GPU target |
| 101 | * |
| 102 | * @return the GPU target which shows the arch |
| 103 | */ |
| 104 | GPUTarget get_arch_from_target(GPUTarget target); |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 105 | |
| 106 | /** Helper function to get the highest OpenCL version supported |
| 107 | * |
| 108 | * @param[in] device A CL device |
| 109 | * |
| 110 | * @return the highest OpenCL version supported |
| 111 | */ |
| 112 | CLVersion get_cl_version(const cl::Device &device); |
| 113 | /** Helper function to check whether the arm_non_uniform_work_group_size extension is supported |
| 114 | * |
| 115 | * @param[in] device A CL device |
| 116 | * |
| 117 | * @return True if the extension is supported |
| 118 | */ |
| 119 | bool non_uniform_workgroup_support(const cl::Device &device); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 120 | } |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 121 | #endif /* __ARM_COMPUTE_CLHELPERS_H__ */ |