Debugging the compilation pipeline

Consider the following two examples. numba_dpex/examples/debug/simple_sum.py:

15import dpctl
16import numpy as np
17
18import numba_dpex as dppy
19
20
21@dppy.kernel(debug=True)
22def data_parallel_sum(a, b, c):
23    i = dppy.get_global_id(0)
24    c[i] = a[i] + b[i]  # Condition breakpoint location
25
26
27global_size = 10
28N = global_size
29
30a = np.array(np.random.random(N), dtype=np.float32)
31b = np.array(np.random.random(N), dtype=np.float32)
32c = np.ones_like(a)
33
34device = dpctl.SyclDevice("opencl:gpu")
35with dpctl.device_context(device):
36    data_parallel_sum[global_size, dppy.DEFAULT_LOCAL_SIZE](a, b, c)
37
38print("Done...")

Example of default Numba execution on a CPU:

15from numba import njit
16
17
18@njit(debug=True)
19def foo(arg):
20    l1 = arg + 6
21    l2 = arg * 5.43
22    l3 = (arg, l1, l2, "bar")
23    print(arg, l1, l2, l3)
24
25
26def main():
27    result = foo(987)
28    print(result)
29
30
31if __name__ == "__main__":
32    main()

Getting the DWARF from binary file

In order to get the DWARF information from a specific kernel, just enable IGC_ShaderDumpEnable variable. IGC will write number of dumps into /tmp/IntelIGC.

export IGC_ShaderDumpEnable=1

To read the DWARF of a kernel, a copy of the IGC generated kernel binary is needed. Run the Python script in a GDB debugger mode, and set a breakpoint in the kernel:

$ export NUMBA_OPT=1
$ gdb-oneapi -q --args python simple_sum.py
(gdb) break simple_sum.py:22
(gdb) run

Once the breakpoint is hit, the kernel has been generated and offloaded. At that point, the IGFX driver (i.e. our GDB debugger driver) has copied the kernel into a file, and saved it at /tmp. All files saved at /tmp/IntelIGC/python_xxx/

Dump generated DWARF from the kernel binary (elf) via llvm-dwarfdump tool:

llvm-dwarfdump xxx.elf

Getting the DWARF from Numba assembly (for njit)

Setting Numba environment variable NUMBA_DUMP_ASSEMBLY dumps the native assembly code of compiled functions.

NUMBA_DUMP_ASSEMBLY=1 python njit-basic.py > njit-basic-asm.txt

Clear file from prints and unrecognized characters (-, =, !, ) Get compiled from assembler:

as -o o njit-basic-asm.txt

Get dwarf with objdump:

objdump -W o > o_dwarf

See also: