Skip to content

Commit

Permalink
opencl: Add a simple "fullheader" kernel interface
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr committed Nov 18, 2014
1 parent 5e1e687 commit cda82f1
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 30 deletions.
31 changes: 31 additions & 0 deletions driver-opencl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,34 @@ cl_int queue_scrypt_kernel(const struct opencl_kernel_info * const kinfo, _clSta
}
#endif

#ifdef USE_OPENCL_FULLHEADER
static
cl_int queue_fullheader_kernel(const struct opencl_kernel_info * const kinfo, _clState * const clState, struct work * const work, __maybe_unused const cl_uint threads)
{
const struct mining_algorithm * const malgo = work_mining_algorithm(work);
const cl_kernel * const kernel = &kinfo->kernel;
unsigned int num = 0;
cl_int status = 0;
uint8_t blkheader[80];

work->nonce_diff = malgo->opencl_min_nonce_diff;

if (!kinfo->goffset)
{
cl_uint nonce_base = work->blk.nonce;
CL_SET_ARG(nonce_base);
}

swap32yes(blkheader, work->data, 80/4);
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, CL_TRUE, 0, sizeof(blkheader), blkheader, 0, NULL, NULL);

CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->outputBuffer);

return status;
}
#endif


static
struct opencl_kernel_interface kernel_interfaces[] = {
Expand All @@ -1254,6 +1282,9 @@ struct opencl_kernel_interface kernel_interfaces[] = {
{"diakgcn", queue_diakgcn_kernel},
{"diablo", queue_diablo_kernel },
#endif
#ifdef USE_OPENCL_FULLHEADER
{"fullheader", queue_fullheader_kernel },
#endif
#ifdef USE_SCRYPT
{"scrypt", queue_scrypt_kernel },
#endif
Expand Down
4 changes: 4 additions & 0 deletions findnonce.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ static void *postcalc_hash(void *userdata)

for (entry = 0; entry < pcd->res[found]; entry++) {
uint32_t nonce = pcd->res[entry];
#ifdef USE_OPENCL_FULLHEADER
if (pcd->kinterface == KL_FULLHEADER)
nonce = swab32(nonce);
#endif

applog(LOG_DEBUG, "OCL NONCE %u found in slot %d", nonce, entry);
submit_nonce(thr, &pcd->work, nonce);
Expand Down
3 changes: 3 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ enum cl_kernels {
KL_DIAKGCN,
KL_DIABLO,
#endif
#ifdef USE_OPENCL_FULLHEADER
KL_FULLHEADER,
#endif
#ifdef USE_SCRYPT
KL_SCRYPT,
#endif
Expand Down
78 changes: 49 additions & 29 deletions ocl.c
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,11 @@ bool opencl_load_kernel(struct cgpu_info * const cgpu, _clState * const clState,
case KL_PHATK:
kernel_goffset_support = 0;
break;
#endif
#ifdef USE_OPENCL_FULLHEADER
case KL_FULLHEADER:
kernel_goffset_support = 1;
break;
#endif
case KL_NONE: case OPENCL_KERNEL_INTERFACE_COUNT:
#ifdef USE_SCRYPT
Expand Down Expand Up @@ -1156,36 +1161,51 @@ bool opencl_load_kernel(struct cgpu_info * const cgpu, _clState * const clState,
free((void*)cgpu->kname);
cgpu->kname = strdup(kernel_file);

#ifdef USE_SCRYPT
if (kernelinfo->interface == KL_SCRYPT && !clState->padbufsize)
#ifdef MAX_CLBUFFER0_SZ
switch (kernelinfo->interface)
{
size_t ipt = (1024 / data->lookup_gap + (1024 % data->lookup_gap > 0));
size_t bufsize = 128 * ipt * data->thread_concurrency;

/* Use the max alloc value which has been rounded to a power of
* 2 greater >= required amount earlier */
if (bufsize > data->max_alloc) {
applog(LOG_WARNING, "Maximum buffer memory device %d supports says %lu", gpu, (unsigned long)data->max_alloc);
applog(LOG_WARNING, "Your scrypt settings come to %lu", (unsigned long)bufsize);
}
applog(LOG_DEBUG, "Creating scrypt buffer sized %lu", (unsigned long)bufsize);
clState->padbufsize = bufsize;

/* This buffer is weird and might work to some degree even if
* the create buffer call has apparently failed, so check if we
* get anything back before we call it a failure. */
clState->padbuffer8 = NULL;
clState->padbuffer8 = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, bufsize, NULL, &status);
if (status != CL_SUCCESS && !clState->padbuffer8) {
applog(LOG_ERR, "Error %d: clCreateBuffer (padbuffer8), decrease TC or increase LG", status);
return false;
}

clState->CLbuffer0 = clCreateBuffer(clState->context, CL_MEM_READ_ONLY, 128, NULL, &status);
if (status != CL_SUCCESS) {
applog(LOG_ERR, "Error %d: clCreateBuffer (CLbuffer0)", status);
return false;
}
#ifdef USE_SCRYPT
case KL_SCRYPT:
if (!clState->padbufsize)
{
size_t ipt = (1024 / data->lookup_gap + (1024 % data->lookup_gap > 0));
size_t bufsize = 128 * ipt * data->thread_concurrency;

/* Use the max alloc value which has been rounded to a power of
* 2 greater >= required amount earlier */
if (bufsize > data->max_alloc) {
applog(LOG_WARNING, "Maximum buffer memory device %d supports says %lu", gpu, (unsigned long)data->max_alloc);
applog(LOG_WARNING, "Your scrypt settings come to %lu", (unsigned long)bufsize);
}
applog(LOG_DEBUG, "Creating scrypt buffer sized %lu", (unsigned long)bufsize);
clState->padbufsize = bufsize;

/* This buffer is weird and might work to some degree even if
* the create buffer call has apparently failed, so check if we
* get anything back before we call it a failure. */
clState->padbuffer8 = NULL;
clState->padbuffer8 = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, bufsize, NULL, &status);
if (status != CL_SUCCESS && !clState->padbuffer8) {
applog(LOG_ERR, "Error %d: clCreateBuffer (padbuffer8), decrease TC or increase LG", status);
return false;
}
}
// NOTE: fallthru
#endif
#ifdef USE_OPENCL_FULLHEADER
case KL_FULLHEADER:
#endif
if (!clState->CLbuffer0)
{
clState->CLbuffer0 = clCreateBuffer(clState->context, CL_MEM_READ_ONLY, MAX_CLBUFFER0_SZ, NULL, &status);
if (status != CL_SUCCESS) {
applog(LOG_ERR, "Error %d: clCreateBuffer (CLbuffer0)", status);
return false;
}
}
break;
default:
break;
}
#endif

Expand Down
12 changes: 11 additions & 1 deletion ocl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@

#include "miner.h"

#define SCRYPT_CLBUFFER0_SZ (128)
#define FULLHEADER_CLBUFFER0_SZ ( 80)
#ifdef USE_SCRYPT
# define MAX_CLBUFFER0_SZ SCRYPT_CLBUFFER0_SZ
#elif USE_OPENCL_FULLHEADER
# define MAX_CLBUFFER0_SZ FULLHEADER_CLBUFFER0_SZ
#endif

struct mining_algorithm;
struct opencl_kernel_info;
typedef struct _clState _clState;
Expand All @@ -21,8 +29,10 @@ struct _clState {
cl_command_queue commandQueue;

cl_mem outputBuffer;
#ifdef USE_SCRYPT
#ifdef MAX_CLBUFFER0_SZ
cl_mem CLbuffer0;
#endif
#ifdef USE_SCRYPT
cl_mem padbuffer8;
size_t padbufsize;
void * cldata;
Expand Down

0 comments on commit cda82f1

Please sign in to comment.