I recently had a chance to use OpenCL to speed up an app I was developing. It was pretty fun, but certainly debugging OpenCL was not so easy. I wish it had more error messages at least.
This is the problem I had:
When I was calling
clEnqueueNDRangeKernel() function, it suddenly gave me
CL_MEM_OBJECT_ALLOCATION_FAILURE error and later I also got OUT_OF_RESOURCE error too. And the following is all the things I tried and how I eventually solved…. This post is more for my own reference if I run into the same issue later. :P
1. Check how much memory is really being allocated for OpenCL
The sum of all the cl_mem buffers I was using was less than3MB. OpenCL's minimal global memory size requirement is 128MB. So no problem here. Move on.
2. Implement notification function
So apparently we can attach a notification function that will get some descriptive messages whenever there's an error. I managed to get a bit more error messages after implementing this:
clEnqueueWriteBuffer() function calls were giving me
CL_MEM_OBJECT_ALLOCATION_FAILURE. But this one didn't really help to solve the problem.
3. Try to run OpenCL on CPU
It ran fine on my Intel CPU, it only happend on my NVidia GPU. So I installed the up-to-date GPU driver. Still same problem :(
4. Check memory stomp
So I looked into my OpenCL code more closely. And it turned out to be I was reading/writing outside of allocated local memory.. DOH! After fixing this, the problem disappeared.. Yay… I solved the problem.. But somehow I still feel stupid. :)