diff --git a/DEBUGGING.md b/DEBUGGING.md new file mode 100644 index 0000000000..44027b318d --- /dev/null +++ b/DEBUGGING.md @@ -0,0 +1,21 @@ +## Debugging with GDB + +Setting the debug environment variable `NUMBA_DPPY_DEBUG` (e.g. `export NUMBA_DPPY_DEBUG=True`) enables the emission of debug info to +the llvm and spirv IR. To disable debugging set this variable to None: (e.g. `export NUMBA_DPPL_DEBUG=`). +Currently, the following debug info is available: +- Source location (filename and line number) is available. +- Setting break points by the line number. +- Stepping over break points. + +### Requirements + +Intel GDB installed to the system +follow the instruction: https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/distribution-for-gdb.html + +### Example debug usage + +```bash +$ gdb -q python +(gdb) break sum.py:13 # Assumes the kernel is in file sum.py, at line 13 +(gdb) run sum.py +``` diff --git a/README.md b/README.md index 92c61fc1bd..483ad7bdad 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,13 @@ python numba_dppy/examples/sum.py ## How Tos -Refer the HowTo.rst guide for an overview of the programming semantics, +Refer the [HowTo.rst](HowTo.rst) guide for an overview of the programming semantics, examples, supported functionalities, and known issues. +## Debugging + +Please follow instructions in the [DEBUGGING.md](DEBUGGING.md) + ## Reporting issues Please use https://github.com/IntelPython/numba-dppy/issues to report issues and bugs. diff --git a/numba_dppy/compiler.py b/numba_dppy/compiler.py index c8a329738a..b93f29801a 100644 --- a/numba_dppy/compiler.py +++ b/numba_dppy/compiler.py @@ -20,16 +20,19 @@ import os from numba.core.compiler import DefaultPassBuilder, CompilerBase -DEBUG=os.environ.get('NUMBA_DPPY_DEBUG', None) + +DEBUG = os.environ.get('NUMBA_DPPY_DEBUG', None) _NUMBA_DPPY_READ_ONLY = "read_only" _NUMBA_DPPY_WRITE_ONLY = "write_only" _NUMBA_DPPY_READ_WRITE = "read_write" + def _raise_no_device_found_error(): error_message = ("No OpenCL device specified. " "Usage : jit_fn[device, globalsize, localsize](...)") raise ValueError(error_message) + def _raise_invalid_kernel_enqueue_args(): error_message = ("Incorrect number of arguments for enquing dppy.kernel. " "Usage: device_env, global size, local size. " @@ -78,9 +81,11 @@ def compile_with_dppy(pyfunc, return_type, args, debug): typingctx = dppy_target.typing_context targetctx = dppy_target.target_context - # TODO handle debug flag + flags = compiler.Flags() # Do not compile (generate native code), just lower (to LLVM) + if debug: + flags.set('debuginfo') flags.set('no_compile') flags.set('no_cpython_wrapper') flags.unset('nrt') @@ -117,6 +122,7 @@ def compile_with_dppy(pyfunc, return_type, args, debug): def compile_kernel(sycl_queue, pyfunc, args, access_types, debug=False): if DEBUG: print("compile_kernel", args) + debug = True if not sycl_queue: # This will be get_current_queue sycl_queue = dpctl.get_current_queue() diff --git a/numba_dppy/target.py b/numba_dppy/target.py index 6444a6e601..147b229e77 100644 --- a/numba_dppy/target.py +++ b/numba_dppy/target.py @@ -254,8 +254,12 @@ def sub_gen_with_global(lty): def declare_function(self, module, fndesc): fnty = self.call_conv.get_function_type(fndesc.restype, fndesc.argtypes) fn = module.get_or_insert_function(fnty, name=fndesc.mangled_name) - fn.attributes.add('alwaysinline') + + if not self.enable_debuginfo: + fn.attributes.add('alwaysinline') + ret = super(DPPYTargetContext, self).declare_function(module, fndesc) + # XXX: Refactor fndesc instead of this special case if fndesc.llvm_func_name.startswith('dppy_py_devfn'): ret.calling_convention = CC_SPIR_FUNC