From f1c6ae22f79863ee01ed164c7355b56e9915cfcb Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 31 Aug 2012 09:13:19 +1000 Subject: [PATCH] Adjust opencl intensity when adjusting thread count to prevent it getting pegged at a value below the minimum threads possible. --- driver-opencl.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/driver-opencl.c b/driver-opencl.c index 6883ada3..ded20c31 100644 --- a/driver-opencl.c +++ b/driver-opencl.c @@ -1106,20 +1106,23 @@ static cl_int queue_scrypt_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_u } #endif -static void set_threads_hashes(unsigned int vectors, unsigned int *threads, - int64_t *hashes, size_t *globalThreads, - unsigned int minthreads, int intensity) +static void set_threads_hashes(unsigned int vectors,int64_t *hashes, size_t *globalThreads, + unsigned int minthreads, __maybe_unused int *intensity) { - if (opt_scrypt) { - if (intensity < 0) - intensity = 0; - *threads = 1 << intensity; - } else - *threads = 1 << (15 + intensity); - if (*threads < minthreads) - *threads = minthreads; - *globalThreads = *threads; - *hashes = *threads * vectors; + unsigned int threads = 0; + + while (threads < minthreads) { + threads = 1 << ((opt_scrypt ? 0 : 15) + *intensity); + if (threads < minthreads) { + if (likely(*intensity < MAX_INTENSITY)) + (*intensity)++; + else + threads = minthreads; + } + } + + *globalThreads = threads; + *hashes = threads * vectors; } #endif /* HAVE_OPENCL */ @@ -1499,15 +1502,13 @@ static int64_t opencl_scanhash(struct thr_info *thr, struct work *work, cl_int status; size_t globalThreads[1]; size_t localThreads[1] = { clState->wsize }; - unsigned int threads; int64_t hashes; /* This finish flushes the readbuffer set with CL_FALSE later */ if (!gpu->dynamic) clFinish(clState->commandQueue); - set_threads_hashes(clState->vwidth, &threads, &hashes, globalThreads, - localThreads[0], gpu->intensity); + set_threads_hashes(clState->vwidth, &hashes, globalThreads, localThreads[0], &gpu->intensity); if (hashes > gpu->max_hashes) gpu->max_hashes = hashes;