• 10/30/2018
  • Public Content

Conditional Breakpoints on Work Items

According to the OpenCL™ standard, work items are executed concurrently. If a work group contains more than one work item, the debugger stops on a breakpoint in every running work item.
When a kernel is compiled with a
option, the compiler generates three implicit variables that define the current work item by mapping to global ID within NDRange . Each variable corresponds with one dimension in the three-dimensional NDRange:
  • __ocl_dbg_gid0
  • __ocl_dbg_gid1
  • __ocl_dbg_gid2
You can use these variables to set conditional breakpoints on a specific work item (or work items).

Setting Conditional Breakpoints

To set conditional breakpoints, use the native GDB* or LLDB* commands for conditional breakpoints.
Consider the following example of using conditional breakpoints with the
  1. Place a breakpoint at a work item on dimension zero with global ID value equal to two:
    (gdb) break kernel.cl:3 if (__ocl_dbg_gid0 == 2)
  2. Answer yes (
    ) when you see the following message, because at this moment, a kernel code does not exist, and it will be generated only after you run an application:
    Make breakpoint pending on future shared library load? (y or [n]) y
    Expected output for this example:
    Breakpoint 3 (kernel.cl:3 if (__ocl_dbg_gid0 == 2)) pending.
  3. Run the application:
    (gdb) run
    If the application successfully stopped on the breakpoint, you will see the following message with a status of the application and a line where the breakpoint was placed:
    [Switching to Thread 0x7fffcffff700 (LWP 26115)] Thread 20 "host_program" hit Breakpoint 1, main_kernel (buf_in=0x1834280 "", buf_out=0x186c880 "") at kernel.cl:3 3           size_t workdim = get_work_dim();
  4. You can use the
    variable to identify a global ID for a specified NDRange dimension. To print the global ID, use the following command:
    (gdb) print __ocl_dbg_gid0
    Expected output for this example:
    $0 = 2

Product and Performance Information


Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.