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