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)
36 HC_LOAD_FUNC(nvml
, nvmlDeviceGetTemperatureThreshold
, NVML_DEVICE_GET_THRESHOLD
, NVML
, 0)
41 void nvml_close (NVML_PTR
*nvml
)
46 hc_dlclose (nvml
->lib
);
52 const char *hm_NVML_nvmlErrorString (NVML_PTR
*nvml
, nvmlReturn_t nvml_rc
)
54 if (!nvml
) return NULL
;
56 return nvml
->nvmlErrorString (nvml_rc
);
59 nvmlReturn_t
hm_NVML_nvmlInit (NVML_PTR
*nvml
)
63 nvmlReturn_t nvml_rc
= nvml
->nvmlInit ();
65 if (nvml_rc
!= NVML_SUCCESS
)
67 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
69 log_info ("WARN: %s %d %s\n", "nvmlInit()", nvml_rc
, string
);
75 nvmlReturn_t
hm_NVML_nvmlShutdown (NVML_PTR
*nvml
)
79 nvmlReturn_t nvml_rc
= nvml
->nvmlShutdown ();
81 if (nvml_rc
!= NVML_SUCCESS
)
83 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
85 log_info ("WARN: %s %d %s\n", "nvmlShutdown()", nvml_rc
, string
);
91 nvmlReturn_t
hm_NVML_nvmlDeviceGetName (NVML_PTR
*nvml
, nvmlDevice_t device
, char *name
, unsigned int length
)
95 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetName (device
, name
, length
);
97 if (nvml_rc
!= NVML_SUCCESS
)
99 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
101 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetName()", nvml_rc
, string
);
107 nvmlReturn_t
hm_NVML_nvmlDeviceGetHandleByIndex (NVML_PTR
*nvml
, int skip_warnings
, unsigned int index
, nvmlDevice_t
*device
)
109 if (!nvml
) return -1;
111 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetHandleByIndex (index
, device
);
113 if (nvml_rc
!= NVML_SUCCESS
)
115 if (skip_warnings
== 0)
117 const char *string
= hm_NVML_nvmlErrorString (nvml
, nvml_rc
);
119 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetHandleByIndex()", nvml_rc
, string
);
126 nvmlReturn_t
hm_NVML_nvmlDeviceGetTemperature (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlTemperatureSensors_t sensorType
, unsigned int *temp
)
128 if (!nvml
) return -1;
130 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetTemperature (device
, sensorType
, temp
);
132 if (nvml_rc
!= NVML_SUCCESS
)
136 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
138 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetTemperature()", nvml_rc, string);
144 nvmlReturn_t
hm_NVML_nvmlDeviceGetFanSpeed (NVML_PTR
*nvml
, int skip_warnings
, nvmlDevice_t device
, unsigned int *speed
)
146 if (!nvml
) return -1;
148 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetFanSpeed (device
, speed
);
150 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", "nvmlDeviceGetFanSpeed()", nvml_rc
, string
);
165 /* only tesla following */
167 nvmlReturn_t
hm_NVML_nvmlDeviceGetPowerUsage (NVML_PTR
*nvml
, nvmlDevice_t device
, unsigned int *power
)
169 if (!nvml
) return -1;
171 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetPowerUsage (device
, power
);
173 if (nvml_rc
!= NVML_SUCCESS
)
177 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
179 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerUsage()", nvml_rc, string);
185 nvmlReturn_t
hm_NVML_nvmlDeviceGetUtilizationRates (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlUtilization_t
*utilization
)
187 if (!nvml
) return -1;
189 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetUtilizationRates (device
, utilization
);
191 if (nvml_rc
!= NVML_SUCCESS
)
193 utilization
->gpu
= -1;
194 utilization
->memory
= -1;
196 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
198 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);
204 nvmlReturn_t
hm_NVML_nvmlDeviceGetClockInfo (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlClockType_t type
, unsigned int *clock
)
206 if (!nvml
) return -1;
208 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetClockInfo (device
, type
, clock
);
210 if (nvml_rc
!= NVML_SUCCESS
)
214 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
216 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);
222 nvmlReturn_t
hm_NVML_nvmlDeviceGetTemperatureThreshold (NVML_PTR
*nvml
, nvmlDevice_t device
, nvmlTemperatureThresholds_t thresholdType
, unsigned int *temp
)
224 if (!nvml
) return -1;
226 nvmlReturn_t nvml_rc
= nvml
->nvmlDeviceGetTemperatureThreshold (device
, thresholdType
, temp
);
228 if (nvml_rc
!= NVML_SUCCESS
)
232 //const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc);
234 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);