From 0ff2f8c5e1dc958ebd099bc8fbe534ee7ce829d1 Mon Sep 17 00:00:00 2001 From: Jens Steube Date: Mon, 27 Jul 2020 15:21:56 +0200 Subject: [PATCH] OpenCL Devices: Utilize PCI domain to improve alias device detection --- docs/changes.txt | 1 + include/types.h | 2 ++ src/backend.c | 38 ++++++++++++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index b89acb341..15696e497 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -24,6 +24,7 @@ - Compile macOS: Fixed makefile target 'clean' to correctly remove *.dSYM folders - Compile ZLIB: Fixed makefile include paths in case USE_SYSTEM_ZLIB is used +- OpenCL Devices: Utilize PCI domain to improve alias device detection - OpenCL Kernels: Added datatypes to literals of enum costants - OpenCL Kernels: Added pure kernels for hash-mode 600 (BLAKE2b-512) - OpenCL Runtime: Add some unstable warnings for some SHA512 based algorithms on AMD GPU on macOS diff --git a/include/types.h b/include/types.h index 2dc786fdb..05b427b9f 100644 --- a/include/types.h +++ b/include/types.h @@ -1056,6 +1056,7 @@ typedef struct hc_device_param int device_id_alias_cnt; int device_id_alias_buf[DEVICES_MAX]; + u8 pcie_domain; u8 pcie_bus; u8 pcie_device; u8 pcie_function; @@ -1437,6 +1438,7 @@ typedef struct hc_device_param cl_device_type opencl_device_type; cl_uint opencl_device_vendor_id; + u32 opencl_platform_id; cl_uint opencl_platform_vendor_id; cl_device_id opencl_device; diff --git a/src/backend.c b/src/backend.c index 5237ec04c..58aa8094f 100644 --- a/src/backend.c +++ b/src/backend.c @@ -39,18 +39,34 @@ static double TARGET_MSEC_PROFILE[4] = { 2, 12, 96, 480 }; static bool is_same_device (const hc_device_param_t *src, const hc_device_param_t *dst) { + // First check by PCI address + + if (src->pcie_domain != dst->pcie_domain) return false; // PCI domain not available on OpenCL if (src->pcie_bus != dst->pcie_bus) return false; if (src->pcie_device != dst->pcie_device) return false; if (src->pcie_function != dst->pcie_function) return false; - // Intel CPU and embedded GPU would survive up to here! - - if (src->opencl_device_type != dst->opencl_device_type) return false; - // macOS still can't distinguish the devices by PCIe bus: if (src->device_processors != dst->device_processors) return false; + // CUDA can't have aliases + + if ((src->is_cuda == true) && (dst->is_cuda == true)) return false; + + // But OpenCL can have aliases + + if ((src->is_opencl == true) && (dst->is_opencl == true)) + { + // Intel CPU and embedded GPU would survive up to here! + + if (src->opencl_device_type != dst->opencl_device_type) return false; + + // There should be no aliases on the same opencl platform + + if (src->opencl_platform_id == dst->opencl_platform_id) return false; + } + return true; } @@ -5473,13 +5489,17 @@ int backend_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) // pcie_bus, pcie_device, pcie_function - int pci_bus_id_nv = 0; - int pci_slot_id_nv = 0; + int pci_domain_id_nv = 0; + int pci_bus_id_nv = 0; + int pci_slot_id_nv = 0; + + if (hc_cuDeviceGetAttribute (hashcat_ctx, &pci_domain_id_nv, CU_DEVICE_ATTRIBUTE_PCI_DOMAIN_ID, cuda_device) == -1) return -1; if (hc_cuDeviceGetAttribute (hashcat_ctx, &pci_bus_id_nv, CU_DEVICE_ATTRIBUTE_PCI_BUS_ID, cuda_device) == -1) return -1; if (hc_cuDeviceGetAttribute (hashcat_ctx, &pci_slot_id_nv, CU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID, cuda_device) == -1) return -1; + device_param->pcie_domain = (u8) (pci_domain_id_nv); device_param->pcie_bus = (u8) (pci_bus_id_nv); device_param->pcie_device = (u8) (pci_slot_id_nv >> 3); device_param->pcie_function = (u8) (pci_slot_id_nv & 7); @@ -5717,6 +5737,10 @@ int backend_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) device_param->is_opencl = true; + // store opencl platform i + + device_param->opencl_platform_id = opencl_platforms_idx; + // check OpenCL version device_param->use_opencl12 = false; @@ -6190,6 +6214,7 @@ int backend_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_TOPOLOGY_AMD, sizeof (amdtopo), &amdtopo, NULL) == -1) return -1; + device_param->pcie_domain = 0; // no attribute to query device_param->pcie_bus = amdtopo.pcie.bus; device_param->pcie_device = amdtopo.pcie.device; device_param->pcie_function = amdtopo.pcie.function; @@ -6204,6 +6229,7 @@ int backend_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) if (hc_clGetDeviceInfo (hashcat_ctx, device_param->opencl_device, CL_DEVICE_PCI_SLOT_ID_NV, sizeof (pci_slot_id_nv), &pci_slot_id_nv, NULL) == -1) return -1; + device_param->pcie_domain = 0; // no attribute to query device_param->pcie_bus = (u8) (pci_bus_id_nv); device_param->pcie_device = (u8) (pci_slot_id_nv >> 3); device_param->pcie_function = (u8) (pci_slot_id_nv & 7);