diff --git a/bench.cpp b/bench.cpp index 3ef7264..87712bd 100644 --- a/bench.cpp +++ b/bench.cpp @@ -68,7 +68,7 @@ bool bench_algo_switch_next(int thr_id) char rate[32] = { 0 }; double hashrate = stats_get_speed(thr_id, thr_hashrates[thr_id]); format_hashrate(hashrate, rate); - applog(LOG_NOTICE, "GPU #%d: %s hashrate = %s", dev_id, algo_names[prev_algo], rate); + gpulog(LOG_NOTICE, thr_id, "%s hashrate = %s", algo_names[prev_algo], rate); // free current algo memory and track mem usage mused = cuda_available_memory(thr_id); @@ -77,8 +77,8 @@ bool bench_algo_switch_next(int thr_id) // check if there is memory leak if (device_mem_free[thr_id] > mfree) { - applog(LOG_WARNING, "GPU #%d, memory leak detected in %s ! %d MB free", - dev_id, algo_names[prev_algo], mfree); + gpulog(LOG_WARNING, thr_id, "memory leak detected in %s ! %d MB free", + algo_names[prev_algo], mfree); } // store used memory per algo algo_mem_used[thr_id][opt_algo] = device_mem_free[thr_id] - mused; diff --git a/ccminer.cpp b/ccminer.cpp index 8baa966..7ff4d24 100644 --- a/ccminer.cpp +++ b/ccminer.cpp @@ -1407,8 +1407,7 @@ static bool wanna_mine(int thr_id) float temp = gpu_temp(cgpu); if (temp > opt_max_temp) { if (!conditional_state[thr_id] && !opt_quiet) - applog(LOG_INFO, "GPU #%d: temperature too high (%.0f°c), waiting...", - device_map[thr_id], temp); + gpulog(LOG_INFO, thr_id, "temperature too high (%.0f°c), waiting...", temp); state = false; } #endif @@ -1637,7 +1636,7 @@ static void *miner_thread(void *userdata) // --benchmark [-a auto] if (opt_benchmark && bench_algo >= 0) { - //applog(LOG_DEBUG, "GPU #%d: loop %d", dev_id, loopcnt); + //gpulog(LOG_DEBUG, thr_id, "loop %d", loopcnt); if (loopcnt >= 3) { if (!bench_algo_switch_next(thr_id) && thr_id == 0) { @@ -1795,9 +1794,8 @@ static void *miner_thread(void *userdata) work.scanned_from = start_nonce; - if (opt_debug) - applog(LOG_DEBUG, "GPU #%d: start=%08x end=%08x range=%08x", - dev_id, start_nonce, max_nonce, (max_nonce-start_nonce)); + gpulog(LOG_DEBUG, thr_id, "start=%08x end=%08x range=%08x", + start_nonce, max_nonce, (max_nonce-start_nonce)); hashes_done = 0; gettimeofday(&tv_start, NULL); @@ -1969,8 +1967,7 @@ static void *miner_thread(void *userdata) work.scanned_to = max_nonce; if (opt_debug && opt_benchmark) { // to debug nonce ranges - applog(LOG_DEBUG, "GPU #%d: ends=%08x range=%08x", dev_id, - nonceptr[0], (nonceptr[0] - start_nonce)); + gpulog(LOG_DEBUG, thr_id, "ends=%08x range=%08x", nonceptr[0], (nonceptr[0] - start_nonce)); } } @@ -1978,9 +1975,9 @@ static void *miner_thread(void *userdata) hashlog_remember_scan_range(&work); /* output */ - if (!opt_quiet && firstwork_time) { + if (!opt_quiet && loopcnt > 1) { format_hashrate(thr_hashrates[thr_id], s); - applog(LOG_INFO, "GPU #%d: %s, %s", dev_id, device_name[dev_id], s); + gpulog(LOG_INFO, thr_id, "%s, %s", device_name[dev_id], s); } /* ignore first loop hashrate */ @@ -3191,6 +3188,8 @@ int main(int argc, char *argv[]) } if (!opt_n_threads) opt_n_threads = active_gpus; + else if (active_gpus > opt_n_threads) + active_gpus = opt_n_threads; // generally doesn't work... let 1 gpu_threads = opt_n_threads / active_gpus; @@ -3270,7 +3269,7 @@ int main(int argc, char *argv[]) bool gpu_reinit = (opt_cudaschedule >= 0); //false cuda_devicenames(); // refresh gpu vendor name applog(LOG_INFO, "NVML GPU monitoring enabled."); - for (int n=0; n < opt_n_threads; n++) { + for (int n=0; n < active_gpus; n++) { if (nvml_set_pstate(hnvml, device_map[n]) == 1) gpu_reinit = true; if (nvml_set_plimit(hnvml, device_map[n]) == 1) @@ -3285,7 +3284,7 @@ int main(int argc, char *argv[]) #endif // force reinit to set default device flags if (opt_cudaschedule >= 0 && !hnvml) { - for (int n=0; n < opt_n_threads; n++) { + for (int n=0; n < active_gpus; n++) { cuda_reset_device(n, NULL); } } diff --git a/cuda.cpp b/cuda.cpp index 54296b3..86f479d 100644 --- a/cuda.cpp +++ b/cuda.cpp @@ -246,8 +246,7 @@ cudaError_t MyStreamSynchronize(cudaStream_t stream, int situation, int thr_id) void cudaReportHardwareFailure(int thr_id, cudaError_t err, const char* func) { struct cgpu_info *gpu = &thr_info[thr_id].gpu; - int dev_id = device_map[thr_id % MAX_GPUS]; gpu->hw_errors++; - applog(LOG_ERR, "GPU #%d: %s %s", dev_id, func, cudaGetErrorString(err)); + gpulog(LOG_ERR, thr_id, "%s %s", func, cudaGetErrorString(err)); sleep(1); } diff --git a/miner.h b/miner.h index 71d8cba..f65a9c3 100644 --- a/miner.h +++ b/miner.h @@ -526,7 +526,7 @@ uint32_t cuda_default_throughput(int thr_id, uint32_t defcount); extern void format_hashrate(double hashrate, char *output); extern void applog(int prio, const char *fmt, ...); -#define gpulog(prio, fmt, thr_id, ...) applog(prio, fmt, thr_id, __VA_ARGS__) +extern void gpulog(int prio, int thr_id, const char *fmt, ...); void get_defconfig_path(char *out, size_t bufsize, char *argv0); extern void cbin2hex(char *out, const char *in, size_t len); extern char *bin2hex(const unsigned char *in, size_t len); diff --git a/util.cpp b/util.cpp index 13d1735..8ed5505 100644 --- a/util.cpp +++ b/util.cpp @@ -147,6 +147,37 @@ void applog(int prio, const char *fmt, ...) va_end(ap); } +extern int gpu_threads; +// Use different prefix if multiple cpu threads per gpu +// Also, auto hide LOG_DEBUG if --debug (-D) is not used +void gpulog(int prio, int thr_id, const char *fmt, ...) +{ + char _ALIGN(128) pfmt[128]; + char _ALIGN(128) line[256]; + int len, dev_id = device_map[thr_id % MAX_GPUS]; + va_list ap; + + if (prio == LOG_DEBUG && !opt_debug) + return; + + if (gpu_threads > 1) + len = snprintf(pfmt, 128, "GPU T%d: %s", thr_id, fmt); + else + len = snprintf(pfmt, 128, "GPU #%d: %s", dev_id, fmt); + pfmt[sizeof(pfmt)-1]='\0'; + + va_start(ap, fmt); + + if (len && vsnprintf(line, sizeof(line), pfmt, ap)) { + line[sizeof(line)-1]='\0'; + applog(prio, "%s", line); + } else { + fprintf(stderr, "%s OOM!\n", __func__); + } + + va_end(ap); +} + /* Get default config.json path (system specific) */ void get_defconfig_path(char *out, size_t bufsize, char *argv0) {