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
));
17 nvml
->lib
= hc_dlopen ("nvml.dll");
21 DWORD BufferSize
= 1024;
23 char *Buffer
= (char *) mymalloc (BufferSize
);
25 RegGetValue (HKEY_LOCAL_MACHINE
, "SOFTWARE\\NVIDIA Corporation\\Global\\NVSMI", "NVSMIPATH", RRF_RT_ANY
, NULL
, (PVOID
) Buffer
, &BufferSize
);
27 strcat (Buffer
, "\\nvml.dll");
29 nvml
->lib
= hc_dlopen (Buffer
);
35 nvml
->lib
= hc_dlopen ("libnvidia-ml.so", RTLD_NOW
);
41 log_info ("WARNING: NVML library load failed, proceed without NVML HWMon enabled.");
46 HC_LOAD_FUNC(nvml
, nvmlErrorString
, NVML_ERROR_STRING
, NVML
, 0)
47 HC_LOAD_FUNC(nvml
, nvmlInit
, NVML_INIT
, NVML
, 0)
48 HC_LOAD_FUNC(nvml
, nvmlShutdown
, NVML_SHUTDOWN
, NVML
, 0)
49 HC_LOAD_FUNC(nvml
, nvmlDeviceGetName
, NVML_DEVICE_GET_NAME
, NVML
, 0)
50 HC_LOAD_FUNC(nvml
, nvmlDeviceGetHandleByIndex
, NVML_DEVICE_GET_HANDLE_BY_INDEX
, NVML
, 0)
51 HC_LOAD_FUNC(nvml
, nvmlDeviceGetTemperature
, NVML_DEVICE_GET_TEMPERATURE
, NVML
, 0)
52 HC_LOAD_FUNC(nvml
, nvmlDeviceGetFanSpeed
, NVML_DEVICE_GET_FAN_SPEED
, NVML
, 0)
53 HC_LOAD_FUNC(nvml
, nvmlDeviceGetPowerUsage
, NVML_DEVICE_GET_POWER_USAGE
, NVML
, 0)
54 HC_LOAD_FUNC(nvml
, nvmlDeviceGetUtilizationRates
, NVML_DEVICE_GET_UTILIZATION_RATES
, NVML
, 0)
55 HC_LOAD_FUNC(nvml
, nvmlDeviceGetClockInfo
, NVML_DEVICE_GET_CLOCKINFO
, NVML
, 0)
56 HC_LOAD_FUNC(nvml
, nvmlDeviceGetTemperatureThreshold
, NVML_DEVICE_GET_THRESHOLD
, NVML
, 0)
57 HC_LOAD_FUNC(nvml
, nvmlDeviceGetCurrPcieLinkGeneration
, NVML_DEVICE_GET_CURRPCIELINKGENERATION
, NVML
, 0)
58 HC_LOAD_FUNC(nvml
, nvmlDeviceGetCurrPcieLinkWidth
, NVML_DEVICE_GET_CURRPCIELINKWIDTH
, NVML
, 0)
59 HC_LOAD_FUNC(nvml
, nvmlDeviceGetCurrentClocksThrottleReasons
, NVML_DEVICE_GET_CURRENTCLOCKSTHROTTLEREASONS
, NVML
, 0)
60 HC_LOAD_FUNC(nvml
, nvmlDeviceGetSupportedClocksThrottleReasons
, NVML_DEVICE_GET_SUPPORTEDCLOCKSTHROTTLEREASONS
, NVML
, 0)
61 HC_LOAD_FUNC(nvml
, nvmlDeviceSetComputeMode
, NVML_DEVICE_SET_COMPUTEMODE
, NVML
, 0)
62 HC_LOAD_FUNC(nvml
, nvmlDeviceSetGpuOperationMode
, NVML_DEVICE_SET_OPERATIONMODE
, NVML
, 0)
63 HC_LOAD_FUNC(nvml
, nvmlDeviceGetPowerManagementLimitConstraints
, NVML_DEVICE_GET_POWERMANAGEMENTLIMITCONSTRAINTS
, NVML
, 0)
64 HC_LOAD_FUNC(nvml
, nvmlDeviceSetPowerManagementLimit
, NVML_DEVICE_SET_POWERMANAGEMENTLIMIT
, NVML
, 0)
65 HC_LOAD_FUNC(nvml
, nvmlDeviceGetPowerManagementLimit
, NVML_DEVICE_GET_POWERMANAGEMENTLIMIT
, NVML
, 0)
70 void nvml_close (NVML_PTR
*nvml
)
75 hc_dlclose (nvml
->lib
);
81 const char *hm_NVML_nvmlErrorString (NVML_PTR
*nvml
, nvmlReturn_t nvml_rc
)
83 if (!nvml
) return NULL
;
85 return nvml
->nvmlErrorString (nvml_rc
);
88 nvmlReturn_t
hm_NVML_nvmlInit (NVML_PTR
*nvml
)
92 nvmlReturn_t nvml_rc
= nvml
->nvmlInit ();
94 if (nvml_rc
!= NVML_SUCCESS
)
96 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
98 log_info ("WARN: %s %d %s\n", "nvmlInit()", nvml_rc
, string
);
104 nvmlReturn_t
hm_NVML_nvmlShutdown (NVML_PTR
*nvml
)
106 if (!nvml
) return -1;
108 nvmlReturn_t nvml_rc
= nvml
->nvmlShutdown ();
110 if (nvml_rc
!= NVML_SUCCESS
)
112 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
114 log_info ("WARN: %s %d %s\n", "nvmlShutdown()", nvml_rc
, string
);
120 nvmlReturn_t
hm_NVML_nvmlDeviceGetName (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, char *name
, unsigned int length
)
122 if (!nvml
) return -1;
124 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetName (device
, name
, length
);
126 if (nvml_rc
!= NVML_SUCCESS
)
128 if (skip_warnings
== 0)
130 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
132 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetName()", nvml_rc
, string
);
139 nvmlReturn_t
hm_NVML_nvmlDeviceGetHandleByIndex (NVML_PTR
*nvml
, int skip_warnings
, unsigned int index
, nvmlDevice_t
*device
)
141 if (!nvml
) return -1;
143 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetHandleByIndex (index
, device
);
145 if (nvml_rc
!= NVML_SUCCESS
)
147 if (skip_warnings
== 0)
149 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
151 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetHandleByIndex()", nvml_rc
, string
);
158 nvmlReturn_t
hm_NVML_nvmlDeviceGetTemperature (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, nvmlTemperatureSensors_t sensorType
, unsigned int *temp
)
160 if (!nvml
) return -1;
162 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetTemperature (device
, sensorType
, temp
);
164 if (nvml_rc
!= NVML_SUCCESS
)
166 if (skip_warnings
== 0)
168 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
170 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetTemperature()", nvml_rc
, string
);
177 nvmlReturn_t
hm_NVML_nvmlDeviceGetFanSpeed (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *speed
)
179 if (!nvml
) return -1;
181 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetFanSpeed (device
, speed
);
183 if (nvml_rc
!= NVML_SUCCESS
)
185 if (skip_warnings
== 0)
187 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
189 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetFanSpeed()", nvml_rc
, string
);
196 nvmlReturn_t
hm_NVML_nvmlDeviceGetPowerUsage (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *power
)
198 if (!nvml
) return -1;
200 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetPowerUsage (device
, power
);
202 if (nvml_rc
!= NVML_SUCCESS
)
204 if (skip_warnings
== 0)
206 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
208 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerUsage()", nvml_rc
, string
);
215 nvmlReturn_t
hm_NVML_nvmlDeviceGetUtilizationRates (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, nvmlUtilization_t
*utilization
)
217 if (!nvml
) return -1;
219 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetUtilizationRates (device
, utilization
);
221 if (nvml_rc
!= NVML_SUCCESS
)
223 if (skip_warnings
== 0)
225 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
227 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc
, string
);
234 nvmlReturn_t
hm_NVML_nvmlDeviceGetClockInfo (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, nvmlClockType_t type
, unsigned int *clock
)
236 if (!nvml
) return -1;
238 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetClockInfo (device
, type
, clock
);
240 if (nvml_rc
!= NVML_SUCCESS
)
242 if (skip_warnings
== 0)
244 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
246 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetClockInfo()", nvml_rc
, string
);
253 nvmlReturn_t
hm_NVML_nvmlDeviceGetTemperatureThreshold (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, nvmlTemperatureThresholds_t thresholdType
, unsigned int *temp
)
255 if (!nvml
) return -1;
257 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetTemperatureThreshold (device
, thresholdType
, temp
);
259 if (nvml_rc
!= NVML_SUCCESS
)
261 if (skip_warnings
== 0)
263 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
265 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetTemperatureThreshold()", nvml_rc
, string
);
272 nvmlReturn_t
hm_NVML_nvmlDeviceGetCurrPcieLinkGeneration (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *currLinkGen
)
274 if (!nvml
) return -1;
276 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetCurrPcieLinkGeneration (device
, currLinkGen
);
278 if (nvml_rc
!= NVML_SUCCESS
)
280 if (skip_warnings
== 0)
282 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
284 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetCurrPcieLinkGeneration()", nvml_rc
, string
);
291 nvmlReturn_t
hm_NVML_nvmlDeviceGetCurrPcieLinkWidth (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *currLinkWidth
)
293 if (!nvml
) return -1;
295 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetCurrPcieLinkWidth (device
, currLinkWidth
);
297 if (nvml_rc
!= NVML_SUCCESS
)
299 if (skip_warnings
== 0)
301 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
303 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetCurrPcieLinkWidth()", nvml_rc
, string
);
310 nvmlReturn_t
hm_NVML_nvmlDeviceGetCurrentClocksThrottleReasons (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned long long *clocksThrottleReasons
)
312 if (!nvml
) return -1;
314 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetCurrentClocksThrottleReasons (device
, clocksThrottleReasons
);
316 if (nvml_rc
!= NVML_SUCCESS
)
318 if (skip_warnings
== 0)
320 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
322 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetCurrentClocksThrottleReasons()", nvml_rc
, string
);
329 nvmlReturn_t
hm_NVML_nvmlDeviceGetSupportedClocksThrottleReasons (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned long long *supportedClocksThrottleReasons
)
331 if (!nvml
) return -1;
333 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetSupportedClocksThrottleReasons (device
, supportedClocksThrottleReasons
);
335 if (nvml_rc
!= NVML_SUCCESS
)
337 if (skip_warnings
== 0)
339 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
341 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetSupportedClocksThrottleReasons()", nvml_rc
, string
);
348 nvmlReturn_t
hm_NVML_nvmlDeviceSetComputeMode (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, nvmlComputeMode_t mode
)
350 if (!nvml
) return -1;
352 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceSetComputeMode (device
, mode
);
354 if (nvml_rc
!= NVML_SUCCESS
)
356 if (skip_warnings
== 0)
358 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
360 log_info ("WARN: %s %d %s\n", "nvmlDeviceSetComputeMode()", nvml_rc
, string
);
367 nvmlReturn_t
hm_NVML_nvmlDeviceSetGpuOperationMode (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, nvmlGpuOperationMode_t mode
)
369 if (!nvml
) return -1;
371 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceSetGpuOperationMode (device
, mode
);
373 if (nvml_rc
!= NVML_SUCCESS
)
375 if (skip_warnings
== 0)
377 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
379 log_info ("WARN: %s %d %s\n", "nvmlDeviceSetGpuOperationMode()", nvml_rc
, string
);
386 nvmlReturn_t
hm_NVML_nvmlDeviceGetPowerManagementLimitConstraints (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *minLimit
, unsigned int *maxLimit
)
388 if (!nvml
) return -1;
390 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetPowerManagementLimitConstraints (device
, minLimit
, maxLimit
);
392 if (nvml_rc
!= NVML_SUCCESS
)
394 if (skip_warnings
== 0)
396 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
398 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerManagementLimitConstraints()", nvml_rc
, string
);
405 nvmlReturn_t
hm_NVML_nvmlDeviceSetPowerManagementLimit (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int limit
)
407 if (!nvml
) return -1;
409 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceSetPowerManagementLimit (device
, limit
);
411 if (nvml_rc
!= NVML_SUCCESS
)
413 if (skip_warnings
== 0)
415 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
417 log_info ("WARN: %s %d %s\n", "nvmlDeviceSetPowerManagementLimit()", nvml_rc
, string
);
424 nvmlReturn_t
hm_NVML_nvmlDeviceGetPowerManagementLimit (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *limit
)
426 if (!nvml
) return -1;
428 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetPowerManagementLimit (device
, limit
);
430 if (nvml_rc
!= NVML_SUCCESS
)
432 if (skip_warnings
== 0)
434 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
436 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerManagementLimit()", nvml_rc
, string
);