Skip to content

Commit b53cc15

Browse files
ystarnaudtroky
authored andcommitted
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.
1 parent ba9818a commit b53cc15

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

driver-opencl.c

+18-12
Original file line numberDiff line numberDiff line change
@@ -91,32 +91,38 @@ char *set_vector(char *arg)
9191
return NULL;
9292
}
9393

94-
char *set_worksize(char *arg)
94+
char *set_worksize(const char *arg)
9595
{
9696
int i, val = 0, device = 0;
97+
char *tmpstr = strdup(arg);
9798
char *nextptr;
9899

99-
nextptr = strtok(arg, ",");
100-
if (nextptr == NULL)
100+
if ((nextptr = strtok(tmpstr, ",")) == NULL) {
101+
free(tmpstr);
101102
return "Invalid parameters for set work size";
102-
val = atoi(nextptr);
103-
if (val < 1 || val > 9999)
104-
return "Invalid value passed to set_worksize";
105-
106-
gpus[device++].work_size = val;
103+
}
107104

108-
while ((nextptr = strtok(NULL, ",")) != NULL) {
105+
do {
109106
val = atoi(nextptr);
110-
if (val < 1 || val > 9999)
107+
108+
if (val < 1 || val > 9999) {
109+
free(tmpstr);
111110
return "Invalid value passed to set_worksize";
111+
}
112112

113+
applog(LOG_DEBUG, "GPU %d Worksize set to %u.", device, val);
113114
gpus[device++].work_size = val;
114-
}
115+
} while ((nextptr = strtok(NULL, ",")) != NULL);
116+
117+
// if only 1 worksize was passed, assign the same worksize for all remaining GPUs
115118
if (device == 1) {
116-
for (i = device; i < MAX_GPUDEVICES; i++)
119+
for (i = device; i < total_devices; ++i) {
117120
gpus[i].work_size = gpus[0].work_size;
121+
applog(LOG_DEBUG, "GPU %d Worksize set to %u.", i, gpus[i].work_size);
122+
}
118123
}
119124

125+
free(tmpstr);
120126
return NULL;
121127
}
122128

driver-opencl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern char *set_intensity(const char *arg);
2020
extern char *set_xintensity(const char *arg);
2121
extern char *set_rawintensity(const char *arg);
2222
extern char *set_vector(char *arg);
23-
extern char *set_worksize(char *arg);
23+
extern char *set_worksize(const char *arg);
2424
extern char *set_shaders(char *arg);
2525
extern char *set_lookup_gap(char *arg);
2626
extern char *set_thread_concurrency(const char *arg);

sgminer.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -6015,7 +6015,7 @@ static void apply_initial_gpu_settings(struct pool *pool)
60156015

60166016
//worksize
60176017
if(!empty_string((opt = get_pool_setting(pool->worksize, default_profile.worksize))))
6018-
set_worksize((char *)opt);
6018+
set_worksize(opt);
60196019

60206020
//apply algorithm
60216021
for (i = 0; i < nDevs; i++)
@@ -6415,7 +6415,7 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work)
64156415
if(opt_isset(pool_switch_options, SWITCHER_APPLY_WORKSIZE))
64166416
{
64176417
if(!empty_string((opt = get_pool_setting(work->pool->worksize, default_profile.worksize))))
6418-
set_worksize((char *)opt);
6418+
set_worksize(opt);
64196419
}
64206420

64216421
#ifdef HAVE_ADL

0 commit comments

Comments
 (0)