Browse Source

Revert "Restart threads by abstracting out the clcontext initialisation and using that instead of probing all cards."

This reverts commit 8f186e61e2.
nfactor-troky
Con Kolivas 13 years ago
parent
commit
42d49ffdc7
  1. 24
      main.c
  2. 93
      ocl.c
  3. 2
      ocl.h

24
main.c

@ -3376,22 +3376,30 @@ static void *reinit_gpu(void *userdata) @@ -3376,22 +3376,30 @@ static void *reinit_gpu(void *userdata)
struct cgpu_info *cgpu = (struct cgpu_info *)userdata;
int gpu = cgpu->cpu_gpu;
struct thr_info *thr;
char name[256];
int thr_id;
_clState *clState;
/* Send threads message to stop */
gpu_devices[gpu] = false;
sleep(5);
for (thr_id = 0; thr_id < gpu_threads; thr_id ++) {
if (dev_from_id(thr_id) != gpu)
continue;
clState = clStates[thr_id];
/* Send it a command. If it responds we can restart */
applog(LOG_WARNING, "Attempting to send GPU command");
clFlush(clState->commandQueue);
clFinish(clState->commandQueue);
thr = &thr_info[thr_id];
thr->rolling = thr->cgpu->rolling = 0;
if (!pthread_cancel(*thr->pth)) {
applog(LOG_WARNING, "Thread still exists, killing it off");
} else
applog(LOG_WARNING, "Thread no longer exists!");
applog(LOG_WARNING, "Thread no longer exists");
/* Lose this ram cause we may get stuck here! */
//tq_freeze(thr->q);
@ -3400,13 +3408,17 @@ static void *reinit_gpu(void *userdata) @@ -3400,13 +3408,17 @@ static void *reinit_gpu(void *userdata)
if (!thr->q)
quit(1, "Failed to tq_new in reinit_gpu");
/* Create a new clstate */
applog(LOG_WARNING, "Attempting to create a new clState");
clState = initCQ(clStates[thr_id], gpu);
/* Lose this ram cause we may dereference in the dying thread! */
//free(clState);
applog(LOG_WARNING, "Command successful, attempting to create new thread");
applog(LOG_WARNING, "Command successful, attempting to reinit device");
applog(LOG_INFO, "Reinit GPU thread %d", thr_id);
clState = initCl(gpu, name, sizeof(name));
if (!clState) {
applog(LOG_ERR, "Failed to reinit GPU thread %d", thr_id);
return NULL;
}
applog(LOG_INFO, "initCl() finished. Found %s", name);
if (unlikely(thr_info_create(thr, NULL, gpuminer_thread, thr))) {
applog(LOG_ERR, "thread %d create failed", thr_id);

93
ocl.c

@ -173,55 +173,6 @@ void patch_opcodes(char *w, unsigned remaining) @@ -173,55 +173,6 @@ void patch_opcodes(char *w, unsigned remaining)
}
}
_clState *initCQ(_clState *clState, unsigned int gpu)
{
cl_int status = 0;
cl_device_id *devices = clState->devices;
/* create a cl program executable for all the devices specified */
status = clBuildProgram(clState->program, 1, &devices[gpu], NULL, NULL, NULL);
if (status != CL_SUCCESS)
{
applog(LOG_ERR, "Error: Building Program (clBuildProgram)");
size_t logSize;
status = clGetProgramBuildInfo(clState->program, devices[gpu], CL_PROGRAM_BUILD_LOG, 0, NULL, &logSize);
char *log = malloc(logSize);
status = clGetProgramBuildInfo(clState->program, devices[gpu], CL_PROGRAM_BUILD_LOG, logSize, log, NULL);
applog(LOG_INFO, "%s", log);
return NULL;
}
/* get a kernel object handle for a kernel with the given name */
clState->kernel = clCreateKernel(clState->program, "search", &status);
if (status != CL_SUCCESS)
{
applog(LOG_ERR, "Error: Creating Kernel from program. (clCreateKernel)");
return NULL;
}
/////////////////////////////////////////////////////////////////
// Create an OpenCL command queue
/////////////////////////////////////////////////////////////////
clState->commandQueue = clCreateCommandQueue(clState->context, devices[gpu],
CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, &status);
if (status != CL_SUCCESS) /* Try again without OOE enable */
clState->commandQueue = clCreateCommandQueue(clState->context, devices[gpu], 0 , &status);
if (status != CL_SUCCESS)
{
applog(LOG_ERR, "Creating Command Queue. (clCreateCommandQueue)");
return NULL;
}
clState->outputBuffer = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, BUFFERSIZE, NULL, &status);
if (status != CL_SUCCESS) {
applog(LOG_ERR, "Error: clCreateBuffer (outputBuffer)");
return NULL;
}
return clState;
}
_clState *initCl(unsigned int gpu, char *name, size_t nameSize)
{
int patchbfi = 0;
@ -285,7 +236,6 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize) @@ -285,7 +236,6 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
cl_device_id *devices;
if (numDevices > 0 ) {
devices = (cl_device_id *)malloc(numDevices*sizeof(cl_device_id));
clState->devices = devices;
/* Now, get the device list data */
@ -676,7 +626,48 @@ built: @@ -676,7 +626,48 @@ built:
applog(LOG_INFO, "Initialising kernel %s with%s BFI_INT patching, %d vectors and worksize %d",
filename, patchbfi ? "" : "out", clState->preferred_vwidth, clState->work_size);
return initCQ(clState, gpu);
/* create a cl program executable for all the devices specified */
status = clBuildProgram(clState->program, 1, &devices[gpu], NULL, NULL, NULL);
if (status != CL_SUCCESS)
{
applog(LOG_ERR, "Error: Building Program (clBuildProgram)");
size_t logSize;
status = clGetProgramBuildInfo(clState->program, devices[gpu], CL_PROGRAM_BUILD_LOG, 0, NULL, &logSize);
char *log = malloc(logSize);
status = clGetProgramBuildInfo(clState->program, devices[gpu], CL_PROGRAM_BUILD_LOG, logSize, log, NULL);
applog(LOG_INFO, "%s", log);
return NULL;
}
/* get a kernel object handle for a kernel with the given name */
clState->kernel = clCreateKernel(clState->program, "search", &status);
if (status != CL_SUCCESS)
{
applog(LOG_ERR, "Error: Creating Kernel from program. (clCreateKernel)");
return NULL;
}
/////////////////////////////////////////////////////////////////
// Create an OpenCL command queue
/////////////////////////////////////////////////////////////////
clState->commandQueue = clCreateCommandQueue(clState->context, devices[gpu],
CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, &status);
if (status != CL_SUCCESS) /* Try again without OOE enable */
clState->commandQueue = clCreateCommandQueue(clState->context, devices[gpu], 0 , &status);
if (status != CL_SUCCESS)
{
applog(LOG_ERR, "Creating Command Queue. (clCreateCommandQueue)");
return NULL;
}
clState->outputBuffer = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, BUFFERSIZE, NULL, &status);
if (status != CL_SUCCESS) {
applog(LOG_ERR, "Error: clCreateBuffer (outputBuffer)");
return NULL;
}
return clState;
}
#endif /* HAVE_OPENCL */

2
ocl.h

@ -18,12 +18,10 @@ typedef struct { @@ -18,12 +18,10 @@ typedef struct {
cl_uint preferred_vwidth;
size_t max_work_size;
size_t work_size;
cl_device_id *devices;
} _clState;
extern char *file_contents(const char *filename, int *length);
extern int clDevicesNum();
extern _clState *initCQ(_clState *clState, unsigned int gpu);
extern _clState *initCl(unsigned int gpu, char *name, size_t nameSize);
#endif /* HAVE_OPENCL */
#endif /* __OCL_H__ */

Loading…
Cancel
Save