Skip to content

cuda_core: derive error enum explanations from bindings docstrings#1860

Open
rwgk wants to merge 5 commits intoNVIDIA:mainfrom
rwgk:enum_explanations_from_docstrings
Open

cuda_core: derive error enum explanations from bindings docstrings#1860
rwgk wants to merge 5 commits intoNVIDIA:mainfrom
rwgk:enum_explanations_from_docstrings

Conversation

@rwgk
Copy link
Copy Markdown
Collaborator

@rwgk rwgk commented Apr 5, 2026

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 with cuda-bindings >= 13.2.0 on the main branch, and cuda-bindings 12.9.6 on the 12.9.x backport branch. See the comment below for a summary of a manual review of the cleaned enum docstrings.

Summary

  • use cleaned enum __doc__ strings for driver/runtime error explanations in cuda_core when 12.9.6 <= cuda-bindings < 13.0.0 or cuda-bindings >= 13.2.0
  • keep the CTK 13.1.1 explanation tables frozen as fallback for bindings versions that do not expose usable enum-member __doc__
  • centralize the version gate + cleanup logic in enum_explanations_helpers.py
  • update cuda_utils coverage to share the same version predicate and verify representative enums expose __doc__ and that explanation text is attached to raised CUDAErrors
  • remove the obsolete toolshed/reformat_cuda_enums_as_py.py

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
@rwgk rwgk added this to the cuda.core v0.7.0 milestone Apr 5, 2026
@rwgk rwgk self-assigned this Apr 5, 2026
@rwgk rwgk added bug Something isn't working P0 High priority - Must do! cuda.core Everything related to the cuda.core module labels Apr 5, 2026
@copy-pr-bot
Copy link
Copy Markdown
Contributor

copy-pr-bot bot commented Apr 5, 2026

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.

@rwgk
Copy link
Copy Markdown
Collaborator Author

rwgk commented Apr 5, 2026

/ok to test

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 5, 2026

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
@rwgk
Copy link
Copy Markdown
Collaborator Author

rwgk commented Apr 5, 2026

/ok to test

@rwgk
Copy link
Copy Markdown
Collaborator Author

rwgk commented Apr 5, 2026

I manually reviewed the cleaned driver/runtime enum-doc output for both cuda-bindings 13.2.0 and cuda-bindings 12.9.6 using this local helper script:

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:

  • the cleaned output looks presentable in both versions
  • I did not see leftover ~, ::, or Sphinx-role markup in the cleaned strings
  • this gave me enough confidence to use the docstring-backed path for 12.9.6 <= cuda-bindings < 13.0.0 as well as cuda-bindings >= 13.2.0
  • the only remaining oddities I noticed look upstream/generated rather than cleanup-related: cudaErrorIncompatibleDriverContext still says this the CUDA Runtime, and cudaErrorApiFailureBase has no docstring (which still falls back to cudaGetErrorString() in cuda_core)

rwgk added 3 commits April 5, 2026 11:49
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
@rwgk
Copy link
Copy Markdown
Collaborator Author

rwgk commented Apr 5, 2026

/ok to test

@rwgk rwgk marked this pull request as ready for review April 5, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cuda.core Everything related to the cuda.core module P0 High priority - Must do!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Move enum explanations and health checks from cuda_core to cuda_bindings

1 participant