Cl_invalid_memory_object

Hello all,
I am new to OpenCL and I am trying to get started with a simple vecAdd function. I am having problems with the clEnqueueReadBuffer() giving me error code -38 which is actually an error for clSetKernelArg. But the when checked, there is no error for clSetKernelArg. I have done some reading and I found out that this problem is due to the premature freeing of the device memory which is allocated. I am quite sure that I am not doing that and I am still facing this problem. Can you please help me with this.

You have a major misunderstanding of how the API operates. CL_INVALID_MEMORY_OBJECT ( -38 ) is returned by multiple functions and it’s clearly specified to be one of the possible return values for clEnqueueReadBuffer. No idea how you managed to get a connection to clSetKernelArg in your head. If you are absolutely sure the buffer is not released, you’re most likely not using the correct variable value.