From b53cc151aa7f770121c2754cdc502f90d6033da4 Mon Sep 17 00:00:00 2001 From: ystarnaud Date: Sun, 9 Nov 2014 18:42:33 -0500 Subject: [PATCH] Fix worksize per GPU Improper use of strtok() on the original config string instead of a copy resulted in the worksize being cut down to GPU0's worksize only after first use. --- driver-opencl.c | 30 ++++++++++++++++++------------ driver-opencl.h | 2 +- sgminer.c | 4 ++-- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/driver-opencl.c b/driver-opencl.c index f46f3162..ed3a87a0 100644 --- a/driver-opencl.c +++ b/driver-opencl.c @@ -91,32 +91,38 @@ char *set_vector(char *arg) return NULL; } -char *set_worksize(char *arg) +char *set_worksize(const char *arg) { int i, val = 0, device = 0; + char *tmpstr = strdup(arg); char *nextptr; - nextptr = strtok(arg, ","); - if (nextptr == NULL) + if ((nextptr = strtok(tmpstr, ",")) == NULL) { + free(tmpstr); return "Invalid parameters for set work size"; - val = atoi(nextptr); - if (val < 1 || val > 9999) - return "Invalid value passed to set_worksize"; - - gpus[device++].work_size = val; + } - while ((nextptr = strtok(NULL, ",")) != NULL) { + do { val = atoi(nextptr); - if (val < 1 || val > 9999) + + if (val < 1 || val > 9999) { + free(tmpstr); return "Invalid value passed to set_worksize"; + } + applog(LOG_DEBUG, "GPU %d Worksize set to %u.", device, val); gpus[device++].work_size = val; - } + } while ((nextptr = strtok(NULL, ",")) != NULL); + + // if only 1 worksize was passed, assign the same worksize for all remaining GPUs if (device == 1) { - for (i = device; i < MAX_GPUDEVICES; i++) + for (i = device; i < total_devices; ++i) { gpus[i].work_size = gpus[0].work_size; + applog(LOG_DEBUG, "GPU %d Worksize set to %u.", i, gpus[i].work_size); + } } + free(tmpstr); return NULL; } diff --git a/driver-opencl.h b/driver-opencl.h index d1e1e5f4..5eb1404b 100644 --- a/driver-opencl.h +++ b/driver-opencl.h @@ -20,7 +20,7 @@ extern char *set_intensity(const char *arg); extern char *set_xintensity(const char *arg); extern char *set_rawintensity(const char *arg); extern char *set_vector(char *arg); -extern char *set_worksize(char *arg); +extern char *set_worksize(const char *arg); extern char *set_shaders(char *arg); extern char *set_lookup_gap(char *arg); extern char *set_thread_concurrency(const char *arg); diff --git a/sgminer.c b/sgminer.c index 18bba5fb..e76a7a01 100644 --- a/sgminer.c +++ b/sgminer.c @@ -6015,7 +6015,7 @@ static void apply_initial_gpu_settings(struct pool *pool) //worksize if(!empty_string((opt = get_pool_setting(pool->worksize, default_profile.worksize)))) - set_worksize((char *)opt); + set_worksize(opt); //apply algorithm for (i = 0; i < nDevs; i++) @@ -6415,7 +6415,7 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work) if(opt_isset(pool_switch_options, SWITCHER_APPLY_WORKSIZE)) { if(!empty_string((opt = get_pool_setting(work->pool->worksize, default_profile.worksize)))) - set_worksize((char *)opt); + set_worksize(opt); } #ifdef HAVE_ADL