From f890cd8134d53bfcb2378b15e971fa936f52759d Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Sat, 19 Feb 2022 21:17:56 +0100 Subject: [PATCH] Improved management of systems with multiple OpenCL platforms and show empty OpenCL platforms only in backend information mode --- docs/changes.txt | 2 ++ src/backend.c | 36 ++++++++++++++++++++++-------------- src/ext_OpenCL.c | 7 ++++++- src/terminal.c | 3 +++ 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index f391dd600..4f7ef789b 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -50,6 +50,7 @@ - Backend Info: Added generic system info to output (must be completed on Windows side) - Backend Info: Added local memory size to output - Backend: with kernel build options, switch from -I to -D INCLUDE_PATH, in order to support Apple Metal runtime +- Backend: improved management of systems with multiple OpenCL platforms - CUDA Backend: moved functions to ext_cuda.c/ext_nvrtc.c and includes to ext_cuda.h/ext_nvrtc.h - Hardware Monitor: Add support for GPU device utilization readings using iokit on Apple Silicon (OpenCL and Metal) - Hash Info: show more information (Updated Hash-Format. Added Autodetect, Self-Test, Potfile and Plaintext encoding) @@ -68,6 +69,7 @@ - OpenCL Runtime: Set default device-type to GPU with Apple Silicon compute devices - Status code: updated negative status code (added kernel create failure and resync) - Status code: updated negative status code, usefull in Unit tests engine (test.sh) +- Terminal: show empty OpenCL platforms only in backend information mode - Tuning Database: Added a warning if a module implements module_extra_tuningdb_block but the installed computing device is not found - Unit tests: added -r (--runtime) option - Unit tests: handle negative status code, skip deprecated hash-types, skip hash-types with known perl modules issues, updated output diff --git a/src/backend.c b/src/backend.c index f370dca28..a1bd6e9c4 100644 --- a/src/backend.c +++ b/src/backend.c @@ -4559,17 +4559,24 @@ int backend_ctx_init (hashcat_ctx_t *hashcat_ctx) ocl_close (hashcat_ctx); } - if (opencl_platforms_cnt) + if (opencl_platforms_cnt > 0) { for (u32 opencl_platforms_idx = 0; opencl_platforms_idx < opencl_platforms_cnt; opencl_platforms_idx++) { + opencl_platforms_name[opencl_platforms_idx] = "N/A"; + opencl_platforms_vendor[opencl_platforms_idx] = "N/A"; + opencl_platforms_version[opencl_platforms_idx] = "N/A"; + opencl_platforms_devices[opencl_platforms_idx] = NULL; + opencl_platforms_vendor_id[opencl_platforms_idx] = 0; + opencl_platforms_devices_cnt[opencl_platforms_idx] = 0; + cl_platform_id opencl_platform = opencl_platforms[opencl_platforms_idx]; size_t param_value_size = 0; // platform vendor - if (hc_clGetPlatformInfo (hashcat_ctx, opencl_platform, CL_PLATFORM_VENDOR, 0, NULL, ¶m_value_size) == -1) return -1; + if (hc_clGetPlatformInfo (hashcat_ctx, opencl_platform, CL_PLATFORM_VENDOR, 0, NULL, ¶m_value_size) == -1) continue; char *opencl_platform_vendor = (char *) hcmalloc (param_value_size); @@ -4577,14 +4584,14 @@ int backend_ctx_init (hashcat_ctx_t *hashcat_ctx) { hcfree (opencl_platform_vendor); - return -1; + continue; } opencl_platforms_vendor[opencl_platforms_idx] = opencl_platform_vendor; // platform name - if (hc_clGetPlatformInfo (hashcat_ctx, opencl_platform, CL_PLATFORM_NAME, 0, NULL, ¶m_value_size) == -1) return -1; + if (hc_clGetPlatformInfo (hashcat_ctx, opencl_platform, CL_PLATFORM_NAME, 0, NULL, ¶m_value_size) == -1) continue; char *opencl_platform_name = (char *) hcmalloc (param_value_size); @@ -4592,14 +4599,14 @@ int backend_ctx_init (hashcat_ctx_t *hashcat_ctx) { hcfree (opencl_platform_name); - return -1; + continue; } opencl_platforms_name[opencl_platforms_idx] = opencl_platform_name; // platform version - if (hc_clGetPlatformInfo (hashcat_ctx, opencl_platform, CL_PLATFORM_VERSION, 0, NULL, ¶m_value_size) == -1) return -1; + if (hc_clGetPlatformInfo (hashcat_ctx, opencl_platform, CL_PLATFORM_VERSION, 0, NULL, ¶m_value_size) == -1) continue; char *opencl_platform_version = (char *) hcmalloc (param_value_size); @@ -4607,7 +4614,7 @@ int backend_ctx_init (hashcat_ctx_t *hashcat_ctx) { hcfree (opencl_platform_version); - return -1; + continue; } opencl_platforms_version[opencl_platforms_idx] = opencl_platform_version; @@ -4669,8 +4676,6 @@ int backend_ctx_init (hashcat_ctx_t *hashcat_ctx) if (CL_rc == -1) { - event_log_error (hashcat_ctx, "clGetDeviceIDs(): %s", val2cstr_cl (CL_rc)); - // Special handling for CL_DEVICE_NOT_FOUND, see: https://github.com/hashcat/hashcat/issues/2455 #define IGNORE_DEVICE_NOT_FOUND 1 @@ -4683,23 +4688,26 @@ int backend_ctx_init (hashcat_ctx_t *hashcat_ctx) const cl_int CL_err = ocl->clGetDeviceIDs (opencl_platform, CL_DEVICE_TYPE_ALL, DEVICES_MAX, opencl_platform_devices, &opencl_platform_devices_cnt); - if (CL_err == CL_DEVICE_NOT_FOUND) + if (CL_err == CL_DEVICE_NOT_FOUND && opencl_platform_devices_cnt > 0) { // we ignore this error } else { - return -1; + hcfree (opencl_platform_devices); + + continue; } } else { - return -1; + hcfree (opencl_platform_devices); + + continue; } } - opencl_platforms_devices[opencl_platforms_idx] = opencl_platform_devices; - + opencl_platforms_devices[opencl_platforms_idx] = opencl_platform_devices; opencl_platforms_devices_cnt[opencl_platforms_idx] = opencl_platform_devices_cnt; } diff --git a/src/ext_OpenCL.c b/src/ext_OpenCL.c index 25dfc94fc..b935c33aa 100644 --- a/src/ext_OpenCL.c +++ b/src/ext_OpenCL.c @@ -456,7 +456,12 @@ int hc_clGetDeviceIDs (void *hashcat_ctx, cl_platform_id platform, cl_device_typ if (CL_err != CL_SUCCESS) { - event_log_error (hashcat_ctx, "clGetDeviceIDs(): %s", val2cstr_cl (CL_err)); + #ifndef DEBUG + if (CL_err != CL_DEVICE_NOT_FOUND) + #endif + { + event_log_error (hashcat_ctx, "clGetDeviceIDs(): %s", val2cstr_cl (CL_err)); + } return -1; } diff --git a/src/terminal.c b/src/terminal.c index 7adace095..e1bf5f706 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -1382,6 +1382,9 @@ void backend_info_compact (hashcat_ctx_t *hashcat_ctx) char *opencl_platform_version = opencl_platforms_version[opencl_platforms_idx]; cl_uint opencl_platform_devices_cnt = opencl_platforms_devices_cnt[opencl_platforms_idx]; + // hide empty OpenCL platforms + if (opencl_platform_devices_cnt == 0) continue; + const size_t len = event_log_info (hashcat_ctx, "OpenCL API (%s) - Platform #%u [%s]", opencl_platform_version, opencl_platforms_idx + 1, opencl_platform_vendor); char line[HCBUFSIZ_TINY] = { 0 };