Update event handling to workaround event handling error in nvidia opencl runtime
[hashcat.git] / src / ext_OpenCL.c
1 /**
2 * Authors.....: Jens Steube <jens.steube@gmail.com>
3 * Gabriele Gristina <matrix@hashcat.net>
4 *
5 * License.....: MIT
6 */
7
8 #include <ext_OpenCL.h>
9
10 const char *val2cstr_cl (cl_int CL_err)
11 {
12 #define CLERR(a) case a: return #a
13
14 switch (CL_err)
15 {
16 CLERR (CL_BUILD_PROGRAM_FAILURE);
17 CLERR (CL_COMPILER_NOT_AVAILABLE);
18 CLERR (CL_DEVICE_NOT_FOUND);
19 CLERR (CL_INVALID_ARG_INDEX);
20 CLERR (CL_INVALID_ARG_SIZE);
21 CLERR (CL_INVALID_ARG_VALUE);
22 CLERR (CL_INVALID_BINARY);
23 CLERR (CL_INVALID_BUFFER_SIZE);
24 CLERR (CL_INVALID_BUILD_OPTIONS);
25 CLERR (CL_INVALID_COMMAND_QUEUE);
26 CLERR (CL_INVALID_CONTEXT);
27 CLERR (CL_INVALID_DEVICE);
28 CLERR (CL_INVALID_DEVICE_TYPE);
29 CLERR (CL_INVALID_EVENT);
30 CLERR (CL_INVALID_EVENT_WAIT_LIST);
31 CLERR (CL_INVALID_GLOBAL_OFFSET);
32 CLERR (CL_INVALID_HOST_PTR);
33 CLERR (CL_INVALID_KERNEL);
34 CLERR (CL_INVALID_KERNEL_ARGS);
35 CLERR (CL_INVALID_KERNEL_DEFINITION);
36 CLERR (CL_INVALID_KERNEL_NAME);
37 CLERR (CL_INVALID_MEM_OBJECT);
38 CLERR (CL_INVALID_OPERATION);
39 CLERR (CL_INVALID_PLATFORM);
40 CLERR (CL_INVALID_PROGRAM);
41 CLERR (CL_INVALID_PROGRAM_EXECUTABLE);
42 CLERR (CL_INVALID_QUEUE_PROPERTIES);
43 CLERR (CL_INVALID_SAMPLER);
44 CLERR (CL_INVALID_VALUE);
45 CLERR (CL_INVALID_WORK_DIMENSION);
46 CLERR (CL_INVALID_WORK_GROUP_SIZE);
47 CLERR (CL_INVALID_WORK_ITEM_SIZE);
48 CLERR (CL_MISALIGNED_SUB_BUFFER_OFFSET);
49 CLERR (CL_MAP_FAILURE);
50 CLERR (CL_MEM_COPY_OVERLAP);
51 CLERR (CL_MEM_OBJECT_ALLOCATION_FAILURE);
52 CLERR (CL_OUT_OF_HOST_MEMORY);
53 CLERR (CL_OUT_OF_RESOURCES);
54 }
55
56 return "CL_UNKNOWN_ERROR";
57 }
58
59 int ocl_init (OCL_PTR *ocl)
60 {
61 if (!ocl)
62 {
63 log_error ("ERROR: opencl library ptr is null");
64
65 exit (-1);
66 }
67
68 memset (ocl, 0, sizeof (hc_opencl_lib_t));
69
70 #ifdef _WIN
71 ocl->lib = hc_dlopen ("OpenCL");
72 #elif OSX
73 ocl->lib = hc_dlopen ("/System/Library/Frameworks/OpenCL.framework/OpenCL", RTLD_NOW);
74 #else
75 ocl->lib = hc_dlopen ("libOpenCL.so", RTLD_NOW);
76 #endif
77
78 if (!ocl->lib)
79 {
80 log_error ("ERROR: cannot load opencl library");
81
82 exit (-1);
83 }
84
85 HC_LOAD_FUNC(ocl, clBuildProgram, OCL_CLBUILDPROGRAM, OpenCL, 1)
86 HC_LOAD_FUNC(ocl, clCreateBuffer, OCL_CLCREATEBUFFER, OpenCL, 1)
87 HC_LOAD_FUNC(ocl, clCreateCommandQueue, OCL_CLCREATECOMMANDQUEUE, OpenCL, 1)
88 HC_LOAD_FUNC(ocl, clCreateContext, OCL_CLCREATECONTEXT, OpenCL, 1)
89 HC_LOAD_FUNC(ocl, clCreateKernel, OCL_CLCREATEKERNEL, OpenCL, 1)
90 HC_LOAD_FUNC(ocl, clCreateProgramWithBinary, OCL_CLCREATEPROGRAMWITHBINARY, OpenCL, 1)
91 HC_LOAD_FUNC(ocl, clCreateProgramWithSource, OCL_CLCREATEPROGRAMWITHSOURCE, OpenCL, 1)
92 HC_LOAD_FUNC(ocl, clEnqueueCopyBuffer, OCL_CLENQUEUECOPYBUFFER, OpenCL, 1)
93 HC_LOAD_FUNC(ocl, clEnqueueFillBuffer, OCL_CLENQUEUEFILLBUFFER, OpenCL, -1)
94 HC_LOAD_FUNC(ocl, clEnqueueMapBuffer, OCL_CLENQUEUEMAPBUFFER, OpenCL, 1)
95 HC_LOAD_FUNC(ocl, clEnqueueNDRangeKernel, OCL_CLENQUEUENDRANGEKERNEL, OpenCL, 1)
96 HC_LOAD_FUNC(ocl, clEnqueueReadBuffer, OCL_CLENQUEUEREADBUFFER, OpenCL, 1)
97 HC_LOAD_FUNC(ocl, clEnqueueUnmapMemObject, OCL_CLENQUEUEUNMAPMEMOBJECT, OpenCL, 1)
98 HC_LOAD_FUNC(ocl, clEnqueueWriteBuffer, OCL_CLENQUEUEWRITEBUFFER, OpenCL, 1)
99 HC_LOAD_FUNC(ocl, clFinish, OCL_CLFINISH, OpenCL, 1)
100 HC_LOAD_FUNC(ocl, clFlush, OCL_CLFLUSH, OpenCL, 1)
101 HC_LOAD_FUNC(ocl, clGetDeviceIDs, OCL_CLGETDEVICEIDS, OpenCL, 1)
102 HC_LOAD_FUNC(ocl, clGetDeviceInfo, OCL_CLGETDEVICEINFO, OpenCL, 1)
103 HC_LOAD_FUNC(ocl, clGetEventInfo, OCL_CLGETEVENTINFO, OpenCL, 1)
104 HC_LOAD_FUNC(ocl, clGetKernelWorkGroupInfo, OCL_CLGETKERNELWORKGROUPINFO, OpenCL, 1)
105 HC_LOAD_FUNC(ocl, clGetPlatformIDs, OCL_CLGETPLATFORMIDS, OpenCL, 1)
106 HC_LOAD_FUNC(ocl, clGetPlatformInfo, OCL_CLGETPLATFORMINFO, OpenCL, 1)
107 HC_LOAD_FUNC(ocl, clGetProgramBuildInfo, OCL_CLGETPROGRAMBUILDINFO, OpenCL, 1)
108 HC_LOAD_FUNC(ocl, clGetProgramInfo, OCL_CLGETPROGRAMINFO, OpenCL, 1)
109 HC_LOAD_FUNC(ocl, clReleaseCommandQueue, OCL_CLRELEASECOMMANDQUEUE, OpenCL, 1)
110 HC_LOAD_FUNC(ocl, clReleaseContext, OCL_CLRELEASECONTEXT, OpenCL, 1)
111 HC_LOAD_FUNC(ocl, clReleaseKernel, OCL_CLRELEASEKERNEL, OpenCL, 1)
112 HC_LOAD_FUNC(ocl, clReleaseMemObject, OCL_CLRELEASEMEMOBJECT, OpenCL, 1)
113 HC_LOAD_FUNC(ocl, clReleaseProgram, OCL_CLRELEASEPROGRAM, OpenCL, 1)
114 HC_LOAD_FUNC(ocl, clSetKernelArg, OCL_CLSETKERNELARG, OpenCL, 1)
115 HC_LOAD_FUNC(ocl, clWaitForEvents, OCL_CLWAITFOREVENTS, OpenCL, 1)
116 HC_LOAD_FUNC(ocl, clGetEventProfilingInfo, OCL_CLGETEVENTPROFILINGINFO, OpenCL, 1)
117 HC_LOAD_FUNC(ocl, clReleaseEvent, CLRELEASEEVENT, OpenCL, 1)
118
119 return 0;
120 }
121
122 void ocl_close (OCL_PTR *ocl)
123 {
124 if (ocl)
125 {
126 if (ocl->lib)
127 hc_dlclose (ocl->lib);
128
129 free (ocl);
130 }
131 }
132
133 cl_int hc_clEnqueueNDRangeKernel (OCL_PTR *ocl, 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, bool exitOnFail)
134 {
135 cl_int CL_err = ocl->clEnqueueNDRangeKernel (command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size, num_events_in_wait_list, event_wait_list, event);
136
137 if (CL_err != CL_SUCCESS)
138 {
139 if (exitOnFail)
140 {
141 log_error ("ERROR: %s : %d : %s\n", "clEnqueueNDRangeKernel()", CL_err, val2cstr_cl (CL_err));
142
143 exit (-1);
144 }
145
146 return (-1);
147 }
148
149 return 0;
150 }
151
152 void hc_clGetEventInfo (OCL_PTR *ocl, cl_event event, cl_event_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
153 {
154 cl_int CL_err = ocl->clGetEventInfo (event, param_name, param_value_size, param_value, param_value_size_ret);
155
156 if (CL_err != CL_SUCCESS)
157 {
158 log_error ("ERROR: %s : %d : %s\n", "clGetEventInfo()", CL_err, val2cstr_cl (CL_err));
159
160 exit (-1);
161 }
162 }
163
164 void hc_clFlush (OCL_PTR *ocl, cl_command_queue command_queue)
165 {
166 cl_int CL_err = ocl->clFlush (command_queue);
167
168 if (CL_err != CL_SUCCESS)
169 {
170 log_error ("ERROR: %s : %d : %s\n", "clFlush()", CL_err, val2cstr_cl (CL_err));
171
172 exit (-1);
173 }
174 }
175
176 void hc_clFinish (OCL_PTR *ocl, cl_command_queue command_queue)
177 {
178 cl_int CL_err = ocl->clFinish (command_queue);
179
180 if (CL_err != CL_SUCCESS)
181 {
182 log_error ("ERROR: %s : %d : %s\n", "clFinish()", CL_err, val2cstr_cl (CL_err));
183
184 exit (-1);
185 }
186 }
187
188 void hc_clSetKernelArg (OCL_PTR *ocl, cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value)
189 {
190 cl_int CL_err = ocl->clSetKernelArg (kernel, arg_index, arg_size, arg_value);
191
192 if (CL_err != CL_SUCCESS)
193 {
194 log_error ("ERROR: %s : %d : %s\n", "clSetKernelArg()", CL_err, val2cstr_cl (CL_err));
195
196 exit (-1);
197 }
198 }
199
200 void hc_clEnqueueWriteBuffer (OCL_PTR *ocl, 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)
201 {
202 cl_int CL_err = ocl->clEnqueueWriteBuffer (command_queue, buffer, blocking_write, offset, cb, ptr, num_events_in_wait_list, event_wait_list, event);
203
204 if (CL_err != CL_SUCCESS)
205 {
206 log_error ("ERROR: %s : %d : %s\n", "clEnqueueWriteBuffer()", CL_err, val2cstr_cl (CL_err));
207
208 exit (-1);
209 }
210 }
211
212 void hc_clEnqueueCopyBuffer (OCL_PTR *ocl, 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)
213 {
214 cl_int CL_err = ocl->clEnqueueCopyBuffer (command_queue, src_buffer, dst_buffer, src_offset, dst_offset, cb, num_events_in_wait_list, event_wait_list, event);
215
216 if (CL_err != CL_SUCCESS)
217 {
218 log_error ("ERROR: %s : %d : %s\n", "clEnqueueCopyBuffer()", CL_err, val2cstr_cl (CL_err));
219
220 exit (-1);
221 }
222 }
223
224 void hc_clEnqueueReadBuffer (OCL_PTR *ocl, 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)
225 {
226 cl_int CL_err = ocl->clEnqueueReadBuffer (command_queue, buffer, blocking_read, offset, cb, ptr, num_events_in_wait_list, event_wait_list, event);
227
228 if (CL_err != CL_SUCCESS)
229 {
230 log_error ("ERROR: %s : %d : %s\n", "clEnqueueReadBuffer()", CL_err, val2cstr_cl (CL_err));
231
232 exit (-1);
233 }
234 }
235
236 void hc_clGetPlatformIDs (OCL_PTR *ocl, cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
237 {
238 cl_int CL_err = ocl->clGetPlatformIDs (num_entries, platforms, num_platforms);
239
240 if (CL_err != CL_SUCCESS)
241 {
242 log_error ("ERROR: %s : %d : %s\n", "clGetPlatformIDs()", CL_err, val2cstr_cl (CL_err));
243
244 exit (-1);
245 }
246 }
247
248 void hc_clGetPlatformInfo (OCL_PTR *ocl, cl_platform_id platform, cl_platform_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
249 {
250 cl_int CL_err = ocl->clGetPlatformInfo (platform, param_name, param_value_size, param_value, param_value_size_ret);
251
252 if (CL_err != CL_SUCCESS)
253 {
254 log_error ("ERROR: %s : %d : %s\n", "clGetPlatformInfo()", CL_err, val2cstr_cl (CL_err));
255
256 exit (-1);
257 }
258 }
259
260 void hc_clGetDeviceIDs (OCL_PTR *ocl, cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, cl_device_id *devices, cl_uint *num_devices)
261 {
262 cl_int CL_err = ocl->clGetDeviceIDs (platform, device_type, num_entries, devices, num_devices);
263
264 if (CL_err != CL_SUCCESS)
265 {
266 log_error ("ERROR: %s : %d : %s\n", "clGetDeviceIDs()", CL_err, val2cstr_cl (CL_err));
267
268 exit (-1);
269 }
270 }
271
272 void hc_clGetDeviceInfo (OCL_PTR *ocl, cl_device_id device, cl_device_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
273 {
274 cl_int CL_err = ocl->clGetDeviceInfo (device, param_name, param_value_size, param_value, param_value_size_ret);
275
276 if (CL_err != CL_SUCCESS)
277 {
278 log_error ("ERROR: %s : %d : %s\n", "clGetDeviceInfo()", CL_err, val2cstr_cl (CL_err));
279
280 exit (-1);
281 }
282 }
283
284 cl_context hc_clCreateContext (OCL_PTR *ocl, 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)
285 {
286 cl_int CL_err;
287
288 cl_context context = ocl->clCreateContext (properties, num_devices, devices, pfn_notify, user_data, &CL_err);
289
290 if (CL_err != CL_SUCCESS)
291 {
292 log_error ("ERROR: %s : %d : %s\n", "clCreateContext()", CL_err, val2cstr_cl (CL_err));
293
294 exit (-1);
295 }
296
297 return (context);
298 }
299
300 cl_command_queue hc_clCreateCommandQueue (OCL_PTR *ocl, cl_context context, cl_device_id device, cl_command_queue_properties properties)
301 {
302 cl_int CL_err;
303
304 cl_command_queue command_queue = ocl->clCreateCommandQueue (context, device, properties, &CL_err);
305
306 if (CL_err != CL_SUCCESS)
307 {
308 log_error ("ERROR: %s : %d : %s\n", "clCreateCommandQueue()", CL_err, val2cstr_cl (CL_err));
309
310 exit (-1);
311 }
312
313 return (command_queue);
314 }
315
316 /*
317 cl_command_queue hc_clCreateCommandQueueWithProperties (cl_context context, cl_device_id device, const cl_queue_properties *properties)
318 {
319 cl_int CL_err;
320
321 cl_command_queue command_queue = clCreateCommandQueueWithProperties (context, device, properties, &CL_err);
322
323 if (CL_err != CL_SUCCESS)
324 {
325 log_error ("ERROR: %s : %d : %s\n", "clCreateCommandQueueWithProperties()", CL_err, val2cstr_cl (CL_err));
326
327 exit (-1);
328 }
329
330 return (command_queue);
331 }
332 */
333
334 cl_mem hc_clCreateBuffer (OCL_PTR *ocl, cl_context context, cl_mem_flags flags, size_t size, void *host_ptr)
335 {
336 cl_int CL_err;
337
338 cl_mem mem = ocl->clCreateBuffer (context, flags, size, host_ptr, &CL_err);
339
340 if (CL_err != CL_SUCCESS)
341 {
342 log_error ("ERROR: %s : %d : %s\n", "clCreateBuffer()", CL_err, val2cstr_cl (CL_err));
343
344 exit (-1);
345 }
346
347 return (mem);
348 }
349
350 cl_program hc_clCreateProgramWithSource (OCL_PTR *ocl, cl_context context, cl_uint count, const char **strings, const size_t *lengths)
351 {
352 cl_int CL_err;
353
354 cl_program program = ocl->clCreateProgramWithSource (context, count, strings, lengths, &CL_err);
355
356 if (CL_err != CL_SUCCESS)
357 {
358 log_error ("ERROR: %s : %d : %s\n", "clCreateProgramWithSource()", CL_err, val2cstr_cl (CL_err));
359
360 exit (-1);
361 }
362
363 return (program);
364 }
365
366 cl_program hc_clCreateProgramWithBinary (OCL_PTR *ocl, 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)
367 {
368 cl_int CL_err;
369
370 cl_program program = ocl->clCreateProgramWithBinary (context, num_devices, device_list, lengths, binaries, binary_status, &CL_err);
371
372 if (CL_err != CL_SUCCESS)
373 {
374 log_error ("ERROR: %s : %d : %s\n", "clCreateProgramWithBinary()", CL_err, val2cstr_cl (CL_err));
375
376 exit (-1);
377 }
378
379 return (program);
380 }
381
382 cl_int hc_clBuildProgram (OCL_PTR *ocl, 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, bool exitOnFail)
383 {
384 cl_int CL_err = ocl->clBuildProgram (program, num_devices, device_list, options, pfn_notify, user_data);
385
386 if (CL_err != CL_SUCCESS)
387 {
388 size_t len = strlen (options) + 1 + 15;
389
390 char *options_update = (char *) mymalloc (len + 1);
391
392 options_update = strncat (options_update, options, len - 1 - 15);
393 options_update = strncat (options_update, " -cl-opt-disable", 1 + 15);
394
395 if (data.quiet == 0) log_error ("\n=== Build failed, retry with optimization disabled ===\n");
396
397 CL_err = ocl->clBuildProgram (program, num_devices, device_list, options_update, pfn_notify, user_data);
398
399 myfree (options_update);
400
401 if (CL_err != CL_SUCCESS)
402 {
403 log_error ("ERROR: %s : %d : %s\n", "clBuildProgram()", CL_err, val2cstr_cl (CL_err));
404
405 log_error ("\n=== Build Options : %s ===\n", options);
406
407 size_t len = 0;
408
409 cl_int err = hc_clGetProgramBuildInfo (ocl, program, *device_list, CL_PROGRAM_BUILD_LOG, 0, NULL, &len);
410
411 if (err == CL_SUCCESS && len > 0)
412 {
413 char *buf = (char *) mymalloc (len + 1);
414
415 if (hc_clGetProgramBuildInfo (ocl, program, *device_list, CL_PROGRAM_BUILD_LOG, len, buf, NULL) == CL_SUCCESS)
416 {
417 fprintf (stderr, "\n=== Build Log (start) ===\n%s\n=== Build Log (end) ===\n", buf);
418 }
419
420 myfree (buf);
421 }
422
423 if (exitOnFail) exit (-1);
424
425 return (-1);
426 }
427 }
428
429 return 0;
430 }
431
432 cl_kernel hc_clCreateKernel (OCL_PTR *ocl, cl_program program, const char *kernel_name)
433 {
434 cl_int CL_err;
435
436 cl_kernel kernel = ocl->clCreateKernel (program, kernel_name, &CL_err);
437
438 if (CL_err != CL_SUCCESS)
439 {
440 log_error ("ERROR: %s %d - %s\n", "clCreateKernel()", CL_err, kernel_name);
441
442 exit (-1);
443 }
444
445 return (kernel);
446 }
447
448 void hc_clReleaseMemObject (OCL_PTR *ocl, cl_mem mem)
449 {
450 cl_int CL_err = ocl->clReleaseMemObject (mem);
451
452 if (CL_err != CL_SUCCESS)
453 {
454 log_error ("ERROR: %s : %d : %s\n", "clReleaseMemObject()", CL_err, val2cstr_cl (CL_err));
455
456 exit (-1);
457 }
458 }
459
460 void hc_clReleaseKernel (OCL_PTR *ocl, cl_kernel kernel)
461 {
462 cl_int CL_err = ocl->clReleaseKernel (kernel);
463
464 if (CL_err != CL_SUCCESS)
465 {
466 log_error ("ERROR: %s : %d : %s\n", "clReleaseProgram()", CL_err, val2cstr_cl (CL_err));
467
468 exit (-1);
469 }
470 }
471
472 void hc_clReleaseProgram (OCL_PTR *ocl, cl_program program)
473 {
474 cl_int CL_err = ocl->clReleaseProgram (program);
475
476 if (CL_err != CL_SUCCESS)
477 {
478 log_error ("ERROR: %s : %d : %s\n", "clReleaseProgram()", CL_err, val2cstr_cl (CL_err));
479
480 exit (-1);
481 }
482 }
483
484 void hc_clReleaseCommandQueue (OCL_PTR *ocl, cl_command_queue command_queue)
485 {
486 cl_int CL_err = ocl->clReleaseCommandQueue (command_queue);
487
488 if (CL_err != CL_SUCCESS)
489 {
490 log_error ("ERROR: %s : %d : %s\n", "clReleaseCommandQueue()", CL_err, val2cstr_cl (CL_err));
491
492 exit (-1);
493 }
494 }
495
496 void hc_clReleaseContext (OCL_PTR *ocl, cl_context context)
497 {
498 cl_int CL_err = ocl->clReleaseContext (context);
499
500 if (CL_err != CL_SUCCESS)
501 {
502 log_error ("ERROR: %s : %d : %s\n", "clReleaseContext()", CL_err, val2cstr_cl (CL_err));
503
504 exit (-1);
505 }
506 }
507
508 void *hc_clEnqueueMapBuffer (OCL_PTR *ocl, 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)
509 {
510 cl_int CL_err;
511
512 void *buf = ocl->clEnqueueMapBuffer (command_queue, buffer, blocking_read, map_flags, offset, cb, num_events_in_wait_list, event_wait_list, event, &CL_err);
513
514 if (CL_err != CL_SUCCESS)
515 {
516 log_error ("ERROR: %s : %d : %s\n", "clEnqueueMapBuffer()", CL_err, val2cstr_cl (CL_err));
517
518 exit (-1);
519 }
520
521 return buf;
522 }
523
524 void hc_clEnqueueUnmapMemObject (OCL_PTR *ocl, 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)
525 {
526 cl_int CL_err = ocl->clEnqueueUnmapMemObject (command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
527
528 if (CL_err != CL_SUCCESS)
529 {
530 log_error ("ERROR: %s : %d : %s\n", "clEnqueueUnmapMemObject()", CL_err, val2cstr_cl (CL_err));
531
532 exit (-1);
533 }
534 }
535
536 cl_int hc_clEnqueueFillBuffer (OCL_PTR *ocl, 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)
537 {
538 cl_int CL_err = -1;
539
540 if (ocl->clEnqueueFillBuffer)
541 {
542 CL_err = ocl->clEnqueueFillBuffer (command_queue, buffer, pattern, pattern_size, offset, size, num_events_in_wait_list, event_wait_list, event);
543
544 if (CL_err != CL_SUCCESS && data.quiet == 0)
545 log_error ("WARNING: %s : %d : %s\n", "clEnqueueFillBuffer()", CL_err, val2cstr_cl (CL_err));
546 }
547
548 return CL_err;
549 }
550
551 void hc_clGetKernelWorkGroupInfo (OCL_PTR *ocl, cl_kernel kernel, cl_device_id device, cl_kernel_work_group_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
552 {
553 cl_int CL_err = ocl->clGetKernelWorkGroupInfo (kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
554
555 if (CL_err != CL_SUCCESS)
556 {
557 log_error ("ERROR: %s : %d : %s\n", "clGetKernelWorkGroupInfo()", CL_err, val2cstr_cl (CL_err));
558
559 exit (-1);
560 }
561 }
562
563 cl_int hc_clGetProgramBuildInfo (OCL_PTR *ocl, cl_program program, cl_device_id device, cl_program_build_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
564 {
565 cl_int CL_err = ocl->clGetProgramBuildInfo (program, device, param_name, param_value_size, param_value, param_value_size_ret);
566
567 if (CL_err != CL_SUCCESS)
568 {
569 log_error ("ERROR: %s : %d : %s\n", "clGetProgramBuildInfo()", CL_err, val2cstr_cl (CL_err));
570
571 return (-1);
572 }
573
574 return CL_err;
575 }
576
577 void hc_clGetProgramInfo (OCL_PTR *ocl, cl_program program, cl_program_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
578 {
579 cl_int CL_err = ocl->clGetProgramInfo (program, param_name, param_value_size, param_value, param_value_size_ret);
580
581 if (CL_err != CL_SUCCESS)
582 {
583 log_error ("ERROR: %s : %d : %s\n", "clGetProgramInfo()", CL_err, val2cstr_cl (CL_err));
584
585 exit (-1);
586 }
587 }
588
589 void hc_clWaitForEvents (OCL_PTR *ocl, cl_uint num_events, const cl_event *event_list)
590 {
591 cl_int CL_err = ocl->clWaitForEvents (num_events, event_list);
592
593 if (CL_err != CL_SUCCESS)
594 {
595 log_error ("ERROR: %s : %d : %s\n", "clWaitForEvents()", CL_err, val2cstr_cl (CL_err));
596
597 exit (-1);
598 }
599 }
600
601 void hc_clGetEventProfilingInfo (OCL_PTR *ocl, cl_event event, cl_profiling_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
602 {
603 cl_int CL_err = ocl->clGetEventProfilingInfo (event, param_name, param_value_size, param_value, param_value_size_ret);
604
605 if (CL_err != CL_SUCCESS)
606 {
607 log_error ("ERROR: %s : %d : %s\n", "clGetEventProfilingInfo()", CL_err, val2cstr_cl (CL_err));
608
609 exit (-1);
610 }
611 }
612
613 void hc_clReleaseEvent (OCL_PTR *ocl, cl_event event)
614 {
615 cl_int CL_err = ocl->clReleaseEvent (event);
616
617 if (CL_err != CL_SUCCESS)
618 {
619 log_error ("ERROR: %s : %d : %s\n", "clReleaseEvent()", CL_err, val2cstr_cl (CL_err));
620
621 exit (-1);
622 }
623 }