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) @@ -194,46 +194,24 @@ char *set_thread_concurrency(char *arg)
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)
{
enum cl_kernels kern;
int i, device = 0;
char *nextptr;
int i, device = 0;
nextptr = strtok(arg, ",");
if (nextptr == NULL)
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) {
kern = select_kernel(nextptr);
if (kern == KL_NONE)
return "Invalid parameter to set_kernel";
gpus[device++].kname = strdup(nextptr);
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) {
for (i = device; i < MAX_GPUDEVICES; i++)
gpus[i].kernel = gpus[0].kernel;
gpus[i].kname = strdup(gpus[0].kname);
}
return NULL;
@ -1303,27 +1281,8 @@ static bool opencl_thread_prepare(struct thr_info *thr) @@ -1303,27 +1281,8 @@ static bool opencl_thread_prepare(struct thr_info *thr)
if (!cgpu->name)
cgpu->name = strdup(name);
if (!cgpu->kname)
{
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;
}
}
cgpu->kname = strdup("ckolivas");
applog(LOG_INFO, "initCl() finished. Found %s", name);
cgtime(&now);
get_datestamp(cgpu->init, sizeof(cgpu->init), &now);
@ -1347,18 +1306,7 @@ static bool opencl_thread_init(struct thr_info *thr) @@ -1347,18 +1306,7 @@ static bool opencl_thread_init(struct thr_info *thr)
return false;
}
switch (clState->chosen_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->queue_kernel_parameters = &queue_scrypt_kernel;
thrdata->res = (uint32_t *)calloc(buffersize, 1);

3
miner.h

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

47
ocl.c

@ -411,13 +411,11 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize) @@ -411,13 +411,11 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
char binaryfilename[255];
char filename[255];
char numbuf[16];
char strbuf[255];
if (cgpu->kernel == KL_NONE) {
applog(LOG_INFO, "Selecting kernel ckolivas");
clState->chosen_kernel = KL_CKOLIVAS;
cgpu->kernel = clState->chosen_kernel;
} else {
clState->chosen_kernel = cgpu->kernel;
if (strcmp(cgpu->kname, "") == 0) {
applog(LOG_INFO, "No kernel specified, selecting kernel ckolivas");
strcpy(cgpu->kname, "ckolivas");
}
/* 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) @@ -431,36 +429,13 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
/* All available kernels only support vector 1 */
cgpu->vwidth = 1;
switch (clState->chosen_kernel) {
case KL_ALEXKARNEW:
applog(LOG_WARNING, "Kernel alexkarnew is experimental.");
strcpy(filename, ALEXKARNEW_KERNNAME".cl");
strcpy(binaryfilename, ALEXKARNEW_KERNNAME);
break;
case KL_ALEXKAROLD:
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;
}
sprintf(strbuf, "%s.cl", cgpu->kname);
strcpy(filename, strbuf);
strcpy(binaryfilename, cgpu->kname);
/* Kernel zuikkis only supports lookup-gap 2 */
if (strcmp(cgpu->kname, "zuikkis") == 0)
cgpu->lookup_gap = 2;
/* Vectors are hard-set to 1 above. */
if (likely(cgpu->vwidth))

20
sgminer.c

@ -4262,25 +4262,7 @@ void write_config(FILE *fcfg) @@ -4262,25 +4262,7 @@ void write_config(FILE *fcfg)
fputs("\",\n\"kernel\" : \"", fcfg);
for(i = 0; i < nDevs; i++) {
fprintf(fcfg, "%s", i > 0 ? "," : "");
switch (gpus[i].kernel) {
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;
}
fprintf(fcfg, "%s", gpus[i].kname);
}
fputs("\",\n\"lookup-gap\" : \"", fcfg);

Loading…
Cancel
Save