blob: 405d5cebd73b2fb89011a936c182d393f9ee622d [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Gian Marco85e6f512018-02-01 16:57:48 +00002 * Copyright (c) 2016-2018 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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: */
Anthony Barbier340a2722018-01-03 16:21:54 +000031#ifndef ARM_COMPUTE_NO_EXCEPTIONS
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032#define CL_HPP_ENABLE_EXCEPTIONS
Anthony Barbier340a2722018-01-03 16:21:54 +000033#endif // ARM_COMPUTE_NO_EXCEPTIONS
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034#define CL_HPP_CL_1_2_DEFAULT_BUILD
35#define CL_HPP_TARGET_OPENCL_VERSION 110
36#define CL_HPP_MINIMUM_OPENCL_VERSION 110
37#include <CL/cl2.hpp>
38
39namespace cl
40{
41static const NDRange Range_128_1 = NDRange(128, 1);
Moritz Pflanzer725788e2017-07-07 15:35:56 +010042} // namespace cl
Anthony Barbier6ff3b192017-09-04 18:44:23 +010043
44namespace arm_compute
45{
46bool opencl_is_available();
Moritz Pflanzer725788e2017-07-07 15:35:56 +010047
48class CLSymbols final
49{
50private:
51 CLSymbols() = default;
52 void load_symbols(void *handle);
53
54public:
55 static CLSymbols &get();
56 bool load(const std::string &library);
57 bool load_default();
58
Anthony Barbier58c4ff12017-11-09 09:15:32 +000059#define DECLARE_FUNCTION_PTR(func_name) \
60 std::function<decltype(func_name)> func_name##_ptr = nullptr
Moritz Pflanzer725788e2017-07-07 15:35:56 +010061
Anthony Barbiera9e15332017-12-22 16:37:30 +000062 DECLARE_FUNCTION_PTR(clCreateContextFromType);
63 DECLARE_FUNCTION_PTR(clCreateCommandQueue);
64 DECLARE_FUNCTION_PTR(clGetContextInfo);
Anthony Barbier58c4ff12017-11-09 09:15:32 +000065 DECLARE_FUNCTION_PTR(clBuildProgram);
66 DECLARE_FUNCTION_PTR(clEnqueueNDRangeKernel);
67 DECLARE_FUNCTION_PTR(clSetKernelArg);
68 DECLARE_FUNCTION_PTR(clReleaseKernel);
69 DECLARE_FUNCTION_PTR(clCreateProgramWithSource);
70 DECLARE_FUNCTION_PTR(clCreateBuffer);
71 DECLARE_FUNCTION_PTR(clRetainKernel);
72 DECLARE_FUNCTION_PTR(clCreateKernel);
73 DECLARE_FUNCTION_PTR(clGetProgramInfo);
74 DECLARE_FUNCTION_PTR(clFlush);
75 DECLARE_FUNCTION_PTR(clFinish);
76 DECLARE_FUNCTION_PTR(clReleaseProgram);
77 DECLARE_FUNCTION_PTR(clRetainContext);
78 DECLARE_FUNCTION_PTR(clCreateProgramWithBinary);
79 DECLARE_FUNCTION_PTR(clReleaseCommandQueue);
80 DECLARE_FUNCTION_PTR(clEnqueueMapBuffer);
81 DECLARE_FUNCTION_PTR(clRetainProgram);
82 DECLARE_FUNCTION_PTR(clGetProgramBuildInfo);
83 DECLARE_FUNCTION_PTR(clEnqueueReadBuffer);
84 DECLARE_FUNCTION_PTR(clEnqueueWriteBuffer);
85 DECLARE_FUNCTION_PTR(clReleaseEvent);
86 DECLARE_FUNCTION_PTR(clReleaseContext);
87 DECLARE_FUNCTION_PTR(clRetainCommandQueue);
88 DECLARE_FUNCTION_PTR(clEnqueueUnmapMemObject);
89 DECLARE_FUNCTION_PTR(clRetainMemObject);
90 DECLARE_FUNCTION_PTR(clReleaseMemObject);
91 DECLARE_FUNCTION_PTR(clGetDeviceInfo);
92 DECLARE_FUNCTION_PTR(clGetDeviceIDs);
93 DECLARE_FUNCTION_PTR(clRetainEvent);
94 DECLARE_FUNCTION_PTR(clGetPlatformIDs);
95 DECLARE_FUNCTION_PTR(clGetKernelWorkGroupInfo);
Gian Marco85e6f512018-02-01 16:57:48 +000096 DECLARE_FUNCTION_PTR(clGetCommandQueueInfo);
97 DECLARE_FUNCTION_PTR(clGetKernelInfo);
98 DECLARE_FUNCTION_PTR(clGetEventProfilingInfo);
Anthony Barbier58c4ff12017-11-09 09:15:32 +000099
100#undef DECLARE_FUNCTION_PTR
Moritz Pflanzer725788e2017-07-07 15:35:56 +0100101
102private:
103 std::pair<bool, bool> _loaded{ false, false };
104};
105} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100106#endif /* __ARM_COMPUTE_OPENCL_H__ */