Skip to content

Commit c5c3381

Browse files
Add flags to generate debug symbols (#27)
* Add flags to generate debug symbols * Merge main to akharche/enable_kernel_debug * Add documentation about how to use gdb Co-authored-by: Sergey Pokhodenko <sergey.pokhodenko@intel.com>
1 parent 2e81acb commit c5c3381

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

DEBUGGING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Debugging with GDB
2+
3+
Setting the debug environment variable `NUMBA_DPPY_DEBUG` (e.g. `export NUMBA_DPPY_DEBUG=True`) enables the emission of debug info to
4+
the llvm and spirv IR. To disable debugging set this variable to None: (e.g. `export NUMBA_DPPL_DEBUG=`).
5+
Currently, the following debug info is available:
6+
- Source location (filename and line number) is available.
7+
- Setting break points by the line number.
8+
- Stepping over break points.
9+
10+
### Requirements
11+
12+
Intel GDB installed to the system
13+
follow the instruction: https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/distribution-for-gdb.html
14+
15+
### Example debug usage
16+
17+
```bash
18+
$ gdb -q python
19+
(gdb) break sum.py:13 # Assumes the kernel is in file sum.py, at line 13
20+
(gdb) run sum.py
21+
```

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@ python numba_dppy/examples/sum.py
5757

5858
## How Tos
5959

60-
Refer the HowTo.rst guide for an overview of the programming semantics,
60+
Refer the [HowTo.rst](HowTo.rst) guide for an overview of the programming semantics,
6161
examples, supported functionalities, and known issues.
6262

63+
## Debugging
64+
65+
Please follow instructions in the [DEBUGGING.md](DEBUGGING.md)
66+
6367
## Reporting issues
6468

6569
Please use https://github.com/IntelPython/numba-dppy/issues to report issues and bugs.

numba_dppy/compiler.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,19 @@
2020
import os
2121
from numba.core.compiler import DefaultPassBuilder, CompilerBase
2222

23-
DEBUG=os.environ.get('NUMBA_DPPY_DEBUG', None)
23+
24+
DEBUG = os.environ.get('NUMBA_DPPY_DEBUG', None)
2425
_NUMBA_DPPY_READ_ONLY = "read_only"
2526
_NUMBA_DPPY_WRITE_ONLY = "write_only"
2627
_NUMBA_DPPY_READ_WRITE = "read_write"
2728

29+
2830
def _raise_no_device_found_error():
2931
error_message = ("No OpenCL device specified. "
3032
"Usage : jit_fn[device, globalsize, localsize](...)")
3133
raise ValueError(error_message)
3234

35+
3336
def _raise_invalid_kernel_enqueue_args():
3437
error_message = ("Incorrect number of arguments for enquing dppy.kernel. "
3538
"Usage: device_env, global size, local size. "
@@ -78,9 +81,11 @@ def compile_with_dppy(pyfunc, return_type, args, debug):
7881

7982
typingctx = dppy_target.typing_context
8083
targetctx = dppy_target.target_context
81-
# TODO handle debug flag
84+
8285
flags = compiler.Flags()
8386
# Do not compile (generate native code), just lower (to LLVM)
87+
if debug:
88+
flags.set('debuginfo')
8489
flags.set('no_compile')
8590
flags.set('no_cpython_wrapper')
8691
flags.unset('nrt')
@@ -117,6 +122,7 @@ def compile_with_dppy(pyfunc, return_type, args, debug):
117122
def compile_kernel(sycl_queue, pyfunc, args, access_types, debug=False):
118123
if DEBUG:
119124
print("compile_kernel", args)
125+
debug = True
120126
if not sycl_queue:
121127
# This will be get_current_queue
122128
sycl_queue = dpctl.get_current_queue()

numba_dppy/target.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,12 @@ def sub_gen_with_global(lty):
254254
def declare_function(self, module, fndesc):
255255
fnty = self.call_conv.get_function_type(fndesc.restype, fndesc.argtypes)
256256
fn = module.get_or_insert_function(fnty, name=fndesc.mangled_name)
257-
fn.attributes.add('alwaysinline')
257+
258+
if not self.enable_debuginfo:
259+
fn.attributes.add('alwaysinline')
260+
258261
ret = super(DPPYTargetContext, self).declare_function(module, fndesc)
262+
259263
# XXX: Refactor fndesc instead of this special case
260264
if fndesc.llvm_func_name.startswith('dppy_py_devfn'):
261265
ret.calling_convention = CC_SPIR_FUNC

0 commit comments

Comments
 (0)