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: load NVML library 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)
69 void nvml_close (NVML_PTR
*nvml
)
74 hc_dlclose (nvml
->lib
);
80 const char *hm_NVML_nvmlErrorString (NVML_PTR
*nvml
, nvmlReturn_t nvml_rc
)
82 if (!nvml
) return NULL
;
84 return nvml
->nvmlErrorString (nvml_rc
);
87 nvmlReturn_t
hm_NVML_nvmlInit (NVML_PTR
*nvml
)
91 nvmlReturn_t nvml_rc
= nvml
->nvmlInit ();
93 if (nvml_rc
!= NVML_SUCCESS
)
95 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
97 log_info ("WARN: %s %d %s\n", "nvmlInit()", nvml_rc
, string
);
103 nvmlReturn_t
hm_NVML_nvmlShutdown (NVML_PTR
*nvml
)
105 if (!nvml
) return -1;
107 nvmlReturn_t nvml_rc
= nvml
->nvmlShutdown ();
109 if (nvml_rc
!= NVML_SUCCESS
)
111 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
113 log_info ("WARN: %s %d %s\n", "nvmlShutdown()", nvml_rc
, string
);
119 nvmlReturn_t
hm_NVML_nvmlDeviceGetName (NVML_PTR
*nvml
, nvmlDevice_t device
, char *name
, unsigned int length
)
121 if (!nvml
) return -1;
123 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetName (device
, name
, length
);
125 if (nvml_rc
!= NVML_SUCCESS
)
127 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
129 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetName()", nvml_rc
, string
);
135 nvmlReturn_t
hm_NVML_nvmlDeviceGetHandleByIndex (NVML_PTR
*nvml
, int skip_warnings
, unsigned int index
, nvmlDevice_t
*device
)
137 if (!nvml
) return -1;
139 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetHandleByIndex (index
, device
);
141 if (nvml_rc
!= NVML_SUCCESS
)
143 if (skip_warnings
== 0)
145 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
147 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetHandleByIndex()", nvml_rc
, string
);
154 nvmlReturn_t
hm_NVML_nvmlDeviceGetTemperature (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlTemperatureSensors_t sensorType
, unsigned int *temp
)
156 if (!nvml
) return -1;
158 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetTemperature (device
, sensorType
, temp
);
160 if (nvml_rc
!= NVML_SUCCESS
)
162 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
164 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetTemperature()", nvml_rc
, string
);
170 nvmlReturn_t
hm_NVML_nvmlDeviceGetFanSpeed (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *speed
)
172 if (!nvml
) return -1;
174 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetFanSpeed (device
, speed
);
176 if (nvml_rc
!= NVML_SUCCESS
)
178 if (skip_warnings
== 0)
180 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
182 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetFanSpeed()", nvml_rc
, string
);
189 nvmlReturn_t
hm_NVML_nvmlDeviceGetPowerUsage (NVML_PTR
*nvml
, nvmlDevice_t device
, unsigned int *power
)
191 if (!nvml
) return -1;
193 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetPowerUsage (device
, power
);
195 if (nvml_rc
!= NVML_SUCCESS
)
197 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
199 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerUsage()", nvml_rc
, string
);
205 nvmlReturn_t
hm_NVML_nvmlDeviceGetUtilizationRates (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlUtilization_t
*utilization
)
207 if (!nvml
) return -1;
209 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetUtilizationRates (device
, utilization
);
211 if (nvml_rc
!= NVML_SUCCESS
)
213 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
215 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc
, string
);
221 nvmlReturn_t
hm_NVML_nvmlDeviceGetClockInfo (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlClockType_t type
, unsigned int *clock
)
223 if (!nvml
) return -1;
225 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetClockInfo (device
, type
, clock
);
227 if (nvml_rc
!= NVML_SUCCESS
)
229 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
231 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc
, string
);
237 nvmlReturn_t
hm_NVML_nvmlDeviceGetTemperatureThreshold (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlTemperatureThresholds_t thresholdType
, unsigned int *temp
)
239 if (!nvml
) return -1;
241 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetTemperatureThreshold (device
, thresholdType
, temp
);
243 if (nvml_rc
!= NVML_SUCCESS
)
245 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
247 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetTemperatureThreshold()", nvml_rc
, string
);
253 nvmlReturn_t
hm_NVML_nvmlDeviceGetCurrPcieLinkGeneration (NVML_PTR
*nvml
, nvmlDevice_t device
, unsigned int *currLinkGen
)
255 if (!nvml
) return -1;
257 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetCurrPcieLinkGeneration (device
, currLinkGen
);
259 if (nvml_rc
!= NVML_SUCCESS
)
261 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
263 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc
, string
);
269 nvmlReturn_t
hm_NVML_nvmlDeviceGetCurrPcieLinkWidth (NVML_PTR
*nvml
, nvmlDevice_t device
, unsigned int *currLinkWidth
)
271 if (!nvml
) return -1;
273 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetCurrPcieLinkWidth (device
, currLinkWidth
);
275 if (nvml_rc
!= NVML_SUCCESS
)
277 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
279 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc
, string
);
285 nvmlReturn_t
hm_NVML_nvmlDeviceGetCurrentClocksThrottleReasons (NVML_PTR
*nvml
, nvmlDevice_t device
, unsigned long long *clocksThrottleReasons
)
287 if (!nvml
) return -1;
289 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetCurrentClocksThrottleReasons (device
, clocksThrottleReasons
);
291 if (nvml_rc
!= NVML_SUCCESS
)
293 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
295 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc
, string
);
301 nvmlReturn_t
hm_NVML_nvmlDeviceGetSupportedClocksThrottleReasons (NVML_PTR
*nvml
, nvmlDevice_t device
, unsigned long long *supportedClocksThrottleReasons
)
303 if (!nvml
) return -1;
305 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetSupportedClocksThrottleReasons (device
, supportedClocksThrottleReasons
);
307 if (nvml_rc
!= NVML_SUCCESS
)
309 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
311 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetSupportedClocksThrottleReasons()", nvml_rc
, string
);
317 nvmlReturn_t
hm_NVML_nvmlDeviceSetComputeMode (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, nvmlComputeMode_t mode
)
319 if (!nvml
) return -1;
321 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceSetComputeMode (device
, mode
);
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", "nvmlDeviceSetComputeMode()", nvml_rc
, string
);
336 nvmlReturn_t
hm_NVML_nvmlDeviceSetGpuOperationMode (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, nvmlGpuOperationMode_t mode
)
338 if (!nvml
) return -1;
340 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceSetGpuOperationMode (device
, mode
);
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", "nvmlDeviceSetGpuOperationMode()", nvml_rc
, string
);
355 nvmlReturn_t
hm_NVML_nvmlDeviceGetPowerManagementLimitConstraints (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *minLimit
, unsigned int *maxLimit
)
357 if (!nvml
) return -1;
359 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetPowerManagementLimitConstraints (device
, minLimit
, maxLimit
);
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", "nvmlDeviceGetPowerManagementLimitConstraints()", nvml_rc
, string
);
374 nvmlReturn_t
hm_NVML_nvmlDeviceSetPowerManagementLimit (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int limit
)
376 if (!nvml
) return -1;
378 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceSetPowerManagementLimit (device
, limit
);
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", "nvmlDeviceSetPowerManagementLimit()", nvml_rc
, string
);