Initial commit
[hashcat.git] / src / ext_OpenCL.c
1 /**
2 * Author......: Jens Steube <jens.steube@gmail.com>
3 * License.....: MIT
4 */
5
6 #include <ext_OpenCL.h>
7
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)
9 {
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);
11
12 if (CL_err != CL_SUCCESS)
13 {
14 log_error ("ERROR: %s %d\n", "clEnqueueNDRangeKernel()", CL_err);
15
16 exit (-1);
17 }
18 }
19
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)
21 {
22 cl_int CL_err = clGetEventInfo (event, param_name, param_value_size, param_value, param_value_size_ret);
23
24 if (CL_err != CL_SUCCESS)
25 {
26 log_error ("ERROR: %s %d\n", "clGetEventInfo()", CL_err);
27
28 exit (-1);
29 }
30 }
31
32 void hc_clFlush (cl_command_queue command_queue)
33 {
34 cl_int CL_err = clFlush (command_queue);
35
36 if (CL_err != CL_SUCCESS)
37 {
38 log_error ("ERROR: %s %d\n", "clFlush()", CL_err);
39
40 exit (-1);
41 }
42 }
43
44 void hc_clFinish (cl_command_queue command_queue)
45 {
46 cl_int CL_err = clFinish (command_queue);
47
48 if (CL_err != CL_SUCCESS)
49 {
50 log_error ("ERROR: %s %d\n", "clFinish()", CL_err);
51
52 exit (-1);
53 }
54 }
55
56 void hc_clSetKernelArg (cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value)
57 {
58 cl_int CL_err = clSetKernelArg (kernel, arg_index, arg_size, arg_value);
59
60 if (CL_err != CL_SUCCESS)
61 {
62 log_error ("ERROR: %s %d\n", "clSetKernelArg()", CL_err);
63
64 exit (-1);
65 }
66 }
67
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)
69 {
70 cl_int CL_err = clEnqueueWriteBuffer (command_queue, buffer, blocking_write, offset, cb, ptr, num_events_in_wait_list, event_wait_list, event);
71
72 if (CL_err != CL_SUCCESS)
73 {
74 log_error ("ERROR: %s %d\n", "clEnqueueWriteBuffer()", CL_err);
75
76 exit (-1);
77 }
78 }
79
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)
81 {
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);
83
84 if (CL_err != CL_SUCCESS)
85 {
86 log_error ("ERROR: %s %d\n", "clEnqueueCopyBuffer()", CL_err);
87
88 exit (-1);
89 }
90 }
91
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)
93 {
94 cl_int CL_err = clEnqueueReadBuffer (command_queue, buffer, blocking_read, offset, cb, ptr, num_events_in_wait_list, event_wait_list, event);
95
96 if (CL_err != CL_SUCCESS)
97 {
98 log_error ("ERROR: %s %d\n", "clEnqueueReadBuffer()", CL_err);
99
100 exit (-1);
101 }
102 }
103
104 void hc_clGetPlatformIDs (cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
105 {
106 cl_int CL_err = clGetPlatformIDs (num_entries, platforms, num_platforms);
107
108 if (CL_err != CL_SUCCESS)
109 {
110 log_error ("ERROR: %s %d\n", "clGetPlatformIDs()", CL_err);
111
112 exit (-1);
113 }
114 }
115
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)
117 {
118 cl_int CL_err = clGetPlatformInfo (platform, param_name, param_value_size, param_value, param_value_size_ret);
119
120 if (CL_err != CL_SUCCESS)
121 {
122 log_error ("ERROR: %s %d\n", "clGetPlatformInfo()", CL_err);
123
124 exit (-1);
125 }
126 }
127
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)
129 {
130 cl_int CL_err = clGetDeviceIDs (platform, device_type, num_entries, devices, num_devices);
131
132 if (CL_err != CL_SUCCESS)
133 {
134 log_error ("ERROR: %s %d\n", "clGetDeviceIDs()", CL_err);
135
136 exit (-1);
137 }
138 }
139
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)
141 {
142 cl_int CL_err = clGetDeviceInfo (device, param_name, param_value_size, param_value, param_value_size_ret);
143
144 if (CL_err != CL_SUCCESS)
145 {
146 log_error ("ERROR: %s %d\n", "clGetDeviceInfo()", CL_err);
147
148 exit (-1);
149 }
150 }
151
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)
153 {
154 cl_int CL_err;
155
156 cl_context context = clCreateContext (properties, num_devices, devices, pfn_notify, user_data, &CL_err);
157
158 if (CL_err != CL_SUCCESS)
159 {
160 log_error ("ERROR: %s %d\n", "clCreateContext()", CL_err);
161
162 exit (-1);
163 }
164
165 return (context);
166 }
167
168 /*
169 cl_command_queue hc_clCreateCommandQueue (cl_context context, cl_device_id device, cl_command_queue_properties properties)
170 {
171 cl_int CL_err;
172
173 cl_command_queue command_queue = clCreateCommandQueue (context, device, properties, &CL_err);
174
175 if (CL_err != CL_SUCCESS)
176 {
177 log_error ("ERROR: %s %d\n", "clCreateCommandQueue()", CL_err);
178
179 exit (-1);
180 }
181
182 return (command_queue);
183 }
184 */
185
186 cl_command_queue hc_clCreateCommandQueueWithProperties (cl_context context, cl_device_id device, const cl_queue_properties *properties)
187 {
188 cl_int CL_err;
189
190 cl_command_queue command_queue = clCreateCommandQueueWithProperties (context, device, properties, &CL_err);
191
192 if (CL_err != CL_SUCCESS)
193 {
194 log_error ("ERROR: %s %d\n", "clCreateCommandQueueWithProperties()", CL_err);
195
196 exit (-1);
197 }
198
199 return (command_queue);
200 }
201
202 cl_mem hc_clCreateBuffer (cl_context context, cl_mem_flags flags, size_t size, void *host_ptr)
203 {
204 cl_int CL_err;
205
206 cl_mem mem = clCreateBuffer (context, flags, size, host_ptr, &CL_err);
207
208 if (CL_err != CL_SUCCESS)
209 {
210 log_error ("ERROR: %s %d\n", "clCreateBuffer()", CL_err);
211
212 exit (-1);
213 }
214
215 return (mem);
216 }
217
218 cl_program hc_clCreateProgramWithSource (cl_context context, cl_uint count, const char **strings, const size_t *lengths)
219 {
220 cl_int CL_err;
221
222 cl_program program = clCreateProgramWithSource (context, count, strings, lengths, &CL_err);
223
224 if (CL_err != CL_SUCCESS)
225 {
226 log_error ("ERROR: %s %d\n", "clCreateProgramWithSource()", CL_err);
227
228 exit (-1);
229 }
230
231 return (program);
232 }
233
234 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)
235 {
236 cl_int CL_err;
237
238 cl_program program = clCreateProgramWithBinary (context, num_devices, device_list, lengths, binaries, binary_status, &CL_err);
239
240 if (CL_err != CL_SUCCESS)
241 {
242 log_error ("ERROR: %s %d\n", "clCreateProgramWithBinary()", CL_err);
243
244 exit (-1);
245 }
246
247 return (program);
248 }
249
250 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)
251 {
252 cl_int CL_err = clBuildProgram (program, num_devices, device_list, options, pfn_notify, user_data);
253
254 if (CL_err != CL_SUCCESS)
255 {
256 log_error ("ERROR: %s %d\n", "clBuildProgram()", CL_err);
257
258 exit (-1);
259 }
260 }
261
262 cl_kernel hc_clCreateKernel (cl_program program, const char *kernel_name)
263 {
264 cl_int CL_err;
265
266 cl_kernel kernel = clCreateKernel (program, kernel_name, &CL_err);
267
268 if (CL_err != CL_SUCCESS)
269 {
270 log_error ("ERROR: %s %d\n", "clCreateKernel()", CL_err);
271
272 exit (-1);
273 }
274
275 return (kernel);
276 }
277
278 void hc_clReleaseMemObject (cl_mem mem)
279 {
280 cl_int CL_err = clReleaseMemObject (mem);
281
282 if (CL_err != CL_SUCCESS)
283 {
284 log_error ("ERROR: %s %d\n", "clReleaseMemObject()", CL_err);
285
286 exit (-1);
287 }
288 }
289
290 void hc_clReleaseKernel (cl_kernel kernel)
291 {
292 cl_int CL_err = clReleaseKernel (kernel);
293
294 if (CL_err != CL_SUCCESS)
295 {
296 log_error ("ERROR: %s %d\n", "clReleaseProgram()", CL_err);
297
298 exit (-1);
299 }
300 }
301
302 void hc_clReleaseProgram (cl_program program)
303 {
304 cl_int CL_err = clReleaseProgram (program);
305
306 if (CL_err != CL_SUCCESS)
307 {
308 log_error ("ERROR: %s %d\n", "clReleaseProgram()", CL_err);
309
310 exit (-1);
311 }
312 }
313
314 void hc_clReleaseCommandQueue (cl_command_queue command_queue)
315 {
316 cl_int CL_err = clReleaseCommandQueue (command_queue);
317
318 if (CL_err != CL_SUCCESS)
319 {
320 log_error ("ERROR: %s %d\n", "clReleaseCommandQueue()", CL_err);
321
322 exit (-1);
323 }
324 }
325
326 void hc_clReleaseContext (cl_context context)
327 {
328 cl_int CL_err = clReleaseContext (context);
329
330 if (CL_err != CL_SUCCESS)
331 {
332 log_error ("ERROR: %s %d\n", "clReleaseContext()", CL_err);
333
334 exit (-1);
335 }
336 }
337
338 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)
339 {
340 cl_int CL_err;
341
342 void *buf = clEnqueueMapBuffer (command_queue, buffer, blocking_read, map_flags, offset, cb, num_events_in_wait_list, event_wait_list, event, &CL_err);
343
344 if (CL_err != CL_SUCCESS)
345 {
346 log_error ("ERROR: %s %d\n", "clEnqueueMapBuffer()", CL_err);
347
348 exit (-1);
349 }
350
351 return buf;
352 }
353
354 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)
355 {
356 cl_int CL_err = clEnqueueUnmapMemObject (command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
357
358 if (CL_err != CL_SUCCESS)
359 {
360 log_error ("ERROR: %s %d\n", "clEnqueueUnmapMemObject()", CL_err);
361
362 exit (-1);
363 }
364 }
365
366 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)
367 {
368 cl_int CL_err = clEnqueueFillBuffer (command_queue, buffer, pattern, pattern_size, offset, size, num_events_in_wait_list, event_wait_list, event);
369
370 if (CL_err != CL_SUCCESS)
371 {
372 log_error ("ERROR: %s %d\n", "clEnqueueFillBuffer()", CL_err);
373
374 exit (-1);
375 }
376 }