From dd740caa98d30055184ea59d93286981a1bcfcb5 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 13 Jul 2012 19:02:43 +1000 Subject: [PATCH] Provide initial support for the scrypt kernel to compile with and mine scrypt with the --scrypt option. --- cgminer.c | 10 +++++++++- driver-opencl.c | 44 +++++++++++++++++++++++--------------------- miner.h | 7 ++++++- ocl.c | 20 ++++++++++++++++---- 4 files changed, 54 insertions(+), 27 deletions(-) diff --git a/cgminer.c b/cgminer.c index 55d3943b..c0084ab7 100644 --- a/cgminer.c +++ b/cgminer.c @@ -107,6 +107,9 @@ int opt_dynamic_interval = 7; int nDevs; int opt_g_threads = 2; int gpu_threads; +#ifdef USE_SCRYPT +bool opt_scrypt; +#endif #endif bool opt_restart = true; static bool opt_nogpu; @@ -863,7 +866,7 @@ static struct opt_table opt_config_table[] = { #ifdef HAVE_OPENCL OPT_WITH_ARG("--kernel|-k", set_kernel, NULL, NULL, - "Override kernel to use (diablo, poclbm, phatk or diakgcn) - one value or comma separated"), + "Override sha256 kernel to use (diablo, poclbm, phatk or diakgcn) - one value or comma separated"), #endif #ifdef USE_ICARUS OPT_WITH_ARG("--icarus-timing", @@ -953,6 +956,11 @@ static struct opt_table opt_config_table[] = { OPT_WITH_ARG("--sched-stop", set_schedtime, NULL, &schedstop, "Set a time of day in HH:MM to stop mining (will quit without a start time)"), +#ifdef USE_SCRYPT + OPT_WITHOUT_ARG("--scrypt", + opt_set_bool, &opt_scrypt, + "Use the scrypt algorithm for mining (litecoin only)"), +#endif OPT_WITH_ARG("--sharelog", set_sharelog, NULL, NULL, "Append share log to file"), diff --git a/driver-opencl.c b/driver-opencl.c index e8a901dc..0d77b4af 100644 --- a/driver-opencl.c +++ b/driver-opencl.c @@ -137,7 +137,7 @@ static enum cl_kernels select_kernel(char *arg) return KL_POCLBM; if (!strcmp(arg, "phatk")) return KL_PHATK; -#ifdef HAVE_SCRYPT +#ifdef USE_SCRYPT if (!strcmp(arg, "scrypt")) return KL_SCRYPT; #endif @@ -150,6 +150,8 @@ char *set_kernel(char *arg) int i, device = 0; char *nextptr; + if (opt_scrypt) + return "Cannot use sha256 kernel with scrypt"; nextptr = strtok(arg, ","); if (nextptr == NULL) return "Invalid parameters for set kernel"; @@ -990,7 +992,7 @@ static cl_int queue_diablo_kernel(_clState *clState, dev_blk_ctx *blk, cl_uint t return status; } -#ifdef HAVE_SCRYPT +#ifdef USE_SCRYPT static cl_int queue_scrypt_kernel(_clState *clState, dev_blk_ctx *blk, cl_uint threads) { cl_int status = 0; @@ -1254,25 +1256,25 @@ static bool opencl_thread_prepare(struct thr_info *thr) if (!cgpu->kname) { switch (clStates[i]->chosen_kernel) { - case KL_DIABLO: - cgpu->kname = "diablo"; - break; - case KL_DIAKGCN: - cgpu->kname = "diakgcn"; - break; - case KL_PHATK: - cgpu->kname = "phatk"; - break; -#ifdef HAVE_SCRYPT - case KL_SCRYPT: - cgpu->kname = "scrypt"; - break; + case KL_DIABLO: + cgpu->kname = "diablo"; + break; + case KL_DIAKGCN: + cgpu->kname = "diakgcn"; + break; + case KL_PHATK: + cgpu->kname = "phatk"; + break; +#ifdef USE_SCRYPT + case KL_SCRYPT: + cgpu->kname = "scrypt"; + break; #endif - case KL_POCLBM: - cgpu->kname = "poclbm"; - break; - default: - break; + case KL_POCLBM: + cgpu->kname = "poclbm"; + break; + default: + break; } } applog(LOG_INFO, "initCl() finished. Found %s", name); @@ -1309,7 +1311,7 @@ static bool opencl_thread_init(struct thr_info *thr) case KL_DIAKGCN: thrdata->queue_kernel_parameters = &queue_diakgcn_kernel; break; -#ifdef HAVE_SCRYPT +#ifdef USE_SCRYPT case KL_SCRYPT: thrdata->queue_kernel_parameters = &queue_scrypt_kernel; break; diff --git a/miner.h b/miner.h index 74824730..c1cbe74e 100644 --- a/miner.h +++ b/miner.h @@ -262,7 +262,7 @@ enum cl_kernels { KL_PHATK, KL_DIAKGCN, KL_DIABLO, -#ifdef HAVE_SCRYPT +#ifdef USE_SCRYPT KL_SCRYPT, #endif }; @@ -620,6 +620,11 @@ extern bool use_syslog; extern struct thr_info *thr_info; extern struct cgpu_info gpus[MAX_GPUDEVICES]; extern int gpu_threads; +#ifdef USE_SCRYPT +extern bool opt_scrypt; +#else +#define opt_scrypt (0) +#endif extern double total_secs; extern int mining_threads; extern struct cgpu_info *cpus; diff --git a/ocl.c b/ocl.c index 464cb4e1..7b802571 100644 --- a/ocl.c +++ b/ocl.c @@ -354,8 +354,11 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize) char numbuf[10]; if (gpus[gpu].kernel == KL_NONE) { - /* Detect all 2.6 SDKs not with Tahiti and use diablo kernel */ - if (!strstr(name, "Tahiti") && + if (opt_scrypt) { + applog(LOG_INFO, "Selecting scrypt kernel"); + clState->chosen_kernel = KL_SCRYPT; + } else if (!strstr(name, "Tahiti") && + /* Detect all 2.6 SDKs not with Tahiti and use diablo kernel */ (strstr(vbuff, "844.4") || // Linux 64 bit ATI 2.6 SDK strstr(vbuff, "851.4") || // Windows 64 bit "" strstr(vbuff, "831.4") || @@ -407,6 +410,10 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize) strcpy(filename, DIAKGCN_KERNNAME".cl"); strcpy(binaryfilename, DIAKGCN_KERNNAME); break; + case KL_SCRYPT: + strcpy(filename, SCRYPT_KERNNAME".cl"); + strcpy(binaryfilename, SCRYPT_KERNNAME); + break; case KL_NONE: /* Shouldn't happen */ case KL_DIABLO: strcpy(filename, DIABLO_KERNNAME".cl"); @@ -528,8 +535,13 @@ build: /* create a cl program executable for all the devices specified */ char *CompilerOptions = calloc(1, 256); - sprintf(CompilerOptions, "-D WORKSIZE=%d -D VECTORS%d -D WORKVEC=%d", - (int)clState->wsize, clState->vwidth, (int)clState->wsize * clState->vwidth); + if (opt_scrypt) { + sprintf(CompilerOptions, "-D LOOKUP_GAP=2 -D CONCURRENT_THREADS=6144 -D WORKSIZE=%d", + (int)clState->wsize); + } else { + sprintf(CompilerOptions, "-D WORKSIZE=%d -D VECTORS%d -D WORKVEC=%d", + (int)clState->wsize, clState->vwidth, (int)clState->wsize * clState->vwidth); + } applog(LOG_DEBUG, "Setting worksize to %d", clState->wsize); if (clState->vwidth > 1) applog(LOG_DEBUG, "Patched source to suit %d vectors", clState->vwidth);