Skip to content
21 changes: 21 additions & 0 deletions DEBUGGING.md
Original file line number Diff line number Diff line change
@@ -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
```
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
10 changes: 8 additions & 2 deletions numba_dppy/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. "
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion numba_dppy/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down