cuda_core: derive error enum explanations from bindings docstrings#1860
cuda_core: derive error enum explanations from bindings docstrings#1860rwgk wants to merge 8 commits intoNVIDIA:mainfrom
Conversation
Use cleaned driver/runtime enum __doc__ text from cuda-bindings 13.2.0+ as the primary source for CUDA error explanations in cuda_core, while freezing the 13.1.1 explanation tables as fallback for older bindings. Centralize the version-gated selection and docstring cleanup helpers, update the driver/runtime explanation modules to use them, add tests that verify representative enums expose __doc__ and that cuda_utils attaches the explanation text, and remove the obsolete enum-reformat toolshed helper script. Made-with: Cursor
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
/ok to test |
|
Treat the 12.9.6 backport line as docstring-capable and reuse the same version predicate in tests so error explanations follow the bindings releases that already expose usable enum docs. Made-with: Cursor
|
/ok to test |
|
I manually reviewed the cleaned driver/runtime enum-doc output for both from __future__ import annotations
import cuda.bindings
from cuda.bindings import driver, runtime
from cuda.core._utils.enum_explanations_helpers import clean_enum_member_docstring
def dump_enum_docs(label, enum_type):
print(f"=== {label} ===")
for member in enum_type:
cleaned = clean_enum_member_docstring(member.__doc__)
print(f"{member.name} ({int(member)})")
print(cleaned if cleaned is not None else "<None>")
print()
def main():
print(f"cuda.bindings.__version__ = {cuda.bindings.__version__}")
print()
dump_enum_docs("driver.CUresult", driver.CUresult)
dump_enum_docs("runtime.cudaError_t", runtime.cudaError_t)
if __name__ == "__main__":
main()High-level result from the manual review:
|
Remove the old Doxygen ``::`` normalization path now that error explanations no longer depend on dict-vs-docstring parity checks. This keeps the helper focused on the cleanup rules that still affect user-facing CUDAError messages. Made-with: Cursor
Clarify that DocstringBackedExplanations is a compatibility shim for the existing ``.get(int(error))`` lookup shape, and trim a low-value implementation note from the docstring cleanup workaround comment. Made-with: Cursor
Remove redundant helper coverage now that DocstringBackedExplanations.get() and clean_enum_member_docstring() are already exercised elsewhere, and simplify the remaining test module imports. Made-with: Cursor
|
/ok to test |
| 999: "This indicates that an unknown internal error has occurred.", | ||
| } | ||
|
|
||
| DRIVER_CU_RESULT_EXPLANATIONS = get_best_available_explanations(driver.CUresult, _FALLBACK_EXPLANATIONS) |
There was a problem hiding this comment.
It would be great to move this one level up so this module full of pre-written results doesn't have to be imported at all if we have a new enough cuda-bindings.
| s = re.sub(r"\*([^*]+)\*", r"\1", s) | ||
| s = re.sub(r"\s+", " ", s).strip() | ||
| s = _fix_hyphenation_wordwrap_spacing(s) | ||
| return s |
There was a problem hiding this comment.
This seems really brittle, but I guess I don't see a way around it. I would prefer to just depend on rst2txt or something, that but seems unmaintained.
| # in cuda-bindings code generation. | ||
| s = s.replace("\n:py:obj:`~.Interactions`", ' "Interactions ') | ||
| s = re.sub( | ||
| r":(?:py:)?(?:obj|func|meth|class|mod|data|const|exc):`([^`]+)`", |
There was a problem hiding this comment.
This regex seems too specific. Could we just use one that would capture any rst directive?
There was a problem hiding this comment.
Something like (untested):
r":(?:[a-z]+:)?(?:[a-z]):`([^`]+)`"
| while prev != s: | ||
| prev = s | ||
| s = re.sub(r"([a-z])- ([a-z])", r"\1-\2", s) | ||
| s = re.sub(r"([a-z]) -([a-z])", r"\1-\2", s) |
There was a problem hiding this comment.
Seems too narrow. Why only perform this on lower-case words?
Broaden the inline-role cleanup to accept generic RST roles and widen the word-wrap hyphen fix beyond lowercase-only cases. Keep the current 13.2.x output unchanged while expanding unit coverage for the newly supported forms. Made-with: Cursor
Add terse comments for the remaining inline regex substitutions so the docstring cleanup steps are easier to follow without changing behavior. Made-with: Cursor
|
My Cursor prompt:
Cursor response: I checked the current import path:
So today, even on Option 1
How it shakes out:
Tradeoff:
Option 2
How it shakes out:
Tradeoff:
Option 3
Tradeoff:
Recommendation
Why I think this is the best fit:
|
Closes #1712
This PR grows out of the validation work under #1805. That work showed that driver/runtime error enums expose usable per-member
__doc__text once a small amount of normalization is applied. The enum docstrings are usable starting withcuda-bindings >= 13.2.0on the main branch, andcuda-bindings 12.9.6on the 12.9.x backport branch. See the comment below for a summary of a manual review of the cleaned enum docstrings.Summary
__doc__strings for driver/runtime error explanations incuda_corewhen12.9.6 <= cuda-bindings < 13.0.0orcuda-bindings >= 13.2.0__doc__enum_explanations_helpers.pycuda_utilscoverage to share the same version predicate and verify representative enums expose__doc__and that explanation text is attached to raisedCUDAErrorstoolshed/reformat_cuda_enums_as_py.py