blob: 644608ff3de8c8dc51fd436c27a98b92977fb488 [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 *);
60 using clReleaseMemObject_func = cl_int (*)(cl_mem);
61 using clEnqueueUnmapMemObject_func = cl_int (*)(cl_command_queue, cl_mem, void *, cl_uint, const cl_event *, cl_event *);
62 using clRetainCommandQueue_func = cl_int (*)(cl_command_queue command_queue);
63 using clReleaseContext_func = cl_int (*)(cl_context);
64 using clReleaseEvent_func = cl_int (*)(cl_event);
65 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 *);
66 using clEnqueueReadBuffer_func = cl_int (*)(cl_command_queue, cl_mem, cl_bool, size_t, size_t, void *, cl_uint, const cl_event *, cl_event *);
67 using clGetProgramBuildInfo_func = cl_int (*)(cl_program, cl_device_id, cl_program_build_info, size_t, void *, size_t *);
68 using clRetainProgram_func = cl_int (*)(cl_program program);
69 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 *);
70 using clReleaseCommandQueue_func = cl_int (*)(cl_command_queue);
71 using clCreateProgramWithBinary_func = cl_program (*)(cl_context, cl_uint, const cl_device_id *, const size_t *, const unsigned char **, cl_int *, cl_int *);
72 using clRetainContext_func = cl_int (*)(cl_context context);
73 using clReleaseProgram_func = cl_int (*)(cl_program program);
74 using clFlush_func = cl_int (*)(cl_command_queue command_queue);
75 using clGetProgramInfo_func = cl_int (*)(cl_program, cl_program_info, size_t, void *, size_t *);
76 using clCreateKernel_func = cl_kernel (*)(cl_program, const char *, cl_int *);
77 using clRetainKernel_func = cl_int (*)(cl_kernel kernel);
78 using clCreateBuffer_func = cl_mem (*)(cl_context, cl_mem_flags, size_t, void *, cl_int *);
79 using clCreateProgramWithSource_func = cl_program (*)(cl_context, cl_uint, const char **, const size_t *, cl_int *);
80 using clReleaseKernel_func = cl_int (*)(cl_kernel kernel);
81 using clGetDeviceInfo_func = cl_int (*)(cl_device_id, cl_device_info, size_t, void *, size_t *);
82 using clGetDeviceIDs_func = cl_int (*)(cl_platform_id, cl_device_type, cl_uint, cl_device_id *, cl_uint *);
83
84 clBuildProgram_func clBuildProgram = nullptr;
85 clEnqueueNDRangeKernel_func clEnqueueNDRangeKernel = nullptr;
86 clSetKernelArg_func clSetKernelArg = nullptr;
87 clReleaseKernel_func clReleaseKernel = nullptr;
88 clCreateProgramWithSource_func clCreateProgramWithSource = nullptr;
89 clCreateBuffer_func clCreateBuffer = nullptr;
90 clRetainKernel_func clRetainKernel = nullptr;
91 clCreateKernel_func clCreateKernel = nullptr;
92 clGetProgramInfo_func clGetProgramInfo = nullptr;
93 clFlush_func clFlush = nullptr;
94 clReleaseProgram_func clReleaseProgram = nullptr;
95 clRetainContext_func clRetainContext = nullptr;
96 clCreateProgramWithBinary_func clCreateProgramWithBinary = nullptr;
97 clReleaseCommandQueue_func clReleaseCommandQueue = nullptr;
98 clEnqueueMapBuffer_func clEnqueueMapBuffer = nullptr;
99 clRetainProgram_func clRetainProgram = nullptr;
100 clGetProgramBuildInfo_func clGetProgramBuildInfo = nullptr;
101 clEnqueueReadBuffer_func clEnqueueReadBuffer = nullptr;
102 clEnqueueWriteBuffer_func clEnqueueWriteBuffer = nullptr;
103 clReleaseEvent_func clReleaseEvent = nullptr;
104 clReleaseContext_func clReleaseContext = nullptr;
105 clRetainCommandQueue_func clRetainCommandQueue = nullptr;
106 clEnqueueUnmapMemObject_func clEnqueueUnmapMemObject = nullptr;
107 clReleaseMemObject_func clReleaseMemObject = nullptr;
108 clGetDeviceInfo_func clGetDeviceInfo = nullptr;
109 clGetDeviceIDs_func clGetDeviceIDs = nullptr;
110
111private:
112 std::pair<bool, bool> _loaded{ false, false };
113};
114} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100115#endif /* __ARM_COMPUTE_OPENCL_H__ */