You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hashcat/src/ext_nvml.c

221 lines
5.4 KiB

9 years ago
/**
9 years ago
* Authors.....: Jens Steube <jens.steube@gmail.com>
* Gabriele Gristina <matrix@hashcat.net>
*
9 years ago
* License.....: MIT
*/
#include <ext_nvml.h>
9 years ago
int nvml_init (NVML_PTR *nvml)
{
9 years ago
if (!nvml) return (-1);
9 years ago
memset (nvml, 0, sizeof (NVML_PTR));
9 years ago
nvml->lib = hc_dlopen ("libnvidia-ml.so", RTLD_NOW);
if (!nvml->lib)
{
//if (data.quiet == 0)
// log_info ("WARNING: load NVML library failed, proceed without NVML HWMon enabled.");
9 years ago
return (-1);
}
9 years ago
HC_LOAD_FUNC(nvml, nvmlErrorString, NVML_ERROR_STRING, NVML, 0)
HC_LOAD_FUNC(nvml, nvmlInit, NVML_INIT, NVML, 0)
HC_LOAD_FUNC(nvml, nvmlShutdown, NVML_SHUTDOWN, 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, nvmlDeviceGetTemperature, NVML_DEVICE_GET_TEMPERATURE, NVML, 0)
HC_LOAD_FUNC(nvml, nvmlDeviceGetFanSpeed, NVML_DEVICE_GET_FAN_SPEED, NVML, 0)
HC_LOAD_FUNC(nvml, nvmlDeviceGetPowerUsage, NVML_DEVICE_GET_POWER_USAGE, NVML, 0)
HC_LOAD_FUNC(nvml, nvmlDeviceGetUtilizationRates, NVML_DEVICE_GET_UTILIZATION_RATES, NVML, 0)
HC_LOAD_FUNC(nvml, nvmlDeviceGetClockInfo, NVML_DEVICE_GET_CLOCKINFO, NVML, 0)
9 years ago
return 0;
}
9 years ago
void nvml_close (NVML_PTR *nvml)
9 years ago
{
9 years ago
if (nvml)
{
9 years ago
if (nvml->lib)
hc_dlclose (nvml->lib);
9 years ago
myfree (nvml);
}
9 years ago
}
9 years ago
const char *hm_NVML_nvmlErrorString (NVML_PTR *nvml, nvmlReturn_t nvml_rc)
{
if (!nvml) return NULL;
return nvml->nvmlErrorString (nvml_rc);
}
nvmlReturn_t hm_NVML_nvmlInit (NVML_PTR *nvml)
{
if (!nvml) return -1;
nvmlReturn_t nvml_rc = nvml->nvmlInit ();
9 years ago
if (nvml_rc != NVML_SUCCESS)
{
9 years ago
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
9 years ago
log_info ("WARN: %s %d %s\n", "nvmlInit()", nvml_rc, string);
}
return nvml_rc;
}
9 years ago
nvmlReturn_t hm_NVML_nvmlShutdown (NVML_PTR *nvml)
9 years ago
{
9 years ago
if (!nvml) return -1;
9 years ago
nvmlReturn_t nvml_rc = nvml->nvmlShutdown ();
9 years ago
if (nvml_rc != NVML_SUCCESS)
{
9 years ago
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
9 years ago
log_info ("WARN: %s %d %s\n", "nvmlShutdown()", nvml_rc, string);
}
return nvml_rc;
}
9 years ago
nvmlReturn_t hm_NVML_nvmlDeviceGetName (NVML_PTR *nvml, nvmlDevice_t device, char *name, unsigned int length)
9 years ago
{
9 years ago
if (!nvml) return -1;
9 years ago
nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetName (device, name, length);
9 years ago
if (nvml_rc != NVML_SUCCESS)
{
9 years ago
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
9 years ago
log_info ("WARN: %s %d %s\n", "nvmlDeviceGetName()", nvml_rc, string);
}
return nvml_rc;
}
9 years ago
nvmlReturn_t hm_NVML_nvmlDeviceGetHandleByIndex (NVML_PTR *nvml, int skip_warnings, unsigned int index, nvmlDevice_t *device)
9 years ago
{
9 years ago
if (!nvml) return -1;
9 years ago
nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetHandleByIndex (index, device);
9 years ago
if (nvml_rc != NVML_SUCCESS)
{
if (skip_warnings == 0)
{
9 years ago
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
9 years ago
log_info ("WARN: %s %d %s\n", "nvmlDeviceGetHandleByIndex()", nvml_rc, string);
}
9 years ago
}
return nvml_rc;
}
9 years ago
nvmlReturn_t hm_NVML_nvmlDeviceGetTemperature (NVML_PTR *nvml, nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int *temp)
9 years ago
{
9 years ago
if (!nvml) return -1;
9 years ago
nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetTemperature (device, sensorType, temp);
9 years ago
if (nvml_rc != NVML_SUCCESS)
{
*temp = -1;
9 years ago
//const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
9 years ago
//log_info ("WARN: %s %d %s\n", "nvmlDeviceGetTemperature()", nvml_rc, string);
}
return nvml_rc;
}
9 years ago
nvmlReturn_t hm_NVML_nvmlDeviceGetFanSpeed (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, unsigned int *speed)
9 years ago
{
9 years ago
if (!nvml) return -1;
9 years ago
nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetFanSpeed (device, speed);
9 years ago
if (nvml_rc != NVML_SUCCESS)
{
*speed = -1;
if (skip_warnings == 0)
{
9 years ago
const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
9 years ago
log_info ("WARN: %s %d %s\n", "nvmlDeviceGetFanSpeed()", nvml_rc, string);
}
9 years ago
}
return nvml_rc;
}
/* only tesla following */
9 years ago
nvmlReturn_t hm_NVML_nvmlDeviceGetPowerUsage (NVML_PTR *nvml, nvmlDevice_t device, unsigned int *power)
9 years ago
{
9 years ago
if (!nvml) return -1;
9 years ago
nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetPowerUsage (device, power);
9 years ago
if (nvml_rc != NVML_SUCCESS)
{
*power = -1;
9 years ago
//const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
9 years ago
//log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerUsage()", nvml_rc, string);
}
return nvml_rc;
}
9 years ago
nvmlReturn_t hm_NVML_nvmlDeviceGetUtilizationRates (NVML_PTR *nvml, nvmlDevice_t device, nvmlUtilization_t *utilization)
9 years ago
{
9 years ago
if (!nvml) return -1;
9 years ago
nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetUtilizationRates (device, utilization);
9 years ago
if (nvml_rc != NVML_SUCCESS)
{
utilization->gpu = -1;
utilization->memory = -1;
9 years ago
//const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
9 years ago
//log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);
}
return nvml_rc;
}
nvmlReturn_t hm_NVML_nvmlDeviceGetClockInfo (NVML_PTR *nvml, nvmlDevice_t device, nvmlClockType_t type, unsigned int *clock)
{
if (!nvml) return -1;
nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetClockInfo (device, type, clock);
if (nvml_rc != NVML_SUCCESS)
{
*clock = -1;
//const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
//log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);
}
return nvml_rc;
}