typedef nvmlDevice_t HM_ADAPTER_NV;
-nvmlReturn_t hc_NVML_nvmlInit (void);
-nvmlReturn_t hc_NVML_nvmlShutdown (void);
-nvmlReturn_t hc_NVML_nvmlDeviceGetName (nvmlDevice_t device, char *name, unsigned int length);
-nvmlReturn_t hc_NVML_nvmlDeviceGetHandleByIndex (unsigned int index, nvmlDevice_t *device);
-nvmlReturn_t hc_NVML_nvmlDeviceGetTemperature (nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int *temp);
-nvmlReturn_t hc_NVML_nvmlDeviceGetFanSpeed (nvmlDevice_t device, unsigned int *speed);
-nvmlReturn_t hc_NVML_nvmlDeviceGetPowerUsage (nvmlDevice_t device, unsigned int *power);
-nvmlReturn_t hc_NVML_nvmlDeviceGetUtilizationRates (nvmlDevice_t device, nvmlUtilization_t *utilization);
+typedef const char * (*NVML_ERROR_STRING) (nvmlReturn_t);
+typedef int (*NVML_INIT) ();
+typedef int (*NVML_SHUTDOWN) ();
+typedef nvmlReturn_t (*NVML_DEVICE_GET_NAME) (nvmlDevice_t, char *, unsigned int);
+typedef nvmlReturn_t (*NVML_DEVICE_GET_HANDLE_BY_INDEX) (unsigned int, nvmlDevice_t *);
+typedef nvmlReturn_t (*NVML_DEVICE_GET_TEMPERATURE) (nvmlDevice_t, nvmlTemperatureSensors_t, unsigned int *);
+typedef nvmlReturn_t (*NVML_DEVICE_GET_FAN_SPEED) (nvmlDevice_t, unsigned int *);
+typedef nvmlReturn_t (*NVML_DEVICE_GET_POWER_USAGE) (nvmlDevice_t, unsigned int *);
+typedef nvmlReturn_t (*NVML_DEVICE_GET_UTILIZATION_RATES) (nvmlDevice_t, nvmlUtilization_t *);
+
+nvmlReturn_t hc_NVML_nvmlInit (HM_LIB hDLL);
+nvmlReturn_t hc_NVML_nvmlShutdown (HM_LIB hDLL);
+nvmlReturn_t hc_NVML_nvmlDeviceGetName (HM_LIB hDLL, nvmlDevice_t device, char *name, unsigned int length);
+nvmlReturn_t hc_NVML_nvmlDeviceGetHandleByIndex (HM_LIB hDLL, int, unsigned int index, nvmlDevice_t *device);
+nvmlReturn_t hc_NVML_nvmlDeviceGetTemperature (HM_LIB hDLL, nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int *temp);
+nvmlReturn_t hc_NVML_nvmlDeviceGetFanSpeed (HM_LIB hDLL, int, nvmlDevice_t device, unsigned int *speed);
+nvmlReturn_t hc_NVML_nvmlDeviceGetPowerUsage (HM_LIB hDLL, nvmlDevice_t device, unsigned int *power);
+nvmlReturn_t hc_NVML_nvmlDeviceGetUtilizationRates (HM_LIB hDLL, nvmlDevice_t device, nvmlUtilization_t *utilization);
#endif
#include <ext_nvml.h>
-nvmlReturn_t hc_NVML_nvmlInit (void)
+//#ifdef _POSIX // implied
+
+void *GetLibFunction (void *pLibrary, const char *name)
+{
+ return dlsym (pLibrary, name);
+}
+
+const char * hc_NVML_nvmlErrorString (HM_LIB hDLL, nvmlReturn_t nvml_rc)
+{
+ NVML_ERROR_STRING nvmlErrorString = (NVML_ERROR_STRING) GetLibFunction (hDLL, "nvmlErrorString");
+
+ if (nvmlErrorString == NULL)
+ {
+ log_error ("ERROR: %s\n", "nvmlErrorString() is missing");
+
+ exit (-1);
+ }
+
+ return nvmlErrorString (nvml_rc);
+}
+
+nvmlReturn_t hc_NVML_nvmlInit (HM_LIB hDLL)
{
+ NVML_INIT nvmlInit = (NVML_INIT) GetLibFunction (hDLL, "nvmlInit");
+
+ if (nvmlInit == NULL)
+ {
+ log_error ("ERROR: %s\n", "nvmlInit() is missing");
+
+ exit (-1);
+ }
+
nvmlReturn_t nvml_rc = nvmlInit ();
if (nvml_rc != NVML_SUCCESS)
{
- const char *string = nvmlErrorString (nvml_rc);
+ const char *string = hc_NVML_nvmlErrorString (hDLL, nvml_rc);
log_info ("WARN: %s %d %s\n", "nvmlInit()", nvml_rc, string);
}
return nvml_rc;
}
-nvmlReturn_t hc_NVML_nvmlShutdown (void)
+nvmlReturn_t hc_NVML_nvmlShutdown (HM_LIB hDLL)
{
+ NVML_SHUTDOWN nvmlShutdown = (NVML_SHUTDOWN) GetLibFunction (hDLL, "nvmlShutdown");
+
+ if (nvmlShutdown == NULL)
+ {
+ log_error ("ERROR: %s\n", "nvmlShutdown() is missing");
+
+ exit (-1);
+ }
+
nvmlReturn_t nvml_rc = nvmlShutdown ();
if (nvml_rc != NVML_SUCCESS)
{
- const char *string = nvmlErrorString (nvml_rc);
+ const char *string = hc_NVML_nvmlErrorString (hDLL, nvml_rc);
log_info ("WARN: %s %d %s\n", "nvmlShutdown()", nvml_rc, string);
}
return nvml_rc;
}
-nvmlReturn_t hc_NVML_nvmlDeviceGetName (nvmlDevice_t device, char *name, unsigned int length)
+nvmlReturn_t hc_NVML_nvmlDeviceGetName (HM_LIB hDLL, nvmlDevice_t device, char *name, unsigned int length)
{
+ NVML_DEVICE_GET_NAME nvmlDeviceGetName = (NVML_DEVICE_GET_NAME) GetLibFunction (hDLL, "nvmlDeviceGetName");
+
+ if (nvmlDeviceGetName == NULL)
+ {
+ log_error ("ERROR: %s\n", "nvmlDeviceGetName() is missing");
+
+ exit (-1);
+ }
+
nvmlReturn_t nvml_rc = nvmlDeviceGetName (device, name, length);
if (nvml_rc != NVML_SUCCESS)
{
- const char *string = nvmlErrorString (nvml_rc);
+ const char *string = hc_NVML_nvmlErrorString (hDLL, nvml_rc);
log_info ("WARN: %s %d %s\n", "nvmlDeviceGetName()", nvml_rc, string);
}
return nvml_rc;
}
-nvmlReturn_t hc_NVML_nvmlDeviceGetHandleByIndex (unsigned int index, nvmlDevice_t *device)
+nvmlReturn_t hc_NVML_nvmlDeviceGetHandleByIndex (HM_LIB hDLL, int skip_warnings, unsigned int index, nvmlDevice_t *device)
{
+ NVML_DEVICE_GET_HANDLE_BY_INDEX nvmlDeviceGetHandleByIndex = (NVML_DEVICE_GET_HANDLE_BY_INDEX) GetLibFunction (hDLL, "nvmlDeviceGetHandleByIndex");
+
+ if (nvmlDeviceGetHandleByIndex == NULL)
+ {
+ log_error ("ERROR: %s\n", "nvmlDeviceGetHandleByIndex() is missing");
+
+ exit (-1);
+ }
+
nvmlReturn_t nvml_rc = nvmlDeviceGetHandleByIndex (index, device);
if (nvml_rc != NVML_SUCCESS)
{
- const char *string = nvmlErrorString (nvml_rc);
+ if (skip_warnings == 0)
+ {
+ const char *string = hc_NVML_nvmlErrorString (hDLL, nvml_rc);
- log_info ("WARN: %s %d %s\n", "nvmlDeviceGetHandleByIndex()", nvml_rc, string);
+ log_info ("WARN: %s %d %s\n", "nvmlDeviceGetHandleByIndex()", nvml_rc, string);
+ }
}
return nvml_rc;
}
-nvmlReturn_t hc_NVML_nvmlDeviceGetTemperature (nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int *temp)
+nvmlReturn_t hc_NVML_nvmlDeviceGetTemperature (HM_LIB hDLL, nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int *temp)
{
+ NVML_DEVICE_GET_TEMPERATURE nvmlDeviceGetTemperature = (NVML_DEVICE_GET_TEMPERATURE) GetLibFunction (hDLL, "nvmlDeviceGetTemperature");
+
+ if (nvmlDeviceGetTemperature == NULL)
+ {
+ log_error ("ERROR: %s\n", "nvmlDeviceGetTemperature() is missing");
+
+ exit (-1);
+ }
+
nvmlReturn_t nvml_rc = nvmlDeviceGetTemperature (device, sensorType, temp);
if (nvml_rc != NVML_SUCCESS)
{
*temp = -1;
- //const char *string = nvmlErrorString (nvml_rc);
+ //const char *string = hc_NVML_nvmlErrorString (hDLL, nvml_rc);
//log_info ("WARN: %s %d %s\n", "nvmlDeviceGetTemperature()", nvml_rc, string);
}
return nvml_rc;
}
-nvmlReturn_t hc_NVML_nvmlDeviceGetFanSpeed (nvmlDevice_t device, unsigned int *speed)
+nvmlReturn_t hc_NVML_nvmlDeviceGetFanSpeed (HM_LIB hDLL, int skip_warnings, nvmlDevice_t device, unsigned int *speed)
{
+ NVML_DEVICE_GET_FAN_SPEED nvmlDeviceGetFanSpeed = (NVML_DEVICE_GET_FAN_SPEED) GetLibFunction (hDLL, "nvmlDeviceGetFanSpeed");
+
+ if (nvmlDeviceGetFanSpeed == NULL)
+ {
+ log_error ("ERROR: %s\n", "nvmlDeviceGetFanSpeed() is missing");
+
+ exit (-1);
+ }
+
nvmlReturn_t nvml_rc = nvmlDeviceGetFanSpeed (device, speed);
if (nvml_rc != NVML_SUCCESS)
{
*speed = -1;
- //const char *string = nvmlErrorString (nvml_rc);
+ if (skip_warnings == 0)
+ {
+ const char *string = hc_NVML_nvmlErrorString (hDLL, nvml_rc);
- //log_info ("WARN: %s %d %s\n", "nvmlDeviceGetFanSpeed()", nvml_rc, string);
+ log_info ("WARN: %s %d %s\n", "nvmlDeviceGetFanSpeed()", nvml_rc, string);
+ }
}
return nvml_rc;
/* only tesla following */
-nvmlReturn_t hc_NVML_nvmlDeviceGetPowerUsage (nvmlDevice_t device, unsigned int *power)
+nvmlReturn_t hc_NVML_nvmlDeviceGetPowerUsage (HM_LIB hDLL, nvmlDevice_t device, unsigned int *power)
{
+ NVML_DEVICE_GET_POWER_USAGE nvmlDeviceGetPowerUsage = (NVML_DEVICE_GET_POWER_USAGE) GetLibFunction (hDLL, "nvmlDeviceGetPowerUsage");
+
+ if (nvmlDeviceGetPowerUsage == NULL)
+ {
+ log_error ("ERROR: %s\n", "nvmlDeviceGetPowerUsage() is missing");
+
+ exit (-1);
+ }
+
nvmlReturn_t nvml_rc = nvmlDeviceGetPowerUsage (device, power);
if (nvml_rc != NVML_SUCCESS)
{
*power = -1;
- //const char *string = nvmlErrorString (nvml_rc);
+ //const char *string = hc_NVML_nvmlErrorString (hDLL, nvml_rc);
//log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerUsage()", nvml_rc, string);
}
return nvml_rc;
}
-nvmlReturn_t hc_NVML_nvmlDeviceGetUtilizationRates (nvmlDevice_t device, nvmlUtilization_t *utilization)
+nvmlReturn_t hc_NVML_nvmlDeviceGetUtilizationRates (HM_LIB hDLL, nvmlDevice_t device, nvmlUtilization_t *utilization)
{
+ NVML_DEVICE_GET_UTILIZATION_RATES nvmlDeviceGetUtilizationRates = (NVML_DEVICE_GET_UTILIZATION_RATES) GetLibFunction (hDLL, "nvmlDeviceGetUtilizationRates");
+
+ if (nvmlDeviceGetUtilizationRates == NULL)
+ {
+ log_error ("ERROR: %s\n", "nvmlDeviceGetUtilizationRates() is missing");
+
+ exit (-1);
+ }
+
nvmlReturn_t nvml_rc = nvmlDeviceGetUtilizationRates (device, utilization);
if (nvml_rc != NVML_SUCCESS)
utilization->gpu = -1;
utilization->memory = -1;
- //const char *string = nvmlErrorString (nvml_rc);
+ //const char *string = hc_NVML_nvmlErrorString (hDLL, nvml_rc);
//log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string);
}
return nvml_rc;
}
+
+//#endif
for (uint i = 0; i < DEVICES_MAX; i++)
{
- // do not use wrapper function to omit warning message
- if (nvmlDeviceGetHandleByIndex (i, &nvGPUHandle[i]) != NVML_SUCCESS) break;
+ if (hc_NVML_nvmlDeviceGetHandleByIndex (data.hm_dll, 1, i, &nvGPUHandle[i]) != NVML_SUCCESS) break;
//can be used to determine if the device by index matches the cuda device by index
//char name[100]; memset (name, 0, sizeof (name));
- //hc_NVML_nvmlDeviceGetName (nvGPUHandle[i], name, sizeof (name) - 1);
+ //hc_NVML_nvmlDeviceGetName (data.hm_dll, nvGPUHandle[i], name, sizeof (name) - 1);
pGpuCount++;
}
}
#endif
-void hm_close_amd (HM_LIB hm_dll)
+void hm_close (HM_LIB hm_dll)
{
#ifdef _POSIX
dlclose (hm_dll);
#endif
}
-HM_LIB hm_init_amd ()
+HM_LIB hm_init ()
{
- #ifdef _POSIX
- HM_LIB hm_dll = dlopen ("libatiadlxx.so", RTLD_LAZY | RTLD_GLOBAL);
+ HM_LIB hm_dll = NULL;
- #elif _WIN
- HM_LIB hm_dll = LoadLibrary ("atiadlxx.dll");
+ if (data.vendor_id == VENDOR_ID_AMD)
+ {
+ #ifdef _POSIX
+ hm_dll = dlopen ("libatiadlxx.so", RTLD_LAZY | RTLD_GLOBAL);
+
+ #elif _WIN
+ hm_dll = LoadLibrary ("atiadlxx.dll");
- if (hm_dll == NULL)
+ if (hm_dll == NULL)
+ {
hm_dll = LoadLibrary ("atiadlxy.dll");
+ }
+ #endif
+ }
+
+ #ifdef LINUX
+ if (data.vendor_id == VENDOR_ID_NV)
+ {
+ hm_dll = dlopen ("libnvidia-ml.so", RTLD_LAZY | RTLD_GLOBAL);
+ }
#endif
return hm_dll;
#ifdef LINUX
int temperature = 0;
- hc_NVML_nvmlDeviceGetTemperature (data.hm_device[device_id].adapter_index.nv, NVML_TEMPERATURE_GPU, (unsigned int *) &temperature);
+ hc_NVML_nvmlDeviceGetTemperature (data.hm_dll, data.hm_device[device_id].adapter_index.nv, NVML_TEMPERATURE_GPU, (unsigned int *) &temperature);
return temperature;
#endif
#ifdef LINUX
int speed = 0;
- hc_NVML_nvmlDeviceGetFanSpeed (data.hm_device[device_id].adapter_index.nv, (unsigned int *) &speed);
+ hc_NVML_nvmlDeviceGetFanSpeed (data.hm_dll, 1, data.hm_device[device_id].adapter_index.nv, (unsigned int *) &speed);
return speed;
#endif
#ifdef LINUX
nvmlUtilization_t utilization;
- hc_NVML_nvmlDeviceGetUtilizationRates (data.hm_device[device_id].adapter_index.nv, &utilization);
+ hc_NVML_nvmlDeviceGetUtilizationRates (data.hm_dll, data.hm_device[device_id].adapter_index.nv, &utilization);
return utilization.gpu;
#endif