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_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: */ |
| 31 | #define CL_HPP_ENABLE_EXCEPTIONS |
| 32 | #define CL_HPP_CL_1_2_DEFAULT_BUILD |
| 33 | #define CL_HPP_TARGET_OPENCL_VERSION 110 |
| 34 | #define CL_HPP_MINIMUM_OPENCL_VERSION 110 |
| 35 | #include <CL/cl2.hpp> |
| 36 | |
| 37 | namespace cl |
| 38 | { |
| 39 | static const NDRange Range_128_1 = NDRange(128, 1); |
Moritz Pflanzer | 725788e | 2017-07-07 15:35:56 +0100 | [diff] [blame] | 40 | } // namespace cl |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 41 | |
| 42 | namespace arm_compute |
| 43 | { |
| 44 | bool opencl_is_available(); |
Moritz Pflanzer | 725788e | 2017-07-07 15:35:56 +0100 | [diff] [blame] | 45 | |
| 46 | class CLSymbols final |
| 47 | { |
| 48 | private: |
| 49 | CLSymbols() = default; |
| 50 | void load_symbols(void *handle); |
| 51 | |
| 52 | public: |
| 53 | static CLSymbols &get(); |
| 54 | bool load(const std::string &library); |
| 55 | bool load_default(); |
| 56 | |
Anthony Barbier | 58c4ff1 | 2017-11-09 09:15:32 +0000 | [diff] [blame] | 57 | #define DECLARE_FUNCTION_PTR(func_name) \ |
| 58 | std::function<decltype(func_name)> func_name##_ptr = nullptr |
Moritz Pflanzer | 725788e | 2017-07-07 15:35:56 +0100 | [diff] [blame] | 59 | |
Anthony Barbier | a9e1533 | 2017-12-22 16:37:30 +0000 | [diff] [blame] | 60 | DECLARE_FUNCTION_PTR(clCreateContextFromType); |
| 61 | DECLARE_FUNCTION_PTR(clCreateCommandQueue); |
| 62 | DECLARE_FUNCTION_PTR(clGetContextInfo); |
Anthony Barbier | 58c4ff1 | 2017-11-09 09:15:32 +0000 | [diff] [blame] | 63 | DECLARE_FUNCTION_PTR(clBuildProgram); |
| 64 | DECLARE_FUNCTION_PTR(clEnqueueNDRangeKernel); |
| 65 | DECLARE_FUNCTION_PTR(clSetKernelArg); |
| 66 | DECLARE_FUNCTION_PTR(clReleaseKernel); |
| 67 | DECLARE_FUNCTION_PTR(clCreateProgramWithSource); |
| 68 | DECLARE_FUNCTION_PTR(clCreateBuffer); |
| 69 | DECLARE_FUNCTION_PTR(clRetainKernel); |
| 70 | DECLARE_FUNCTION_PTR(clCreateKernel); |
| 71 | DECLARE_FUNCTION_PTR(clGetProgramInfo); |
| 72 | DECLARE_FUNCTION_PTR(clFlush); |
| 73 | DECLARE_FUNCTION_PTR(clFinish); |
| 74 | DECLARE_FUNCTION_PTR(clReleaseProgram); |
| 75 | DECLARE_FUNCTION_PTR(clRetainContext); |
| 76 | DECLARE_FUNCTION_PTR(clCreateProgramWithBinary); |
| 77 | DECLARE_FUNCTION_PTR(clReleaseCommandQueue); |
| 78 | DECLARE_FUNCTION_PTR(clEnqueueMapBuffer); |
| 79 | DECLARE_FUNCTION_PTR(clRetainProgram); |
| 80 | DECLARE_FUNCTION_PTR(clGetProgramBuildInfo); |
| 81 | DECLARE_FUNCTION_PTR(clEnqueueReadBuffer); |
| 82 | DECLARE_FUNCTION_PTR(clEnqueueWriteBuffer); |
| 83 | DECLARE_FUNCTION_PTR(clReleaseEvent); |
| 84 | DECLARE_FUNCTION_PTR(clReleaseContext); |
| 85 | DECLARE_FUNCTION_PTR(clRetainCommandQueue); |
| 86 | DECLARE_FUNCTION_PTR(clEnqueueUnmapMemObject); |
| 87 | DECLARE_FUNCTION_PTR(clRetainMemObject); |
| 88 | DECLARE_FUNCTION_PTR(clReleaseMemObject); |
| 89 | DECLARE_FUNCTION_PTR(clGetDeviceInfo); |
| 90 | DECLARE_FUNCTION_PTR(clGetDeviceIDs); |
| 91 | DECLARE_FUNCTION_PTR(clRetainEvent); |
| 92 | DECLARE_FUNCTION_PTR(clGetPlatformIDs); |
| 93 | DECLARE_FUNCTION_PTR(clGetKernelWorkGroupInfo); |
| 94 | |
| 95 | #undef DECLARE_FUNCTION_PTR |
Moritz Pflanzer | 725788e | 2017-07-07 15:35:56 +0100 | [diff] [blame] | 96 | |
| 97 | private: |
| 98 | std::pair<bool, bool> _loaded{ false, false }; |
| 99 | }; |
| 100 | } // namespace arm_compute |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 101 | #endif /* __ARM_COMPUTE_OPENCL_H__ */ |