diff --git a/docs/changes.txt b/docs/changes.txt index ccd6f2ee2..2ba1ed9f2 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -52,6 +52,7 @@ - CUDA Backend: Give detailed warning if either the NVIDIA CUDA or the NVIDIA RTC library cannot be initialized - CUDA Backend: Do not warn about missing CUDA SDK installation if --backend-ignore-cuda is used - CUDA Backend: Use blocking events to avoid 100% CPU core usage (per GPU) +- OpenCL Runtime: Workaround JiT compiler deadlock on NVIDIA driver >= 465.89 - RAR3 Kernels: Improved loop code, improving performance by 23% - Startup time: Improved the startup time by avoiding some time intensive operations for skipped devices diff --git a/include/backend.h b/include/backend.h index 517e18bba..e9b7a9d4f 100644 --- a/include/backend.h +++ b/include/backend.h @@ -80,6 +80,7 @@ int hc_cuLinkDestroy (hashcat_ctx_t *hashcat_ctx, CUlinkState state) int hc_cuLinkComplete (hashcat_ctx_t *hashcat_ctx, CUlinkState state, void **cubinOut, size_t *sizeOut); int hc_clBuildProgram (hashcat_ctx_t *hashcat_ctx, 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); +int hc_clCompileProgram (hashcat_ctx_t *hashcat_ctx, cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, cl_uint num_input_headers, const cl_program *input_headers, const char **header_include_names, void (CL_CALLBACK *pfn_notify) (cl_program program, void *user_data), void *user_data); int hc_clCreateBuffer (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_mem *mem); int hc_clCreateCommandQueue (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_device_id device, cl_command_queue_properties properties, cl_command_queue *command_queue); int hc_clCreateContext (hashcat_ctx_t *hashcat_ctx, const cl_context_properties *properties, cl_uint num_devices, const cl_device_id *devices, void (CL_CALLBACK *pfn_notify) (const char *errinfo, const void *private_info, size_t cb, void *user_data), void *user_data, cl_context *context); @@ -103,6 +104,7 @@ int hc_clGetPlatformIDs (hashcat_ctx_t *hashcat_ctx, cl_uint num_entrie int hc_clGetPlatformInfo (hashcat_ctx_t *hashcat_ctx, cl_platform_id platform, cl_platform_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret); int hc_clGetProgramBuildInfo (hashcat_ctx_t *hashcat_ctx, 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); int hc_clGetProgramInfo (hashcat_ctx_t *hashcat_ctx, cl_program program, cl_program_info param_name, size_t param_value_size, void *param_value, size_t * param_value_size_ret); +int hc_clLinkProgram (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_uint num_devices, const cl_device_id *device_list, const char *options, cl_uint num_input_programs, const cl_program *input_programs, void (CL_CALLBACK *pfn_notify) (cl_program program, void *user_data), void *user_data, cl_program *program); int hc_clReleaseCommandQueue (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue); int hc_clReleaseContext (hashcat_ctx_t *hashcat_ctx, cl_context context); int hc_clReleaseEvent (hashcat_ctx_t *hashcat_ctx, cl_event event); diff --git a/include/ext_OpenCL.h b/include/ext_OpenCL.h index 0fc0d01b9..54f3b4182 100644 --- a/include/ext_OpenCL.h +++ b/include/ext_OpenCL.h @@ -38,6 +38,7 @@ typedef union #define CL_PLATFORMS_MAX 16 typedef cl_int (CL_API_CALL *OCL_CLBUILDPROGRAM) (cl_program, cl_uint, const cl_device_id *, const char *, void (CL_CALLBACK *)(cl_program, void *), void *); +typedef cl_int (CL_API_CALL *OCL_CLCOMPILEPROGRAM) (cl_program, cl_uint, const cl_device_id *, const char *, cl_uint, const cl_program *, const char **, void (CL_CALLBACK *)(cl_program, void *), void *); typedef cl_mem (CL_API_CALL *OCL_CLCREATEBUFFER) (cl_context, cl_mem_flags, size_t, void *, cl_int *); typedef cl_command_queue (CL_API_CALL *OCL_CLCREATECOMMANDQUEUE) (cl_context, cl_device_id, cl_command_queue_properties, cl_int *); typedef cl_context (CL_API_CALL *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 *); @@ -61,6 +62,7 @@ typedef cl_int (CL_API_CALL *OCL_CLGETPLATFORMIDS) (cl_uint, typedef cl_int (CL_API_CALL *OCL_CLGETPLATFORMINFO) (cl_platform_id, cl_platform_info, size_t, void *, size_t *); typedef cl_int (CL_API_CALL *OCL_CLGETPROGRAMBUILDINFO) (cl_program, cl_device_id, cl_program_build_info, size_t, void *, size_t *); typedef cl_int (CL_API_CALL *OCL_CLGETPROGRAMINFO) (cl_program, cl_program_info, size_t, void *, size_t *); +typedef cl_program (CL_API_CALL *OCL_CLLINKPROGRAM) (cl_context, cl_uint, const cl_device_id *, const char *, cl_uint, const cl_program *, void (CL_CALLBACK *) (cl_program, void *), void *, cl_int *); typedef cl_int (CL_API_CALL *OCL_CLRELEASECOMMANDQUEUE) (cl_command_queue); typedef cl_int (CL_API_CALL *OCL_CLRELEASECONTEXT) (cl_context); typedef cl_int (CL_API_CALL *OCL_CLRELEASEEVENT) (cl_event); @@ -75,6 +77,7 @@ typedef struct hc_opencl_lib hc_dynlib_t lib; OCL_CLBUILDPROGRAM clBuildProgram; + OCL_CLCOMPILEPROGRAM clCompileProgram; OCL_CLCREATEBUFFER clCreateBuffer; OCL_CLCREATECOMMANDQUEUE clCreateCommandQueue; OCL_CLCREATECONTEXT clCreateContext; @@ -98,6 +101,7 @@ typedef struct hc_opencl_lib OCL_CLGETPLATFORMINFO clGetPlatformInfo; OCL_CLGETPROGRAMBUILDINFO clGetProgramBuildInfo; OCL_CLGETPROGRAMINFO clGetProgramInfo; + OCL_CLLINKPROGRAM clLinkProgram; OCL_CLRELEASECOMMANDQUEUE clReleaseCommandQueue; OCL_CLRELEASECONTEXT clReleaseContext; OCL_CLRELEASEEVENT clReleaseEvent; diff --git a/src/backend.c b/src/backend.c index 804787d57..bc5ce0fe1 100644 --- a/src/backend.c +++ b/src/backend.c @@ -2183,6 +2183,7 @@ int ocl_init (hashcat_ctx_t *hashcat_ctx) if (ocl->lib == NULL) return -1; HC_LOAD_FUNC (ocl, clBuildProgram, OCL_CLBUILDPROGRAM, OpenCL, 1); + HC_LOAD_FUNC (ocl, clCompileProgram, OCL_CLCOMPILEPROGRAM, OpenCL, 1); HC_LOAD_FUNC (ocl, clCreateBuffer, OCL_CLCREATEBUFFER, OpenCL, 1); HC_LOAD_FUNC (ocl, clCreateCommandQueue, OCL_CLCREATECOMMANDQUEUE, OpenCL, 1); HC_LOAD_FUNC (ocl, clCreateContext, OCL_CLCREATECONTEXT, OpenCL, 1); @@ -2205,6 +2206,7 @@ int ocl_init (hashcat_ctx_t *hashcat_ctx) HC_LOAD_FUNC (ocl, clGetPlatformInfo, OCL_CLGETPLATFORMINFO, OpenCL, 1); HC_LOAD_FUNC (ocl, clGetProgramBuildInfo, OCL_CLGETPROGRAMBUILDINFO, OpenCL, 1); HC_LOAD_FUNC (ocl, clGetProgramInfo, OCL_CLGETPROGRAMINFO, OpenCL, 1); + HC_LOAD_FUNC (ocl, clLinkProgram, OCL_CLLINKPROGRAM, OpenCL, 1); HC_LOAD_FUNC (ocl, clReleaseCommandQueue, OCL_CLRELEASECOMMANDQUEUE, OpenCL, 1); HC_LOAD_FUNC (ocl, clReleaseContext, OCL_CLRELEASECONTEXT, OpenCL, 1); HC_LOAD_FUNC (ocl, clReleaseKernel, OCL_CLRELEASEKERNEL, OpenCL, 1); @@ -2571,6 +2573,44 @@ int hc_clBuildProgram (hashcat_ctx_t *hashcat_ctx, cl_program program, cl_uint n return 0; } +int hc_clCompileProgram (hashcat_ctx_t *hashcat_ctx, cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, cl_uint num_input_headers, const cl_program *input_headers, const char **header_include_names, void (CL_CALLBACK *pfn_notify) (cl_program program, void *user_data), void *user_data) +{ + backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx; + + OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl; + + const cl_int CL_err = ocl->clCompileProgram (program, num_devices, device_list, options, num_input_headers, input_headers, header_include_names, pfn_notify, user_data); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clCompileProgram(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clLinkProgram (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_uint num_devices, const cl_device_id *device_list, const char *options, cl_uint num_input_programs, const cl_program *input_programs, void (CL_CALLBACK *pfn_notify) (cl_program program, void *user_data), void *user_data, cl_program *program) +{ + backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx; + + OCL_PTR *ocl = (OCL_PTR *) backend_ctx->ocl; + + cl_int CL_err; + + *program = ocl->clLinkProgram (context, num_devices, device_list, options, num_input_programs, input_programs, pfn_notify, user_data, &CL_err); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clLinkProgram(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + int hc_clCreateKernel (hashcat_ctx_t *hashcat_ctx, cl_program program, const char *kernel_name, cl_kernel *kernel) { backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx; @@ -7707,17 +7747,17 @@ static bool load_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_p if (device_param->is_opencl == true) { - if (hc_clCreateProgramWithSource (hashcat_ctx, device_param->opencl_context, 1, (const char **) kernel_sources, NULL, opencl_program) == -1) return false; - - const int CL_rc = hc_clBuildProgram (hashcat_ctx, *opencl_program, 1, &device_param->opencl_device, build_options_buf, NULL, NULL); - - //if (CL_rc == -1) return -1; - size_t build_log_size = 0; - hc_clGetProgramBuildInfo (hashcat_ctx, *opencl_program, device_param->opencl_device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + int CL_rc; - //if (CL_rc == -1) return -1; + cl_program p1 = NULL; + + if (hc_clCreateProgramWithSource (hashcat_ctx, device_param->opencl_context, 1, (const char **) kernel_sources, NULL, &p1) == -1) return false; + + CL_rc = hc_clCompileProgram (hashcat_ctx, p1, 1, &device_param->opencl_device, build_options_buf, 0, NULL, NULL, NULL, NULL); + + hc_clGetProgramBuildInfo (hashcat_ctx, p1, device_param->opencl_device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); #if defined (DEBUG) if ((build_log_size > 1) || (CL_rc == -1)) @@ -7727,7 +7767,7 @@ static bool load_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_p { char *build_log = (char *) hcmalloc (build_log_size + 1); - const int rc_clGetProgramBuildInfo = hc_clGetProgramBuildInfo (hashcat_ctx, *opencl_program, device_param->opencl_device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); + const int rc_clGetProgramBuildInfo = hc_clGetProgramBuildInfo (hashcat_ctx, p1, device_param->opencl_device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); if (rc_clGetProgramBuildInfo == -1) return false; @@ -7738,6 +7778,21 @@ static bool load_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_p if (CL_rc == -1) return false; + cl_program t2[1]; + + t2[0] = p1; + + cl_program fin; + + if (hc_clLinkProgram (hashcat_ctx, device_param->opencl_context, 1, &device_param->opencl_device, NULL, 1, t2, NULL, NULL, &fin) == -1) return false; + + // it seems errors caused by clLinkProgram() do not go into CL_PROGRAM_BUILD + // I couldn't find any information on the web explaining how else to retrieve the error messages from the linker + + *opencl_program = fin; + + hc_clReleaseProgram (hashcat_ctx, p1); + if (cache_disable == false) { size_t binary_size;