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

binary code

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 =,”-g”);

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


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 CodeXL™

AMD CodeXL offers comprehensive GPU debugging with the ability debug OpenCL™ & OpenGL API calls and OpenCL™ kernels. t enables developers to step through the source code to find bugs, optimize performance and reduce memory consumption. The debugger includes real-time OpenCL™ kernel debugging, which allows developers to step into the kernel execution directly from the API calls, debug inside the kernel, view all variable values across different work groups and work items – and all this on a single computer with a single GPU. Learn more at the CodeXL page .

Next Topic: Optimizing Applications

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