2 * Authors.....: Jens Steube <jens.steube@gmail.com>
3 * Gabriele Gristina <matrix@hashcat.net>
10 int nvml_init (NVML_PTR
*nvml
)
12 if (!nvml
) return (-1);
14 memset (nvml
, 0, sizeof (NVML_PTR
));
16 nvml
->lib
= hc_dlopen ("libnvidia-ml.so", RTLD_NOW
);
20 //if (data.quiet == 0)
21 // log_info ("WARNING: load NVML library failed, proceed without NVML HWMon enabled.");
26 HC_LOAD_FUNC(nvml
, nvmlErrorString
, NVML_ERROR_STRING
, NVML
, 0)
27 HC_LOAD_FUNC(nvml
, nvmlInit
, NVML_INIT
, NVML
, 0)
28 HC_LOAD_FUNC(nvml
, nvmlShutdown
, NVML_SHUTDOWN
, NVML
, 0)
29 HC_LOAD_FUNC(nvml
, nvmlDeviceGetName
, NVML_DEVICE_GET_NAME
, NVML
, 0)
30 HC_LOAD_FUNC(nvml
, nvmlDeviceGetHandleByIndex
, NVML_DEVICE_GET_HANDLE_BY_INDEX
, NVML
, 0)
31 HC_LOAD_FUNC(nvml
, nvmlDeviceGetTemperature
, NVML_DEVICE_GET_TEMPERATURE
, NVML
, 0)
32 HC_LOAD_FUNC(nvml
, nvmlDeviceGetFanSpeed
, NVML_DEVICE_GET_FAN_SPEED
, NVML
, 0)
33 HC_LOAD_FUNC(nvml
, nvmlDeviceGetPowerUsage
, NVML_DEVICE_GET_POWER_USAGE
, NVML
, 0)
34 HC_LOAD_FUNC(nvml
, nvmlDeviceGetUtilizationRates
, NVML_DEVICE_GET_UTILIZATION_RATES
, NVML
, 0)
39 void nvml_close (NVML_PTR
*nvml
)
44 hc_dlclose (nvml
->lib
);
50 const char *hm_NVML_nvmlErrorString (NVML_PTR
*nvml
, nvmlReturn_t nvml_rc
)
52 if (!nvml
) return NULL
;
54 return nvml
->nvmlErrorString (nvml_rc
);
57 nvmlReturn_t
hm_NVML_nvmlInit (NVML_PTR
*nvml
)
61 nvmlReturn_t nvml_rc
= nvml
->nvmlInit ();
63 if (nvml_rc
!= NVML_SUCCESS
)
65 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
67 log_info ("WARN: %s %d %s\n", "nvmlInit()", nvml_rc
, string
);
73 nvmlReturn_t
hm_NVML_nvmlShutdown (NVML_PTR
*nvml
)
77 nvmlReturn_t nvml_rc
= nvml
->nvmlShutdown ();
79 if (nvml_rc
!= NVML_SUCCESS
)
81 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
83 log_info ("WARN: %s %d %s\n", "nvmlShutdown()", nvml_rc
, string
);
89 nvmlReturn_t
hm_NVML_nvmlDeviceGetName (NVML_PTR
*nvml
, nvmlDevice_t device
, char *name
, unsigned int length
)
93 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetName (device
, name
, length
);
95 if (nvml_rc
!= NVML_SUCCESS
)
97 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
99 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetName()", nvml_rc
, string
);
105 nvmlReturn_t
hm_NVML_nvmlDeviceGetHandleByIndex (NVML_PTR
*nvml
, int skip_warnings
, unsigned int index
, nvmlDevice_t
*device
)
107 if (!nvml
) return -1;
109 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetHandleByIndex (index
, device
);
111 if (nvml_rc
!= NVML_SUCCESS
)
113 if (skip_warnings
== 0)
115 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
117 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetHandleByIndex()", nvml_rc
, string
);
124 nvmlReturn_t
hm_NVML_nvmlDeviceGetTemperature (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlTemperatureSensors_t sensorType
, unsigned int *temp
)
126 if (!nvml
) return -1;
128 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetTemperature (device
, sensorType
, temp
);
130 if (nvml_rc
!= NVML_SUCCESS
)
134 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
136 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetTemperature()", nvml_rc, string);
142 nvmlReturn_t
hm_NVML_nvmlDeviceGetFanSpeed (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *speed
)
144 if (!nvml
) return -1;
146 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetFanSpeed (device
, speed
);
148 if (nvml_rc
!= NVML_SUCCESS
)
152 if (skip_warnings
== 0)
154 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
156 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetFanSpeed()", nvml_rc
, string
);
163 /* only tesla following */
165 nvmlReturn_t
hm_NVML_nvmlDeviceGetPowerUsage (NVML_PTR
*nvml
, nvmlDevice_t device
, unsigned int *power
)
167 if (!nvml
) return -1;
169 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetPowerUsage (device
, power
);
171 if (nvml_rc
!= NVML_SUCCESS
)
175 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
177 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerUsage()", nvml_rc, string);
183 nvmlReturn_t
hm_NVML_nvmlDeviceGetUtilizationRates (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlUtilization_t
*utilization
)
185 if (!nvml
) return -1;
187 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetUtilizationRates (device
, utilization
);
189 if (nvml_rc
!= NVML_SUCCESS
)
191 utilization
->gpu
= -1;
192 utilization
->memory
= -1;
194 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
196 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);