1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-22 22:58:30 +00:00

Make use of nvmlDeviceGetCount()

This commit is contained in:
jsteube 2016-10-11 12:18:06 +02:00
parent afd44130fc
commit a3bf6fd4ef
2 changed files with 36 additions and 13 deletions

View File

@ -168,6 +168,7 @@ typedef nvmlDevice_t HM_ADAPTER_NVML;
typedef const char * (*NVML_API_CALL NVML_ERROR_STRING) (nvmlReturn_t); typedef const char * (*NVML_API_CALL NVML_ERROR_STRING) (nvmlReturn_t);
typedef int (*NVML_API_CALL NVML_INIT) (void); typedef int (*NVML_API_CALL NVML_INIT) (void);
typedef int (*NVML_API_CALL NVML_SHUTDOWN) (void); typedef int (*NVML_API_CALL NVML_SHUTDOWN) (void);
typedef nvmlReturn_t (*NVML_API_CALL NVML_DEVICE_GET_COUNT) (unsigned int *);
typedef nvmlReturn_t (*NVML_API_CALL NVML_DEVICE_GET_NAME) (nvmlDevice_t, char *, unsigned int); typedef nvmlReturn_t (*NVML_API_CALL NVML_DEVICE_GET_NAME) (nvmlDevice_t, char *, unsigned int);
typedef nvmlReturn_t (*NVML_API_CALL NVML_DEVICE_GET_HANDLE_BY_INDEX) (unsigned int, nvmlDevice_t *); typedef nvmlReturn_t (*NVML_API_CALL NVML_DEVICE_GET_HANDLE_BY_INDEX) (unsigned int, nvmlDevice_t *);
typedef nvmlReturn_t (*NVML_API_CALL NVML_DEVICE_GET_TEMPERATURE) (nvmlDevice_t, nvmlTemperatureSensors_t, unsigned int *); typedef nvmlReturn_t (*NVML_API_CALL NVML_DEVICE_GET_TEMPERATURE) (nvmlDevice_t, nvmlTemperatureSensors_t, unsigned int *);
@ -199,6 +200,7 @@ typedef struct hm_nvml_lib
NVML_ERROR_STRING nvmlErrorString; NVML_ERROR_STRING nvmlErrorString;
NVML_INIT nvmlInit; NVML_INIT nvmlInit;
NVML_SHUTDOWN nvmlShutdown; NVML_SHUTDOWN nvmlShutdown;
NVML_DEVICE_GET_COUNT nvmlDeviceGetCount;
NVML_DEVICE_GET_NAME nvmlDeviceGetName; NVML_DEVICE_GET_NAME nvmlDeviceGetName;
NVML_DEVICE_GET_HANDLE_BY_INDEX nvmlDeviceGetHandleByIndex; NVML_DEVICE_GET_HANDLE_BY_INDEX nvmlDeviceGetHandleByIndex;
NVML_DEVICE_GET_TEMPERATURE nvmlDeviceGetTemperature; NVML_DEVICE_GET_TEMPERATURE nvmlDeviceGetTemperature;

View File

