1 #include <CL/cl.h>
2 #include <CL/cl_gl.h>
3 #include <CL/cl_egl.h>
4 #include <CL/cl_ext.h>
5 #include <CL/cl_gl_ext.h>
6 #include <dlfcn.h>
7 
8 
9 void* libHandle = nullptr;
10 
11 #define FUNC_TYPES(rettype, fname, fargs, callArgs)     \
12 typedef rettype (* fname ## _t) fargs;
13 
14 #define FUNC_SYM(rettype, fname, fargs, callArgs)                                                     \
15 rettype fname fargs {                                                                                 \
16   if (!libHandle)                                                                                     \
17     libHandle = dlopen( "libOpenCL.so", RTLD_NOW | RTLD_GLOBAL );                                     \
18                                                                                                       \
19   static fname ## _t func = nullptr;                                                                  \
20   if (!func)                                                                                          \
21     func = reinterpret_cast< fname ## _t >(dlsym(libHandle, #fname));                                 \
22                                                                                                       \
23   return func callArgs;                                                                               \
24                                                                                                       \
25 }
26 
27 #define CL_MACRO FUNC_TYPES
28 #include "apis.h"
29 #undef CL_MACRO
30 
31 #define CL_MACRO FUNC_SYM
32 #include "apis.h"
33 #undef CL_MACRO
34 
35