Commit b085c338f64b8438f39dc70e7b05a9f27c22bfbf

Con Kolivas 2012-07-13T20:28:36

Make scrypt buffers and midstate compatible with cgminer.

diff --git a/driver-opencl.c b/driver-opencl.c
index 0d77b4a..d50f1ff 100644
--- a/driver-opencl.c
+++ b/driver-opencl.c
@@ -995,8 +995,25 @@ static cl_int queue_diablo_kernel(_clState *clState, dev_blk_ctx *blk, cl_uint t
 #ifdef USE_SCRYPT
 static cl_int queue_scrypt_kernel(_clState *clState, dev_blk_ctx *blk, cl_uint threads)
 {
+	cl_uint4 *midstate = (cl_uint4 *)blk->midstate;
+	cl_kernel *kernel = &clState->kernel;
+	unsigned int num = 0;
 	cl_int status = 0;
+	int i;
 
+	CL_SET_ARG(clState->CLbuffer0);
+	CL_SET_ARG(clState->outputBuffer);
+	CL_SET_ARG(clState->padbuffer8);
+	CL_SET_VARG(4, &midstate[0]);
+	CL_SET_VARG(4, &midstate[16]);
+
+#if 0
+	clSetKernelArg(clState->kernel,0,sizeof(cl_mem), &clState->CLbuffer[0]);
+	clSetKernelArg(clState->kernel,1,sizeof(cl_mem), &clState->CLbuffer[1]);
+	clSetKernelArg(clState->kernel,2,sizeof(cl_mem), &clState->padbuffer8);
+	clSetKernelArg(clState->kernel,3,sizeof(cl_uint4), &midstate[0]);
+	clSetKernelArg(clState->kernel,4,sizeof(cl_uint4), &midstate[16]);
+#endif
 	return status;
 }
 #endif
@@ -1330,6 +1347,10 @@ static bool opencl_thread_init(struct thr_info *thr)
 		return false;
 	}
 
+#ifdef USE_SCRYPT
+	if (opt_scrypt)
+		status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, BUFFERSIZE, blank_res, 0, NULL,NULL);
+#endif
 	status = clEnqueueWriteBuffer(clState->commandQueue, clState->outputBuffer, CL_TRUE, 0,
 			BUFFERSIZE, blank_res, 0, NULL, NULL);
 	if (unlikely(status != CL_SUCCESS)) {
@@ -1456,7 +1477,7 @@ static int64_t opencl_scanhash(struct thr_info *thr, struct work *work,
 	status = clEnqueueReadBuffer(clState->commandQueue, clState->outputBuffer, CL_FALSE, 0,
 			BUFFERSIZE, thrdata->res, 0, NULL, NULL);
 	if (unlikely(status != CL_SUCCESS)) {
-		applog(LOG_ERR, "Error: clEnqueueReadBuffer failed. (clEnqueueReadBuffer)");
+		applog(LOG_ERR, "Error: clEnqueueReadBuffer failed error %d. (clEnqueueReadBuffer)", status);
 		return -1;
 	}
 
diff --git a/findnonce.c b/findnonce.c
index 98d7f0e..4e40de5 100644
--- a/findnonce.c
+++ b/findnonce.c
@@ -127,6 +127,10 @@ void precalc_hash(dev_blk_ctx *blk, uint32_t *state, uint32_t *data) {
 	blk->fiveA = blk->ctx_f + SHA256_K[5];
 	blk->sixA = blk->ctx_g + SHA256_K[6];
 	blk->sevenA = blk->ctx_h + SHA256_K[7];
+
+#ifdef USE_SCRYPT
+	blk->midstate = (unsigned char *)state;
+#endif
 }
 
 #define P(t) (W[(t)&0xF] = W[(t-16)&0xF] + (rotate(W[(t-15)&0xF], 25) ^ rotate(W[(t-15)&0xF], 14) ^ (W[(t-15)&0xF] >> 3)) + W[(t-7)&0xF] + (rotate(W[(t-2)&0xF], 15) ^ rotate(W[(t-2)&0xF], 13) ^ (W[(t-2)&0xF] >> 10)))
diff --git a/miner.h b/miner.h
index c1cbe74..1261ea5 100644
--- a/miner.h
+++ b/miner.h
@@ -672,6 +672,9 @@ typedef struct {
 	cl_uint B1addK6, PreVal0addK7, W16addK16, W17addK17;
 	cl_uint zeroA, zeroB;
 	cl_uint oneA, twoA, threeA, fourA, fiveA, sixA, sevenA;
+#ifdef USE_SCRYPT
+	unsigned char *midstate;
+#endif
 } dev_blk_ctx;
 #else
 typedef struct {
diff --git a/ocl.c b/ocl.c
index 7b80257..c6944e6 100644
--- a/ocl.c
+++ b/ocl.c
@@ -536,7 +536,7 @@ build:
 	char *CompilerOptions = calloc(1, 256);
 
 	if (opt_scrypt) {
-		sprintf(CompilerOptions, "-D LOOKUP_GAP=2 -D CONCURRENT_THREADS=6144 -D WORKSIZE=%d",
+		sprintf(CompilerOptions, "-D LOOKUP_GAP=2 -D CONCURRENT_THREADS=512 -D WORKSIZE=%d",
 			(int)clState->wsize);
 	} else {
 		sprintf(CompilerOptions, "-D WORKSIZE=%d -D VECTORS%d -D WORKVEC=%d",
@@ -732,6 +732,10 @@ built:
 		return NULL;
 	}
 
+#ifdef USE_SCRYPT
+	if (opt_scrypt)
+		clState->CLbuffer0 = clCreateBuffer(clState->context, CL_MEM_READ_ONLY, 128, NULL, &status);
+#endif
 	clState->outputBuffer = clCreateBuffer(clState->context, CL_MEM_WRITE_ONLY, BUFFERSIZE, NULL, &status);
 	if (status != CL_SUCCESS) {
 		applog(LOG_ERR, "Error %d: clCreateBuffer (outputBuffer)", status);
diff --git a/ocl.h b/ocl.h
index 2f2f2c2..fddcc67 100644
--- a/ocl.h
+++ b/ocl.h
@@ -19,6 +19,10 @@ typedef struct {
 	cl_command_queue commandQueue;
 	cl_program program;
 	cl_mem outputBuffer;
+#ifdef USE_SCRYPT
+	cl_mem CLbuffer0;
+	cl_mem padbuffer8;
+#endif
 	bool hasBitAlign;
 	bool hasOpenCL11plus;
 	bool goffset;