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)
35 HC_LOAD_FUNC(nvml
, nvmlDeviceGetClockInfo
, NVML_DEVICE_GET_CLOCKINFO
, NVML
, 0)
36 HC_LOAD_FUNC(nvml
, nvmlDeviceGetTemperatureThreshold
, NVML_DEVICE_GET_THRESHOLD
, NVML
, 0)
37 HC_LOAD_FUNC(nvml
, nvmlDeviceGetCurrPcieLinkGeneration
, NVML_DEVICE_GET_CURRPCIELINKGENERATION
, NVML
, 0)
38 HC_LOAD_FUNC(nvml
, nvmlDeviceGetCurrPcieLinkWidth
, NVML_DEVICE_GET_CURRPCIELINKWIDTH
, NVML
, 0)
43 void nvml_close (NVML_PTR
*nvml
)
48 hc_dlclose (nvml
->lib
);
54 const char *hm_NVML_nvmlErrorString (NVML_PTR
*nvml
, nvmlReturn_t nvml_rc
)
56 if (!nvml
) return NULL
;
58 return nvml
->nvmlErrorString (nvml_rc
);
61 nvmlReturn_t
hm_NVML_nvmlInit (NVML_PTR
*nvml
)
65 nvmlReturn_t nvml_rc
= nvml
->nvmlInit ();
67 if (nvml_rc
!= NVML_SUCCESS
)
69 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
71 log_info ("WARN: %s %d %s\n", "nvmlInit()", nvml_rc
, string
);
77 nvmlReturn_t
hm_NVML_nvmlShutdown (NVML_PTR
*nvml
)
81 nvmlReturn_t nvml_rc
= nvml
->nvmlShutdown ();
83 if (nvml_rc
!= NVML_SUCCESS
)
85 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
87 log_info ("WARN: %s %d %s\n", "nvmlShutdown()", nvml_rc
, string
);
93 nvmlReturn_t
hm_NVML_nvmlDeviceGetName (NVML_PTR
*nvml
, nvmlDevice_t device
, char *name
, unsigned int length
)
97 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetName (device
, name
, length
);
99 if (nvml_rc
!= NVML_SUCCESS
)
101 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
103 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetName()", nvml_rc
, string
);
109 nvmlReturn_t
hm_NVML_nvmlDeviceGetHandleByIndex (NVML_PTR
*nvml
, int skip_warnings
, unsigned int index
, nvmlDevice_t
*device
)
111 if (!nvml
) return -1;
113 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetHandleByIndex (index
, device
);
115 if (nvml_rc
!= NVML_SUCCESS
)
117 if (skip_warnings
== 0)
119 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
121 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetHandleByIndex()", nvml_rc
, string
);
128 nvmlReturn_t
hm_NVML_nvmlDeviceGetTemperature (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlTemperatureSensors_t sensorType
, unsigned int *temp
)
130 if (!nvml
) return -1;
132 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetTemperature (device
, sensorType
, temp
);
134 if (nvml_rc
!= NVML_SUCCESS
)
138 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
140 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetTemperature()", nvml_rc, string);
146 nvmlReturn_t
hm_NVML_nvmlDeviceGetFanSpeed (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *speed
)
148 if (!nvml
) return -1;
150 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetFanSpeed (device
, speed
);
152 if (nvml_rc
!= NVML_SUCCESS
)
156 if (skip_warnings
== 0)
158 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
160 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetFanSpeed()", nvml_rc
, string
);
167 /* only tesla following */
169 nvmlReturn_t
hm_NVML_nvmlDeviceGetPowerUsage (NVML_PTR
*nvml
, nvmlDevice_t device
, unsigned int *power
)
171 if (!nvml
) return -1;
173 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetPowerUsage (device
, power
);
175 if (nvml_rc
!= NVML_SUCCESS
)
179 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
181 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerUsage()", nvml_rc, string);
187 nvmlReturn_t
hm_NVML_nvmlDeviceGetUtilizationRates (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlUtilization_t
*utilization
)
189 if (!nvml
) return -1;
191 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetUtilizationRates (device
, utilization
);
193 if (nvml_rc
!= NVML_SUCCESS
)
195 utilization
->gpu
= -1;
196 utilization
->memory
= -1;
198 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
200 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);
206 nvmlReturn_t
hm_NVML_nvmlDeviceGetClockInfo (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlClockType_t type
, unsigned int *clock
)
208 if (!nvml
) return -1;
210 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetClockInfo (device
, type
, clock
);
212 if (nvml_rc
!= NVML_SUCCESS
)
216 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
218 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);
224 nvmlReturn_t
hm_NVML_nvmlDeviceGetTemperatureThreshold (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlTemperatureThresholds_t thresholdType
, unsigned int *temp
)
226 if (!nvml
) return -1;
228 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetTemperatureThreshold (device
, thresholdType
, temp
);
230 if (nvml_rc
!= NVML_SUCCESS
)
234 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
236 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);
242 nvmlReturn_t
hm_NVML_nvmlDeviceGetCurrPcieLinkGeneration (NVML_PTR
*nvml
, nvmlDevice_t device
, unsigned int *currLinkGen
)
244 if (!nvml
) return -1;
246 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetCurrPcieLinkGeneration (device
, currLinkGen
);
248 if (nvml_rc
!= NVML_SUCCESS
)
252 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
254 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);
260 nvmlReturn_t
hm_NVML_nvmlDeviceGetCurrPcieLinkWidth (NVML_PTR
*nvml
, nvmlDevice_t device
, unsigned int *currLinkWidth
)
262 if (!nvml
) return -1;
264 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetCurrPcieLinkWidth (device
, currLinkWidth
);
266 if (nvml_rc
!= NVML_SUCCESS
)
270 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
272 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);