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)
63 void nvml_close (NVML_PTR
*nvml
)
68 hc_dlclose (nvml
->lib
);
74 const char *hm_NVML_nvmlErrorString (NVML_PTR
*nvml
, nvmlReturn_t nvml_rc
)
76 if (!nvml
) return NULL
;
78 return nvml
->nvmlErrorString (nvml_rc
);
81 nvmlReturn_t
hm_NVML_nvmlInit (NVML_PTR
*nvml
)
85 nvmlReturn_t nvml_rc
= nvml
->nvmlInit ();
87 if (nvml_rc
!= NVML_SUCCESS
)
89 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
91 log_info ("WARN: %s %d %s\n", "nvmlInit()", nvml_rc
, string
);
97 nvmlReturn_t
hm_NVML_nvmlShutdown (NVML_PTR
*nvml
)
101 nvmlReturn_t nvml_rc
= nvml
->nvmlShutdown ();
103 if (nvml_rc
!= NVML_SUCCESS
)
105 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
107 log_info ("WARN: %s %d %s\n", "nvmlShutdown()", nvml_rc
, string
);
113 nvmlReturn_t
hm_NVML_nvmlDeviceGetName (NVML_PTR
*nvml
, nvmlDevice_t device
, char *name
, unsigned int length
)
115 if (!nvml
) return -1;
117 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetName (device
, name
, length
);
119 if (nvml_rc
!= NVML_SUCCESS
)
121 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
123 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetName()", nvml_rc
, string
);
129 nvmlReturn_t
hm_NVML_nvmlDeviceGetHandleByIndex (NVML_PTR
*nvml
, int skip_warnings
, unsigned int index
, nvmlDevice_t
*device
)
131 if (!nvml
) return -1;
133 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetHandleByIndex (index
, device
);
135 if (nvml_rc
!= NVML_SUCCESS
)
137 if (skip_warnings
== 0)
139 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
141 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetHandleByIndex()", nvml_rc
, string
);
148 nvmlReturn_t
hm_NVML_nvmlDeviceGetTemperature (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlTemperatureSensors_t sensorType
, unsigned int *temp
)
150 if (!nvml
) return -1;
152 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetTemperature (device
, sensorType
, temp
);
154 if (nvml_rc
!= NVML_SUCCESS
)
158 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
160 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetTemperature()", nvml_rc, string);
166 nvmlReturn_t
hm_NVML_nvmlDeviceGetFanSpeed (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *speed
)
168 if (!nvml
) return -1;
170 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetFanSpeed (device
, speed
);
172 if (nvml_rc
!= NVML_SUCCESS
)
176 if (skip_warnings
== 0)
178 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
180 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetFanSpeed()", nvml_rc
, string
);
187 /* only tesla following */
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
)
199 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
201 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerUsage()", nvml_rc, string);
207 nvmlReturn_t
hm_NVML_nvmlDeviceGetUtilizationRates (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlUtilization_t
*utilization
)
209 if (!nvml
) return -1;
211 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetUtilizationRates (device
, utilization
);
213 if (nvml_rc
!= NVML_SUCCESS
)
215 utilization
->gpu
= -1;
216 utilization
->memory
= -1;
218 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
220 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);
226 nvmlReturn_t
hm_NVML_nvmlDeviceGetClockInfo (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlClockType_t type
, unsigned int *clock
)
228 if (!nvml
) return -1;
230 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetClockInfo (device
, type
, clock
);
232 if (nvml_rc
!= NVML_SUCCESS
)
236 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
238 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);
244 nvmlReturn_t
hm_NVML_nvmlDeviceGetTemperatureThreshold (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlTemperatureThresholds_t thresholdType
, unsigned int *temp
)
246 if (!nvml
) return -1;
248 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetTemperatureThreshold (device
, thresholdType
, temp
);
250 if (nvml_rc
!= NVML_SUCCESS
)
254 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
256 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);
262 nvmlReturn_t
hm_NVML_nvmlDeviceGetCurrPcieLinkGeneration (NVML_PTR
*nvml
, nvmlDevice_t device
, unsigned int *currLinkGen
)
264 if (!nvml
) return -1;
266 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetCurrPcieLinkGeneration (device
, currLinkGen
);
268 if (nvml_rc
!= NVML_SUCCESS
)
272 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
274 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);
280 nvmlReturn_t
hm_NVML_nvmlDeviceGetCurrPcieLinkWidth (NVML_PTR
*nvml
, nvmlDevice_t device
, unsigned int *currLinkWidth
)
282 if (!nvml
) return -1;
284 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetCurrPcieLinkWidth (device
, currLinkWidth
);
286 if (nvml_rc
!= NVML_SUCCESS
)
290 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
292 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);