OpenCL Zone - Header Image
The recommended approach for developing your OpenCL™ application is to:1. First develop your OpenCL™ targeting an x86 CPU. Debugging your application on the CPU offers you much more information and flexibility than trying to debug your application directly on the GPU.2. Once your application works with OpenCL™ on the CPU, you can retarget your application for the available GPUs in your system and focus on any GPU-specific optimizations that you wish to make.3. Also, when you are making any GPU-specific optimizations to your OpenCL™ code, you can easily retarget your application for an x86 CPU at any time in case you need to debug any functionality issues introduced during GPU optimization.When in doubt, double-check your results on the CPU.

Debugging with the AMD APP SDK

AMD APP Computing provides an experimental feature that lets you use the GNU project debugger, GDB, to debug kernels on x86 CPUs running Linux or cygwin/minGW under Windows.

Step 1: Setting the Environment

The OpenCL program to be debugged first is compiled by passing the “-g” option to the compiler through the options string to clBuildProgram. For example, using the C++ API:

err = program.build(devices,”-g”);

To avoid source changes, set the environment variable as follows:

CPU_COMPILER_OPTIONS=”-g”

Step 2: Setting the Breakpoint in an OpenCL Kernel

To set a breakpoint, use:

b [N | function | kernel_name]

where N is the line number in the source code, function is the function name, and kernel_name is constructed as follows: if the name of the kernel is bitonicSort, the kernel_name is __OpenCL_bitonicSort_kernel.

Note that if no breakpoint is set, the program does not stop until execution is complete. Also note that OpenCL kernel symbols are not visible in the debugger until the kernel is loaded. A simple way to check for known OpenCL symbols is to set a breakpoint in the host code at clEnqueueNDRangeKernel, and to use the GDB info functions __OpenCL command.

See Chapter 3 in the AMD APP SDK OpenCL™ Programming Guide for a Sample GDB Session.

Debugging Tools

AMD gDEBugger™

gDEBugger is an OpenCL™ and OpenGL debugger and memory analyzer integrated into Microsoft® Visual Studio®. gDEBugger offers real-time OpenCL kernel debugging, which allows developers to step into the kernel execution directly from the API call that issues it, debug inside the kernel, view all variable values across the different work groups and work items – and all this on a single computer with a single GPU.

Learn more at the gDEBugger product page .

View the AMD Fusion Developer Summit “Advanced OpenCL and OpenGL Debugging and Profiling” tutorial that demonstrates advanced debugging and profiling techniques to detect bugs and optimize the performance of parallel processing and 3D graphics applications.
» Download PDF

 Next Topic: Optimizing Applications

OpenCL and the OpenCL logo are trademarks of Apple Inc. used by permission by Khronos.