Merge pull request #156 from gm4tr1x/master
[hashcat.git] / include / ext_OpenCL.h
1 /**
2 * Authors.....: Jens Steube <jens.steube@gmail.com>
3 * Gabriele Gristina <matrix@hashcat.net>
4 *
5 * License.....: MIT
6 */
7
8 #ifndef EXT_OPENCL_H
9 #define EXT_OPENCL_H
10
11 #include <common.h>
12
13 #define CL_USE_DEPRECATED_OPENCL_1_2_APIS
14 #define CL_USE_DEPRECATED_OPENCL_2_0_APIS
15
16 #ifdef OSX
17 #include <OpenCL/cl.h>
18 #endif
19
20 #ifdef WIN
21 #include <CL/cl.h>
22 // #include <CL/cl_ext.h> // used for CL_DEVICE_TOPOLOGY_AMD but broken for dual GPU
23 #endif
24
25 #ifdef LINUX
26 #include <CL/cl.h>
27 // #include <CL/cl_ext.h> // used for CL_DEVICE_TOPOLOGY_AMD but broken for dual GPU
28 #endif
29
30 #include <shared.h>
31
32 typedef cl_mem (*OCL_CLCREATEBUFFER) (cl_context, cl_mem_flags, size_t, void *, cl_int *);
33 typedef cl_command_queue (*OCL_CLCREATECOMMANDQUEUE) (cl_context, cl_device_id, cl_command_queue_properties, cl_int *);
34 typedef cl_context (*OCL_CLCREATECONTEXT) (const cl_context_properties *, cl_uint, const cl_device_id *, void (CL_CALLBACK *)(const char *, const void *, size_t, void *), void *, cl_int *);
35 typedef cl_kernel (*OCL_CLCREATEKERNEL) (cl_program, const char *, cl_int *);
36 typedef cl_program (*OCL_CLCREATEPROGRAMWITHSOURCE) (cl_context, cl_uint, const char **, const size_t *, cl_int *);
37 typedef cl_program (*OCL_CLCREATEPROGRAMWITHBINARY) (cl_context, cl_uint, const cl_device_id *, const size_t *, const unsigned char **, cl_int *, cl_int *);
38 typedef cl_int (*OCL_CLBUILDPROGRAM) (cl_program, cl_uint, const cl_device_id *, const char *, void (CL_CALLBACK *)(cl_program, void *), void *);
39 typedef cl_int (*OCL_CLENQUEUENDRANGEKERNEL) (cl_command_queue, cl_kernel, cl_uint, const size_t *, const size_t *, const size_t *, cl_uint, const cl_event *, cl_event *);
40 typedef cl_int (*OCL_CLENQUEUEREADBUFFER) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, const void *, cl_uint, const cl_event *, cl_event *);
41 typedef cl_int (*OCL_CLENQUEUEWRITEBUFFER) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, const void *, cl_uint, const cl_event *, cl_event *);
42 typedef cl_int (*OCL_CLENQUEUECOPYBUFFER) (cl_command_queue, cl_mem, cl_mem, size_t, size_t, size_t, cl_uint, const cl_event *, cl_event *);
43 typedef cl_int (*OCL_CLFLUSH) (cl_command_queue);
44 typedef cl_int (*OCL_CLFINISH) (cl_command_queue);
45 typedef cl_int (*OCL_CLGETDEVICEIDS) (cl_platform_id, cl_device_type, cl_uint, cl_device_id *, cl_uint *);
46 typedef cl_int (*OCL_CLGETDEVICEINFO) (cl_device_id, cl_device_info, size_t, void *, size_t *);
47 typedef cl_int (*OCL_CLGETPLATFORMIDS) (cl_uint, cl_platform_id *, cl_uint *);
48 typedef cl_int (*OCL_CLGETPLATFORMINFO) (cl_platform_id, cl_platform_info, size_t, void *, size_t *);
49 typedef cl_int (*OCL_CLRELEASECOMMANDQUEUE) (cl_command_queue);
50 typedef cl_int (*OCL_CLRELEASECONTEXT) (cl_context);
51 typedef cl_int (*OCL_CLRELEASEKERNEL) (cl_kernel);
52 typedef cl_int (*OCL_CLRELEASEMEMOBJECT) (cl_mem);
53 typedef cl_int (*OCL_CLRELEASEPROGRAM) (cl_program);
54 typedef cl_int (*OCL_CLSETKERNELARG) (cl_kernel, cl_uint, size_t, const void *);
55 typedef void * (*OCL_CLENQUEUEMAPBUFFER) (cl_command_queue, cl_mem, cl_bool, cl_map_flags, size_t, size_t, cl_uint, const cl_event *, cl_event *, cl_int *);
56 typedef cl_int (*OCL_CLENQUEUEUNMAPMEMOBJECT) (cl_command_queue, cl_mem, void *, cl_uint, const cl_event *, cl_event *);
57 typedef cl_int (*OCL_CLENQUEUEFILLBUFFER) (cl_command_queue, cl_mem, const void *, size_t, size_t, size_t, cl_uint, const cl_event *, cl_event *);
58 typedef cl_int (*OCL_CLGETKERNELWORKGROUPINFO) (cl_kernel, cl_device_id, cl_kernel_work_group_info, size_t, void *, size_t *);
59 typedef cl_int (*OCL_CLGETPROGRAMBUILDINFO) (cl_program, cl_device_id, cl_program_build_info, size_t, void *, size_t *);
60 typedef cl_int (*OCL_CLGETPROGRAMINFO) (cl_program, cl_program_info, size_t, void *, size_t *);
61 typedef cl_int (*OCL_CLGETEVENTINFO) (cl_event, cl_event_info, size_t, void *, size_t *);
62
63 typedef struct
64 {
65 OCL_LIB lib;
66
67 OCL_CLBUILDPROGRAM clBuildProgram;
68 OCL_CLCREATEBUFFER clCreateBuffer;
69 OCL_CLCREATECOMMANDQUEUE clCreateCommandQueue;
70 OCL_CLCREATECONTEXT clCreateContext;
71 OCL_CLCREATEKERNEL clCreateKernel;
72 OCL_CLCREATEPROGRAMWITHBINARY clCreateProgramWithBinary;
73 OCL_CLCREATEPROGRAMWITHSOURCE clCreateProgramWithSource;
74 OCL_CLENQUEUECOPYBUFFER clEnqueueCopyBuffer;
75 OCL_CLENQUEUEFILLBUFFER clEnqueueFillBuffer;
76 OCL_CLENQUEUEMAPBUFFER clEnqueueMapBuffer;
77 OCL_CLENQUEUENDRANGEKERNEL clEnqueueNDRangeKernel;
78 OCL_CLENQUEUEREADBUFFER clEnqueueReadBuffer;
79 OCL_CLENQUEUEUNMAPMEMOBJECT clEnqueueUnmapMemObject;
80 OCL_CLENQUEUEWRITEBUFFER clEnqueueWriteBuffer;
81 OCL_CLFINISH clFinish;
82 OCL_CLFLUSH clFlush;
83 OCL_CLGETDEVICEIDS clGetDeviceIDs;
84 OCL_CLGETDEVICEINFO clGetDeviceInfo;
85 OCL_CLGETEVENTINFO clGetEventInfo;
86 OCL_CLGETKERNELWORKGROUPINFO clGetKernelWorkGroupInfo;
87 OCL_CLGETPLATFORMIDS clGetPlatformIDs;
88 OCL_CLGETPLATFORMINFO clGetPlatformInfo;
89 OCL_CLGETPROGRAMBUILDINFO clGetProgramBuildInfo;
90 OCL_CLGETPROGRAMINFO clGetProgramInfo;
91 OCL_CLRELEASECOMMANDQUEUE clReleaseCommandQueue;
92 OCL_CLRELEASECONTEXT clReleaseContext;
93 OCL_CLRELEASEKERNEL clReleaseKernel;
94 OCL_CLRELEASEMEMOBJECT clReleaseMemObject;
95 OCL_CLRELEASEPROGRAM clReleaseProgram;
96 OCL_CLSETKERNELARG clSetKernelArg;
97
98 } hc_opencl_lib_t;
99
100 #define OCL_PTR hc_opencl_lib_t
101
102 void ocl_init (OCL_PTR *ocl);
103 void ocl_close (OCL_PTR *ocl);
104
105 cl_mem hc_clCreateBuffer (OCL_PTR *ocl, cl_context context, cl_mem_flags flags, size_t size, void *host_ptr);
106 cl_command_queue hc_clCreateCommandQueue (OCL_PTR *ocl, cl_context context, cl_device_id device, cl_command_queue_properties properties);
107 //cl_command_queue hc_clCreateCommandQueueWithProperties (cl_context context, cl_device_id device, const cl_queue_properties *properties);
108 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);
109 cl_kernel hc_clCreateKernel (OCL_PTR *ocl, cl_program program, const char *kernel_name);
110 cl_program hc_clCreateProgramWithSource (OCL_PTR *ocl, cl_context context, cl_uint count, const char **strings, const size_t *lengths);
111 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);
112 void 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);
113 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);
114 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);
115 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);
116 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);
117 void hc_clFlush (OCL_PTR *ocl, cl_command_queue command_queue);
118 void hc_clFinish (OCL_PTR *ocl, cl_command_queue command_queue);
119 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);
120 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);
121 void hc_clGetPlatformIDs (OCL_PTR *ocl, cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms);
122 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);
123 void hc_clReleaseCommandQueue (OCL_PTR *ocl, cl_command_queue command_queue);
124 void hc_clReleaseContext (OCL_PTR *ocl, cl_context context);
125 void hc_clReleaseKernel (OCL_PTR *ocl, cl_kernel kernel);
126 void hc_clReleaseMemObject (OCL_PTR *ocl, cl_mem mem);
127 void hc_clReleaseProgram (OCL_PTR *ocl, cl_program program);
128 void hc_clSetKernelArg (OCL_PTR *ocl, cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value);
129 void *hc_clEnqueueMapBuffer (OCL_PTR *ocl, cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_map, 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);
130 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);
131 void 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);
132 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);
133 void 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);
134 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);
135 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);
136 #endif