Skip to content

pathfinder: add toolkit-info parser and display-driver release helpers - #2012

Closed
rwgk wants to merge 5 commits into
mainfrom
rwgk/stacked/pathfinder/utils_driver_and_toolkit_info
Closed

pathfinder: add toolkit-info parser and display-driver release helpers#2012
rwgk wants to merge 5 commits into
mainfrom
rwgk/stacked/pathfinder/utils_driver_and_toolkit_info

Conversation

@rwgk

@rwgkrwgk commented May 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Extracted from #1977 (xref #1038) so the underlying cuda.pathfinder._utils plumbing can be reviewed independently of the larger compatibility guard-rails work that consumes it. Five commits, scoped strictly to cuda_pathfinder/cuda/pathfinder/_utils/{driver_info,toolkit_info}.py and their unit tests; nothing else is touched.

Changes

  • toolkit-info parser. Add cuda.pathfinder._utils.toolkit_info, a small utility that reads the CUDA_VERSION macro from cuda.h so callers can infer CTK major.minor from toolkit headers without depending on version.json.

  • Shared encoded-CUDA-version decoding. Centralize encoded CUDA version parsing and validation so toolkit and driver version helpers stay aligned and cuda.h parsing gets consistent string conversion and error reporting.

  • Display-driver release metadata. Add DriverReleaseVersion and query_driver_release_version() in cuda.pathfinder._utils.driver_info. The helper queries nvmlSystemGetDriverVersion() via ctypes against the NVML library loaded through pathfinder's existing dynamic-lib loader, and parses the result into a frozen dataclass exposing both the raw text (e.g. "595.58.03") and the branch number (e.g. 595) used by NVIDIA's published minor-version compatibility tables.

  • try/finally around NVML init/shutdown. The matched nvmlInit_v2() / nvmlShutdown() pair runs under a single try/finally, with sys.exc_info()[1] preserving the asymmetric error precedence: when both the body and shutdown fail, the body's error wins (Python keeps the shutdown error on __context__ for debugging); when only shutdown fails, the shutdown error surfaces. Comments document that NVML's init/shutdown is reference-counted, so this balanced pair is safe even when the caller has already initialized NVML elsewhere in the process.

  • Tests. Direct coverage of the dataclass parsers, the cache-clear lifecycle, the QueryDriverReleaseVersionError wrapping, the fake-NVML end-to-end path, and the full success/failure cleanup matrix (body-ok+shutdown-fail, body-fail+shutdown-ok, body-fail+shutdown-fail).

rwgkand others added 5 commits May 3, 2026 20:17
Introduce a small toolkit-info utility that reads the CUDA_VERSION macro from cuda.h so follow-up guard-rails changes can infer CTK major.minor from toolkit headers without depending on version.json.
Made-with: Cursor
Centralize encoded CUDA version parsing and validation so toolkit and driver version helpers stay aligned and cuda.h parsing gets consistent string conversion and error reporting.
Made-with: Cursor
Introduce ``DriverReleaseVersion`` and ``query_driver_release_version()``
in ``cuda.pathfinder._utils.driver_info`` so callers can read the
display-driver release shown as ``Driver Version`` in ``nvidia-smi``
(for example ``595.58.03``, branch ``595``). The helper queries
``nvmlSystemGetDriverVersion()`` via ``ctypes`` against the NVML library
loaded through pathfinder's existing dynamic-lib loader, and parses the
result into a frozen dataclass exposing both the raw text and the
branch number used by NVIDIA's published minor-version compatibility
tables.
Tests cover the dataclass parser, the cache-clear lifecycle, the
``QueryDriverReleaseVersionError`` wrapping, and a fake-NVML
end-to-end path that asserts the shutdown call always runs.
Co-authored-by: Cursor <cursoragent@cursor.com>
Remove ``test_query_driver_release_version_returns_parsed_dataclass``
and ``test_query_driver_cuda_version_returns_parsed_dataclass``: both
shadow the dataclass parsers (``DriverReleaseVersion.from_text`` and
``DriverCudaVersion.from_encoded``), which already have direct
coverage, and the wrapping/error paths are still exercised by the
remaining mocked tests.
Co-authored-by: Cursor <cursoragent@cursor.com>
…nt contract
Collapse the duplicated ``nvmlShutdown()`` calls in
``_query_driver_release_version_text`` into a single ``try/finally`` so
the cleanup always runs in one place. The asymmetric error-precedence
rule is preserved via ``sys.exc_info()[1]``: when both the NVML body and
shutdown fail, the body's error wins (Python keeps the shutdown error
on ``__context__`` for debugging); when only shutdown fails, the
shutdown error surfaces.
Add comments above the matched ``nvmlInit_v2()`` / ``nvmlShutdown()``
pair noting that NVML's init/shutdown is reference-counted, so this
balanced pair is safe even when the caller has already initialized NVML
elsewhere in the process. Pre-empts a question raised in review on
PR #2000.
Add two focused tests filling out the cleanup matrix:
- ``test_query_driver_release_version_text_raises_when_only_shutdown_fails``
asserts a non-zero shutdown status surfaces when the body succeeded.
- ``test_query_driver_release_version_text_body_error_wins_when_both_fail``
locks in the body-error-wins precedence when both calls fail.
Co-authored-by: Cursor <cursoragent@cursor.com>
@rwgkrwgk added this to the cuda.pathfinder next milestone May 4, 2026
@rwgkrwgk self-assigned this May 4, 2026
@rwgkrwgk added P0 High priority - Must do! feature New feature or request cuda.pathfinder Everything related to the cuda.pathfinder module labels May 4, 2026
@copy-pr-bot

Copy link
Copy Markdown
Contributor

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

rwgk commented May 4, 2026

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@github-actions

Copy link
Copy Markdown

@rwgk
rwgk marked this pull request as ready for review May 4, 2026 06:05
@mdboommdboom mentioned this pull request Jun 10, 2026
1 task
@rwgk

rwgk commented Aug 4, 2026

Copy link
Copy Markdown
ContributorAuthor

Closing this PR (and PR #1977) so I can rebuild the work as a native stacked PR series using GitHub's newly announced stacked pull requests feature, which is currently rolling out in public preview:

This indicates that the new feature is already available in this repo (the list is empty because there are no stacks yet):

$ gh api repos/NVIDIA/cuda-python/stacks
[]

I’ll link the replacement PRs here once they're available.

@rwgkrwgk closed this Aug 4, 2026
@rwgk
rwgk deleted the rwgk/stacked/pathfinder/utils_driver_and_toolkit_info branch August 4, 2026 08:24
@rwgk

rwgk commented Aug 5, 2026

Copy link
Copy Markdown
ContributorAuthor

The corresponding new PR is #2505

github-actionsBot pushed a commit that referenced this pull request Aug 6, 2026
Removed preview folders for the following PRs:
- PR #1977
- PR #2012
- PR #2390
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.pathfinderEverything related to the cuda.pathfinder modulefeatureNew feature or requestP0High priority - Must do!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@rwgk