Tutorial: Debugging with Intel® Distribution for GDB*

Basic Debugging

The Array Transform sample contains a simple kernel, as shown below:

54        h.parallel_for(data_range, [=](id<1> index) {
55            size_t id0 = GetDim(index, 0);
56            int element = in[index];  // breakpoint-here
57            int result = element + 50;
58            if (id0 % 2 == 0) {
59                result = result + 50;  // then-branch
60            } else {
61                result = -1;  // else-branch
62            }
63            out[index] = result;
64        });

Define a breakpoint at line 56:

break 56

Expected output:

Breakpoint 1 at 0x405800: file /path/to/array-transform.cpp, line 56.

Note

Do not expect the output you receive will match exactly the one provided in the tutorial. The output may vary due to the nature of parallelism and different machine properties. The ellipsis [...] denotes output omitted for brevity.

Run the program:

run cpu

When the thread hits the breakpoint, you should see the following output:

Starting program: <path_to_array-transform> cpu
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff37dc700 (LWP 21540)]
[New Thread 0x7fffdba79700 (LWP 21605)]
[New Thread 0x7fffdb678700 (LWP 21606)]
[New Thread 0x7fffdb277700 (LWP 21607)]
[SYCL] Using device: [Intel® Core™ i7-7567U CPU @ 3.50GHz] from [Intel® OpenCL]
[Switching to Thread 0x7fffdb678700 (LWP 21606)]

Thread 4 "array-transform" hit Breakpoint 1, main::$_1::operator()[...]
  at array-transform.cpp:56
56        int element = in[index]; // breakpoint-here

Now you can issue the usual Intel® Distribution for GDB* commands to inspect the local variables, print a stack trace, and get information on threads.

Note

For your convenience, common Intel® Distribution for GDB* commands are provided in the reference sheet.

Keep debugging and display the value of the index variable:

print index

Expected output:

$1 = cl::sycl::id<1> = {24}

Continue debugging:

continue

You should see the next breakpoint hit event, which comes from another thread.

Continuing.
[Switching to Thread 0x7fffdba79700 (LWP 21605)]

Thread 3 "array-transform" hit Breakpoint 1, main::$_1::operator()[...]
  at array-transform.cpp:56
56        int element = in[index]; // breakpoint-here

If you print the value of the index variable now:

print index

The output will differ from the previous one:

$2 = cl::sycl::id<1> = {32}

To print data elements, use the bracket operator of the accessor:

print in[index]

Expected output:

$3 = 132

You can also print the accessor contents the following ways:

  • print in
    Expected output:
    $4 = {[...], MData = 0x7fffffffd3e0}
  • x /4dw in.MData​
    Expected output:
    0x7fffffffde30: 100    101    102    103
    where the x command examines the memory contents at the given address and /4dw specifies that the examination output must contain four items in decimal format, word-length each.