Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Gian Marco | 85e6f51 | 2018-02-01 16:57:48 +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_OPENCL_H__ |
| 25 | #define __ARM_COMPUTE_OPENCL_H__ |
| 26 | |
Moritz Pflanzer | 725788e | 2017-07-07 15:35:56 +0100 | [diff] [blame] | 27 | #include <string> |
| 28 | #include <utility> |
| 29 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | /* Configure the Khronos C++ wrapper to target OpenCL 1.2: */ |
Anthony Barbier | 340a272 | 2018-01-03 16:21:54 +0000 | [diff] [blame] | 31 | #ifndef ARM_COMPUTE_NO_EXCEPTIONS |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | #define CL_HPP_ENABLE_EXCEPTIONS |
Anthony Barbier | 340a272 | 2018-01-03 16:21:54 +0000 | [diff] [blame] | 33 | #endif // ARM_COMPUTE_NO_EXCEPTIONS |
Anthony Barbier | 8b2fdc9 | 2018-08-09 11:42:38 +0100 | [diff] [blame] | 34 | #define CL_TARGET_OPENCL_VERSION 200 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 35 | #define CL_HPP_TARGET_OPENCL_VERSION 110 |
| 36 | #define CL_HPP_MINIMUM_OPENCL_VERSION 110 |
Anthony Barbier | 8b2fdc9 | 2018-08-09 11:42:38 +0100 | [diff] [blame] | 37 | #pragma GCC diagnostic push |
| 38 | #pragma GCC diagnostic ignored "-Weffc++" |
| 39 | #pragma GCC diagnostic ignored "-Wignored-qualifiers" |
Georgios Pinitas | 67d94d2 | 2018-10-09 18:48:37 +0100 | [diff] [blame] | 40 | #if defined(__GNUG__) && __GNUG__ >= 8 |
| 41 | #pragma GCC diagnostic ignored "-Wcatch-value" |
| 42 | #endif // defined(__GNUG__) && __GNUG__ >= 8 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 43 | #include <CL/cl2.hpp> |
Anthony Barbier | 8b2fdc9 | 2018-08-09 11:42:38 +0100 | [diff] [blame] | 44 | #pragma GCC diagnostic pop |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 45 | |
| 46 | namespace cl |
| 47 | { |
| 48 | static const NDRange Range_128_1 = NDRange(128, 1); |
Moritz Pflanzer | 725788e | 2017-07-07 15:35:56 +0100 | [diff] [blame] | 49 | } // namespace cl |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 50 | |
| 51 | namespace arm_compute |
| 52 | { |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 53 | /** Check if OpenCL is available. |
| 54 | * |
| 55 | * @return True if OpenCL is available. |
| 56 | */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 57 | bool opencl_is_available(); |
Moritz Pflanzer | 725788e | 2017-07-07 15:35:56 +0100 | [diff] [blame] | 58 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 59 | /** Class for loading OpenCL symbols. */ |
Moritz Pflanzer | 725788e | 2017-07-07 15:35:56 +0100 | [diff] [blame] | 60 | class CLSymbols final |
| 61 | { |
| 62 | private: |
| 63 | CLSymbols() = default; |
| 64 | void load_symbols(void *handle); |
| 65 | |
| 66 | public: |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 67 | /** Get the static instance of CLSymbols. |
| 68 | * |
| 69 | * @return The static instance of CLSymbols. |
| 70 | */ |
Moritz Pflanzer | 725788e | 2017-07-07 15:35:56 +0100 | [diff] [blame] | 71 | static CLSymbols &get(); |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 72 | /** Load symbols from the given OpenCL library path. |
| 73 | * |
| 74 | * @param[in] library Path to the OpenCL library. |
| 75 | * |
| 76 | * @return True if loading the library is successful. |
| 77 | */ |
Moritz Pflanzer | 725788e | 2017-07-07 15:35:56 +0100 | [diff] [blame] | 78 | bool load(const std::string &library); |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 79 | /** Load symbols from any of the default OpenCL library names. |
| 80 | * |
| 81 | * @return True if loading any library is successful. |
| 82 | */ |
Moritz Pflanzer | 725788e | 2017-07-07 15:35:56 +0100 | [diff] [blame] | 83 | bool load_default(); |
| 84 | |
Anthony Barbier | 58c4ff1 | 2017-11-09 09:15:32 +0000 | [diff] [blame] | 85 | #define DECLARE_FUNCTION_PTR(func_name) \ |
| 86 | std::function<decltype(func_name)> func_name##_ptr = nullptr |
Moritz Pflanzer | 725788e | 2017-07-07 15:35:56 +0100 | [diff] [blame] | 87 | |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 88 | DECLARE_FUNCTION_PTR(clCreateContext); |
Anthony Barbier | a9e1533 | 2017-12-22 16:37:30 +0000 | [diff] [blame] | 89 | DECLARE_FUNCTION_PTR(clCreateContextFromType); |
| 90 | DECLARE_FUNCTION_PTR(clCreateCommandQueue); |
| 91 | DECLARE_FUNCTION_PTR(clGetContextInfo); |
Anthony Barbier | 58c4ff1 | 2017-11-09 09:15:32 +0000 | [diff] [blame] | 92 | DECLARE_FUNCTION_PTR(clBuildProgram); |
| 93 | DECLARE_FUNCTION_PTR(clEnqueueNDRangeKernel); |
| 94 | DECLARE_FUNCTION_PTR(clSetKernelArg); |
| 95 | DECLARE_FUNCTION_PTR(clReleaseKernel); |
| 96 | DECLARE_FUNCTION_PTR(clCreateProgramWithSource); |
| 97 | DECLARE_FUNCTION_PTR(clCreateBuffer); |
| 98 | DECLARE_FUNCTION_PTR(clRetainKernel); |
| 99 | DECLARE_FUNCTION_PTR(clCreateKernel); |
| 100 | DECLARE_FUNCTION_PTR(clGetProgramInfo); |
| 101 | DECLARE_FUNCTION_PTR(clFlush); |
| 102 | DECLARE_FUNCTION_PTR(clFinish); |
| 103 | DECLARE_FUNCTION_PTR(clReleaseProgram); |
| 104 | DECLARE_FUNCTION_PTR(clRetainContext); |
| 105 | DECLARE_FUNCTION_PTR(clCreateProgramWithBinary); |
| 106 | DECLARE_FUNCTION_PTR(clReleaseCommandQueue); |
| 107 | DECLARE_FUNCTION_PTR(clEnqueueMapBuffer); |
| 108 | DECLARE_FUNCTION_PTR(clRetainProgram); |
| 109 | DECLARE_FUNCTION_PTR(clGetProgramBuildInfo); |
| 110 | DECLARE_FUNCTION_PTR(clEnqueueReadBuffer); |
| 111 | DECLARE_FUNCTION_PTR(clEnqueueWriteBuffer); |
| 112 | DECLARE_FUNCTION_PTR(clReleaseEvent); |
| 113 | DECLARE_FUNCTION_PTR(clReleaseContext); |
| 114 | DECLARE_FUNCTION_PTR(clRetainCommandQueue); |
| 115 | DECLARE_FUNCTION_PTR(clEnqueueUnmapMemObject); |
| 116 | DECLARE_FUNCTION_PTR(clRetainMemObject); |
| 117 | DECLARE_FUNCTION_PTR(clReleaseMemObject); |
| 118 | DECLARE_FUNCTION_PTR(clGetDeviceInfo); |
| 119 | DECLARE_FUNCTION_PTR(clGetDeviceIDs); |
| 120 | DECLARE_FUNCTION_PTR(clRetainEvent); |
| 121 | DECLARE_FUNCTION_PTR(clGetPlatformIDs); |
| 122 | DECLARE_FUNCTION_PTR(clGetKernelWorkGroupInfo); |
Gian Marco | 85e6f51 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 123 | DECLARE_FUNCTION_PTR(clGetCommandQueueInfo); |
| 124 | DECLARE_FUNCTION_PTR(clGetKernelInfo); |
| 125 | DECLARE_FUNCTION_PTR(clGetEventProfilingInfo); |
Pablo Tello | e86a09f | 2018-01-11 15:44:48 +0000 | [diff] [blame] | 126 | DECLARE_FUNCTION_PTR(clSVMAlloc); |
| 127 | DECLARE_FUNCTION_PTR(clSVMFree); |
| 128 | DECLARE_FUNCTION_PTR(clEnqueueSVMMap); |
| 129 | DECLARE_FUNCTION_PTR(clEnqueueSVMUnmap); |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 130 | DECLARE_FUNCTION_PTR(clEnqueueMarker); |
| 131 | DECLARE_FUNCTION_PTR(clWaitForEvents); |
Anthony Barbier | 58c4ff1 | 2017-11-09 09:15:32 +0000 | [diff] [blame] | 132 | |
| 133 | #undef DECLARE_FUNCTION_PTR |
Moritz Pflanzer | 725788e | 2017-07-07 15:35:56 +0100 | [diff] [blame] | 134 | |
| 135 | private: |
| 136 | std::pair<bool, bool> _loaded{ false, false }; |
| 137 | }; |
| 138 | } // namespace arm_compute |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 139 | #endif /* __ARM_COMPUTE_OPENCL_H__ */ |