From 0fae3a43946be8f6eeb5b1745bea135644cbc24b Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Mon, 13 Dec 2021 22:42:42 +0100 Subject: [PATCH 1/3] Added support for Apple Silicon compute devices --- src/backend.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/backend.c b/src/backend.c index 182095f6c..e7eb6a34d 100644 --- a/src/backend.c +++ b/src/backend.c @@ -5170,13 +5170,6 @@ int run_opencl_kernel_bzero (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *devi // with apple GPU clEnqueueWriteBuffer() return CL_INVALID_VALUE, workaround - if (device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE && \ - (device_param->opencl_device_vendor_id == VENDOR_ID_INTEL_SDK || device_param->opencl_device_vendor_id == VENDOR_ID_APPLE) && \ - device_param->opencl_device_type & CL_DEVICE_TYPE_GPU) - { - return run_opencl_kernel_memset (hashcat_ctx, device_param, buf, 0, 0, size); - } - if (num16d) { const u64 kernel_threads = device_param->kernel_wgs_bzero; @@ -5196,7 +5189,20 @@ int run_opencl_kernel_bzero (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *devi if (num16m) { - if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, buf, CL_FALSE, num16d * 16, num16m, bzeros, 0, NULL, NULL) == -1) return -1; + if (device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE && \ + (device_param->opencl_device_vendor_id == VENDOR_ID_INTEL_SDK || device_param->opencl_device_vendor_id == VENDOR_ID_APPLE) && \ + device_param->opencl_device_type & CL_DEVICE_TYPE_GPU) + { + u8 *bzeros_apple = (u8 *) hccalloc (num16m, sizeof (u8)); + + if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, buf, CL_TRUE, num16d * 16, num16m, bzeros_apple, 0, NULL, NULL) == -1) return -1; + + hcfree (bzeros_apple); + } + else + { + if (hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->opencl_command_queue, buf, CL_FALSE, num16d * 16, num16m, bzeros, 0, NULL, NULL) == -1) return -1; + } } return 0; @@ -10535,7 +10541,7 @@ static bool load_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_p // workaround opencl issue with Apple Silicon - if (strcmp (device_param->device_name, "Apple M") != 0) + if (strncmp (device_param->device_name, "Apple M", 7) == 0) { if (hc_clCreateProgramWithSource (hashcat_ctx, device_param->opencl_context, 1, (const char **) kernel_sources, NULL, opencl_program) == -1) return false; @@ -10562,7 +10568,7 @@ static bool load_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_p int rc_clGetProgramBuildInfo; - if (strcmp (device_param->device_name, "Apple M") != 0) + if (strncmp (device_param->device_name, "Apple M", 7) == 0) { rc_clGetProgramBuildInfo = hc_clGetProgramBuildInfo (hashcat_ctx, *opencl_program, device_param->opencl_device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); } @@ -10589,10 +10595,7 @@ static bool load_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_p // workaround opencl issue with Apple Silicon - if (strcmp (device_param->device_name, "Apple M") != 0) - { - } - else + if (strncmp (device_param->device_name, "Apple M", 7) != 0) { cl_program t2[1]; From 3fd6dac523fcf00cbe1a331621e1dd22521d2ba4 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Tue, 14 Dec 2021 00:37:17 +0100 Subject: [PATCH 2/3] Set default device-type to GPU with Apple M1 --- src/backend.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/backend.c b/src/backend.c index e7eb6a34d..05b62925c 100644 --- a/src/backend.c +++ b/src/backend.c @@ -341,11 +341,27 @@ static bool setup_opencl_device_types_filter (hashcat_ctx_t *hashcat_ctx, const { #if defined (__APPLE__) - // For apple use CPU only, because GPU drivers are not reliable - // The user can explicitly enable GPU by setting -D2 + #include - //opencl_device_types_filter = CL_DEVICE_TYPE_ALL & ~CL_DEVICE_TYPE_GPU; - opencl_device_types_filter = CL_DEVICE_TYPE_CPU; + size_t size; + cpu_type_t cpu_type = 0; + size = sizeof (cpu_type); + sysctlbyname ("hw.cputype", &cpu_type, &size, NULL, 0); + + if (cpu_type == 0x100000c) + { + // For apple M1* use GPU only, because CPU device it is not recognized by OpenCL + + opencl_device_types_filter = CL_DEVICE_TYPE_GPU; + } + else + { + // For apple use CPU only, because GPU drivers are not reliable + // The user can explicitly enable GPU by setting -D2 + + //opencl_device_types_filter = CL_DEVICE_TYPE_ALL & ~CL_DEVICE_TYPE_GPU; + opencl_device_types_filter = CL_DEVICE_TYPE_CPU; + } #else From b53624d0a36b1954cdead8ab20e93934ffbd40d3 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Tue, 14 Dec 2021 19:42:35 +0100 Subject: [PATCH 3/3] update changes and credits --- docs/changes.txt | 2 ++ docs/credits.txt | 1 + 2 files changed, 3 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index a18355a87..4f8bc53eb 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -22,6 +22,8 @@ - Tuning Database: Added a warning if a module implements module_extra_tuningdb_block but the installed computing device is not found - Usage Screen: On windows console, wait for any keypress if usage_mini_print() is used - User Options: Add new module function module_hash_decode_postprocess() to override hash specific configurations from command line +- OpenCL Runtime: Added support to use Apple Silicon compute devices +- OpenCL Runtime: Set default device-type to GPU with Apple Silicon compute devices * changes v6.2.4 -> v6.2.5 diff --git a/docs/credits.txt b/docs/credits.txt index 002014c51..62c5b04e1 100644 --- a/docs/credits.txt +++ b/docs/credits.txt @@ -22,6 +22,7 @@ Gabriele "matrix" Gristina (@gm4tr1x) * Compressed wordlist feature * OpenCL Info feature * Apple macOS port +* Apple Silicon support * Hardware monitor initial code base and maintenance * Test suite initial code base * Makefile initial code base