You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG]: Compiling PTX with undefined extern succeeds and produces empty kernel #920
and I'd assume that either linker would yell because of lack of extern definition. It sounds like the linker decides to just prune undefined externs without raising an error?!
Traceback (most recent call last):
File "/local/home/leof/dev/cuda-python/cuda_core/debug_nvjitlink.py", line 64, in <module>
linker.link(target_type="cubin")
File "/local/home/leof/dev/cuda-python/cuda_core/cuda/core/experimental/_linker.py", line 483, in link
_nvjitlink.complete(self._mnff.handle)
File "cuda/bindings/nvjitlink.pyx", line 165, in cuda.bindings.nvjitlink.complete
File "cuda/bindings/nvjitlink.pyx", line 175, in cuda.bindings.nvjitlink.complete
File "cuda/bindings/nvjitlink.pyx", line 75, in cuda.bindings.nvjitlink.check_status
cuda.bindings.nvjitlink.nvJitLinkError: ERROR_INTERNAL (6)
Linker error log: error : Undefined reference to '_Z1Cii' in ''
error : Undefined reference to '_Z1Zv' in ''
ERROR 9: finish
The example in the previous comment that doesn't require -g has a kernel in it calling the extern device function, but the original example has a device function calling an extern device function.
So, it looks like this is a difference in the configurations for the link between ptxas and nvJitLink - ptxas seems to try to produce a relocatable cubin by default, and nvJitLink seems to try to produce a fully linked one - So it's probably just discarding the caller in the original example and therefore an error is not being produced. When -g is applied, that probably disables the optimization that prunes dead functions, so the error gets emitted.
Adding options like -Xptxas=-c" and -Xptxas=-ewp don't seem to help though. Perhaps nvJitLink is running ptxas in compile-only (-c) mode to create a relocatable cubin, but then also linking the output causing the device function with a call to an undefined function to be dropped anyway.
Activity
leofang commentedon Aug 28, 2025
This is odd 🤔 Internally, if compiling to PTX is requested, we dispatch to the linker which would invoke either nvJitLink (if exists) or cuLink:
cuda-python/cuda_core/cuda/core/experimental/_program.py
Lines 408 to 413 in 1137e15
and I'd assume that either linker would yell because of lack of extern definition. It sounds like the linker decides to just prune undefined externs without raising an error?!
isVoid commentedon Aug 28, 2025
compiledoesn't invoke the linker under the hood. Theget_ltoirmethod from library returns the nvvm compiled result only:https://github.com/NVIDIA/numba-cuda/blob/main/numba_cuda/numba/cuda/codegen.py#L267-L283
gmarkall commentedon Aug 29, 2025
@isVoid This is
compilefromcuda.core.experimental.Programthough, notnumba.cuda.compile.leofang commentedon Sep 4, 2025
We should see an error raised mentioning "undefined reference"
cuda-python/cuda_core/tests/test_linker.py
Lines 147 to 168 in fa07cf5
Not sure why it does not happen. Still digging...
leofang commentedon Sep 8, 2025
@gmarkall I see that if we pass
instead of
nvJitLink will raise the expected error:
Do you think this is a bug in nvJitLink?
gmarkall commentedon Oct 9, 2025
I think so. If I compile and run
with
then I get
but if I change the options to
then I get
leofang commentedon Oct 9, 2025
@gmarkall I am scratching my head again because the following script is equivalent to what we test as mentioned above, and it does raise an error:
but it does not need
-g(debug=True) 🤔gmarkall commentedon Oct 9, 2025
The example in the previous comment that doesn't require
-ghas a kernel in it calling the extern device function, but the original example has a device function calling an extern device function.So, it looks like this is a difference in the configurations for the link between
ptxasand nvJitLink -ptxasseems to try to produce a relocatable cubin by default, and nvJitLink seems to try to produce a fully linked one - So it's probably just discarding the caller in the original example and therefore an error is not being produced. When-gis applied, that probably disables the optimization that prunes dead functions, so the error gets emitted.gmarkall commentedon Oct 9, 2025
Adding options like
-Xptxas=-c"and-Xptxas=-ewpdon't seem to help though. Perhaps nvJitLink is running ptxas in compile-only (-c) mode to create a relocatable cubin, but then also linking the output causing the device function with a call to an undefined function to be dropped anyway.