Browse Source

core: simplify kernel selection code.

WIP!

Use a string instead of a state-machine-ey kernel selection mechanism
where kernel names have to be predefined. This should allow just dropping
new kernels into dir `kernel` without bloating the code in three other
places.

Is in dire need of a cleanup, function parameter check, edge case check -
all the usual testing.

In particular, checking these definitions/keywords:

* enum cl_kernels
* kname
* [c]gpu[s]->kernel (and similar)
* memory cleanup after strdup()?..
* chosen_kernel
* queue_scrypt_kernel
* strbuf
* initCl
build-mingw
Noel Maersk 11 years ago
parent
commit
1333ed576d
  1. 72
      driver-opencl.c
  2. 3
      miner.h
  3. 47
      ocl.c
  4. 20
      sgminer.c

72
driver-opencl.c

@ -194,46 +194,24 @@ char *set_thread_concurrency(char *arg)
return NULL; return NULL;
} }
static enum cl_kernels select_kernel(char *arg)
{
if (!strcmp(arg, ALEXKARNEW_KERNNAME))
return KL_ALEXKARNEW;
if (!strcmp(arg, ALEXKAROLD_KERNNAME))
return KL_ALEXKAROLD;
if (!strcmp(arg, CKOLIVAS_KERNNAME))
return KL_CKOLIVAS;
if (!strcmp(arg, ZUIKKIS_KERNNAME))
return KL_ZUIKKIS;
if (!strcmp(arg, PSW_KERNNAME))
return KL_PSW;
return KL_NONE;
}
char *set_kernel(char *arg) char *set_kernel(char *arg)
{ {
enum cl_kernels kern;
int i, device = 0;
char *nextptr; char *nextptr;
int i, device = 0;
nextptr = strtok(arg, ","); nextptr = strtok(arg, ",");
if (nextptr == NULL) if (nextptr == NULL)
return "Invalid parameters for set kernel"; return "Invalid parameters for set kernel";
kern = select_kernel(nextptr);
if (kern == KL_NONE)
return "Invalid parameter to set_kernel";
gpus[device++].kernel = kern;
while ((nextptr = strtok(NULL, ",")) != NULL) { gpus[device++].kname = strdup(nextptr);
kern = select_kernel(nextptr);
if (kern == KL_NONE)
return "Invalid parameter to set_kernel";
gpus[device++].kernel = kern; while ((nextptr = strtok(NULL, ",")) != NULL)
} gpus[device++].kname = strdup(nextptr);
/* If only one kernel name provided, use same for all GPUs. */
if (device == 1) { if (device == 1) {
for (i = device; i < MAX_GPUDEVICES; i++) for (i = device; i < MAX_GPUDEVICES; i++)
gpus[i].kernel = gpus[0].kernel; gpus[i].kname = strdup(gpus[0].kname);
} }
return NULL; return NULL;
@ -1303,27 +1281,8 @@ static bool opencl_thread_prepare(struct thr_info *thr)
if (!cgpu->name) if (!cgpu->name)
cgpu->name = strdup(name); cgpu->name = strdup(name);
if (!cgpu->kname) if (!cgpu->kname)
{ cgpu->kname = strdup("ckolivas");
switch (clStates[i]->chosen_kernel) {
case KL_ALEXKARNEW:
cgpu->kname = ALEXKARNEW_KERNNAME;
break;
case KL_ALEXKAROLD:
cgpu->kname = ALEXKAROLD_KERNNAME;
break;
case KL_CKOLIVAS:
cgpu->kname = CKOLIVAS_KERNNAME;
break;
case KL_ZUIKKIS:
cgpu->kname = ZUIKKIS_KERNNAME;
break;
case KL_PSW:
cgpu->kname = PSW_KERNNAME;
break;
default:
break;
}
}
applog(LOG_INFO, "initCl() finished. Found %s", name); applog(LOG_INFO, "initCl() finished. Found %s", name);
cgtime(&now); cgtime(&now);
get_datestamp(cgpu->init, sizeof(cgpu->init), &now); get_datestamp(cgpu->init, sizeof(cgpu->init), &now);
@ -1347,18 +1306,7 @@ static bool opencl_thread_init(struct thr_info *thr)
return false; return false;
} }
switch (clState->chosen_kernel) { thrdata->queue_kernel_parameters = &queue_scrypt_kernel;
case KL_ALEXKARNEW:
case KL_ALEXKAROLD:
case KL_CKOLIVAS:
case KL_PSW:
case KL_ZUIKKIS:
thrdata->queue_kernel_parameters = &queue_scrypt_kernel;
break;
default:
applog(LOG_ERR, "Failed to choose kernel in opencl_thread_init");
break;
}
thrdata->res = (uint32_t *)calloc(buffersize, 1); thrdata->res = (uint32_t *)calloc(buffersize, 1);

