Jul 11, 2012

Why Da Hell Am I Inventing the Wheel Again?

My goal of this week: finishing the Screen Space Decal presentation that I'll give out at Siggraph 2012. If it was purely just making a ppt file I think I would have been more inspired to finish it. The problem is that I'm not with Relic any more and I have no access to their codebase or running editor.  So, I'm re-implementing all the features again just to have a demo program where I can take enough screen captures.

It's pretty boring to be honest. I'm not really learning anything by doing this. Just repeating what I already know inside out. Anyways all the feature implementation is done, and some test assets are all placed.  So I'll try to finish this week.

I have a couple of interesting projects I wanna work on after this, so I might be able to use that as my motivation to finish the presentation... we will seee...


Jul 8, 2012

OpenCL: Getting OUT_OF_RESOURCE or CL_MEM_OBJECT_ALLOCATION_FAILURE?

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. :)