CL_INVALID_VALUE error in clEnqueueReadBuffer

errcode = clEnqueueReadBuffer(clCPUCommandQueue, ptrout_mem_objCPU, CL_TRUE, readoffsetCPU, readsizeCPU, ptrout, 0, NULL, NULL);
if (errcode != CL_SUCCESS) printf("Error in reading CPU Buffer
");

errcode = clEnqueueReadBuffer(clGPUCommandQueue, ptrout_mem_objGPU, CL_TRUE, readoffsetGPU, readsizeGPU, ptrout + ((splittingPoint) * DIM_LOCAL_WORK_GROUP_Y) * nrowsif , 0, NULL, NULL);
if (errcode != CL_SUCCESS) printf("Error in reading GPU Buffer
");
if (errcode == CL_INVALID_VALUE) printf("Invalid Value
");

CL_INVALID_VALUE error is generated by clEnqueueReadBuffer for the clGPUCommandQueue.

Could someone point out the issue here?
I am not able to find out the problem.

The documentation (https://www.khronos.org/registry/OpenCL/sdk/1.0/docs/man/xhtml/clEnqueueReadBuffer.html) says that clEnqueueReadBuffers can return CL_INVALID_VALUE “if the region being read specified by (offset, cb) is out of bounds or if ptr is a NULL value.”

So did you check those? It seems like it is related to your readoffsetGPU, readsizeGPU variables, or your ptrout offset calculation. Try putting that calculation into a local variable first and print out the value. Is it what you were expecting? Note that the type of your pointer will matter; when you increment or add something to a pointer the steps are based on the type it points to.

[QUOTE=Dithermaster;43851]The documentation (https://www.khronos.org/registry/OpenCL/sdk/1.0/docs/man/xhtml/clEnqueueReadBuffer.html) says that clEnqueueReadBuffers can return CL_INVALID_VALUE “if the region being read specified by (offset, cb) is out of bounds or if ptr is a NULL value.”

So did you check those? It seems like it is related to your readoffsetGPU, readsizeGPU variables, or your ptrout offset calculation. Try putting that calculation into a local variable first and print out the value. Is it what you were expecting? Note that the type of your pointer will matter; when you increment or add something to a pointer the steps are based on the type it points to.[/QUOTE]

At some risk of sounding like a broken record, you can easily get this information from an Intercept Layer for OpenCL Applications call log:

https://github.com/intel/opencl-intercept-layer
https://github.com/intel/opencl-intercept-layer/blob/master/docs/controls.md#calllogging-bool

It will also log the size of the buffer when it is allocated, which you will need to know to determine if offset + size is out of bounds.