diff --git a/ccminer.cpp b/ccminer.cpp index 4bfde2e..aba7a87 100644 --- a/ccminer.cpp +++ b/ccminer.cpp @@ -63,7 +63,7 @@ int cuda_finddevice(char *name); #include "nvml.h" #ifdef USE_WRAPNVML -wrap_nvml_handle *hnvml = NULL; +nvml_handle *hnvml = NULL; #endif #ifdef __linux /* Linux specific policy and affinity management */ @@ -407,7 +407,7 @@ void proper_exit(int reason) #endif #ifdef USE_WRAPNVML if (hnvml) - wrap_nvml_destroy(hnvml); + nvml_destroy(hnvml); #endif free(opt_syslog_pfx); free(opt_api_allow); @@ -2214,11 +2214,11 @@ int main(int argc, char *argv[]) #ifdef USE_WRAPNVML #ifndef WIN32 /* nvml is currently not the best choice on Windows (only in x64) */ - hnvml = wrap_nvml_create(); + hnvml = nvml_create(); if (hnvml) applog(LOG_INFO, "NVML GPU monitoring enabled."); #else - if (wrap_nvapi_init() == 0) + if (nvapi_init() == 0) applog(LOG_INFO, "NVAPI GPU monitoring enabled."); #endif else diff --git a/nvml.cpp b/nvml.cpp index 9939a99..0458e9d 100644 --- a/nvml.cpp +++ b/nvml.cpp @@ -31,7 +31,7 @@ int cuda_num_devices(); #ifdef USE_WRAPNVML -extern wrap_nvml_handle *hnvml; +extern nvml_handle *hnvml; extern char driver_version[32]; static uint32_t device_bus_ids[8] = { 0 }; @@ -77,10 +77,10 @@ static uint32_t device_bus_ids[8] = { 0 }; } #endif -wrap_nvml_handle * wrap_nvml_create() +nvml_handle * nvml_create() { int i=0; - wrap_nvml_handle *nvmlh = NULL; + nvml_handle *nvmlh = NULL; #if defined(WIN32) /* Windows (do not use slashes, else ExpandEnvironmentStrings will mix them) */ @@ -106,45 +106,53 @@ wrap_nvml_handle * wrap_nvml_create() return NULL; } - nvmlh = (wrap_nvml_handle *) calloc(1, sizeof(wrap_nvml_handle)); + nvmlh = (nvml_handle *) calloc(1, sizeof(nvml_handle)); nvmlh->nvml_dll = nvml_dll; - nvmlh->nvmlInit = (wrap_nvmlReturn_t (*)(void)) + nvmlh->nvmlInit = (nvmlReturn_t (*)(void)) wrap_dlsym(nvmlh->nvml_dll, "nvmlInit_v2"); if (!nvmlh->nvmlInit) { - nvmlh->nvmlInit = (wrap_nvmlReturn_t (*)(void)) + nvmlh->nvmlInit = (nvmlReturn_t (*)(void)) wrap_dlsym(nvmlh->nvml_dll, "nvmlInit"); } - nvmlh->nvmlDeviceGetCount = (wrap_nvmlReturn_t (*)(int *)) + nvmlh->nvmlDeviceGetCount = (nvmlReturn_t (*)(int *)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetCount_v2"); - nvmlh->nvmlDeviceGetHandleByIndex = (wrap_nvmlReturn_t (*)(int, wrap_nvmlDevice_t *)) + nvmlh->nvmlDeviceGetHandleByIndex = (nvmlReturn_t (*)(int, nvmlDevice_t *)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetHandleByIndex_v2"); - nvmlh->nvmlDeviceGetApplicationsClock = (wrap_nvmlReturn_t (*)(wrap_nvmlDevice_t, wrap_nvmlClockType_t, unsigned int *)) + nvmlh->nvmlDeviceGetAPIRestriction = (nvmlReturn_t (*)(nvmlDevice_t, nvmlRestrictedAPI_t, nvmlEnableState_t *)) + wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetAPIRestriction"); + nvmlh->nvmlDeviceSetAPIRestriction = (nvmlReturn_t (*)(nvmlDevice_t, nvmlRestrictedAPI_t, nvmlEnableState_t)) + wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceSetAPIRestriction"); + nvmlh->nvmlDeviceGetDefaultApplicationsClock = (nvmlReturn_t (*)(nvmlDevice_t, nvmlClockType_t, unsigned int *clock)) + wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetDefaultApplicationsClock"); + nvmlh->nvmlDeviceGetApplicationsClock = (nvmlReturn_t (*)(nvmlDevice_t, nvmlClockType_t, unsigned int *clocks)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetApplicationsClock"); - nvmlh->nvmlDeviceGetClockInfo = (wrap_nvmlReturn_t (*)(wrap_nvmlDevice_t, wrap_nvmlClockType_t, unsigned int *)) + nvmlh->nvmlDeviceSetApplicationsClocks = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int mem, unsigned int gpu)) + wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceSetApplicationsClocks"); + nvmlh->nvmlDeviceGetClockInfo = (nvmlReturn_t (*)(nvmlDevice_t, nvmlClockType_t, unsigned int *clock)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetClockInfo"); - nvmlh->nvmlDeviceGetPciInfo = (wrap_nvmlReturn_t (*)(wrap_nvmlDevice_t, wrap_nvmlPciInfo_t *)) + nvmlh->nvmlDeviceGetPciInfo = (nvmlReturn_t (*)(nvmlDevice_t, nvmlPciInfo_t *)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPciInfo"); - nvmlh->nvmlDeviceGetName = (wrap_nvmlReturn_t (*)(wrap_nvmlDevice_t, char *, int)) + nvmlh->nvmlDeviceGetName = (nvmlReturn_t (*)(nvmlDevice_t, char *, int)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetName"); - nvmlh->nvmlDeviceGetTemperature = (wrap_nvmlReturn_t (*)(wrap_nvmlDevice_t, int, unsigned int *)) + nvmlh->nvmlDeviceGetTemperature = (nvmlReturn_t (*)(nvmlDevice_t, int, unsigned int *)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetTemperature"); - nvmlh->nvmlDeviceGetFanSpeed = (wrap_nvmlReturn_t (*)(wrap_nvmlDevice_t, unsigned int *)) + nvmlh->nvmlDeviceGetFanSpeed = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetFanSpeed"); - nvmlh->nvmlDeviceGetPerformanceState = (wrap_nvmlReturn_t (*)(wrap_nvmlDevice_t, int *)) + nvmlh->nvmlDeviceGetPerformanceState = (nvmlReturn_t (*)(nvmlDevice_t, int *)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPowerUsage"); - nvmlh->nvmlDeviceGetSerial = (wrap_nvmlReturn_t (*)(wrap_nvmlDevice_t, char *, unsigned int)) + nvmlh->nvmlDeviceGetSerial = (nvmlReturn_t (*)(nvmlDevice_t, char *, unsigned int)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetSerial"); - nvmlh->nvmlDeviceGetUUID = (wrap_nvmlReturn_t (*)(wrap_nvmlDevice_t, char *, unsigned int)) + nvmlh->nvmlDeviceGetUUID = (nvmlReturn_t (*)(nvmlDevice_t, char *, unsigned int)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetUUID"); - nvmlh->nvmlDeviceGetVbiosVersion = (wrap_nvmlReturn_t (*)(wrap_nvmlDevice_t, char *, unsigned int)) + nvmlh->nvmlDeviceGetVbiosVersion = (nvmlReturn_t (*)(nvmlDevice_t, char *, unsigned int)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetVbiosVersion"); - nvmlh->nvmlSystemGetDriverVersion = (wrap_nvmlReturn_t (*)(char *, unsigned int)) + nvmlh->nvmlSystemGetDriverVersion = (nvmlReturn_t (*)(char *, unsigned int)) wrap_dlsym(nvmlh->nvml_dll, "nvmlSystemGetDriverVersion"); - nvmlh->nvmlErrorString = (char* (*)(wrap_nvmlReturn_t)) + nvmlh->nvmlErrorString = (char* (*)(nvmlReturn_t)) wrap_dlsym(nvmlh->nvml_dll, "nvmlErrorString"); - nvmlh->nvmlShutdown = (wrap_nvmlReturn_t (*)()) + nvmlh->nvmlShutdown = (nvmlReturn_t (*)()) wrap_dlsym(nvmlh->nvml_dll, "nvmlShutdown"); if (nvmlh->nvmlInit == NULL || @@ -179,13 +187,14 @@ wrap_nvml_handle * wrap_nvml_create() return NULL; } - nvmlh->devs = (wrap_nvmlDevice_t *) calloc(nvmlh->nvml_gpucount, sizeof(wrap_nvmlDevice_t)); + nvmlh->devs = (nvmlDevice_t *) calloc(nvmlh->nvml_gpucount, sizeof(nvmlDevice_t)); nvmlh->nvml_pci_domain_id = (unsigned int*) calloc(nvmlh->nvml_gpucount, sizeof(unsigned int)); nvmlh->nvml_pci_bus_id = (unsigned int*) calloc(nvmlh->nvml_gpucount, sizeof(unsigned int)); - nvmlh->nvml_pci_device_id = (unsigned int*)calloc(nvmlh->nvml_gpucount, sizeof(unsigned int)); - nvmlh->nvml_pci_subsys_id = (unsigned int*)calloc(nvmlh->nvml_gpucount, sizeof(unsigned int)); + nvmlh->nvml_pci_device_id = (unsigned int*) calloc(nvmlh->nvml_gpucount, sizeof(unsigned int)); + nvmlh->nvml_pci_subsys_id = (unsigned int*) calloc(nvmlh->nvml_gpucount, sizeof(unsigned int)); nvmlh->nvml_cuda_device_id = (int*) calloc(nvmlh->nvml_gpucount, sizeof(int)); nvmlh->cuda_nvml_device_id = (int*) calloc(nvmlh->cuda_gpucount, sizeof(int)); + nvmlh->app_clocks = (nvmlEnableState_t*) calloc(nvmlh->nvml_gpucount, sizeof(nvmlEnableState_t)); /* Obtain GPU device handles we're going to need repeatedly... */ for (i=0; invml_gpucount; i++) { @@ -195,12 +204,39 @@ wrap_nvml_handle * wrap_nvml_create() /* Query PCI info for each NVML device, and build table for mapping of */ /* CUDA device IDs to NVML device IDs and vice versa */ for (i=0; invml_gpucount; i++) { - wrap_nvmlPciInfo_t pciinfo; + nvmlPciInfo_t pciinfo; + nvmlh->nvmlDeviceGetPciInfo(nvmlh->devs[i], &pciinfo); nvmlh->nvml_pci_domain_id[i] = pciinfo.domain; nvmlh->nvml_pci_bus_id[i] = pciinfo.bus; nvmlh->nvml_pci_device_id[i] = pciinfo.device; nvmlh->nvml_pci_subsys_id[i] = pciinfo.pci_device_id; + + nvmlh->app_clocks[i] = NVML_FEATURE_UNKNOWN; + if (nvmlh->nvmlDeviceSetAPIRestriction) { + nvmlh->nvmlDeviceSetAPIRestriction(nvmlh->devs[i], NVML_RESTRICTED_API_SET_APPLICATION_CLOCKS, + NVML_FEATURE_ENABLED); + /* there is only this API_SET_APPLICATION_CLOCKS on the 750 Ti (340.58) */ + } + if (nvmlh->nvmlDeviceGetAPIRestriction) { + nvmlh->nvmlDeviceGetAPIRestriction(nvmlh->devs[i], NVML_RESTRICTED_API_SET_APPLICATION_CLOCKS, + &nvmlh->app_clocks[i]); + if (nvmlh->app_clocks[i] == NVML_FEATURE_ENABLED && opt_debug) { + applog(LOG_DEBUG, "NVML application clock feature is allowed"); +#if 0 + uint32_t mem; + nvmlReturn_t rc; + rc = nvmlh->nvmlDeviceGetDefaultApplicationsClock(nvmlh->devs[i], NVML_CLOCK_MEM, &mem); + if (rc == NVML_SUCCESS) + applog(LOG_DEBUG, "nvmlDeviceGetDefaultApplicationsClock: mem %u", mem); + else + applog(LOG_DEBUG, "nvmlDeviceGetDefaultApplicationsClock: %s", nvmlh->nvmlErrorString(rc)); + rc = nvmlh->nvmlDeviceSetApplicationsClocks(nvmlh->devs[i], mem, 1228000); + if (rc != NVML_SUCCESS) + applog(LOG_DEBUG, "nvmlDeviceSetApplicationsClocks: %s", nvmlh->nvmlErrorString(rc)); +#endif + } + } } /* build mapping of NVML device IDs to CUDA IDs */ @@ -230,41 +266,41 @@ wrap_nvml_handle * wrap_nvml_create() return nvmlh; } -int wrap_nvml_get_gpucount(wrap_nvml_handle *nvmlh, int *gpucount) +int nvml_get_gpucount(nvml_handle *nvmlh, int *gpucount) { *gpucount = nvmlh->nvml_gpucount; return 0; } -int wrap_cuda_get_gpucount(wrap_nvml_handle *nvmlh, int *gpucount) +int cuda_get_gpucount(nvml_handle *nvmlh, int *gpucount) { *gpucount = nvmlh->cuda_gpucount; return 0; } -int wrap_nvml_get_gpu_name(wrap_nvml_handle *nvmlh, int cudaindex, char *namebuf, int bufsize) +int nvml_get_gpu_name(nvml_handle *nvmlh, int cudaindex, char *namebuf, int bufsize) { int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex]; if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount) return -1; - if (nvmlh->nvmlDeviceGetName(nvmlh->devs[gpuindex], namebuf, bufsize) != WRAPNVML_SUCCESS) + if (nvmlh->nvmlDeviceGetName(nvmlh->devs[gpuindex], namebuf, bufsize) != NVML_SUCCESS) return -1; return 0; } -int wrap_nvml_get_tempC(wrap_nvml_handle *nvmlh, int cudaindex, unsigned int *tempC) +int nvml_get_tempC(nvml_handle *nvmlh, int cudaindex, unsigned int *tempC) { - wrap_nvmlReturn_t rc; + nvmlReturn_t rc; int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex]; if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount) return -1; rc = nvmlh->nvmlDeviceGetTemperature(nvmlh->devs[gpuindex], 0u /* NVML_TEMPERATURE_GPU */, tempC); - if (rc != WRAPNVML_SUCCESS) { + if (rc != NVML_SUCCESS) { return -1; } @@ -272,15 +308,15 @@ int wrap_nvml_get_tempC(wrap_nvml_handle *nvmlh, int cudaindex, unsigned int *te } -int wrap_nvml_get_fanpcnt(wrap_nvml_handle *nvmlh, int cudaindex, unsigned int *fanpcnt) +int nvml_get_fanpcnt(nvml_handle *nvmlh, int cudaindex, unsigned int *fanpcnt) { - wrap_nvmlReturn_t rc; + nvmlReturn_t rc; int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex]; if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount) return -1; rc = nvmlh->nvmlDeviceGetFanSpeed(nvmlh->devs[gpuindex], fanpcnt); - if (rc != WRAPNVML_SUCCESS) { + if (rc != NVML_SUCCESS) { return -1; } @@ -288,14 +324,14 @@ int wrap_nvml_get_fanpcnt(wrap_nvml_handle *nvmlh, int cudaindex, unsigned int * } /* Not Supported on 750Ti 340.23 */ -int wrap_nvml_get_power_usage(wrap_nvml_handle *nvmlh, int cudaindex, unsigned int *milliwatts) +int nvml_get_power_usage(nvml_handle *nvmlh, int cudaindex, unsigned int *milliwatts) { int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex]; if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount) return -1; - wrap_nvmlReturn_t res = nvmlh->nvmlDeviceGetPowerUsage(nvmlh->devs[gpuindex], milliwatts); - if (res != WRAPNVML_SUCCESS) { + nvmlReturn_t res = nvmlh->nvmlDeviceGetPowerUsage(nvmlh->devs[gpuindex], milliwatts); + if (res != NVML_SUCCESS) { if (opt_debug) applog(LOG_DEBUG, "nvmlDeviceGetPowerUsage: %s", nvmlh->nvmlErrorString(res)); return -1; @@ -305,14 +341,14 @@ int wrap_nvml_get_power_usage(wrap_nvml_handle *nvmlh, int cudaindex, unsigned i } /* Not Supported on 750Ti 340.23 */ -int wrap_nvml_get_pstate(wrap_nvml_handle *nvmlh, int cudaindex, int *pstate) +int nvml_get_pstate(nvml_handle *nvmlh, int cudaindex, int *pstate) { int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex]; if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount) return -1; - wrap_nvmlReturn_t res = nvmlh->nvmlDeviceGetPerformanceState(nvmlh->devs[gpuindex], pstate); - if (res != WRAPNVML_SUCCESS) { + nvmlReturn_t res = nvmlh->nvmlDeviceGetPerformanceState(nvmlh->devs[gpuindex], pstate); + if (res != NVML_SUCCESS) { //if (opt_debug) // applog(LOG_DEBUG, "nvmlDeviceGetPerformanceState: %s", nvmlh->nvmlErrorString(res)); return -1; @@ -321,7 +357,7 @@ int wrap_nvml_get_pstate(wrap_nvml_handle *nvmlh, int cudaindex, int *pstate) return 0; } -int wrap_nvml_get_busid(wrap_nvml_handle *nvmlh, int cudaindex, int *busid) +int nvml_get_busid(nvml_handle *nvmlh, int cudaindex, int *busid) { int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex]; if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount) @@ -331,17 +367,17 @@ int wrap_nvml_get_busid(wrap_nvml_handle *nvmlh, int cudaindex, int *busid) return 0; } -int wrap_nvml_get_serial(wrap_nvml_handle *nvmlh, int cudaindex, char *sn, int maxlen) +int nvml_get_serial(nvml_handle *nvmlh, int cudaindex, char *sn, int maxlen) { uint32_t subids = 0; char uuid[NVML_DEVICE_UUID_BUFFER_SIZE]; int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex]; - wrap_nvmlReturn_t res; + nvmlReturn_t res; if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount) return -1; res = nvmlh->nvmlDeviceGetSerial(nvmlh->devs[gpuindex], sn, maxlen); - if (res == WRAPNVML_SUCCESS) { + if (res == NVML_SUCCESS) { return 0; } @@ -350,7 +386,7 @@ int wrap_nvml_get_serial(wrap_nvml_handle *nvmlh, int cudaindex, char *sn, int m // todo: check if there is vendor id is inside memset(uuid, 0, sizeof(uuid)); res = nvmlh->nvmlDeviceGetUUID(nvmlh->devs[gpuindex], uuid, sizeof(uuid)-1); - if (res != WRAPNVML_SUCCESS) { + if (res != NVML_SUCCESS) { if (opt_debug) applog(LOG_DEBUG, "nvmlDeviceGetUUID: %s", nvmlh->nvmlErrorString(res)); return -1; @@ -360,15 +396,15 @@ int wrap_nvml_get_serial(wrap_nvml_handle *nvmlh, int cudaindex, char *sn, int m return 0; } -int wrap_nvml_get_bios(wrap_nvml_handle *nvmlh, int cudaindex, char *desc, int maxlen) +int nvml_get_bios(nvml_handle *nvmlh, int cudaindex, char *desc, int maxlen) { uint32_t subids = 0; int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex]; if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount) return -1; - wrap_nvmlReturn_t res = nvmlh->nvmlDeviceGetVbiosVersion(nvmlh->devs[gpuindex], desc, maxlen); - if (res != WRAPNVML_SUCCESS) { + nvmlReturn_t res = nvmlh->nvmlDeviceGetVbiosVersion(nvmlh->devs[gpuindex], desc, maxlen); + if (res != NVML_SUCCESS) { if (opt_debug) applog(LOG_DEBUG, "nvmlDeviceGetVbiosVersion: %s", nvmlh->nvmlErrorString(res)); return -1; @@ -376,7 +412,7 @@ int wrap_nvml_get_bios(wrap_nvml_handle *nvmlh, int cudaindex, char *desc, int m return 0; } -int wrap_nvml_get_info(wrap_nvml_handle *nvmlh, int cudaindex, uint16_t *vid, uint16_t *pid) +int nvml_get_info(nvml_handle *nvmlh, int cudaindex, uint16_t *vid, uint16_t *pid) { uint32_t subids = 0; int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex]; @@ -389,7 +425,7 @@ int wrap_nvml_get_info(wrap_nvml_handle *nvmlh, int cudaindex, uint16_t *vid, ui return 0; } -int wrap_nvml_destroy(wrap_nvml_handle *nvmlh) +int nvml_destroy(nvml_handle *nvmlh) { nvmlh->nvmlShutdown(); @@ -401,6 +437,7 @@ int wrap_nvml_destroy(wrap_nvml_handle *nvmlh) free(nvmlh->nvml_pci_subsys_id); free(nvmlh->nvml_cuda_device_id); free(nvmlh->cuda_nvml_device_id); + free(nvmlh->app_clocks); free(nvmlh->devs); free(nvmlh); @@ -581,7 +618,7 @@ int nvapi_getbios(unsigned int devNum, char *desc, unsigned int maxlen) return 0; } -int wrap_nvapi_init() +int nvapi_init() { int num_gpus = cuda_num_devices(); NvAPI_Status ret = NvAPI_Initialize(); @@ -658,7 +695,7 @@ int gpu_fanpercent(struct cgpu_info *gpu) { unsigned int pct = 0; if (hnvml) { - wrap_nvml_get_fanpcnt(hnvml, gpu->gpu_id, &pct); + nvml_get_fanpcnt(hnvml, gpu->gpu_id, &pct); } #ifdef WIN32 else { @@ -679,7 +716,7 @@ float gpu_temp(struct cgpu_info *gpu) float tc = 0.0; unsigned int tmp = 0; if (hnvml) { - wrap_nvml_get_tempC(hnvml, gpu->gpu_id, &tmp); + nvml_get_tempC(hnvml, gpu->gpu_id, &tmp); tc = (float)tmp; } #ifdef WIN32 @@ -696,7 +733,7 @@ int gpu_pstate(struct cgpu_info *gpu) int pstate = -1; int support = -1; if (hnvml) { - support = wrap_nvml_get_pstate(hnvml, gpu->gpu_id, &pstate); + support = nvml_get_pstate(hnvml, gpu->gpu_id, &pstate); } #ifdef WIN32 if (support == -1) { @@ -713,7 +750,7 @@ int gpu_busid(struct cgpu_info *gpu) int busid = -1; int support = -1; if (hnvml) { - support = wrap_nvml_get_busid(hnvml, gpu->gpu_id, &busid); + support = nvml_get_busid(hnvml, gpu->gpu_id, &busid); } #ifdef WIN32 if (support == -1) { @@ -729,7 +766,7 @@ unsigned int gpu_power(struct cgpu_info *gpu) unsigned int mw = 0; int support = -1; if (hnvml) { - support = wrap_nvml_get_power_usage(hnvml, gpu->gpu_id, &mw); + support = nvml_get_power_usage(hnvml, gpu->gpu_id, &mw); } #ifdef WIN32 if (support == -1) { @@ -753,9 +790,9 @@ int gpu_info(struct cgpu_info *gpu) if (hnvml) { gpu->nvml_id = (int8_t) hnvml->cuda_nvml_device_id[id]; - wrap_nvml_get_info(hnvml, id, &gpu->gpu_vid, &gpu->gpu_pid); - wrap_nvml_get_serial(hnvml, id, gpu->gpu_sn, sizeof(gpu->gpu_sn)); - wrap_nvml_get_bios(hnvml, id, gpu->gpu_desc, sizeof(gpu->gpu_desc)); + nvml_get_info(hnvml, id, &gpu->gpu_vid, &gpu->gpu_pid); + nvml_get_serial(hnvml, id, gpu->gpu_sn, sizeof(gpu->gpu_sn)); + nvml_get_bios(hnvml, id, gpu->gpu_desc, sizeof(gpu->gpu_desc)); } #ifdef WIN32 gpu->nvapi_id = (int8_t) nvapi_dev_map[id]; diff --git a/nvml.h b/nvml.h index 2703377..0e3cd89 100644 --- a/nvml.h +++ b/nvml.h @@ -17,16 +17,7 @@ #include "miner.h" -/* - * Ugly hacks to avoid dependencies on the real nvml.h until it starts - * getting included with the CUDA toolkit or a GDK that's got a known - * install location, etc. - */ -typedef enum wrap_nvmlReturn_enum { - WRAPNVML_SUCCESS = 0 -} wrap_nvmlReturn_t; - -typedef void * wrap_nvmlDevice_t; +typedef void * nvmlDevice_t; /* our own version of the PCI info struct */ typedef struct { @@ -40,13 +31,40 @@ typedef struct { unsigned int res1; unsigned int res2; unsigned int res3; -} wrap_nvmlPciInfo_t; - -typedef enum nvmlClockType_t { -NVML_CLOCK_GRAPHICS = 0, -NVML_CLOCK_SM = 1, -NVML_CLOCK_MEM = 2 -} wrap_nvmlClockType_t; +} nvmlPciInfo_t; + +enum nvmlEnableState_t { + NVML_FEATURE_DISABLED = 0, + NVML_FEATURE_ENABLED = 1, + NVML_FEATURE_UNKNOWN = 2 +}; + +enum nvmlRestrictedAPI_t { + NVML_RESTRICTED_API_SET_APPLICATION_CLOCKS = 0, + NVML_RESTRICTED_API_SET_AUTO_BOOSTED_CLOCKS = 1, + NVML_RESTRICTED_API_COUNT = 2 +}; + +enum nvmlReturn_t { + NVML_SUCCESS = 0, + NVML_ERROR_UNINITIALIZED = 1, + NVML_ERROR_INVALID_ARGUMENT = 2, + NVML_ERROR_NOT_SUPPORTED = 3, + NVML_ERROR_NO_PERMISSION = 4, + NVML_ERROR_ALREADY_INITIALIZED = 5, + NVML_ERROR_NOT_FOUND = 6, + NVML_ERROR_INSUFFICIENT_SIZE = 7, + NVML_ERROR_INSUFFICIENT_POWER = 8, + NVML_ERROR_DRIVER_NOT_LOADED = 9, + NVML_ERROR_TIMEOUT = 10, + NVML_ERROR_UNKNOWN = 999 +}; + +enum nvmlClockType_t { + NVML_CLOCK_GRAPHICS = 0, + NVML_CLOCK_SM = 1, + NVML_CLOCK_MEM = 2 +}; #define NVML_DEVICE_SERIAL_BUFFER_SIZE 30 #define NVML_DEVICE_UUID_BUFFER_SIZE 80 @@ -66,46 +84,51 @@ typedef struct { unsigned int *nvml_pci_subsys_id; int *nvml_cuda_device_id; /* map NVML dev to CUDA dev */ int *cuda_nvml_device_id; /* map CUDA dev to NVML dev */ - wrap_nvmlDevice_t *devs; - wrap_nvmlReturn_t (*nvmlInit)(void); - wrap_nvmlReturn_t (*nvmlDeviceGetCount)(int *); - wrap_nvmlReturn_t (*nvmlDeviceGetHandleByIndex)(int, wrap_nvmlDevice_t *); - wrap_nvmlReturn_t (*nvmlDeviceGetClockInfo)(wrap_nvmlDevice_t, wrap_nvmlClockType_t, unsigned int *); - wrap_nvmlReturn_t (*nvmlDeviceGetApplicationsClock)(wrap_nvmlDevice_t, wrap_nvmlClockType_t, unsigned int *); - wrap_nvmlReturn_t (*nvmlDeviceGetPciInfo)(wrap_nvmlDevice_t, wrap_nvmlPciInfo_t *); - wrap_nvmlReturn_t (*nvmlDeviceGetName)(wrap_nvmlDevice_t, char *, int); - wrap_nvmlReturn_t (*nvmlDeviceGetTemperature)(wrap_nvmlDevice_t, int, unsigned int *); - wrap_nvmlReturn_t (*nvmlDeviceGetFanSpeed)(wrap_nvmlDevice_t, unsigned int *); - wrap_nvmlReturn_t (*nvmlDeviceGetPerformanceState)(wrap_nvmlDevice_t, int *); /* enum */ - wrap_nvmlReturn_t (*nvmlDeviceGetPowerUsage)(wrap_nvmlDevice_t, unsigned int *); - wrap_nvmlReturn_t (*nvmlDeviceGetSerial)(wrap_nvmlDevice_t, char *serial, unsigned int len); - wrap_nvmlReturn_t (*nvmlDeviceGetUUID)(wrap_nvmlDevice_t, char *uuid, unsigned int len); - wrap_nvmlReturn_t (*nvmlDeviceGetVbiosVersion)(wrap_nvmlDevice_t, char *version, unsigned int len); - wrap_nvmlReturn_t (*nvmlSystemGetDriverVersion)(char *version, unsigned int len); - char* (*nvmlErrorString)(wrap_nvmlReturn_t); - wrap_nvmlReturn_t (*nvmlShutdown)(void); -} wrap_nvml_handle; - - -wrap_nvml_handle * wrap_nvml_create(); -int wrap_nvml_destroy(wrap_nvml_handle *nvmlh); + nvmlDevice_t *devs; + nvmlEnableState_t *app_clocks; + nvmlReturn_t (*nvmlInit)(void); + nvmlReturn_t (*nvmlDeviceGetCount)(int *); + nvmlReturn_t (*nvmlDeviceGetHandleByIndex)(int, nvmlDevice_t *); + nvmlReturn_t (*nvmlDeviceGetAPIRestriction)(nvmlDevice_t, nvmlRestrictedAPI_t, nvmlEnableState_t *); + nvmlReturn_t (*nvmlDeviceSetAPIRestriction)(nvmlDevice_t, nvmlRestrictedAPI_t, nvmlEnableState_t); + nvmlReturn_t (*nvmlDeviceGetDefaultApplicationsClock)(nvmlDevice_t, nvmlClockType_t, unsigned int *); + nvmlReturn_t (*nvmlDeviceGetApplicationsClock)(nvmlDevice_t, nvmlClockType_t, unsigned int *); + nvmlReturn_t (*nvmlDeviceSetApplicationsClocks)(nvmlDevice_t, unsigned int, unsigned int); + nvmlReturn_t (*nvmlDeviceGetClockInfo)(nvmlDevice_t, nvmlClockType_t, unsigned int *); + nvmlReturn_t (*nvmlDeviceGetPciInfo)(nvmlDevice_t, nvmlPciInfo_t *); + nvmlReturn_t (*nvmlDeviceGetName)(nvmlDevice_t, char *, int); + nvmlReturn_t (*nvmlDeviceGetTemperature)(nvmlDevice_t, int, unsigned int *); + nvmlReturn_t (*nvmlDeviceGetFanSpeed)(nvmlDevice_t, unsigned int *); + nvmlReturn_t (*nvmlDeviceGetPerformanceState)(nvmlDevice_t, int *); /* enum */ + nvmlReturn_t (*nvmlDeviceGetPowerUsage)(nvmlDevice_t, unsigned int *); + nvmlReturn_t (*nvmlDeviceGetSerial)(nvmlDevice_t, char *serial, unsigned int len); + nvmlReturn_t (*nvmlDeviceGetUUID)(nvmlDevice_t, char *uuid, unsigned int len); + nvmlReturn_t (*nvmlDeviceGetVbiosVersion)(nvmlDevice_t, char *version, unsigned int len); + nvmlReturn_t (*nvmlSystemGetDriverVersion)(char *version, unsigned int len); + char* (*nvmlErrorString)(nvmlReturn_t); + nvmlReturn_t (*nvmlShutdown)(void); +} nvml_handle; + + +nvml_handle * nvml_create(); +int nvml_destroy(nvml_handle *nvmlh); /* * Query the number of GPUs seen by NVML */ -int wrap_nvml_get_gpucount(wrap_nvml_handle *nvmlh, int *gpucount); +int nvml_get_gpucount(nvml_handle *nvmlh, int *gpucount); /* * Query the number of GPUs seen by CUDA */ -int wrap_cuda_get_gpucount(wrap_nvml_handle *nvmlh, int *gpucount); +int cuda_get_gpucount(nvml_handle *nvmlh, int *gpucount); /* * query the name of the GPU model from the CUDA device ID * */ -int wrap_nvml_get_gpu_name(wrap_nvml_handle *nvmlh, +int nvml_get_gpu_name(nvml_handle *nvmlh, int gpuindex, char *namebuf, int bufsize); @@ -113,13 +136,13 @@ int wrap_nvml_get_gpu_name(wrap_nvml_handle *nvmlh, /* * Query the current GPU temperature (Celsius), from the CUDA device ID */ -int wrap_nvml_get_tempC(wrap_nvml_handle *nvmlh, +int nvml_get_tempC(nvml_handle *nvmlh, int gpuindex, unsigned int *tempC); /* * Query the current GPU fan speed (percent) from the CUDA device ID */ -int wrap_nvml_get_fanpcnt(wrap_nvml_handle *nvmlh, +int nvml_get_fanpcnt(nvml_handle *nvmlh, int gpuindex, unsigned int *fanpcnt); /* @@ -129,7 +152,7 @@ int wrap_nvml_get_fanpcnt(wrap_nvml_handle *nvmlh, * limited in some cases only to Tesla series GPUs. * If the query is run on an unsupported GPU, this routine will return -1. */ -int wrap_nvml_get_power_usage(wrap_nvml_handle *nvmlh, +int nvml_get_power_usage(nvml_handle *nvmlh, int gpuindex, unsigned int *milliwatts); @@ -147,7 +170,7 @@ int gpu_info(struct cgpu_info *gpu); /* nvapi functions */ #ifdef WIN32 -int wrap_nvapi_init(); +int nvapi_init(); #endif #endif /* USE_WRAPNVML */