Breakpoints#

A breakpoint makes your program stop whenever a certain point in the program is reached.

You can set breakpoints with the break command to specify the place where your program should stop in the kernel. Define breakpoints by line numbers or function names.

You have several ways to set breakpoints:
  • break <function>

  • break <filename>:<linenumber>

  • break <filename>:<function>

  • break if <condition>

See also:

Consider the following numba-dpex kernel code (refer numba_dpex/examples/debug/simple_sum.py for full example):

 5import dpnp as np
 6
 7import numba_dpex as ndpx
 8
 9
10@ndpx.kernel(debug=True)
11def data_parallel_sum(item, a, b, c):
12    i = item.get_id(0)
13    c[i] = a[i] + b[i]  # Condition breakpoint location
14
15
16global_size = 10
17N = global_size
18
19a = np.array(np.random.random(N), dtype=np.float32)
20b = np.array(np.random.random(N), dtype=np.float32)
21c = np.ones_like(a)
22
23ndpx.call_kernel(data_parallel_sum, ndpx.Range(global_size), a, b, c)
24
25print("Done...")

break function#

The debugger output:

$ NUMBA_OPT=0 gdb-oneapi -q python
(gdb) set breakpoint pending on
(gdb) break data_parallel_sum
(gdb) run simple_sum.py
...
Thread 2.2 hit Breakpoint 1, with SIMD lanes [0-7], __main__::data_parallel_sum () at simple_sum.py:20
20          @dpex.kernel(debug=True)
(gdb) continue
Thread 2.3 hit Breakpoint 1, with SIMD lanes [0-1], __main__::data_parallel_sum () at simple_sum.py:20
20          @dpex.kernel(debug=True)
(gdb) continue
...
Done...

break filename:linenumber#

The debugger output:

$ NUMBA_OPT=0 gdb-oneapi -q python
(gdb) set breakpoint pending on
(gdb) break simple_sum.py:20
(gdb) run simple_sum.py
...
Thread 2.2 hit Breakpoint 1, with SIMD lanes [0-7], __main__::data_parallel_sum () at simple_sum.py:20
20          @dpex.kernel(debug=True)
(gdb) continue
Thread 2.3 hit Breakpoint 1, with SIMD lanes [0-1], __main__::data_parallel_sum () at simple_sum.py:20
20          @dpex.kernel(debug=True)
(gdb) continue
...
Done...

break filename:function#

The debugger output:

$ NUMBA_OPT=0 gdb-oneapi -q python
(gdb) set breakpoint pending on
(gdb) break simple_sum.py:data_parallel_sum
(gdb) run simple_sum.py
...
Thread 2.2 hit Breakpoint 1, with SIMD lanes [0-7], __main__::data_parallel_sum () at simple_sum.py:20
20          @dpex.kernel(debug=True)
(gdb) continue
Thread 2.3 hit Breakpoint 1, with SIMD lanes [0-1], __main__::data_parallel_sum () at simple_sum.py:20
20          @dpex.kernel(debug=True)
(gdb) continue
...
Done...

break if cond#

The debugger output:

$ NUMBA_OPT=0 gdb-oneapi -q python
(gdb) set breakpoint pending on
(gdb) break simple_sum.py:23 if i == 1
(gdb) run simple_sum.py
...
Thread 2.2 hit Breakpoint 1, with SIMD lane 1, __main__::data_parallel_sum () at simple_sum.py:23
23          c[i] = a[i] + b[i]
(gdb) print i
$1 = 1
(gdb) continue
...
Done...

Breakpoints with nested functions#

Consider numba-dpex kernel code. See the source file numba_dpex/examples/debug/simple_dpex_func.py:

 5import dpnp as np
 6
 7import numba_dpex as ndpx
 8
 9
10@ndpx.device_func(debug=True)
11def func_sum(a_in_func, b_in_func):
12    result = a_in_func + b_in_func  # breakpoint location
13    return result
14
15
16@ndpx.kernel(debug=True)
17def kernel_sum(item, a_in_kernel, b_in_kernel, c_in_kernel):
18    i = item.get_id(0)
19    c_in_kernel[i] = func_sum(a_in_kernel[i], b_in_kernel[i])
20
21
22global_size = 10
23a = np.arange(global_size, dtype=np.float32)
24b = np.arange(global_size, dtype=np.float32)
25c = np.empty_like(a)
26
27ndpx.call_kernel(kernel_sum, ndpx.Range(global_size), a, b, c)
28
29print("Done...")

The debugger output:

$ NUMBA_OPT=0 gdb-oneapi -q python
(gdb) set breakpoint pending on
(gdb) break simple_dpex_func.py:func_sum
(gdb) run simple_dpex_func.py
...
Thread 2.2 hit Breakpoint 1, with SIMD lanes [0-7], __main__::func_sum () at simple_dpex_func.py:22
22          result = a_in_func + b_in_func
(gdb) continue
Thread 2.3 hit Breakpoint 1, with SIMD lanes [0-1], __main__::func_sum () at simple_dpex_func.py:22
22          result = a_in_func + b_in_func
(gdb) continue
...
Done...