CUDA: Fix linkage of device functions when compiling for debug #7162
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
I can get the reproducer in the original issue to work If I turn off the
diff --git a/numba/cuda/codegen.py b/numba/cuda/codegen.py index 70dcb10d6..5cfdaf6f1 100644 --- a/numba/cuda/codegen.py +++ b/numba/cuda/codegen.py @@ -125,7 +125,7 @@ class CUDACodeLibrary(serialize.ReduceMixin, CodeLibrary): else: # Otherwise, we compile all modules with NVVM at once because this # results in better optimization than separate compilation. - ptxes = [nvvm.llvm_to_ptx(irs, **options)] + ptxes = [nvvm.llvm_to_ptx(ir, **options) for ir in irs] # Sometimes the result from NVVM contains trailing whitespace and # nulls, which we strip so that the assembly dump looks a little diff --git a/numba/cuda/cudadrv/nvvm.py b/numba/cuda/cudadrv/nvvm.py index eb631b703..963022c5c 100644 --- a/numba/cuda/cudadrv/nvvm.py +++ b/numba/cuda/cudadrv/nvvm.py @@ -706,6 +706,9 @@ def llvm_to_ptx(llvmir, **opts): for mod in llvmir: mod = llvm_replace(mod) cu.add_module(mod.encode('utf8')) + + if "!llvm.dbg.cu" not in mod: + opts.pop("debug", None) cu.lazy_add_module(libdevice.get()) return cu.compile(**opts)
however, the test will still fail with:
numba.cuda.cudadrv.driver.LinkerError:  Call to cuLinkComplete results in CUDA_ERROR_UNKNOWN error : Undefined reference to '_ZN5numba4cuda5tests6cudapy14test_debuginfo17TestCudaDebugInfo29_test_chained_device_function12$3clocals$3e11kernel$2422Eii' in '<cudapy-ptx>'
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.