Skip to content

Commit e27cb85

Browse files
gmarkalljiel-nv
andauthored
Add a CUDA DI Builder (#104)
This will be the basis for customising CUDA DI generation. This initial implementation corrects the type for boolean values. * Boolean debug info: correct name when datamodel is present * Add a test for the boolean type fix --------- Co-authored-by: jiel-nv <[email protected]>
1 parent 11e747c commit e27cb85

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

numba_cuda/numba/cuda/debuginfo.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from llvmlite import ir
2+
from numba.core import types
3+
from numba.core.debuginfo import DIBuilder
4+
5+
_BYTE_SIZE = 8
6+
7+
8+
class CUDADIBuilder(DIBuilder):
9+
10+
def _var_type(self, lltype, size, datamodel=None):
11+
is_bool = False
12+
13+
if isinstance(lltype, ir.IntType):
14+
if datamodel is None:
15+
if size == 1:
16+
name = str(lltype)
17+
is_bool = True
18+
elif isinstance(datamodel.fe_type, types.Boolean):
19+
name = str(datamodel.fe_type)
20+
is_bool = True
21+
22+
# Booleans should use our implementation until upstream Numba is fixed
23+
if is_bool:
24+
m = self.module
25+
bitsize = _BYTE_SIZE * size
26+
ditok = "DW_ATE_boolean"
27+
28+
return m.add_debug_info('DIBasicType', {
29+
'name': name,
30+
'size': bitsize,
31+
'encoding': ir.DIToken(ditok),
32+
})
33+
34+
# For other cases, use upstream Numba implementation
35+
return super()._var_type(lltype, size, datamodel=datamodel)

numba_cuda/numba/cuda/target.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import llvmlite.binding as ll
44
from llvmlite import ir
55

6-
from numba.core import (cgutils, config, debuginfo, itanium_mangler, types,
7-
typing, utils)
6+
from numba.core import cgutils, config, itanium_mangler, types, typing, utils
87
from numba.core.dispatcher import Dispatcher
98
from numba.core.base import BaseContext
109
from numba.core.callconv import BaseCallConv, MinimalCallConv
@@ -13,6 +12,7 @@
1312

1413
from .cudadrv import nvvm
1514
from numba.cuda import codegen, nvvmutils, ufuncs
15+
from numba.cuda.debuginfo import CUDADIBuilder
1616
from numba.cuda.models import cuda_data_manager
1717

1818
# -----------------------------------------------------------------------------
@@ -80,7 +80,7 @@ def enable_nrt(self):
8080

8181
@property
8282
def DIBuilder(self):
83-
return debuginfo.DIBuilder
83+
return CUDADIBuilder
8484

8585
@property
8686
def enable_boundscheck(self):

numba_cuda/numba/cuda/tests/cudapy/test_debuginfo.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ def f(cond):
9090
match = re.compile(pat).search(llvm_ir)
9191
self.assertIsNone(match, msg=llvm_ir)
9292

93+
def test_bool_type(self):
94+
sig = (types.int32, types.int32)
95+
96+
@cuda.jit("void(int32, int32)", debug=True, opt=False)
97+
def f(x, y):
98+
z = x == y # noqa: F841
99+
100+
llvm_ir = f.inspect_llvm(sig)
101+
102+
# extract the metadata node id from `type` field of DILocalVariable
103+
pat = r'!DILocalVariable\(.*name:\s+"z".*type:\s+!(\d+)'
104+
match = re.compile(pat).search(llvm_ir)
105+
self.assertIsNotNone(match, msg=llvm_ir)
106+
mdnode_id = match.group(1)
107+
108+
# verify the DIBasicType has correct encoding attribute DW_ATE_boolean
109+
pat = rf'!{mdnode_id}\s+=\s+!DIBasicType\(.*DW_ATE_boolean'
110+
match = re.compile(pat).search(llvm_ir)
111+
self.assertIsNotNone(match, msg=llvm_ir)
112+
93113
@unittest.skip("Wrappers no longer exist")
94114
def test_wrapper_has_debuginfo(self):
95115
sig = (types.int32[::1],)

0 commit comments

Comments
 (0)