blob: 6780e23c2dc2db82ee84d38c9e48dc57a99f5a55 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
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 Pflanzer725788e2017-07-07 15:35:56 +010027#include <string>
28#include <utility>
29
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030/* 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
37namespace cl
38{
39static const NDRange Range_128_1 = NDRange(128, 1);
Moritz Pflanzer725788e2017-07-07 15:35:56 +010040} // namespace cl
Anthony Barbier6ff3b192017-09-04 18:44:23 +010041
42namespace arm_compute
43{
44bool opencl_is_available();
Moritz Pflanzer725788e2017-07-07 15:35:56 +010045
46class CLSymbols final
47{
48private:
49 CLSymbols() = default;
50 void load_symbols(void *handle);
51
52public:
53 static CLSymbols &get();
54 bool load(const std::string &library);
55 bool load_default();
56
57 using clBuildProgram_func = cl_int (*)(cl_program, cl_uint, const cl_device_id *, const char *, void (*pfn_notify)(cl_program, void *), void *);
58 using clEnqueueNDRangeKernel_func = cl_int (*)(cl_command_queue, cl_kernel, cl_uint, const size_t *, const size_t *, const size_t *, cl_uint, const cl_event *, cl_event *);
59 using clSetKernelArg_func = cl_int (*)(cl_kernel, cl_uint, size_t, const void *);
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010060 using clRetainMemObject_func = cl_int (*)(cl_mem);
Moritz Pflanzer725788e2017-07-07 15:35:56 +010061 using clReleaseMemObject_func = cl_int (*)(cl_mem);
62 using clEnqueueUnmapMemObject_func = cl_int (*)(cl_command_queue, cl_mem, void *, cl_uint, const cl_event *, cl_event *);
63 using clRetainCommandQueue_func = cl_int (*)(cl_command_queue command_queue);
64 using clReleaseContext_func = cl_int (*)(cl_context);
65 using clReleaseEvent_func = cl_int (*)(cl_event);
66 using clEnqueueWriteBuffer_func = cl_int (*)(cl_command_queue, cl_mem, cl_bool, size_t, size_t, const void *, cl_uint, const cl_event *, cl_event *);
67 using clEnqueueReadBuffer_func = cl_int (*)(cl_command_queue, cl_mem, cl_bool, size_t, size_t, void *, cl_uint, const cl_event *, cl_event *);
68 using clGetProgramBuildInfo_func = cl_int (*)(cl_program, cl_device_id, cl_program_build_info, size_t, void *, size_t *);
69 using clRetainProgram_func = cl_int (*)(cl_program program);
70 using clEnqueueMapBuffer_func = void *(*)(cl_command_queue, cl_mem, cl_bool, cl_map_flags, size_t, size_t, cl_uint, const cl_event *, cl_event *, cl_int *);
71 using clReleaseCommandQueue_func = cl_int (*)(cl_command_queue);
72 using clCreateProgramWithBinary_func = cl_program (*)(cl_context, cl_uint, const cl_device_id *, const size_t *, const unsigned char **, cl_int *, cl_int *);
73 using clRetainContext_func = cl_int (*)(cl_context context);
74 using clReleaseProgram_func = cl_int (*)(cl_program program);
75 using clFlush_func = cl_int (*)(cl_command_queue command_queue);
Gian Marco Iodice63d76a72017-08-11 11:56:52 +010076 using clFinish_func = cl_int (*)(cl_command_queue command_queue);
Moritz Pflanzer725788e2017-07-07 15:35:56 +010077 using clGetProgramInfo_func = cl_int (*)(cl_program, cl_program_info, size_t, void *, size_t *);
78 using clCreateKernel_func = cl_kernel (*)(cl_program, const char *, cl_int *);
79 using clRetainKernel_func = cl_int (*)(cl_kernel kernel);
80 using clCreateBuffer_func = cl_mem (*)(cl_context, cl_mem_flags, size_t, void *, cl_int *);
81 using clCreateProgramWithSource_func = cl_program (*)(cl_context, cl_uint, const char **, const size_t *, cl_int *);
82 using clReleaseKernel_func = cl_int (*)(cl_kernel kernel);
83 using clGetDeviceInfo_func = cl_int (*)(cl_device_id, cl_device_info, size_t, void *, size_t *);
84 using clGetDeviceIDs_func = cl_int (*)(cl_platform_id, cl_device_type, cl_uint, cl_device_id *, cl_uint *);
Giorgio Arena9fe41442017-08-23 16:36:24 +010085 using clRetainEvent_func = cl_int (*)(cl_event);
steniu01f01f9de2017-09-27 17:00:11 +010086 using clGetPlatformIDs_func = cl_int (*)(cl_uint, cl_platform_id *, cl_uint *);
Abel Bernabeu5a6e0532017-09-28 09:53:45 +010087 using clGetKernelWorkGroupInfo_func = cl_int (*)(cl_kernel, cl_device_id, cl_kernel_work_group_info, size_t, void *, size_t *);
Moritz Pflanzer725788e2017-07-07 15:35:56 +010088
89 clBuildProgram_func clBuildProgram = nullptr;
90 clEnqueueNDRangeKernel_func clEnqueueNDRangeKernel = nullptr;
91 clSetKernelArg_func clSetKernelArg = nullptr;
92 clReleaseKernel_func clReleaseKernel = nullptr;
93 clCreateProgramWithSource_func clCreateProgramWithSource = nullptr;
94 clCreateBuffer_func clCreateBuffer = nullptr;
95 clRetainKernel_func clRetainKernel = nullptr;
96 clCreateKernel_func clCreateKernel = nullptr;
97 clGetProgramInfo_func clGetProgramInfo = nullptr;
98 clFlush_func clFlush = nullptr;
Gian Marco Iodice63d76a72017-08-11 11:56:52 +010099 clFinish_func clFinish = nullptr;
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100100 clReleaseProgram_func clReleaseProgram = nullptr;
101 clRetainContext_func clRetainContext = nullptr;
102 clCreateProgramWithBinary_func clCreateProgramWithBinary = nullptr;
103 clReleaseCommandQueue_func clReleaseCommandQueue = nullptr;
104 clEnqueueMapBuffer_func clEnqueueMapBuffer = nullptr;
105 clRetainProgram_func clRetainProgram = nullptr;
106 clGetProgramBuildInfo_func clGetProgramBuildInfo = nullptr;
107 clEnqueueReadBuffer_func clEnqueueReadBuffer = nullptr;
108 clEnqueueWriteBuffer_func clEnqueueWriteBuffer = nullptr;
109 clReleaseEvent_func clReleaseEvent = nullptr;
110 clReleaseContext_func clReleaseContext = nullptr;
111 clRetainCommandQueue_func clRetainCommandQueue = nullptr;
112 clEnqueueUnmapMemObject_func clEnqueueUnmapMemObject = nullptr;
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100113 clRetainMemObject_func clRetainMemObject = nullptr;
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100114 clReleaseMemObject_func clReleaseMemObject = nullptr;
115 clGetDeviceInfo_func clGetDeviceInfo = nullptr;
116 clGetDeviceIDs_func clGetDeviceIDs = nullptr;
Giorgio Arena9fe41442017-08-23 16:36:24 +0100117 clRetainEvent_func clRetainEvent = nullptr;
steniu01f01f9de2017-09-27 17:00:11 +0100118 clGetPlatformIDs_func clGetPlatformIDs = nullptr;
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100119 clGetKernelWorkGroupInfo_func clGetKernelWorkGroupInfo = nullptr;
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100120
121private:
122 std::pair<bool, bool> _loaded{ false, false };
123};
124} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100125#endif /* __ARM_COMPUTE_OPENCL_H__ */