Make scrypt buffers and midstate compatible with cgminer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
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;