Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I debug an OpenCL kernel in Xcode 4.1?

I have some OpenCL kernels that aren't doing what they should be, and I would love to debug them in Xcode. Is this possible?

If not, is there any way I can use printf() in my CPU-based kernels? When I use printf() in my kernels the OpenCL compiler always gives me a whole bunch of errors.

like image 722
A Person Avatar asked Aug 27 '11 05:08

A Person


3 Answers

Casting the format string to const char * appears to fix this problem.

This works for me on Lion:

printf((char const *)"%d %d\n", dl, dll);

This has the error described above:

printf("%d %d\n", dl, dll);
like image 122
Sean True Avatar answered Nov 17 '22 15:11

Sean True


Have you tried adding this pragma to enable printf?

#pragma OPENCL EXTENSION cl_amd_printf : enable
like image 30
Nigel Avatar answered Nov 17 '22 15:11

Nigel


You might also want to try using Quartz Composer to test out your kernels. If you have access to the WWDC 2010 videos, I believe they show how to use Quartz Composer for rapid prototyping of OpenCL kernels in Sessions 416: "Harnessing OpenCL in Your Application" or 418: "Maximizing OpenCL Performance". There were also some good sessions on this during WWDC 2009 and 2008 that might also be available via ADC on iTunes.

Using Quartz Composer, you can quickly set up inputs and outputs for a kernel, then monitor the results in realtime. You can avoid the change-compile-test cycle because everything is compiled as you type. Syntax errors and the like will pop up as you change code, which makes it fairly easy to identify those.

I've used this tool to develop and test out OpenGL shaders, which have many things in common with OpenCL kernels.

like image 1
Brad Larson Avatar answered Nov 17 '22 15:11

Brad Larson