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):
15
16
17global_size = 10
18N = global_size
19
20a = np.array(np.random.random(N), dtype=np.float32)
21b = np.array(np.random.random(N), dtype=np.float32)
22c = np.ones_like(a)
23
24data_parallel_sum[ndpx.Range(global_size)](a, b, c)
25
26print("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:
15
16@ndpx.kernel(debug=True)
17def kernel_sum(a_in_kernel, b_in_kernel, c_in_kernel):
18 i = ndpx.get_global_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
27kernel_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...