Skip to content

Commit 95e7852

Browse files
authored
Merge pull request #7514 from sklam/enh/fixup_cuda_7177
Fixup cuda debuginfo emission for 7177
2 parents 944dcee + 83ac172 commit 95e7852

4 files changed

Lines changed: 41 additions & 30 deletions

File tree

‎numba/core/debuginfo.py‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def mark_location(self, builder, line):
4040
pass
4141

4242
@abc.abstractmethod
43-
def mark_subprogram(self, function, fndesc, line):
43+
def mark_subprogram(self, function, qualname, argnames, argtypes, line):
4444
"""Emit source location information for the given function.
4545
"""
4646
pass
@@ -70,7 +70,7 @@ def mark_variable(self, builder, allocavalue, name, lltype, size, line,
7070
def mark_location(self, builder, line):
7171
pass
7272

73-
def mark_subprogram(self, function, fndesc, line):
73+
def mark_subprogram(self, function, qualname, argnames, argtypes, line):
7474
pass
7575

7676
def initialize(self):
@@ -308,9 +308,9 @@ def mark_variable(self, builder, allocavalue, name, lltype, size, line,
308308
def mark_location(self, builder, line):
309309
builder.debug_metadata = self._add_location(line)
310310

311-
def mark_subprogram(self, function, fndesc, line):
312-
name = fndesc.qualname
313-
argmap = {argname: fndesc.typemap[argname] for argname in fndesc.args}
311+
def mark_subprogram(self, function, qualname, argnames, argtypes, line):
312+
name = qualname
313+
argmap = dict(zip(argnames, argtypes))
314314
di_subp = self._add_subprogram(name=name, linkagename=function.name,
315315
line=line, function=function,
316316
argmap=argmap)
@@ -492,10 +492,18 @@ def mark_location(self, builder, line):
492492
md = self._di_location(line)
493493
call.set_metadata('numba.dbg', md)
494494

495-
def mark_subprogram(self, function, fndesc, line):
496-
self._add_subprogram(name=fndesc.name, linkagename=function.name,
495+
def mark_subprogram(self, function, qualname, argnames, argtypes, line):
496+
argmap = dict(zip(argnames, argtypes))
497+
self._add_subprogram(name=qualname, linkagename=function.name,
497498
line=line)
498499

500+
def _add_subprogram(self, name, linkagename, line):
501+
"""Emit subprogram metadata
502+
"""
503+
subp = self._di_subprogram(name, linkagename, line)
504+
self.subprograms.append(subp)
505+
return subp
506+
499507
#
500508
# Helper methods to create the metadata nodes.
501509
#

‎numba/core/lowering.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ def pre_lower(self):
131131
# EnvironmentManager.
132132
self.pyapi = None
133133
self.debuginfo.mark_subprogram(function=self.builder.function,
134-
fndesc=self.fndesc,
134+
qualname=self.fndesc.qualname,
135+
argnames=self.fndesc.args,
136+
argtypes=self.fndesc.argtypes,
135137
line=self.defn_loc.line)
136138

137139
def post_lower(self):

‎numba/cuda/compiler.py‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,10 @@ def compile_ptx(pyfunc, args, debug=False, lineinfo=False, device=False,
232232
if device:
233233
lib = cres.library
234234
else:
235-
fname = cres.fndesc.llvm_func_name
236235
tgt = cres.target_context
237236
filename = cres.type_annotation.filename
238237
linenum = int(cres.type_annotation.linenum)
239-
lib, kernel = tgt.prepare_cuda_kernel(cres.library, fname,
240-
cres.signature.args, debug,
238+
lib, kernel = tgt.prepare_cuda_kernel(cres.library, cres.fndesc, debug,
241239
nvvm_options, filename, linenum)
242240

243241
cc = cc or config.CUDA_DEFAULT_PTX_CC
@@ -557,14 +555,11 @@ def __init__(self, py_func, argtypes, link=None, debug=False,
557555
inline=inline,
558556
fastmath=fastmath,
559557
nvvm_options=nvvm_options)
560-
fname = cres.fndesc.llvm_func_name
561-
args = cres.signature.args
562-
563558
tgt_ctx = cres.target_context
564559
code = self.py_func.__code__
565560
filename = code.co_filename
566561
linenum = code.co_firstlineno
567-
lib, kernel = tgt_ctx.prepare_cuda_kernel(cres.library, fname, args,
562+
lib, kernel = tgt_ctx.prepare_cuda_kernel(cres.library, cres.fndesc,
568563
debug, nvvm_options,
569564
filename, linenum,
570565
max_registers)

‎numba/cuda/target.py‎

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def call_conv(self):
125125
def mangler(self, name, argtypes, *, abi_tags=()):
126126
return itanium_mangler.mangle(name, argtypes, abi_tags=abi_tags)
127127

128-
def prepare_cuda_kernel(self, codelib, func_name, argtypes, debug,
128+
def prepare_cuda_kernel(self, codelib, fndesc, debug,
129129
nvvm_options, filename, linenum,
130130
max_registers=None):
131131
"""
@@ -140,51 +140,57 @@ def prepare_cuda_kernel(self, codelib, func_name, argtypes, debug,
140140
141141
codelib: The CodeLibrary containing the device function to wrap
142142
in a kernel call.
143-
func_name: The mangled name of the device function.
144-
argtypes: An iterable of the types of arguments to the kernel.
143+
fndesc: The FunctionDescriptor of the source function.
145144
debug: Whether to compile with debug.
146145
nvvm_options: Dict of NVVM options used when compiling the new library.
147146
filename: The source filename that the function is contained in.
148147
linenum: The source line that the function is on.
149148
max_registers: The max_registers argument for the code library.
150149
"""
151-
kernel_name = itanium_mangler.prepend_namespace(func_name, ns='cudapy')
150+
kernel_name = itanium_mangler.prepend_namespace(
151+
fndesc.llvm_func_name, ns='cudapy',
152+
)
152153
library = self.codegen().create_library(f'{codelib.name}_kernel_',
153154
entry_name=kernel_name,
154155
nvvm_options=nvvm_options,
155156
max_registers=max_registers)
156157
library.add_linking_library(codelib)
157-
wrapper = self.generate_kernel_wrapper(library, kernel_name, func_name,
158-
argtypes, debug, filename,
159-
linenum)
158+
wrapper = self.generate_kernel_wrapper(library, fndesc, kernel_name,
159+
debug, filename, linenum)
160160
return library, wrapper
161161

162-
def generate_kernel_wrapper(self, library, kernel_name, func_name,
163-
argtypes, debug, filename, linenum):
162+
def generate_kernel_wrapper(self, library, fndesc, kernel_name, debug,
163+
filename, linenum):
164164
"""
165165
Generate the kernel wrapper in the given ``library``.
166-
The function being wrapped have the name ``fname`` and argument types
167-
``argtypes``. The wrapper function is returned.
166+
The function being wrapped is described by ``fndesc``.
167+
The wrapper function is returned.
168168
"""
169+
170+
argtypes = fndesc.argtypes
169171
arginfo = self.get_arg_packer(argtypes)
170172
argtys = list(arginfo.argument_types)
171173
wrapfnty = ir.FunctionType(ir.VoidType(), argtys)
172174
wrapper_module = self.create_module("cuda.kernel.wrapper")
173175
fnty = ir.FunctionType(ir.IntType(32),
174176
[self.call_conv.get_return_type(types.pyobject)]
175177
+ argtys)
176-
func = ir.Function(wrapper_module, fnty, func_name)
178+
func = ir.Function(wrapper_module, fnty, fndesc.llvm_func_name)
177179

178180
prefixed = itanium_mangler.prepend_namespace(func.name, ns='cudapy')
179181
wrapfn = ir.Function(wrapper_module, wrapfnty, prefixed)
180182
builder = ir.IRBuilder(wrapfn.append_basic_block(''))
181183

182184
if debug:
183-
debuginfo = self.DIBuilder(module=wrapper_module, filepath=filename)
184-
debuginfo.mark_subprogram(wrapfn, kernel_name, linenum)
185+
debuginfo = self.DIBuilder(
186+
module=wrapper_module, filepath=filename, cgctx=self,
187+
)
188+
debuginfo.mark_subprogram(
189+
wrapfn, kernel_name, fndesc.args, argtypes, linenum,
190+
)
185191
debuginfo.mark_location(builder, linenum)
186192

187-
# Define error handling variables
193+
# Define error handling variable
188194
def define_error_gv(postfix):
189195
name = wrapfn.name + postfix
190196
gv = cgutils.add_global_variable(wrapper_module, ir.IntType(32),

0 commit comments

Comments
 (0)