From ff96015f53cf0dab30a97756fe45b2213efc6378 Mon Sep 17 00:00:00 2001 From: Jens Steube Date: Wed, 14 Apr 2021 15:22:30 +0200 Subject: [PATCH] Add OPTS_TYPE_NATIVE_THREADS for use by plugin developer to enforce native thread count (useful for scrypt) --- include/types.h | 1 + src/backend.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/include/types.h b/include/types.h index 3dfa6f162..e6dd881a7 100644 --- a/include/types.h +++ b/include/types.h @@ -435,6 +435,7 @@ typedef enum opts_type OPTS_TYPE_DYNAMIC_SHARED = (1ULL << 48), // use dynamic shared memory (note: needs special kernel changes) OPTS_TYPE_SELF_TEST_DISABLE = (1ULL << 49), // some algos use JiT in combinations with a salt or create too much startup time OPTS_TYPE_MP_MULTI_DISABLE = (1ULL << 50), // do not multiply the kernel-accel with the multiprocessor count per device to allow more fine-tuned workload settings + OPTS_TYPE_NATIVE_THREADS = (1ULL << 51), // forces "native" thread count: CPU=1, GPU-Intel=8, GPU-AMD=64 (wavefront), GPU-NV=32 (warps) } opts_type_t; diff --git a/src/backend.c b/src/backend.c index 0872e20d3..ef544858c 100644 --- a/src/backend.c +++ b/src/backend.c @@ -8166,6 +8166,62 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx) const u32 device_processors = device_param->device_processors; + if (hashconfig->opts_type & OPTS_TYPE_MP_MULTI_DISABLE) + { + u32 native_accel = device_processors; + + if ((native_accel >= device_param->kernel_accel_min) && (native_accel <= device_param->kernel_accel_max)) + { + device_param->kernel_accel_min = native_accel; + device_param->kernel_accel_max = native_accel; + } + } + + /** + * device threads + */ + + if (hashconfig->opts_type & OPTS_TYPE_NATIVE_THREADS) + { + u32 native_threads = 0; + + if (device_param->opencl_device_type & CL_DEVICE_TYPE_CPU) + { + native_threads = 1; + } + else if (device_param->opencl_device_type & CL_DEVICE_TYPE_GPU) + { + // for GPU we need to distinguish by vendor + + if (device_param->opencl_device_vendor_id == VENDOR_ID_INTEL_SDK) + { + native_threads = 8; + } + else if (device_param->opencl_device_vendor_id == VENDOR_ID_AMD) + { + native_threads = 64; + } + else + { + native_threads = 32; + } + } + else + { + // abort? + } + + if ((native_threads >= device_param->kernel_threads_min) && (native_threads <= device_param->kernel_threads_max)) + { + device_param->kernel_threads_min = native_threads; + device_param->kernel_threads_max = native_threads; + } + else + { + // abort? + } + } + /** * create context for each device */