Repository navigation
CUDA: Fix source location on kernel entry and enable breakpoints to be set on kernels by mangled name #6841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
7d226f3
7f77680
1f9d320
448b0d8
772ed7f
10d57b3
02fad5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,9 +200,11 @@ def compile_ptx(pyfunc, args, debug=False, device=False, fastmath=False, | |
| else: | ||
| fname = cres.fndesc.llvm_func_name | ||
| tgt = cres.target_context | ||
| filename = cres.type_annotation.filename | ||
| linenum = int(cres.type_annotation.linenum) | ||
| lib, kernel = tgt.prepare_cuda_kernel(cres.library, fname, | ||
| cres.signature.args, debug, | ||
| nvvm_options) | ||
| nvvm_options, filename, linenum) | ||
|
|
||
| cc = cc or config.CUDA_DEFAULT_PTX_CC | ||
| ptx = lib.get_asm_str(cc=cc) | ||
|
|
@@ -479,8 +481,11 @@ def __init__(self, py_func, argtypes, link=None, debug=False, inline=False, | |
| } | ||
|
|
||
| tgt_ctx = cres.target_context | ||
| filename = cres.type_annotation.filename | ||
| linenum = int(cres.type_annotation.linenum) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the line number being a string in the type annotation is a minor problem, as LLVM expects line numbers to be integers (e.g.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| lib, kernel = tgt_ctx.prepare_cuda_kernel(cres.library, fname, args, | ||
| debug, nvvm_options, | ||
| filename, linenum, | ||
| max_registers) | ||
|
|
||
| if not link: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,7 +117,8 @@ def mangler(self, name, argtypes): | |
| return itanium_mangler.mangle(name, argtypes) | ||
|
|
||
| def prepare_cuda_kernel(self, codelib, func_name, argtypes, debug, | ||
| nvvm_options, max_registers=None): | ||
| nvvm_options, filename, linenum, | ||
| max_registers=None): | ||
| """ | ||
| Adapt a code library ``codelib`` with the numba compiled CUDA kernel | ||
| with name ``fname`` and arguments ``argtypes`` for NVVM. | ||
|
|
@@ -134,6 +135,8 @@ def prepare_cuda_kernel(self, codelib, func_name, argtypes, debug, | |
| argtypes: An iterable of the types of arguments to the kernel. | ||
| debug: Whether to compile with debug. | ||
| nvvm_options: Dict of NVVM options used when compiling the new library. | ||
| filename: The source filename that the function is contained in. | ||
| linenum: The source line that the function is on. | ||
|
Comment on lines
+147
to
+148
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if someone materialized a function from a string?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| max_registers: The max_registers argument for the code library. | ||
| """ | ||
| kernel_name = itanium_mangler.prepend_namespace(func_name, ns='cudapy') | ||
|
|
@@ -143,11 +146,12 @@ def prepare_cuda_kernel(self, codelib, func_name, argtypes, debug, | |
| max_registers=max_registers) | ||
| library.add_linking_library(codelib) | ||
| wrapper = self.generate_kernel_wrapper(library, kernel_name, func_name, | ||
| argtypes, debug) | ||
| argtypes, debug, filename, | ||
| linenum) | ||
| return library, wrapper | ||
|
|
||
| def generate_kernel_wrapper(self, library, kernel_name, func_name, | ||
| argtypes, debug): | ||
| argtypes, debug, filename, linenum): | ||
| """ | ||
| Generate the kernel wrapper in the given ``library``. | ||
| The function being wrapped have the name ``fname`` and argument types | ||
|
|
@@ -166,6 +170,11 @@ def generate_kernel_wrapper(self, library, kernel_name, func_name, | |
| wrapfn = ir.Function(wrapper_module, wrapfnty, prefixed) | ||
| builder = ir.IRBuilder(wrapfn.append_basic_block('')) | ||
|
|
||
| if debug: | ||
| debuginfo = self.DIBuilder(module=wrapper_module, filepath=filename) | ||
| debuginfo.mark_subprogram(wrapfn, kernel_name, linenum) | ||
| debuginfo.mark_location(builder, linenum) | ||
|
|
||
| # Define error handling variables | ||
| def define_error_gv(postfix): | ||
| name = wrapfn.name + postfix | ||
|
|
@@ -225,6 +234,8 @@ def define_error_gv(postfix): | |
|
|
||
| nvvm.set_cuda_kernel(wrapfn) | ||
| library.add_ir_module(wrapper_module) | ||
| if debug: | ||
| debuginfo.finalize() | ||
| library.finalize() | ||
| wrapfn = library.get_function(wrapfn.name) | ||
| return wrapfn | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's weird that I have to get the source file name from the type annotation at this stage, but I think the function IR is now lost (it was never saved after the pipeline finished).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably in the
self.py_func.__code__.co_filenameandcres.fndesc.lookup_module.__file__too if they are preferable? IIRC the compile result doesn't hold reference to the IR as the IR could hold reference to e.g. globals, some of which might be large (e.g. NumPy arrays) and this would create memory pressure etc.