3
miner.h

@ -471,7 +471,7 @@ struct cgpu_info {
int64_t max_hashes; int64_t max_hashes;
const char *kname; char *kname;
bool mapped; bool mapped;
int virtual_gpu; int virtual_gpu;
int virtual_adl; int virtual_adl;
@ -482,7 +482,6 @@ struct cgpu_info {
cl_uint vwidth; cl_uint vwidth;
size_t work_size; size_t work_size;
enum cl_kernels kernel;
cl_ulong max_alloc; cl_ulong max_alloc;
int opt_lg, lookup_gap; int opt_lg, lookup_gap;

47
ocl.c

@ -411,13 +411,11 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
char binaryfilename[255]; char binaryfilename[255];
char filename[255]; char filename[255];
char numbuf[16]; char numbuf[16];
char strbuf[255];
if (cgpu->kernel == KL_NONE) { if (strcmp(cgpu->kname, "") == 0) {
applog(LOG_INFO, "Selecting kernel ckolivas"); applog(LOG_INFO, "No kernel specified, selecting kernel ckolivas");
clState->chosen_kernel = KL_CKOLIVAS; strcpy(cgpu->kname, "ckolivas");
cgpu->kernel = clState->chosen_kernel;
} else {
clState->chosen_kernel = cgpu->kernel;
} }
/* For some reason 2 vectors is still better even if the card says /* For some reason 2 vectors is still better even if the card says
@ -431,36 +429,13 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
/* All available kernels only support vector 1 */ /* All available kernels only support vector 1 */
cgpu->vwidth = 1; cgpu->vwidth = 1;
switch (clState->chosen_kernel) { sprintf(strbuf, "%s.cl", cgpu->kname);
case KL_ALEXKARNEW: strcpy(filename, strbuf);
applog(LOG_WARNING, "Kernel alexkarnew is experimental."); strcpy(binaryfilename, cgpu->kname);
strcpy(filename, ALEXKARNEW_KERNNAME".cl");
strcpy(binaryfilename, ALEXKARNEW_KERNNAME); /* Kernel zuikkis only supports lookup-gap 2 */
break; if (strcmp(cgpu->kname, "zuikkis") == 0)
case KL_ALEXKAROLD: cgpu->lookup_gap = 2;
applog(LOG_WARNING, "Kernel alexkarold is experimental.");
strcpy(filename, ALEXKAROLD_KERNNAME".cl");
strcpy(binaryfilename, ALEXKAROLD_KERNNAME);
break;
case KL_CKOLIVAS:
strcpy(filename, CKOLIVAS_KERNNAME".cl");
strcpy(binaryfilename, CKOLIVAS_KERNNAME);
break;
case KL_PSW:
applog(LOG_WARNING, "Kernel psw is experimental.");
strcpy(filename, PSW_KERNNAME".cl");
strcpy(binaryfilename, PSW_KERNNAME);
break;
case KL_ZUIKKIS:
applog(LOG_WARNING, "Kernel zuikkis is experimental.");
strcpy(filename, ZUIKKIS_KERNNAME".cl");
strcpy(binaryfilename, ZUIKKIS_KERNNAME);
/* Kernel only supports lookup-gap 2 */
cgpu->lookup_gap = 2;
break;
case KL_NONE: /* Shouldn't happen */
break;
}
/* Vectors are hard-set to 1 above. */ /* Vectors are hard-set to 1 above. */
if (likely(cgpu->vwidth)) if (likely(cgpu->vwidth))

20
sgminer.c

@ -4262,25 +4262,7 @@ void write_config(FILE *fcfg)
fputs("\",\n\"kernel\" : \"", fcfg); fputs("\",\n\"kernel\" : \"", fcfg);
for(i = 0; i < nDevs; i++) { for(i = 0; i < nDevs; i++) {
fprintf(fcfg, "%s", i > 0 ? "," : ""); fprintf(fcfg, "%s", i > 0 ? "," : "");
switch (gpus[i].kernel) { fprintf(fcfg, "%s", gpus[i].kname);
case KL_NONE: // Shouldn't happen
break;
case KL_ALEXKARNEW:
fprintf(fcfg, ALEXKARNEW_KERNNAME);
break;
case KL_ALEXKAROLD:
fprintf(fcfg, ALEXKAROLD_KERNNAME);
break;
case KL_CKOLIVAS:
fprintf(fcfg, CKOLIVAS_KERNNAME);
break;
case KL_PSW:
fprintf(fcfg, PSW_KERNNAME);
break;
case KL_ZUIKKIS:
fprintf(fcfg, ZUIKKIS_KERNNAME);
break;
}
} }
fputs("\",\n\"lookup-gap\" : \"", fcfg); fputs("\",\n\"lookup-gap\" : \"", fcfg);

Loading…
Cancel
Save