From 8c4b25426f83e3ee872da332350242469613b74c Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 3 Jul 2016 12:00:20 +0200 Subject: [PATCH] nvapi: device led flash on submit disabled by default, require --led=100 on nvidia compatible devices Gigabyte RGB led hack is not perfect for the moment, can fail and require a reboot. --- ccminer.cpp | 5 +++++ nvml.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++----- nvml.h | 4 ++++ 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/ccminer.cpp b/ccminer.cpp index 620b90e..ae7f6ae 100644 --- a/ccminer.cpp +++ b/ccminer.cpp @@ -1255,7 +1255,9 @@ static void *workio_thread(void *userdata) ok = workio_get_work(wc, curl); break; case WC_SUBMIT_WORK: + gpu_led_on(device_map[wc->thr->id]); ok = workio_submit_work(wc, curl); + gpu_led_off(device_map[wc->thr->id]); break; case WC_ABORT: default: /* should never happen */ @@ -1642,6 +1644,8 @@ static void *miner_thread(void *userdata) } } + gpu_led_off(dev_id); + while (!abort_flag) { struct timeval tv_start, tv_end, diff; unsigned long hashes_done; @@ -2200,6 +2204,7 @@ static void *miner_thread(void *userdata) /* if nonce found, submit work */ if (rc > 0 && !opt_benchmark) { + gpu_led_percent(dev_id, 50); if (!submit_work(mythr, &work)) break; diff --git a/nvml.cpp b/nvml.cpp index fdadedb..4f3e260 100644 --- a/nvml.cpp +++ b/nvml.cpp @@ -38,6 +38,7 @@ extern uint32_t device_plimit[MAX_GPUS]; extern uint8_t device_tlimit[MAX_GPUS]; extern int8_t device_pstate[MAX_GPUS]; extern int32_t device_led[MAX_GPUS]; +int32_t device_led_state[MAX_GPUS] = { 0 }; uint32_t clock_prev[MAX_GPUS] = { 0 }; uint32_t clock_prev_mem[MAX_GPUS] = { 0 }; @@ -979,17 +980,18 @@ static int SetGigabyteRGBLogo(unsigned int devNum, uint32_t RGB) //ret = NvAPI_DLL_I2CWriteEx(phys[devNum], i2cInfo, data); ret = NvAPI_DLL_I2CReadEx(phys[devNum], i2cInfo, data); + ret = NvAPI_DLL_I2CReadEx(phys[devNum], i2cInfo, data); free(i2cInfo); return (int) ret; } -int nvapi_set_led(unsigned int devNum, int32_t RGB, char *device_name) +int nvapi_set_led(unsigned int devNum, int RGB, char *device_name) { uint16_t vid = 0, pid = 0; NvAPI_Status ret; if (strstr(device_name, "Gigabyte GTX 10")) { if (opt_debug) - applog(LOG_DEBUG, " Set RGB led to %06x", RGB); + applog(LOG_DEBUG, "GPU %x: Set RGB led to %06x", (int) phys[devNum], RGB); return SetGigabyteRGBLogo(devNum, (uint32_t) RGB); } else { NV_GPU_QUERY_ILLUMINATION_SUPPORT_PARM* illu; @@ -1004,7 +1006,7 @@ int nvapi_set_led(unsigned int devNum, int32_t RGB, char *device_name) led->Attribute = NV_GPU_IA_LOGO_BRIGHTNESS; NvAPI_GPU_GetIllumination(led); if (opt_debug) - applog(LOG_DEBUG, " Led level was %u, set to %d", RGB); + applog(LOG_DEBUG, "GPU %x: Led level was %d, set to %d", (int) phys[devNum], led->Value, RGB); led->Value = (uint32_t) RGB; ret = NvAPI_GPU_SetIllumination((NV_GPU_SET_ILLUMINATION_PARM*) led); free(led); @@ -1597,7 +1599,11 @@ int nvapi_init_settings() // dunno how via nvapi or/and pascal } if (device_led[dev_id] != -1) { - nvapi_set_led(nvapi_dev_map[dev_id], device_led[dev_id], device_name[dev_id]); + int err = nvapi_set_led(nvapi_dev_map[dev_id], device_led[dev_id], device_name[dev_id]); + if (err != 0) { + gpulog(LOG_WARNING, n, "Unable to set led value (err %d)", err); + } + device_led_state[dev_id] = device_led[dev_id]; } } @@ -1609,7 +1615,7 @@ unsigned int nvapi_devnum(int dev_id) return nvapi_dev_map[dev_id]; } -#endif +#endif /* WIN32 : Windows specific (nvapi) */ /* api functions -------------------------------------- */ @@ -1809,3 +1815,36 @@ int gpu_info(struct cgpu_info *gpu) } #endif /* USE_WRAPNVML */ + + +void gpu_led_on(int dev_id) +{ +#if defined(WIN32) && defined(USE_WRAPNVML) + int value = device_led[dev_id]; + if (device_led_state[dev_id] != value) { + if (nvapi_set_led(nvapi_dev_map[dev_id], value, device_name[dev_id]) == 0) + device_led_state[dev_id] = value; + } +#endif +} + +void gpu_led_percent(int dev_id, int percent) +{ +#if defined(WIN32) && defined(USE_WRAPNVML) + int value = (device_led[dev_id] * percent) / 100; + if (device_led_state[dev_id] != value) { + if (nvapi_set_led(nvapi_dev_map[dev_id], value, device_name[dev_id]) == 0) + device_led_state[dev_id] = value; + } +#endif +} + +void gpu_led_off(int dev_id) +{ +#if defined(WIN32) && defined(USE_WRAPNVML) + if (device_led_state[dev_id]) { + if (nvapi_set_led(nvapi_dev_map[dev_id], 0, device_name[dev_id]) == 0) + device_led_state[dev_id] = 0; + } +#endif +} diff --git a/nvml.h b/nvml.h index d6130af..7785bd6 100644 --- a/nvml.h +++ b/nvml.h @@ -234,3 +234,7 @@ int nvapiMemGetInfo(int dev_id, size_t *free, size_t *total); #endif #endif /* USE_WRAPNVML */ + +void gpu_led_on(int dev_id); +void gpu_led_percent(int dev_id, int percent); +void gpu_led_off(int dev_id);