Revert "Restart threads by abstracting out the clcontext initialisation and using that instead of probing all cards." This reverts commit 8f186e61e250e71bd606cabb52795eaa0c9ad423.
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
diff --git a/main.c b/main.c
index 095ac2f..bc11af5 100644
--- a/main.c
+++ b/main.c
@@ -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)
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);
diff --git a/ocl.c b/ocl.c
index 5fde373..45f7095 100644
--- a/ocl.c
+++ b/ocl.c
@@ -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)
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:
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 */
diff --git a/ocl.h b/ocl.h
index 0960a4c..3c2a5ce 100644
--- a/ocl.h
+++ b/ocl.h
@@ -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__ */