2 * Authors.....: Jens Steube <jens.steube@gmail.com>
3 * Gabriele Gristina <matrix@hashcat.net>
10 int nvml_init (NVML_PTR
*nvml
)
14 memset (nvml
, 0, sizeof (NVML_PTR
));
17 nvml
->lib
= hc_dlopen ("nvml.dll");
21 DWORD BufferSize
= 1024;
25 char *Buffer
= (char *) mymalloc (BufferSize
+ 1);
29 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE
, TEXT("SOFTWARE\\NVIDIA Corporation\\Global\\NVSMI"), 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
)
31 if (RegQueryValueEx (hKey
, TEXT("NVSMIPATH"), NULL
, &Type
, (PVOID
) Buffer
, &BufferSize
) == ERROR_SUCCESS
)
33 Buffer
[BufferSize
] = 0;
38 log_info ("WARNING: NVML library load failed, proceed without NVML HWMon enabled.");
48 log_info ("WARNING: NVML library load failed, proceed without NVML HWMon enabled.");
53 strcat (Buffer
, "\\nvml.dll");
55 nvml
->lib
= hc_dlopen (Buffer
);
61 nvml
->lib
= hc_dlopen ("libnvidia-ml.so", RTLD_NOW
);
67 log_info ("WARNING: NVML library load failed, proceed without NVML HWMon enabled.");
72 HC_LOAD_FUNC(nvml
, nvmlErrorString
, NVML_ERROR_STRING
, NVML
, 0)
73 HC_LOAD_FUNC(nvml
, nvmlInit
, NVML_INIT
, NVML
, 0)
74 HC_LOAD_FUNC(nvml
, nvmlShutdown
, NVML_SHUTDOWN
, NVML
, 0)
75 HC_LOAD_FUNC(nvml
, nvmlDeviceGetName
, NVML_DEVICE_GET_NAME
, NVML
, 0)
76 HC_LOAD_FUNC(nvml
, nvmlDeviceGetHandleByIndex
, NVML_DEVICE_GET_HANDLE_BY_INDEX
, NVML
, 0)
77 HC_LOAD_FUNC(nvml
, nvmlDeviceGetTemperature
, NVML_DEVICE_GET_TEMPERATURE
, NVML
, 0)
78 HC_LOAD_FUNC(nvml
, nvmlDeviceGetFanSpeed
, NVML_DEVICE_GET_FAN_SPEED
, NVML
, 0)
79 HC_LOAD_FUNC(nvml
, nvmlDeviceGetPowerUsage
, NVML_DEVICE_GET_POWER_USAGE
, NVML
, 0)
80 HC_LOAD_FUNC(nvml
, nvmlDeviceGetUtilizationRates
, NVML_DEVICE_GET_UTILIZATION_RATES
, NVML
, 0)
81 HC_LOAD_FUNC(nvml
, nvmlDeviceGetClockInfo
, NVML_DEVICE_GET_CLOCKINFO
, NVML
, 0)
82 HC_LOAD_FUNC(nvml
, nvmlDeviceGetTemperatureThreshold
, NVML_DEVICE_GET_THRESHOLD
, NVML
, 0)
83 HC_LOAD_FUNC(nvml
, nvmlDeviceGetCurrPcieLinkGeneration
, NVML_DEVICE_GET_CURRPCIELINKGENERATION
, NVML
, 0)
84 HC_LOAD_FUNC(nvml
, nvmlDeviceGetCurrPcieLinkWidth
, NVML_DEVICE_GET_CURRPCIELINKWIDTH
, NVML
, 0)
85 HC_LOAD_FUNC(nvml
, nvmlDeviceGetCurrentClocksThrottleReasons
, NVML_DEVICE_GET_CURRENTCLOCKSTHROTTLEREASONS
, NVML
, 0)
86 HC_LOAD_FUNC(nvml
, nvmlDeviceGetSupportedClocksThrottleReasons
, NVML_DEVICE_GET_SUPPORTEDCLOCKSTHROTTLEREASONS
, NVML
, 0)
87 HC_LOAD_FUNC(nvml
, nvmlDeviceSetComputeMode
, NVML_DEVICE_SET_COMPUTEMODE
, NVML
, 0)
88 HC_LOAD_FUNC(nvml
, nvmlDeviceSetGpuOperationMode
, NVML_DEVICE_SET_OPERATIONMODE
, NVML
, 0)
89 HC_LOAD_FUNC(nvml
, nvmlDeviceGetPowerManagementLimitConstraints
, NVML_DEVICE_GET_POWERMANAGEMENTLIMITCONSTRAINTS
, NVML
, 0)
90 HC_LOAD_FUNC(nvml
, nvmlDeviceSetPowerManagementLimit
, NVML_DEVICE_SET_POWERMANAGEMENTLIMIT
, NVML
, 0)
91 HC_LOAD_FUNC(nvml
, nvmlDeviceGetPowerManagementLimit
, NVML_DEVICE_GET_POWERMANAGEMENTLIMIT
, NVML
, 0)
96 void nvml_close (NVML_PTR
*nvml
)
101 hc_dlclose (nvml
->lib
);
107 const char *hm_NVML_nvmlErrorString (NVML_PTR
*nvml
, nvmlReturn_t nvml_rc
)
109 if (!nvml
) return NULL
;
111 return nvml
->nvmlErrorString (nvml_rc
);
114 nvmlReturn_t
hm_NVML_nvmlInit (NVML_PTR
*nvml
)
116 if (!nvml
) return -1;
118 nvmlReturn_t nvml_rc
= nvml
->nvmlInit ();
120 if (nvml_rc
!= NVML_SUCCESS
)
122 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
124 log_info ("WARN: %s %d %s\n", "nvmlInit()", nvml_rc
, string
);
130 nvmlReturn_t
hm_NVML_nvmlShutdown (NVML_PTR
*nvml
)
132 if (!nvml
) return -1;
134 nvmlReturn_t nvml_rc
= nvml
->nvmlShutdown ();
136 if (nvml_rc
!= NVML_SUCCESS
)
138 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
140 log_info ("WARN: %s %d %s\n", "nvmlShutdown()", nvml_rc
, string
);
146 nvmlReturn_t
hm_NVML_nvmlDeviceGetName (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, char *name
, unsigned int length
)
148 if (!nvml
) return -1;
150 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetName (device
, name
, length
);
152 if (nvml_rc
!= NVML_SUCCESS
)
154 if (skip_warnings
== 0)
156 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
158 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetName()", nvml_rc
, string
);
165 nvmlReturn_t
hm_NVML_nvmlDeviceGetHandleByIndex (NVML_PTR
*nvml
, int skip_warnings
, unsigned int index
, nvmlDevice_t
*device
)
167 if (!nvml
) return -1;
169 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetHandleByIndex (index
, device
);
171 if (nvml_rc
!= NVML_SUCCESS
)
173 if (skip_warnings
== 0)
175 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
177 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetHandleByIndex()", nvml_rc
, string
);
184 nvmlReturn_t
hm_NVML_nvmlDeviceGetTemperature (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, nvmlTemperatureSensors_t sensorType
, unsigned int *temp
)
186 if (!nvml
) return -1;
188 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetTemperature (device
, sensorType
, temp
);
190 if (nvml_rc
!= NVML_SUCCESS
)
192 if (skip_warnings
== 0)
194 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
196 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetTemperature()", nvml_rc
, string
);
203 nvmlReturn_t
hm_NVML_nvmlDeviceGetFanSpeed (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *speed
)
205 if (!nvml
) return -1;
207 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetFanSpeed (device
, speed
);
209 if (nvml_rc
!= NVML_SUCCESS
)
211 if (skip_warnings
== 0)
213 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
215 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetFanSpeed()", nvml_rc
, string
);
222 nvmlReturn_t
hm_NVML_nvmlDeviceGetPowerUsage (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *power
)
224 if (!nvml
) return -1;
226 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetPowerUsage (device
, power
);
228 if (nvml_rc
!= NVML_SUCCESS
)
230 if (skip_warnings
== 0)
232 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
234 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerUsage()", nvml_rc
, string
);
241 nvmlReturn_t
hm_NVML_nvmlDeviceGetUtilizationRates (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, nvmlUtilization_t
*utilization
)
243 if (!nvml
) return -1;
245 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetUtilizationRates (device
, utilization
);
247 if (nvml_rc
!= NVML_SUCCESS
)
249 if (skip_warnings
== 0)
251 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
253 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc
, string
);
260 nvmlReturn_t
hm_NVML_nvmlDeviceGetClockInfo (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, nvmlClockType_t type
, unsigned int *clock
)
262 if (!nvml
) return -1;
264 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetClockInfo (device
, type
, clock
);
266 if (nvml_rc
!= NVML_SUCCESS
)
268 if (skip_warnings
== 0)
270 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
272 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetClockInfo()", nvml_rc
, string
);
279 nvmlReturn_t
hm_NVML_nvmlDeviceGetTemperatureThreshold (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, nvmlTemperatureThresholds_t thresholdType
, unsigned int *temp
)
281 if (!nvml
) return -1;
283 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetTemperatureThreshold (device
, thresholdType
, temp
);
285 if (nvml_rc
!= NVML_SUCCESS
)
287 if (skip_warnings
== 0)
289 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
291 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetTemperatureThreshold()", nvml_rc
, string
);
298 nvmlReturn_t
hm_NVML_nvmlDeviceGetCurrPcieLinkGeneration (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *currLinkGen
)
300 if (!nvml
) return -1;
302 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetCurrPcieLinkGeneration (device
, currLinkGen
);
304 if (nvml_rc
!= NVML_SUCCESS
)
306 if (skip_warnings
== 0)
308 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
310 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetCurrPcieLinkGeneration()", nvml_rc
, string
);
317 nvmlReturn_t
hm_NVML_nvmlDeviceGetCurrPcieLinkWidth (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *currLinkWidth
)
319 if (!nvml
) return -1;
321 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetCurrPcieLinkWidth (device
, currLinkWidth
);
323 if (nvml_rc
!= NVML_SUCCESS
)
325 if (skip_warnings
== 0)
327 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
329 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetCurrPcieLinkWidth()", nvml_rc
, string
);
336 nvmlReturn_t
hm_NVML_nvmlDeviceGetCurrentClocksThrottleReasons (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned long long *clocksThrottleReasons
)
338 if (!nvml
) return -1;
340 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetCurrentClocksThrottleReasons (device
, clocksThrottleReasons
);
342 if (nvml_rc
!= NVML_SUCCESS
)
344 if (skip_warnings
== 0)
346 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
348 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetCurrentClocksThrottleReasons()", nvml_rc
, string
);
355 nvmlReturn_t
hm_NVML_nvmlDeviceGetSupportedClocksThrottleReasons (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned long long *supportedClocksThrottleReasons
)
357 if (!nvml
) return -1;
359 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetSupportedClocksThrottleReasons (device
, supportedClocksThrottleReasons
);
361 if (nvml_rc
!= NVML_SUCCESS
)
363 if (skip_warnings
== 0)
365 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
367 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetSupportedClocksThrottleReasons()", nvml_rc
, string
);
374 nvmlReturn_t
hm_NVML_nvmlDeviceSetComputeMode (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, nvmlComputeMode_t mode
)
376 if (!nvml
) return -1;
378 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceSetComputeMode (device
, mode
);
380 if (nvml_rc
!= NVML_SUCCESS
)
382 if (skip_warnings
== 0)
384 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
386 log_info ("WARN: %s %d %s\n", "nvmlDeviceSetComputeMode()", nvml_rc
, string
);
393 nvmlReturn_t
hm_NVML_nvmlDeviceSetGpuOperationMode (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, nvmlGpuOperationMode_t mode
)
395 if (!nvml
) return -1;
397 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceSetGpuOperationMode (device
, mode
);
399 if (nvml_rc
!= NVML_SUCCESS
)
401 if (skip_warnings
== 0)
403 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
405 log_info ("WARN: %s %d %s\n", "nvmlDeviceSetGpuOperationMode()", nvml_rc
, string
);
412 nvmlReturn_t
hm_NVML_nvmlDeviceGetPowerManagementLimitConstraints (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *minLimit
, unsigned int *maxLimit
)
414 if (!nvml
) return -1;
416 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetPowerManagementLimitConstraints (device
, minLimit
, maxLimit
);
418 if (nvml_rc
!= NVML_SUCCESS
)
420 if (skip_warnings
== 0)
422 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
424 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerManagementLimitConstraints()", nvml_rc
, string
);
431 nvmlReturn_t
hm_NVML_nvmlDeviceSetPowerManagementLimit (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int limit
)
433 if (!nvml
) return -1;
435 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceSetPowerManagementLimit (device
, limit
);
437 if (nvml_rc
!= NVML_SUCCESS
)
439 if (skip_warnings
== 0)
441 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
443 log_info ("WARN: %s %d %s\n", "nvmlDeviceSetPowerManagementLimit()", nvml_rc
, string
);
450 nvmlReturn_t
hm_NVML_nvmlDeviceGetPowerManagementLimit (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *limit
)
452 if (!nvml
) return -1;
454 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetPowerManagementLimit (device
, limit
);
456 if (nvml_rc
!= NVML_SUCCESS
)
458 if (skip_warnings
== 0)
460 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
462 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerManagementLimit()", nvml_rc
, string
);