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