- Dropped all vector code since new GPU's are all scalar, makes the code much easier
[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
203 cl_mem hc_clCreateBuffer (cl_context context, cl_mem_flags flags, size_t size, void *host_ptr)
204 {
205 cl_int CL_err;
206
207 cl_mem mem = clCreateBuffer (context, flags, size, host_ptr, &CL_err);
208
209 if (CL_err != CL_SUCCESS)
210 {
211 log_error ("ERROR: %s %d\n", "clCreateBuffer()", CL_err);
212
213 exit (-1);
214 }
215
216 return (mem);
217 }
218
219 cl_program hc_clCreateProgramWithSource (cl_context context, cl_uint count, const char **strings, const size_t *lengths)
220 {
221 cl_int CL_err;
222
223 cl_program program = clCreateProgramWithSource (context, count, strings, lengths, &CL_err);
224
225 if (CL_err != CL_SUCCESS)
226 {
227 log_error ("ERROR: %s %d\n", "clCreateProgramWithSource()", CL_err);
228
229 exit (-1);
230 }
231
232 return (program);
233 }
234
235 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)
236 {
237 cl_int CL_err;
238
239 cl_program program = clCreateProgramWithBinary (context, num_devices, device_list, lengths, binaries, binary_status, &CL_err);
240
241 if (CL_err != CL_SUCCESS)
242 {
243 log_error ("ERROR: %s %d\n", "clCreateProgramWithBinary()", CL_err);
244
245 exit (-1);
246 }
247
248 return (program);
249 }
250
251 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)
252 {
253 cl_int CL_err = clBuildProgram (program, num_devices, device_list, options, pfn_notify, user_data);
254
255 if (CL_err != CL_SUCCESS)
256 {
257 log_error ("ERROR: %s %d\n", "clBuildProgram()", CL_err);
258
259 exit (-1);
260 }
261 }
262
263 cl_kernel hc_clCreateKernel (cl_program program, const char *kernel_name)
264 {
265 cl_int CL_err;
266
267 cl_kernel kernel = clCreateKernel (program, kernel_name, &CL_err);
268
269 if (CL_err != CL_SUCCESS)
270 {
271 log_error ("ERROR: %s %d\n", "clCreateKernel()", CL_err);
272
273 exit (-1);
274 }
275
276 return (kernel);
277 }
278
279 void hc_clReleaseMemObject (cl_mem mem)
280 {
281 cl_int CL_err = clReleaseMemObject (mem);
282
283 if (CL_err != CL_SUCCESS)
284 {
285 log_error ("ERROR: %s %d\n", "clReleaseMemObject()", CL_err);
286
287 exit (-1);
288 }
289 }
290
291 void hc_clReleaseKernel (cl_kernel kernel)
292 {
293 cl_int CL_err = clReleaseKernel (kernel);
294
295 if (CL_err != CL_SUCCESS)
296 {
297 log_error ("ERROR: %s %d\n", "clReleaseProgram()", CL_err);
298
299 exit (-1);
300 }
301 }
302
303 void hc_clReleaseProgram (cl_program program)
304 {
305 cl_int CL_err = clReleaseProgram (program);
306
307 if (CL_err != CL_SUCCESS)
308 {
309 log_error ("ERROR: %s %d\n", "clReleaseProgram()", CL_err);
310
311 exit (-1);
312 }
313 }
314
315 void hc_clReleaseCommandQueue (cl_command_queue command_queue)
316 {
317 cl_int CL_err = clReleaseCommandQueue (command_queue);
318
319 if (CL_err != CL_SUCCESS)
320 {
321 log_error ("ERROR: %s %d\n", "clReleaseCommandQueue()", CL_err);
322
323 exit (-1);
324 }
325 }
326
327 void hc_clReleaseContext (cl_context context)
328 {
329 cl_int CL_err = clReleaseContext (context);
330
331 if (CL_err != CL_SUCCESS)
332 {
333 log_error ("ERROR: %s %d\n", "clReleaseContext()", CL_err);
334
335 exit (-1);
336 }
337 }
338
339 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)
340 {
341 cl_int CL_err;
342
343 void *buf = clEnqueueMapBuffer (command_queue, buffer, blocking_read, map_flags, offset, cb, num_events_in_wait_list, event_wait_list, event, &CL_err);
344
345 if (CL_err != CL_SUCCESS)
346 {
347 log_error ("ERROR: %s %d\n", "clEnqueueMapBuffer()", CL_err);
348
349 exit (-1);
350 }
351
352 return buf;
353 }
354
355 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)
356 {
357 cl_int CL_err = clEnqueueUnmapMemObject (command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
358
359 if (CL_err != CL_SUCCESS)
360 {
361 log_error ("ERROR: %s %d\n", "clEnqueueUnmapMemObject()", CL_err);
362
363 exit (-1);
364 }
365 }
366
367 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)
368 {
369 cl_int CL_err = clEnqueueFillBuffer (command_queue, buffer, pattern, pattern_size, offset, size, num_events_in_wait_list, event_wait_list, event);
370
371 if (CL_err != CL_SUCCESS)
372 {
373 log_error ("ERROR: %s %d\n", "clEnqueueFillBuffer()", CL_err);
374
375 exit (-1);
376 }
377 }