2 * Author......: Jens Steube <jens.steube@gmail.com>
6 #include <ext_OpenCL.h>
8 void hc_clEnqueueNDRangeKernel (cl_command_queue command_queue
, cl_kernel kernel
, cl_uint work_dim
, const size_t *global_work_offset
, const size_t *global_work_size
, const size_t *local_work_size
, cl_uint num_events_in_wait_list
, const cl_event
*event_wait_list
, cl_event
*event
)
10 cl_int CL_err
= clEnqueueNDRangeKernel (command_queue
, kernel
, work_dim
, global_work_offset
, global_work_size
, local_work_size
, num_events_in_wait_list
, event_wait_list
, event
);
12 if (CL_err
!= CL_SUCCESS
)
14 log_error ("ERROR: %s %d\n", "clEnqueueNDRangeKernel()", CL_err
);
20 void hc_clGetEventInfo (cl_event event
, cl_event_info param_name
, size_t param_value_size
, void *param_value
, size_t *param_value_size_ret
)
22 cl_int CL_err
= clGetEventInfo (event
, param_name
, param_value_size
, param_value
, param_value_size_ret
);
24 if (CL_err
!= CL_SUCCESS
)
26 log_error ("ERROR: %s %d\n", "clGetEventInfo()", CL_err
);
32 void hc_clFlush (cl_command_queue command_queue
)
34 cl_int CL_err
= clFlush (command_queue
);
36 if (CL_err
!= CL_SUCCESS
)
38 log_error ("ERROR: %s %d\n", "clFlush()", CL_err
);
44 void hc_clFinish (cl_command_queue command_queue
)
46 cl_int CL_err
= clFinish (command_queue
);
48 if (CL_err
!= CL_SUCCESS
)
50 log_error ("ERROR: %s %d\n", "clFinish()", CL_err
);
56 void hc_clSetKernelArg (cl_kernel kernel
, cl_uint arg_index
, size_t arg_size
, const void *arg_value
)
58 cl_int CL_err
= clSetKernelArg (kernel
, arg_index
, arg_size
, arg_value
);
60 if (CL_err
!= CL_SUCCESS
)
62 log_error ("ERROR: %s %d\n", "clSetKernelArg()", CL_err
);
68 void hc_clEnqueueWriteBuffer (cl_command_queue command_queue
, cl_mem buffer
, cl_bool blocking_write
, size_t offset
, size_t cb
, const void *ptr
, cl_uint num_events_in_wait_list
, const cl_event
*event_wait_list
, cl_event
*event
)
70 cl_int CL_err
= clEnqueueWriteBuffer (command_queue
, buffer
, blocking_write
, offset
, cb
, ptr
, num_events_in_wait_list
, event_wait_list
, event
);
72 if (CL_err
!= CL_SUCCESS
)
74 log_error ("ERROR: %s %d\n", "clEnqueueWriteBuffer()", CL_err
);
80 void hc_clEnqueueCopyBuffer (cl_command_queue command_queue
, cl_mem src_buffer
, cl_mem dst_buffer
, size_t src_offset
, size_t dst_offset
, size_t cb
, cl_uint num_events_in_wait_list
, const cl_event
*event_wait_list
, cl_event
*event
)
82 cl_int CL_err
= clEnqueueCopyBuffer (command_queue
, src_buffer
, dst_buffer
, src_offset
, dst_offset
, cb
, num_events_in_wait_list
, event_wait_list
, event
);
84 if (CL_err
!= CL_SUCCESS
)
86 log_error ("ERROR: %s %d\n", "clEnqueueCopyBuffer()", CL_err
);
92 void hc_clEnqueueReadBuffer (cl_command_queue command_queue
, cl_mem buffer
, cl_bool blocking_read
, size_t offset
, size_t cb
, void *ptr
, cl_uint num_events_in_wait_list
, const cl_event
*event_wait_list
, cl_event
*event
)
94 cl_int CL_err
= clEnqueueReadBuffer (command_queue
, buffer
, blocking_read
, offset
, cb
, ptr
, num_events_in_wait_list
, event_wait_list
, event
);
96 if (CL_err
!= CL_SUCCESS
)
98 log_error ("ERROR: %s %d\n", "clEnqueueReadBuffer()", CL_err
);
104 void hc_clGetPlatformIDs (cl_uint num_entries
, cl_platform_id
*platforms
, cl_uint
*num_platforms
)
106 cl_int CL_err
= clGetPlatformIDs (num_entries
, platforms
, num_platforms
);
108 if (CL_err
!= CL_SUCCESS
)
110 log_error ("ERROR: %s %d\n", "clGetPlatformIDs()", CL_err
);
116 void hc_clGetPlatformInfo (cl_platform_id platform
, cl_platform_info param_name
, size_t param_value_size
, void *param_value
, size_t *param_value_size_ret
)
118 cl_int CL_err
= clGetPlatformInfo (platform
, param_name
, param_value_size
, param_value
, param_value_size_ret
);
120 if (CL_err
!= CL_SUCCESS
)
122 log_error ("ERROR: %s %d\n", "clGetPlatformInfo()", CL_err
);
128 void hc_clGetDeviceIDs (cl_platform_id platform
, cl_device_type device_type
, cl_uint num_entries
, cl_device_id
*devices
, cl_uint
*num_devices
)
130 cl_int CL_err
= clGetDeviceIDs (platform
, device_type
, num_entries
, devices
, num_devices
);
132 if (CL_err
!= CL_SUCCESS
)
134 log_error ("ERROR: %s %d\n", "clGetDeviceIDs()", CL_err
);
140 void hc_clGetDeviceInfo (cl_device_id device
, cl_device_info param_name
, size_t param_value_size
, void *param_value
, size_t *param_value_size_ret
)
142 cl_int CL_err
= clGetDeviceInfo (device
, param_name
, param_value_size
, param_value
, param_value_size_ret
);
144 if (CL_err
!= CL_SUCCESS
)
146 log_error ("ERROR: %s %d\n", "clGetDeviceInfo()", CL_err
);
152 cl_context
hc_clCreateContext (cl_context_properties
*properties
, cl_uint num_devices
, const cl_device_id
*devices
, void (CL_CALLBACK
*pfn_notify
) (const char *, const void *, size_t, void *), void *user_data
)
156 cl_context context
= clCreateContext (properties
, num_devices
, devices
, pfn_notify
, user_data
, &CL_err
);
158 if (CL_err
!= CL_SUCCESS
)
160 log_error ("ERROR: %s %d\n", "clCreateContext()", CL_err
);
169 cl_command_queue
hc_clCreateCommandQueue (cl_context context
, cl_device_id device
, cl_command_queue_properties properties
)
173 cl_command_queue command_queue
= clCreateCommandQueue (context
, device
, properties
, &CL_err
);
175 if (CL_err
!= CL_SUCCESS
)
177 log_error ("ERROR: %s %d\n", "clCreateCommandQueue()", CL_err
);
182 return (command_queue
);
186 cl_command_queue hc_clCreateCommandQueueWithProperties (cl_context context, cl_device_id device, const cl_queue_properties *properties)
190 cl_command_queue command_queue = clCreateCommandQueueWithProperties (context, device, properties, &CL_err);
192 if (CL_err != CL_SUCCESS)
194 log_error ("ERROR: %s %d\n", "clCreateCommandQueueWithProperties()", CL_err);
199 return (command_queue);
203 cl_mem
hc_clCreateBuffer (cl_context context
, cl_mem_flags flags
, size_t size
, void *host_ptr
)
207 cl_mem mem
= clCreateBuffer (context
, flags
, size
, host_ptr
, &CL_err
);
209 if (CL_err
!= CL_SUCCESS
)
211 log_error ("ERROR: %s %d\n", "clCreateBuffer()", CL_err
);
219 cl_program
hc_clCreateProgramWithSource (cl_context context
, cl_uint count
, const char **strings
, const size_t *lengths
)
223 cl_program program
= clCreateProgramWithSource (context
, count
, strings
, lengths
, &CL_err
);
225 if (CL_err
!= CL_SUCCESS
)
227 log_error ("ERROR: %s %d\n", "clCreateProgramWithSource()", CL_err
);
235 cl_program
hc_clCreateProgramWithBinary (cl_context context
, cl_uint num_devices
, const cl_device_id
*device_list
, const size_t *lengths
, const unsigned char **binaries
, cl_int
*binary_status
)
239 cl_program program
= clCreateProgramWithBinary (context
, num_devices
, device_list
, lengths
, binaries
, binary_status
, &CL_err
);
241 if (CL_err
!= CL_SUCCESS
)
243 log_error ("ERROR: %s %d\n", "clCreateProgramWithBinary()", CL_err
);
251 void hc_clBuildProgram (cl_program program
, cl_uint num_devices
, const cl_device_id
*device_list
, const char *options
, void (CL_CALLBACK
*pfn_notify
) (cl_program program
, void *user_data
), void *user_data
)
253 cl_int CL_err
= clBuildProgram (program
, num_devices
, device_list
, options
, pfn_notify
, user_data
);
255 if (CL_err
!= CL_SUCCESS
)
257 log_error ("ERROR: %s %d\n", "clBuildProgram()", CL_err
);
259 // If we exit here we can't see the error message
264 cl_kernel
hc_clCreateKernel (cl_program program
, const char *kernel_name
)
268 cl_kernel kernel
= clCreateKernel (program
, kernel_name
, &CL_err
);
270 if (CL_err
!= CL_SUCCESS
)
272 log_error ("ERROR: %s %d - %s\n", "clCreateKernel()", CL_err
, kernel_name
);
280 void hc_clReleaseMemObject (cl_mem mem
)
282 cl_int CL_err
= clReleaseMemObject (mem
);
284 if (CL_err
!= CL_SUCCESS
)
286 log_error ("ERROR: %s %d\n", "clReleaseMemObject()", CL_err
);
292 void hc_clReleaseKernel (cl_kernel kernel
)
294 cl_int CL_err
= clReleaseKernel (kernel
);
296 if (CL_err
!= CL_SUCCESS
)
298 log_error ("ERROR: %s %d\n", "clReleaseProgram()", CL_err
);
304 void hc_clReleaseProgram (cl_program program
)
306 cl_int CL_err
= clReleaseProgram (program
);
308 if (CL_err
!= CL_SUCCESS
)
310 log_error ("ERROR: %s %d\n", "clReleaseProgram()", CL_err
);
316 void hc_clReleaseCommandQueue (cl_command_queue command_queue
)
318 cl_int CL_err
= clReleaseCommandQueue (command_queue
);
320 if (CL_err
!= CL_SUCCESS
)
322 log_error ("ERROR: %s %d\n", "clReleaseCommandQueue()", CL_err
);
328 void hc_clReleaseContext (cl_context context
)
330 cl_int CL_err
= clReleaseContext (context
);
332 if (CL_err
!= CL_SUCCESS
)
334 log_error ("ERROR: %s %d\n", "clReleaseContext()", CL_err
);
340 void *hc_clEnqueueMapBuffer (cl_command_queue command_queue
, cl_mem buffer
, cl_bool blocking_read
, cl_map_flags map_flags
, size_t offset
, size_t cb
, cl_uint num_events_in_wait_list
, const cl_event
*event_wait_list
, cl_event
*event
)
344 void *buf
= clEnqueueMapBuffer (command_queue
, buffer
, blocking_read
, map_flags
, offset
, cb
, num_events_in_wait_list
, event_wait_list
, event
, &CL_err
);
346 if (CL_err
!= CL_SUCCESS
)
348 log_error ("ERROR: %s %d\n", "clEnqueueMapBuffer()", CL_err
);
356 void hc_clEnqueueUnmapMemObject (cl_command_queue command_queue
, cl_mem memobj
, void *mapped_ptr
, cl_uint num_events_in_wait_list
, const cl_event
*event_wait_list
, cl_event
*event
)
358 cl_int CL_err
= clEnqueueUnmapMemObject (command_queue
, memobj
, mapped_ptr
, num_events_in_wait_list
, event_wait_list
, event
);
360 if (CL_err
!= CL_SUCCESS
)
362 log_error ("ERROR: %s %d\n", "clEnqueueUnmapMemObject()", CL_err
);
368 void hc_clEnqueueFillBuffer (cl_command_queue command_queue
, cl_mem buffer
, const void *pattern
, size_t pattern_size
, size_t offset
, size_t size
, cl_uint num_events_in_wait_list
, const cl_event
*event_wait_list
, cl_event
*event
)
370 cl_int CL_err
= clEnqueueFillBuffer (command_queue
, buffer
, pattern
, pattern_size
, offset
, size
, num_events_in_wait_list
, event_wait_list
, event
);
372 if (CL_err
!= CL_SUCCESS
)
374 log_error ("ERROR: %s %d\n", "clEnqueueFillBuffer()", CL_err
);