@ -79,6 +79,7 @@ static int nvml_init (hashcat_ctx_t *hashcat_ctx)
HC_LOAD_FUNC(nvml, nvmlErrorString, NVML_ERROR_STRING, NVML, 0) HC_LOAD_FUNC(nvml, nvmlErrorString, NVML_ERROR_STRING, NVML, 0)
HC_LOAD_FUNC(nvml, nvmlInit, NVML_INIT, NVML, 0) HC_LOAD_FUNC(nvml, nvmlInit, NVML_INIT, NVML, 0)
HC_LOAD_FUNC(nvml, nvmlShutdown, NVML_SHUTDOWN, NVML, 0) HC_LOAD_FUNC(nvml, nvmlShutdown, NVML_SHUTDOWN, NVML, 0)
HC_LOAD_FUNC(nvml, nvmlDeviceGetCount, NVML_DEVICE_GET_COUNT, NVML, 0)
HC_LOAD_FUNC(nvml, nvmlDeviceGetName, NVML_DEVICE_GET_NAME, NVML, 0) HC_LOAD_FUNC(nvml, nvmlDeviceGetName, NVML_DEVICE_GET_NAME, NVML, 0)
HC_LOAD_FUNC(nvml, nvmlDeviceGetHandleByIndex, NVML_DEVICE_GET_HANDLE_BY_INDEX, NVML, 0) HC_LOAD_FUNC(nvml, nvmlDeviceGetHandleByIndex, NVML_DEVICE_GET_HANDLE_BY_INDEX, NVML, 0)
HC_LOAD_FUNC(nvml, nvmlDeviceGetTemperature, NVML_DEVICE_GET_TEMPERATURE, NVML, 0) HC_LOAD_FUNC(nvml, nvmlDeviceGetTemperature, NVML_DEVICE_GET_TEMPERATURE, NVML, 0)
@ -160,6 +161,26 @@ static int hm_NVML_nvmlShutdown (hashcat_ctx_t *hashcat_ctx)
return 0; return 0;
} }
static int hm_NVML_nvmlDeviceGetCount (hashcat_ctx_t *hashcat_ctx, unsigned int *deviceCount)
{
hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx;
NVML_PTR *nvml = hwmon_ctx->hm_nvml;
const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetCount (deviceCount);
if (nvml_rc != NVML_SUCCESS)
{
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
event_log_error (hashcat_ctx, "nvmlDeviceGetCount(): %s", string);
return -1;
}
return 0;
}
static int hm_NVML_nvmlDeviceGetHandleByIndex (hashcat_ctx_t *hashcat_ctx, unsigned int index, nvmlDevice_t *device) static int hm_NVML_nvmlDeviceGetHandleByIndex (hashcat_ctx_t *hashcat_ctx, unsigned int index, nvmlDevice_t *device)
{ {
hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx;
@ -1869,27 +1890,27 @@ static int hm_get_adapter_index_nvapi (hashcat_ctx_t *hashcat_ctx, HM_ADAPTER_NV
static int hm_get_adapter_index_nvml (hashcat_ctx_t *hashcat_ctx, HM_ADAPTER_NVML *nvmlGPUHandle) static int hm_get_adapter_index_nvml (hashcat_ctx_t *hashcat_ctx, HM_ADAPTER_NVML *nvmlGPUHandle)
{ {
int pGpuCount = 0; unsigned int deviceCount = 0;
for (u32 i = 0; i < DEVICES_MAX; i++) hm_NVML_nvmlDeviceGetCount (hashcat_ctx, &deviceCount);
{
if (hm_NVML_nvmlDeviceGetHandleByIndex (hashcat_ctx, i, &nvmlGPUHandle[i]) == -1) break;
// can be used to determine if the device by index matches the cuda device by index if (deviceCount == 0)
// char name[100]; memset (name, 0, sizeof (name));
// hm_NVML_nvmlDeviceGetName (hashcat_ctx, nvGPUHandle[i], name, sizeof (name) - 1);
pGpuCount++;
}
if (pGpuCount == 0)
{ {
event_log_error (hashcat_ctx, "No NVML adapters found"); event_log_error (hashcat_ctx, "No NVML adapters found");
return 0; return 0;
} }
return (pGpuCount); for (u32 i = 0; i < deviceCount; i++)
{
if (hm_NVML_nvmlDeviceGetHandleByIndex (hashcat_ctx, i, &nvmlGPUHandle[i]) == -1) break;
// can be used to determine if the device by index matches the cuda device by index
// char name[100]; memset (name, 0, sizeof (name));
// hm_NVML_nvmlDeviceGetName (hashcat_ctx, nvGPUHandle[i], name, sizeof (name) - 1);
}
return (deviceCount);
} }
static void hm_sort_adl_adapters_by_busid_devid (u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo) static void hm_sort_adl_adapters_by_busid_devid (u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo)