I am trying to implement the Motion estimation algorithm using open CL.
I have written a code to calculate the SAD values in open CL and tried running on NVIDIA GE 9400GT GPU.
I am trying to encode Video with resolution 320x240. I have allocated 2 buffers with memory 320x240x2 bytes each. One for current frame and other for the reference frame.
I copied the data to the allocated buffers using clEnqueueWriteBuffer.

The problem I am facing is that the code is running fine for 10MBs, after that the SAD values are not proper. Some time I am getting the CL_INVALID_COMMAND_QUEUE error from clEnqueueTask function and some other time I am getting the same error from clEnqueueReadbuffer. I am using cl_Finish after each operation.

1). My doubt is whether I can allocate the memory for the complete frame.
2). Why the code is failing to run after running properly for 10 times.
3). Is memory the only issue or is there any other issue.