Compute Library  18.05
OpenCL.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2018 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 
27 #include <string>
28 #include <utility>
29 
30 /* Configure the Khronos C++ wrapper to target OpenCL 1.2: */
31 #ifndef ARM_COMPUTE_NO_EXCEPTIONS
32 #define CL_HPP_ENABLE_EXCEPTIONS
33 #endif // ARM_COMPUTE_NO_EXCEPTIONS
34 #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 
39 namespace cl
40 {
41 static const NDRange Range_128_1 = NDRange(128, 1);
42 } // namespace cl
43 
44 namespace arm_compute
45 {
50 bool opencl_is_available();
51 
53 class CLSymbols final
54 {
55 private:
56  CLSymbols() = default;
57  void load_symbols(void *handle);
58 
59 public:
64  static CLSymbols &get();
71  bool load(const std::string &library);
76  bool load_default();
77 
78 #define DECLARE_FUNCTION_PTR(func_name) \
79  std::function<decltype(func_name)> func_name##_ptr = nullptr
80 
81  DECLARE_FUNCTION_PTR(clCreateContextFromType);
82  DECLARE_FUNCTION_PTR(clCreateCommandQueue);
83  DECLARE_FUNCTION_PTR(clGetContextInfo);
84  DECLARE_FUNCTION_PTR(clBuildProgram);
85  DECLARE_FUNCTION_PTR(clEnqueueNDRangeKernel);
86  DECLARE_FUNCTION_PTR(clSetKernelArg);
87  DECLARE_FUNCTION_PTR(clReleaseKernel);
88  DECLARE_FUNCTION_PTR(clCreateProgramWithSource);
89  DECLARE_FUNCTION_PTR(clCreateBuffer);
90  DECLARE_FUNCTION_PTR(clRetainKernel);
91  DECLARE_FUNCTION_PTR(clCreateKernel);
92  DECLARE_FUNCTION_PTR(clGetProgramInfo);
95  DECLARE_FUNCTION_PTR(clReleaseProgram);
96  DECLARE_FUNCTION_PTR(clRetainContext);
97  DECLARE_FUNCTION_PTR(clCreateProgramWithBinary);
98  DECLARE_FUNCTION_PTR(clReleaseCommandQueue);
99  DECLARE_FUNCTION_PTR(clEnqueueMapBuffer);
100  DECLARE_FUNCTION_PTR(clRetainProgram);
101  DECLARE_FUNCTION_PTR(clGetProgramBuildInfo);
102  DECLARE_FUNCTION_PTR(clEnqueueReadBuffer);
103  DECLARE_FUNCTION_PTR(clEnqueueWriteBuffer);
104  DECLARE_FUNCTION_PTR(clReleaseEvent);
105  DECLARE_FUNCTION_PTR(clReleaseContext);
106  DECLARE_FUNCTION_PTR(clRetainCommandQueue);
107  DECLARE_FUNCTION_PTR(clEnqueueUnmapMemObject);
108  DECLARE_FUNCTION_PTR(clRetainMemObject);
109  DECLARE_FUNCTION_PTR(clReleaseMemObject);
110  DECLARE_FUNCTION_PTR(clGetDeviceInfo);
111  DECLARE_FUNCTION_PTR(clGetDeviceIDs);
112  DECLARE_FUNCTION_PTR(clRetainEvent);
113  DECLARE_FUNCTION_PTR(clGetPlatformIDs);
114  DECLARE_FUNCTION_PTR(clGetKernelWorkGroupInfo);
115  DECLARE_FUNCTION_PTR(clGetCommandQueueInfo);
116  DECLARE_FUNCTION_PTR(clGetKernelInfo);
117  DECLARE_FUNCTION_PTR(clGetEventProfilingInfo);
118  DECLARE_FUNCTION_PTR(clSVMAlloc);
120  DECLARE_FUNCTION_PTR(clEnqueueSVMMap);
121  DECLARE_FUNCTION_PTR(clEnqueueSVMUnmap);
122  DECLARE_FUNCTION_PTR(clEnqueueMarker);
123  DECLARE_FUNCTION_PTR(clWaitForEvents);
124 
125 #undef DECLARE_FUNCTION_PTR
126 
127 private:
128  std::pair<bool, bool> _loaded{ false, false };
129 };
130 } // namespace arm_compute
131 #endif /* __ARM_COMPUTE_OPENCL_H__ */
Class for loading OpenCL symbols.
Definition: OpenCL.h:53
bool opencl_is_available()
Check if OpenCL is available.
This file contains all available output stages for GEMMLowp on OpenCL.
std::unique_ptr< AssetsLibrary > library
Definition: main.cpp:59
#define DECLARE_FUNCTION_PTR(func_name)
Definition: OpenCL.h:78