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)
40 void nvml_close (NVML_PTR
*nvml
)
45 hc_dlclose (nvml
->lib
);
51 const char *hm_NVML_nvmlErrorString (NVML_PTR
*nvml
, nvmlReturn_t nvml_rc
)
53 if (!nvml
) return NULL
;
55 return nvml
->nvmlErrorString (nvml_rc
);
58 nvmlReturn_t
hm_NVML_nvmlInit (NVML_PTR
*nvml
)
62 nvmlReturn_t nvml_rc
= nvml
->nvmlInit ();
64 if (nvml_rc
!= NVML_SUCCESS
)
66 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
68 log_info ("WARN: %s %d %s\n", "nvmlInit()", nvml_rc
, string
);
74 nvmlReturn_t
hm_NVML_nvmlShutdown (NVML_PTR
*nvml
)
78 nvmlReturn_t nvml_rc
= nvml
->nvmlShutdown ();
80 if (nvml_rc
!= NVML_SUCCESS
)
82 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
84 log_info ("WARN: %s %d %s\n", "nvmlShutdown()", nvml_rc
, string
);
90 nvmlReturn_t
hm_NVML_nvmlDeviceGetName (NVML_PTR
*nvml
, nvmlDevice_t device
, char *name
, unsigned int length
)
94 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetName (device
, name
, length
);
96 if (nvml_rc
!= NVML_SUCCESS
)
98 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
100 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetName()", nvml_rc
, string
);
106 nvmlReturn_t
hm_NVML_nvmlDeviceGetHandleByIndex (NVML_PTR
*nvml
, int skip_warnings
, unsigned int index
, nvmlDevice_t
*device
)
108 if (!nvml
) return -1;
110 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetHandleByIndex (index
, device
);
112 if (nvml_rc
!= NVML_SUCCESS
)
114 if (skip_warnings
== 0)
116 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
118 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetHandleByIndex()", nvml_rc
, string
);
125 nvmlReturn_t
hm_NVML_nvmlDeviceGetTemperature (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlTemperatureSensors_t sensorType
, unsigned int *temp
)
127 if (!nvml
) return -1;
129 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetTemperature (device
, sensorType
, temp
);
131 if (nvml_rc
!= NVML_SUCCESS
)
135 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
137 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetTemperature()", nvml_rc, string);
143 nvmlReturn_t
hm_NVML_nvmlDeviceGetFanSpeed (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *speed
)
145 if (!nvml
) return -1;
147 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetFanSpeed (device
, speed
);
149 if (nvml_rc
!= NVML_SUCCESS
)
153 if (skip_warnings
== 0)
155 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
157 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetFanSpeed()", nvml_rc
, string
);
164 /* only tesla following */
166 nvmlReturn_t
hm_NVML_nvmlDeviceGetPowerUsage (NVML_PTR
*nvml
, nvmlDevice_t device
, unsigned int *power
)
168 if (!nvml
) return -1;
170 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetPowerUsage (device
, power
);
172 if (nvml_rc
!= NVML_SUCCESS
)
176 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
178 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerUsage()", nvml_rc, string);
184 nvmlReturn_t
hm_NVML_nvmlDeviceGetUtilizationRates (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlUtilization_t
*utilization
)
186 if (!nvml
) return -1;
188 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetUtilizationRates (device
, utilization
);
190 if (nvml_rc
!= NVML_SUCCESS
)
192 utilization
->gpu
= -1;
193 utilization
->memory
= -1;
195 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
197 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);
203 nvmlReturn_t
hm_NVML_nvmlDeviceGetClockInfo (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlClockType_t type
, unsigned int *clock
)
205 if (!nvml
) return -1;
207 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetClockInfo (device
, type
, clock
);
209 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);