2 * Author......: Jens Steube <jens.steube@gmail.com>
8 //#ifdef _POSIX // implied
10 void *GetLibFunction (void *pLibrary
, const char *name
)
12 return dlsym (pLibrary
, name
);
15 const char * hc_NVML_nvmlErrorString (HM_LIB hDLL
, nvmlReturn_t nvml_rc
)
17 NVML_ERROR_STRING nvmlErrorString
= (NVML_ERROR_STRING
) GetLibFunction (hDLL
, "nvmlErrorString");
19 if (nvmlErrorString
== NULL
)
21 log_error ("ERROR: %s\n", "nvmlErrorString() is missing");
26 return nvmlErrorString (nvml_rc
);
29 nvmlReturn_t
hc_NVML_nvmlInit (HM_LIB hDLL
)
31 NVML_INIT nvmlInit
= (NVML_INIT
) GetLibFunction (hDLL
, "nvmlInit");
35 log_error ("ERROR: %s\n", "nvmlInit() is missing");
40 nvmlReturn_t nvml_rc
= nvmlInit ();
42 if (nvml_rc
!= NVML_SUCCESS
)
44 const char *string
= hc_NVML_nvmlErrorString (hDLL
, nvml_rc
);
46 log_info ("WARN: %s %d %s\n", "nvmlInit()", nvml_rc
, string
);
52 nvmlReturn_t
hc_NVML_nvmlShutdown (HM_LIB hDLL
)
54 NVML_SHUTDOWN nvmlShutdown
= (NVML_SHUTDOWN
) GetLibFunction (hDLL
, "nvmlShutdown");
56 if (nvmlShutdown
== NULL
)
58 log_error ("ERROR: %s\n", "nvmlShutdown() is missing");
63 nvmlReturn_t nvml_rc
= nvmlShutdown ();
65 if (nvml_rc
!= NVML_SUCCESS
)
67 const char *string
= hc_NVML_nvmlErrorString (hDLL
, nvml_rc
);
69 log_info ("WARN: %s %d %s\n", "nvmlShutdown()", nvml_rc
, string
);
75 nvmlReturn_t
hc_NVML_nvmlDeviceGetName (HM_LIB hDLL
, nvmlDevice_t device
, char *name
, unsigned int length
)
77 NVML_DEVICE_GET_NAME nvmlDeviceGetName
= (NVML_DEVICE_GET_NAME
) GetLibFunction (hDLL
, "nvmlDeviceGetName");
79 if (nvmlDeviceGetName
== NULL
)
81 log_error ("ERROR: %s\n", "nvmlDeviceGetName() is missing");
86 nvmlReturn_t nvml_rc
= nvmlDeviceGetName (device
, name
, length
);
88 if (nvml_rc
!= NVML_SUCCESS
)
90 const char *string
= hc_NVML_nvmlErrorString (hDLL
, nvml_rc
);
92 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetName()", nvml_rc
, string
);
98 nvmlReturn_t
hc_NVML_nvmlDeviceGetHandleByIndex (HM_LIB hDLL
, int skip_warnings
, unsigned int index
, nvmlDevice_t
*device
)
100 NVML_DEVICE_GET_HANDLE_BY_INDEX nvmlDeviceGetHandleByIndex
= (NVML_DEVICE_GET_HANDLE_BY_INDEX
) GetLibFunction (hDLL
, "nvmlDeviceGetHandleByIndex");
102 if (nvmlDeviceGetHandleByIndex
== NULL
)
104 log_error ("ERROR: %s\n", "nvmlDeviceGetHandleByIndex() is missing");
109 nvmlReturn_t nvml_rc
= nvmlDeviceGetHandleByIndex (index
, device
);
111 if (nvml_rc
!= NVML_SUCCESS
)
113 if (skip_warnings
== 0)
115 const char *string
= hc_NVML_nvmlErrorString (hDLL
, nvml_rc
);
117 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetHandleByIndex()", nvml_rc
, string
);
124 nvmlReturn_t
hc_NVML_nvmlDeviceGetTemperature (HM_LIB hDLL
, nvmlDevice_t device
, nvmlTemperatureSensors_t sensorType
, unsigned int *temp
)
126 NVML_DEVICE_GET_TEMPERATURE nvmlDeviceGetTemperature
= (NVML_DEVICE_GET_TEMPERATURE
) GetLibFunction (hDLL
, "nvmlDeviceGetTemperature");
128 if (nvmlDeviceGetTemperature
== NULL
)
130 log_error ("ERROR: %s\n", "nvmlDeviceGetTemperature() is missing");
135 nvmlReturn_t nvml_rc
= nvmlDeviceGetTemperature (device
, sensorType
, temp
);
137 if (nvml_rc
!= NVML_SUCCESS
)
141 //const char *string = hc_NVML_nvmlErrorString (hDLL, nvml_rc);
143 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetTemperature()", nvml_rc, string);
149 nvmlReturn_t
hc_NVML_nvmlDeviceGetFanSpeed (HM_LIB hDLL
, int skip_warnings
, nvmlDevice_t device
, unsigned int *speed
)
151 NVML_DEVICE_GET_FAN_SPEED nvmlDeviceGetFanSpeed
= (NVML_DEVICE_GET_FAN_SPEED
) GetLibFunction (hDLL
, "nvmlDeviceGetFanSpeed");
153 if (nvmlDeviceGetFanSpeed
== NULL
)
155 log_error ("ERROR: %s\n", "nvmlDeviceGetFanSpeed() is missing");
160 nvmlReturn_t nvml_rc
= nvmlDeviceGetFanSpeed (device
, speed
);
162 if (nvml_rc
!= NVML_SUCCESS
)
166 if (skip_warnings
== 0)
168 const char *string
= hc_NVML_nvmlErrorString (hDLL
, nvml_rc
);
170 log_info ("WARN: %s %d %s\n", "nvmlDeviceGetFanSpeed()", nvml_rc
, string
);
177 /* only tesla following */
179 nvmlReturn_t
hc_NVML_nvmlDeviceGetPowerUsage (HM_LIB hDLL
, nvmlDevice_t device
, unsigned int *power
)
181 NVML_DEVICE_GET_POWER_USAGE nvmlDeviceGetPowerUsage
= (NVML_DEVICE_GET_POWER_USAGE
) GetLibFunction (hDLL
, "nvmlDeviceGetPowerUsage");
183 if (nvmlDeviceGetPowerUsage
== NULL
)
185 log_error ("ERROR: %s\n", "nvmlDeviceGetPowerUsage() is missing");
190 nvmlReturn_t nvml_rc
= nvmlDeviceGetPowerUsage (device
, power
);
192 if (nvml_rc
!= NVML_SUCCESS
)
196 //const char *string = hc_NVML_nvmlErrorString (hDLL, nvml_rc);
198 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerUsage()", nvml_rc, string);
204 nvmlReturn_t
hc_NVML_nvmlDeviceGetUtilizationRates (HM_LIB hDLL
, nvmlDevice_t device
, nvmlUtilization_t
*utilization
)
206 NVML_DEVICE_GET_UTILIZATION_RATES nvmlDeviceGetUtilizationRates
= (NVML_DEVICE_GET_UTILIZATION_RATES
) GetLibFunction (hDLL
, "nvmlDeviceGetUtilizationRates");
208 if (nvmlDeviceGetUtilizationRates
== NULL
)
210 log_error ("ERROR: %s\n", "nvmlDeviceGetUtilizationRates() is missing");
215 nvmlReturn_t nvml_rc
= nvmlDeviceGetUtilizationRates (device
, utilization
);
217 if (nvml_rc
!= NVML_SUCCESS
)
219 utilization
->gpu
= -1;
220 utilization
->memory
= -1;
222 //const char *string = hc_NVML_nvmlErrorString (hDLL, nvml_rc);
224 //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);