Reputation: 432
I'm having a hard time determining why a segmentation fault occurs randomly at the following line in my code:
rc = clEnqueueReadBuffer(ompctx->clctx->queue,
ompctx->result, CL_TRUE, 0, sizeof(int), &pos,
1, &ompctx->clctx->ev1, NULL);
ompctx->result is a memory object used as an array of integers and pos is a host object declared as:
int pos
I tried with pos declared on the stack and in the global space and the result doesn't change. I tried with waiting for the last kernel to finish (as above, although I shouldn't because I have an in-order command queue) and without waiting, the result is still the same.
I'm using AMD APP v2.8 and I tried on an i7 with 8 CPUs and on a AMD FirePro v8800. Both exhibit the same problem.
Am I missing something obvious? What else should I check for?
Upvotes: 0
Views: 2215
Reputation: 88
Because you have the blocking argument set to CL_TRUE, clEnqueueReadBuffer will not return until the transfer is completed, which means that all of the previous commands enqueued before the transfer will also have to be completed. It is likely that one of your previous OpenCL calls enqueued a command that writes out of bounds or something (because it happens randomly) and the command is not executed until clEnqueueReadBuffer is called. Try calling clFinish on your command queue after each OpenCL call you make to force each command to complete right after it's enqueued, and insert a couple printf statements so you can figure out which one is really failing.
Upvotes: 7