Friday 12 March 2010

Debugging OpenCL

"The dusk was repeating them (his very last words) in a persistent whisper all around us, in a whisper that seemed to swell menacingly like the first whisper of a rising wind. 'The horror! the horror!'"

Heart of Darkness by Joseph Conrad.

I could lie here and tell you that you just set a nice little breakpoint wherever you fancy in your OpenCL kernel then mouse over whatever variable to inspect it. But then, I'd be lying.

The sad truth is that debugging OpenCL kernels is a frustrating black box like process. Yes, you can put a printf statement in there if you run on the CPU not the GPU. Problem is, your work group size will have to be one. To me, that seems to render printf useless for all but the simplest kernels.

What I have discovered to be useful is to add more global memory parameters solely for the purpose of debugging. To these, write out whatever variables your interested in. It's as good as printf, almost!

All that said, there is light at the end of the tunnel. Personally I'm gagging to get my hands on a beta version of the gDEBugger tool promised by Graphic Remedy. If it does what it says on the tin it will be a fantastically useful product.

3 comments:

  1. That sounds similar to what I've done in the past with embedded systems. We created a cyclic buffer of a fixed size in memory where logging statements were dumped. (The cyclic aspect was because we had a restricted amount of memory and favoured overwriting old log messages over stomping over all available memory!)

    We'd then be able to use the host debugger to look at that memory space and read the log messages. Now I think about it, I'm sure we wrote a tool to run on the host that allowed us to fetch that memory space and dump it to stdout even without the debugger's assistance.

    It's a little more involved creating a library to do all this, but once it's done, it should work well for multiple projects... Come to think of it, it sounds like the kind of thing that would make a great open source project. :-)

    ReplyDelete
  2. The ATI Stream SDK has experimental support for debugging OpenCL kernels with gdb.

    See: http://developer.amd.com/gpu/ATIStreamSDK/assets/Debugging_OpenCL_with_GDB_on_x86_CPUs.pdf

    ReplyDelete
  3. You can use approach to debug from my post http://suhorukov.blogspot.com/2011/12/opencl-kernel-debugging-for-java-host.html

    ReplyDelete