-
Notifications
You must be signed in to change notification settings - Fork 54
Pass the -numba-debug flag to libnvvm #681
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
base: main
Are you sure you want to change the base?
Pass the -numba-debug flag to libnvvm #681
Conversation
When using the CUDA Toolkit release 13.1 or later for debug builds, we need to pass the -numba-debug flag to libnvvm in order to enable enhanced debug information. Closes NVIDIA#679
Greptile SummaryAdds support for passing the Major changes:
Issues found:
Confidence Score: 4/5
Important Files Changed
|
…bnvvm. As suggested by leofang, the original approach of determinging if the -numba-debug flag should be used is unreliable. Instead, use the pattern from one of the tests and compile a test program to examine it's PTX output version to deduce the CUDA Toolkit version. This result is cached in the NVVM singleton.
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.
Additional Comments (3)
-
numba_cuda/numba/cuda/cudadrv/nvvm.py, line 254-255 (link)syntax: Incorrect type for
optionsparameter.nvvmVerifyProgramexpectsPOINTER(c_char_p)but receives a Python list. -
numba_cuda/numba/cuda/cudadrv/nvvm.py, line 257 (link)syntax: Same issue: incorrect type for
optionsparameter. Must useoption_ptrsinstead. -
numba_cuda/numba/cuda/cudadrv/nvvm.py, line 274-275 (link)logic: Unconditional destruction of potentially uninitialized program handle. If
nvvmCreateProgramfails at line 239,programremains an emptyc_void_p()and destroying it could cause issues.
1 file reviewed, 3 comments
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.
Additional Comments (3)
-
numba_cuda/numba/cuda/cudadrv/nvvm.py, line 262 (link)syntax: use
c_size_t()instead ofc_int()to match function signature -
numba_cuda/numba/cuda/cudadrv/nvvm.py, line 255-256 (link)syntax: options must be encoded to bytes for ctypes
-
numba_cuda/numba/cuda/cudadrv/nvvm.py, line 277-279 (link)logic: calling
check_errorin finally block can raise exception during error handling, masking the original error. wrap in try-except or check error without raising
1 file reviewed, 3 comments
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.
Additional Comments (1)
-
numba_cuda/numba/cuda/cudadrv/nvvm.py, line 283-285 (link)logic: re-raising the exception defeats the graceful fallback logic. If test program compilation fails,
_libnvvm_cuda_versionstaysNonebut the exception propagates, preventing the caller from using the fallback behavior. Consider removing theraiseto allow silent failure and returnNone.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
1 file reviewed, 1 comment
|
/ok to test 6764681 |
| try: | ||
| self.check_error(err, "Failed to destroy test program.") | ||
| except Exception: | ||
| pass |
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.
I think there's no point checking the error if we're going to swallow the exception the check will raise anyway.
| try: | |
| self.check_error(err, "Failed to destroy test program.") | |
| except Exception: | |
| pass |
| err = self.nvvmGetCompiledResult(program, ptx_data) | ||
| self.check_error(err, "Failed to get test program compiled result.") | ||
| except Exception as exception: | ||
| print(f"Exception compiling test program: {exception}") |
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.
This should probably be a warning rather than a print:
| print(f"Exception compiling test program: {exception}") | |
| warnings.warn( | |
| f"Exception compiling test program: {exception}", | |
| category=NvvmWarning | |
| ) |
| self.check_error(err, "Failed to get test program compiled result.") | ||
| except Exception as exception: | ||
| print(f"Exception compiling test program: {exception}") | ||
| raise exception |
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.
I don't think we should re-raise the exception, just let it pass - otherwise I'd expect it to propagate all the way back to the user, which we may not want.
| raise exception |
| self._libnvvm_cuda_version = ( | ||
| get_minimal_required_cuda_ver_from_ptx_ver(ptx_version) | ||
| ) | ||
| except Exception: |
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 seems that the only likely exception we'd expect from the PTX version functions is a ValueError - anything else is a bit more surprising so we should let it manifest to expose the underlying bug instead:
| except Exception: | |
| except ValueError: |
| # pass in the -numba-debug flag. | ||
| if "g" in options: | ||
| ctk_version = self.driver.get_cuda_version() | ||
| if ctk_version is None or ctk_version >= (13, 1): |
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.
If we couldn't determine the version of the CTK, that could be because the version is 12.x because the necessary PTX version functions weren't present in the CUDA bindings for 12.x. So I think it'd be safer to assume we don't pass the -numba-debug flag if we can't determine the version:
| if ctk_version is None or ctk_version >= (13, 1): | |
| if ctk_version is not None and ctk_version >= (13, 1): |
gmarkall
left a comment
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.
I made some comments on the diff, but I also saw that the CI is failing.
If you set up commit signing (so that your commits show as "Verified" rather than "Unverified") you should be able to trigger the CI yourself by commenting /ok to test as well.
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.
1 file reviewed, 1 comment
| except Exception as exception: | ||
| print(f"Exception compiling test program: {exception}") | ||
| raise exception |
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.
logic: catching the exception, printing it, and re-raising defeats the purpose of graceful fallback. the code at lines 299-305 expects exceptions to be silently caught, allowing _libnvvm_cuda_version to remain None. this re-raise will prevent the function from returning None on error.
| except Exception as exception: | |
| print(f"Exception compiling test program: {exception}") | |
| raise exception | |
| except Exception: | |
| pass |
When using the CUDA Toolkit release 13.1 or later for debug builds, we need to pass the -numba-debug flag to libnvvm in order to enable enhanced debug information.
Closes #679