1 /* This file is part of GEGL
2  *
3  * GEGL is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 3 of the License, or (at your option) any later version.
7  *
8  * GEGL is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with GEGL; if not, see <https://www.gnu.org/licenses/>.
15  *
16  * Copyright 2012 Victor Oliveira (victormatheus@gmail.com)
17  */
18 
19 #ifndef __GEGL_CL_INIT_H__
20 #define __GEGL_CL_INIT_H__
21 
22 #include "gegl-cl-types.h"
23 
24 const char *      gegl_cl_errstring(cl_int err);
25 
26 gboolean          gegl_cl_init (GError **error);
27 
28 gboolean          gegl_cl_init_with_opengl (GError **error);
29 
30 void              gegl_cl_cleanup (void);
31 
32 gboolean          gegl_cl_is_accelerated (void);
33 
34 gboolean          gegl_cl_has_gl_sharing (void);
35 
36 void              gegl_cl_disable (void);
37 
38 void              gegl_cl_hard_disable (void);
39 
40 cl_platform_id    gegl_cl_get_platform (void);
41 
42 cl_device_id      gegl_cl_get_device (void);
43 
44 cl_context        gegl_cl_get_context (void);
45 
46 cl_command_queue  gegl_cl_get_command_queue (void);
47 
48 cl_ulong          gegl_cl_get_local_mem_size (void);
49 
50 size_t            gegl_cl_get_iter_width (void);
51 
52 size_t            gegl_cl_get_iter_height (void);
53 
54 void              gegl_cl_set_profiling (gboolean enable);
55 
56 void              gegl_cl_set_default_device_type (cl_device_type default_device_type);
57 
58 gboolean          gegl_cl_has_extension (const char *extension_name);
59 
60 typedef struct
61 {
62   cl_program  program;
63   cl_kernel  *kernel;
64   size_t     *work_group_size;
65 } GeglClRunData;
66 
67 GeglClRunData *   gegl_cl_compile_and_build (const char *program_source,
68                                              const char *kernel_name[]);
69 
70 extern gboolean _gegl_cl_is_accelerated;
71 
72 #define gegl_cl_is_accelerated()   _gegl_cl_is_accelerated
73 
74 #define GEGL_CL_CHUNK_SIZE 1024 * 1024
75 
76 #ifdef __GEGL_CL_INIT_MAIN__
77 
78 t_clGetPlatformIDs  gegl_clGetPlatformIDs  = NULL;
79 t_clGetPlatformInfo gegl_clGetPlatformInfo = NULL;
80 t_clGetDeviceIDs    gegl_clGetDeviceIDs    = NULL;
81 t_clGetDeviceInfo   gegl_clGetDeviceInfo   = NULL;
82 
83 t_clCreateContext           gegl_clCreateContext           = NULL;
84 t_clCreateContextFromType   gegl_clCreateContextFromType   = NULL;
85 t_clCreateCommandQueue      gegl_clCreateCommandQueue      = NULL;
86 t_clCreateProgramWithSource gegl_clCreateProgramWithSource = NULL;
87 t_clBuildProgram            gegl_clBuildProgram            = NULL;
88 t_clGetProgramBuildInfo     gegl_clGetProgramBuildInfo     = NULL;
89 t_clCreateKernel            gegl_clCreateKernel            = NULL;
90 t_clSetKernelArg            gegl_clSetKernelArg            = NULL;
91 t_clGetKernelWorkGroupInfo  gegl_clGetKernelWorkGroupInfo  = NULL;
92 t_clCreateBuffer            gegl_clCreateBuffer            = NULL;
93 t_clEnqueueWriteBuffer      gegl_clEnqueueWriteBuffer      = NULL;
94 t_clEnqueueReadBuffer       gegl_clEnqueueReadBuffer       = NULL;
95 t_clEnqueueCopyBuffer       gegl_clEnqueueCopyBuffer       = NULL;
96 t_clEnqueueReadBufferRect   gegl_clEnqueueReadBufferRect   = NULL;
97 t_clEnqueueWriteBufferRect  gegl_clEnqueueWriteBufferRect  = NULL;
98 t_clEnqueueCopyBufferRect   gegl_clEnqueueCopyBufferRect   = NULL;
99 t_clCreateImage2D           gegl_clCreateImage2D           = NULL;
100 t_clCreateImage3D           gegl_clCreateImage3D           = NULL;
101 t_clEnqueueWriteImage       gegl_clEnqueueWriteImage       = NULL;
102 t_clEnqueueReadImage        gegl_clEnqueueReadImage        = NULL;
103 t_clEnqueueCopyImage        gegl_clEnqueueCopyImage        = NULL;
104 t_clEnqueueCopyBufferToImage gegl_clEnqueueCopyBufferToImage = NULL;
105 t_clEnqueueCopyImageToBuffer gegl_clEnqueueCopyImageToBuffer = NULL;
106 t_clEnqueueNDRangeKernel    gegl_clEnqueueNDRangeKernel    = NULL;
107 t_clEnqueueBarrier          gegl_clEnqueueBarrier          = NULL;
108 t_clFinish                  gegl_clFinish                  = NULL;
109 
110 t_clGetEventProfilingInfo   gegl_clGetEventProfilingInfo   = NULL;
111 
112 t_clEnqueueMapBuffer        gegl_clEnqueueMapBuffer        = NULL;
113 t_clEnqueueMapImage         gegl_clEnqueueMapImage         = NULL;
114 t_clEnqueueUnmapMemObject   gegl_clEnqueueUnmapMemObject   = NULL;
115 
116 t_clReleaseKernel       gegl_clReleaseKernel       = NULL;
117 t_clReleaseProgram      gegl_clReleaseProgram      = NULL;
118 t_clReleaseCommandQueue gegl_clReleaseCommandQueue = NULL;
119 t_clReleaseContext      gegl_clReleaseContext      = NULL;
120 t_clReleaseMemObject    gegl_clReleaseMemObject    = NULL;
121 
122 t_clGetExtensionFunctionAddress gegl_clGetExtensionFunctionAddress = NULL;
123 
124 t_clCreateFromGLTexture2D    gegl_clCreateFromGLTexture2D = NULL;
125 t_clEnqueueAcquireGLObjects  gegl_clEnqueueAcquireGLObjects = NULL;
126 t_clEnqueueReleaseGLObjects  gegl_clEnqueueReleaseGLObjects = NULL;
127 
128 #else
129 
130 extern t_clGetPlatformIDs  gegl_clGetPlatformIDs;
131 extern t_clGetPlatformInfo gegl_clGetPlatformInfo;
132 extern t_clGetDeviceIDs    gegl_clGetDeviceIDs;
133 extern t_clGetDeviceInfo   gegl_clGetDeviceInfo;
134 
135 extern t_clCreateContext           gegl_clCreateContext;
136 extern t_clCreateContextFromType   gegl_clCreateContextFromType;
137 extern t_clCreateCommandQueue      gegl_clCreateCommandQueue;
138 extern t_clCreateProgramWithSource gegl_clCreateProgramWithSource;
139 extern t_clBuildProgram            gegl_clBuildProgram;
140 extern t_clGetProgramBuildInfo     gegl_clGetProgramBuildInfo;
141 extern t_clCreateKernel            gegl_clCreateKernel;
142 extern t_clSetKernelArg            gegl_clSetKernelArg;
143 extern t_clGetKernelWorkGroupInfo  gegl_clGetKernelWorkGroupInfo;
144 extern t_clCreateBuffer            gegl_clCreateBuffer;
145 extern t_clEnqueueWriteBuffer      gegl_clEnqueueWriteBuffer;
146 extern t_clEnqueueReadBuffer       gegl_clEnqueueReadBuffer;
147 extern t_clEnqueueReadBufferRect   gegl_clEnqueueReadBufferRect;
148 extern t_clEnqueueWriteBufferRect  gegl_clEnqueueWriteBufferRect;
149 extern t_clEnqueueCopyBufferRect   gegl_clEnqueueCopyBufferRect;
150 extern t_clCreateImage2D           gegl_clCreateImage2D;
151 extern t_clCreateImage3D           gegl_clCreateImage3D;
152 extern t_clEnqueueWriteImage       gegl_clEnqueueWriteImage;
153 extern t_clEnqueueReadImage        gegl_clEnqueueReadImage;
154 extern t_clEnqueueCopyImage        gegl_clEnqueueCopyImage;
155 extern t_clEnqueueCopyBuffer       gegl_clEnqueueCopyBuffer;
156 extern t_clEnqueueCopyBufferToImage gegl_clEnqueueCopyBufferToImage;
157 extern t_clEnqueueCopyImageToBuffer gegl_clEnqueueCopyImageToBuffer;
158 extern t_clEnqueueNDRangeKernel    gegl_clEnqueueNDRangeKernel;
159 extern t_clEnqueueBarrier          gegl_clEnqueueBarrier;
160 extern t_clFinish                  gegl_clFinish;
161 
162 extern t_clGetEventProfilingInfo   gegl_clGetEventProfilingInfo;
163 
164 extern t_clEnqueueMapBuffer        gegl_clEnqueueMapBuffer;
165 extern t_clEnqueueMapImage         gegl_clEnqueueMapImage;
166 extern t_clEnqueueUnmapMemObject   gegl_clEnqueueUnmapMemObject;
167 
168 extern t_clReleaseKernel       gegl_clReleaseKernel;
169 extern t_clReleaseProgram      gegl_clReleaseProgram;
170 extern t_clReleaseCommandQueue gegl_clReleaseCommandQueue;
171 extern t_clReleaseContext      gegl_clReleaseContext;
172 extern t_clReleaseMemObject    gegl_clReleaseMemObject;
173 
174 extern t_clGetExtensionFunctionAddress gegl_clGetExtensionFunctionAddress;
175 
176 extern t_clCreateFromGLTexture2D gegl_clCreateFromGLTexture2D;
177 extern t_clEnqueueAcquireGLObjects gegl_clEnqueueAcquireGLObjects;
178 extern t_clEnqueueReleaseGLObjects gegl_clEnqueueReleaseGLObjects;
179 
180 #endif
181 
182 #endif  /* __GEGL_CL_INIT_H__ */
183