Added the execution time of the running kernel to the status display
[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
118 return 0;
119 }
120
121 void ocl_close (OCL_PTR *ocl)
122 {
123 if (ocl)
124 {
125 if (ocl->lib)
126 hc_dlclose (ocl->lib);
127
128 free (ocl);
129 }
130 }
131
132 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)
133 {
134 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);
135
136 if (CL_err != CL_SUCCESS)
137 {
138 if (exitOnFail)
139 {
140 log_error ("ERROR: %s : %d : %s\n", "clEnqueueNDRangeKernel()", CL_err, val2cstr_cl (CL_err));
141
142 exit (-1);
143 }
144
145 return (-1);
146 }
147
148 return 0;
149 }
150
151 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)
152 {
153 cl_int CL_err = ocl->clGetEventInfo (event, param_name, param_value_size, param_value, param_value_size_ret);
154
155 if (CL_err != CL_SUCCESS)
156 {
157 log_error ("ERROR: %s : %d : %s\n", "clGetEventInfo()", CL_err, val2cstr_cl (CL_err));
158
159 exit (-1);
160 }
161 }
162
163 void hc_clFlush (OCL_PTR *ocl, cl_command_queue command_queue)
164 {
165 cl_int CL_err = ocl->clFlush (command_queue);
166
167 if (CL_err != CL_SUCCESS)
168 {
169 log_error ("ERROR: %s : %d : %s\n", "clFlush()", CL_err, val2cstr_cl (CL_err));
170
171 exit (-1);
172 }
173 }
174
175 void hc_clFinish (OCL_PTR *ocl, cl_command_queue command_queue)
176 {
177 cl_int CL_err = ocl->clFinish (command_queue);
178
179 if (CL_err != CL_SUCCESS)
180 {
181 log_error ("ERROR: %s : %d : %s\n", "clFinish()", CL_err, val2cstr_cl (CL_err));
182
183 exit (-1);
184 }
185 }
186
187 void hc_clSetKernelArg (OCL_PTR *ocl, cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value)
188 {
189 cl_int CL_err = ocl->clSetKernelArg (kernel, arg_index, arg_size, arg_value);
190
191 if (CL_err != CL_SUCCESS)
192 {
193 log_error ("ERROR: %s : %d : %s\n", "clSetKernelArg()", CL_err, val2cstr_cl (CL_err));
194
195 exit (-1);
196 }
197 }
198
199 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)
200 {
201 cl_int CL_err = ocl->clEnqueueWriteBuffer (command_queue, buffer, blocking_write, offset, cb, ptr, num_events_in_wait_list, event_wait_list, event);
202
203 if (CL_err != CL_SUCCESS)
204 {
205 log_error ("ERROR: %s : %d : %s\n", "clEnqueueWriteBuffer()", CL_err, val2cstr_cl (CL_err));
206
207 exit (-1);
208 }
209 }
210
211 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)
212 {
213 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);
214
215 if (CL_err != CL_SUCCESS)
216 {
217 log_error ("ERROR: %s : %d : %s\n", "clEnqueueCopyBuffer()", CL_err, val2cstr_cl (CL_err));
218
219 exit (-1);
220 }
221 }
222
223 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)
224 {
225 cl_int CL_err = ocl->clEnqueueReadBuffer (command_queue, buffer, blocking_read, offset, cb, ptr, num_events_in_wait_list, event_wait_list, event);
226
227 if (CL_err != CL_SUCCESS)
228 {
229 log_error ("ERROR: %s : %d : %s\n", "clEnqueueReadBuffer()", CL_err, val2cstr_cl (CL_err));
230
231 exit (-1);
232 }
233 }
234
235 void hc_clGetPlatformIDs (OCL_PTR *ocl, cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
236 {
237 cl_int CL_err = ocl->clGetPlatformIDs (num_entries, platforms, num_platforms);
238
239 if (CL_err != CL_SUCCESS)
240 {
241 log_error ("ERROR: %s : %d : %s\n", "clGetPlatformIDs()", CL_err, val2cstr_cl (CL_err));
242
243 exit (-1);
244 }
245 }
246
247 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)
248 {
249 cl_int CL_err = ocl->clGetPlatformInfo (platform, param_name, param_value_size, param_value, param_value_size_ret);
250
251 if (CL_err != CL_SUCCESS)
252 {
253 log_error ("ERROR: %s : %d : %s\n", "clGetPlatformInfo()", CL_err, val2cstr_cl (CL_err));
254
255 exit (-1);
256 }
257 }
258
259 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)
260 {
261 cl_int CL_err = ocl->clGetDeviceIDs (platform, device_type, num_entries, devices, num_devices);
262
263 if (CL_err != CL_SUCCESS)
264 {
265 log_error ("ERROR: %s : %d : %s\n", "clGetDeviceIDs()", CL_err, val2cstr_cl (CL_err));
266
267 exit (-1);
268 }
269 }
270
271 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)
272 {
273 cl_int CL_err = ocl->clGetDeviceInfo (device, param_name, param_value_size, param_value, param_value_size_ret);
274
275 if (CL_err != CL_SUCCESS)
276 {
277 log_error ("ERROR: %s : %d : %s\n", "clGetDeviceInfo()", CL_err, val2cstr_cl (CL_err));
278
279 exit (-1);
280 }
281 }
282
283 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)
284 {
285 cl_int CL_err;
286
287 cl_context context = ocl->clCreateContext (properties, num_devices, devices, pfn_notify, user_data, &CL_err);
288
289 if (CL_err != CL_SUCCESS)
290 {
291 log_error ("ERROR: %s : %d : %s\n", "clCreateContext()", CL_err, val2cstr_cl (CL_err));
292
293 exit (-1);
294 }
295
296 return (context);
297 }
298
299 cl_command_queue hc_clCreateCommandQueue (OCL_PTR *ocl, cl_context context, cl_device_id device, cl_command_queue_properties properties)
300 {
301 cl_int CL_err;
302
303 cl_command_queue command_queue = ocl->clCreateCommandQueue (context, device, properties, &CL_err);
304
305 if (CL_err != CL_SUCCESS)
306 {
307 log_error ("ERROR: %s : %d : %s\n", "clCreateCommandQueue()", CL_err, val2cstr_cl (CL_err));
308
309 exit (-1);
310 }
311
312 return (command_queue);
313 }
314
315 /*
316 cl_command_queue hc_clCreateCommandQueueWithProperties (cl_context context, cl_device_id device, const cl_queue_properties *properties)
317 {
318 cl_int CL_err;
319
320 cl_command_queue command_queue = clCreateCommandQueueWithProperties (context, device, properties, &CL_err);
321
322 if (CL_err != CL_SUCCESS)
323 {
324 log_error ("ERROR: %s : %d : %s\n", "clCreateCommandQueueWithProperties()", CL_err, val2cstr_cl (CL_err));
325
326 exit (-1);
327 }
328
329 return (command_queue);
330 }
331 */
332
333 cl_mem hc_clCreateBuffer (OCL_PTR *ocl, cl_context context, cl_mem_flags flags, size_t size, void *host_ptr)
334 {
335 cl_int CL_err;
336
337 cl_mem mem = ocl->clCreateBuffer (context, flags, size, host_ptr, &CL_err);
338
339 if (CL_err != CL_SUCCESS)
340 {
341 log_error ("ERROR: %s : %d : %s\n", "clCreateBuffer()", CL_err, val2cstr_cl (CL_err));
342
343 exit (-1);
344 }
345
346 return (mem);
347 }
348
349 cl_program hc_clCreateProgramWithSource (OCL_PTR *ocl, cl_context context, cl_uint count, const char **strings, const size_t *lengths)
350 {
351 cl_int CL_err;
352
353 cl_program program = ocl->clCreateProgramWithSource (context, count, strings, lengths, &CL_err);
354
355 if (CL_err != CL_SUCCESS)
356 {
357 log_error ("ERROR: %s : %d : %s\n", "clCreateProgramWithSource()", CL_err, val2cstr_cl (CL_err));
358
359 exit (-1);
360 }
361
362 return (program);
363 }
364
365 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)
366 {
367 cl_int CL_err;
368
369 cl_program program = ocl->clCreateProgramWithBinary (context, num_devices, device_list, lengths, binaries, binary_status, &CL_err);
370
371 if (CL_err != CL_SUCCESS)
372 {
373 log_error ("ERROR: %s : %d : %s\n", "clCreateProgramWithBinary()", CL_err, val2cstr_cl (CL_err));
374
375 exit (-1);
376 }
377
378 return (program);
379 }
380
381 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)
382 {
383 cl_int CL_err = ocl->clBuildProgram (program, num_devices, device_list, options, pfn_notify, user_data);
384
385 if (CL_err != CL_SUCCESS)
386 {
387 size_t len = strlen (options) + 1 + 15;
388
389 char *options_update = (char *) mymalloc (len + 1);
390
391 options_update = strncat (options_update, options, len - 1 - 15);
392 options_update = strncat (options_update, " -cl-opt-disable", 1 + 15);
393
394 if (data.quiet == 0) log_error ("\n=== Build failed, retry with optimization disabled ===\n");
395
396 CL_err = ocl->clBuildProgram (program, num_devices, device_list, options_update, pfn_notify, user_data);
397
398 myfree (options_update);
399
400 if (CL_err != CL_SUCCESS)
401 {
402 log_error ("ERROR: %s : %d : %s\n", "clBuildProgram()", CL_err, val2cstr_cl (CL_err));
403
404 log_error ("\n=== Build Options : %s ===\n", options);
405
406 size_t len = 0;
407
408 cl_int err = hc_clGetProgramBuildInfo (ocl, program, *device_list, CL_PROGRAM_BUILD_LOG, 0, NULL, &len);
409
410 if (err == CL_SUCCESS && len > 0)
411 {
412 char *buf = (char *) mymalloc (len + 1);
413
414 if (hc_clGetProgramBuildInfo (ocl, program, *device_list, CL_PROGRAM_BUILD_LOG, len, buf, NULL) == CL_SUCCESS)
415 {
416 fprintf (stderr, "\n=== Build Log (start) ===\n%s\n=== Build Log (end) ===\n", buf);
417 }
418
419 myfree (buf);
420 }
421
422 if (exitOnFail) exit (-1);
423
424 return (-1);
425 }
426 }
427
428 return 0;
429 }
430
431 cl_kernel hc_clCreateKernel (OCL_PTR *ocl, cl_program program, const char *kernel_name)
432 {
433 cl_int CL_err;
434
435 cl_kernel kernel = ocl->clCreateKernel (program, kernel_name, &CL_err);
436
437 if (CL_err != CL_SUCCESS)
438 {
439 log_error ("ERROR: %s %d - %s\n", "clCreateKernel()", CL_err, kernel_name);
440
441 exit (-1);
442 }
443
444 return (kernel);
445 }
446
447 void hc_clReleaseMemObject (OCL_PTR *ocl, cl_mem mem)
448 {
449 cl_int CL_err = ocl->clReleaseMemObject (mem);
450
451 if (CL_err != CL_SUCCESS)
452 {
453 log_error ("ERROR: %s : %d : %s\n", "clReleaseMemObject()", CL_err, val2cstr_cl (CL_err));
454
455 exit (-1);
456 }
457 }
458
459 void hc_clReleaseKernel (OCL_PTR *ocl, cl_kernel kernel)
460 {
461 cl_int CL_err = ocl->clReleaseKernel (kernel);
462
463 if (CL_err != CL_SUCCESS)
464 {
465 log_error ("ERROR: %s : %d : %s\n", "clReleaseProgram()", CL_err, val2cstr_cl (CL_err));
466
467 exit (-1);
468 }
469 }
470
471 void hc_clReleaseProgram (OCL_PTR *ocl, cl_program program)
472 {
473 cl_int CL_err = ocl->clReleaseProgram (program);
474
475 if (CL_err != CL_SUCCESS)
476 {
477 log_error ("ERROR: %s : %d : %s\n", "clReleaseProgram()", CL_err, val2cstr_cl (CL_err));
478
479 exit (-1);
480 }
481 }
482
483 void hc_clReleaseCommandQueue (OCL_PTR *ocl, cl_command_queue command_queue)
484 {
485 cl_int CL_err = ocl->clReleaseCommandQueue (command_queue);
486
487 if (CL_err != CL_SUCCESS)
488 {
489 log_error ("ERROR: %s : %d : %s\n", "clReleaseCommandQueue()", CL_err, val2cstr_cl (CL_err));
490
491 exit (-1);
492 }
493 }
494
495 void hc_clReleaseContext (OCL_PTR *ocl, cl_context context)
496 {
497 cl_int CL_err = ocl->clReleaseContext (context);
498
499 if (CL_err != CL_SUCCESS)
500 {
501 log_error ("ERROR: %s : %d : %s\n", "clReleaseContext()", CL_err, val2cstr_cl (CL_err));
502
503 exit (-1);
504 }
505 }
506
507 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)
508 {
509 cl_int CL_err;
510
511 void *buf = ocl->clEnqueueMapBuffer (command_queue, buffer, blocking_read, map_flags, offset, cb, num_events_in_wait_list, event_wait_list, event, &CL_err);
512
513 if (CL_err != CL_SUCCESS)
514 {
515 log_error ("ERROR: %s : %d : %s\n", "clEnqueueMapBuffer()", CL_err, val2cstr_cl (CL_err));
516
517 exit (-1);
518 }
519
520 return buf;
521 }
522
523 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)
524 {
525 cl_int CL_err = ocl->clEnqueueUnmapMemObject (command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
526
527 if (CL_err != CL_SUCCESS)
528 {
529 log_error ("ERROR: %s : %d : %s\n", "clEnqueueUnmapMemObject()", CL_err, val2cstr_cl (CL_err));
530
531 exit (-1);
532 }
533 }
534
535 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)
536 {
537 cl_int CL_err = -1;
538
539 if (ocl->clEnqueueFillBuffer)
540 {
541 CL_err = ocl->clEnqueueFillBuffer (command_queue, buffer, pattern, pattern_size, offset, size, num_events_in_wait_list, event_wait_list, event);
542
543 if (CL_err != CL_SUCCESS && data.quiet == 0)
544 log_error ("WARNING: %s : %d : %s\n", "clEnqueueFillBuffer()", CL_err, val2cstr_cl (CL_err));
545 }
546
547 return CL_err;
548 }
549
550 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)
551 {
552 cl_int CL_err = ocl->clGetKernelWorkGroupInfo (kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
553
554 if (CL_err != CL_SUCCESS)
555 {
556 log_error ("ERROR: %s : %d : %s\n", "clGetKernelWorkGroupInfo()", CL_err, val2cstr_cl (CL_err));
557
558 exit (-1);
559 }
560 }
561
562 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)
563 {
564 cl_int CL_err = ocl->clGetProgramBuildInfo (program, device, param_name, param_value_size, param_value, param_value_size_ret);
565
566 if (CL_err != CL_SUCCESS)
567 {
568 log_error ("ERROR: %s : %d : %s\n", "clGetProgramBuildInfo()", CL_err, val2cstr_cl (CL_err));
569
570 return (-1);
571 }
572
573 return CL_err;
574 }
575
576 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)
577 {
578 cl_int CL_err = ocl->clGetProgramInfo (program, param_name, param_value_size, param_value, param_value_size_ret);
579
580 if (CL_err != CL_SUCCESS)
581 {
582 log_error ("ERROR: %s : %d : %s\n", "clGetProgramInfo()", CL_err, val2cstr_cl (CL_err));
583
584 exit (-1);
585 }
586 }
587
588 void hc_clWaitForEvents (OCL_PTR *ocl, cl_uint num_events, const cl_event *event_list)
589 {
590 cl_int CL_err = ocl->clWaitForEvents (num_events, event_list);
591
592 if (CL_err != CL_SUCCESS)
593 {
594 log_error ("ERROR: %s : %d : %s\n", "clWaitForEvents()", CL_err, val2cstr_cl (CL_err));
595
596 exit (-1);
597 }
598 }
599
600 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)
601 {
602 cl_int CL_err = ocl->clGetEventProfilingInfo (event, param_name, param_value_size, param_value, param_value_size_ret);
603
604 if (CL_err != CL_SUCCESS)
605 {
606 log_error ("ERROR: %s : %d : %s\n", "clGetEventProfilingInfo()", CL_err, val2cstr_cl (CL_err));
607
608 exit (-1);
609 }
610 }