Skip to content

Commit ebd2229

Browse files
leofangclaude
andcommitted
Split into get_user_mode_driver_version and get_kernel_mode_driver_version
Per review feedback, split the consolidated get_driver_version() into two separate functions so each returns a simple tuple[int, ...]: - get_user_mode_driver_version(): works with or without NVML (falls back to cuDriverGetVersion), returns (major, minor) - get_kernel_mode_driver_version(): requires NVML, returns (major, minor, patch) or (major, minor) on WSL Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d2d387e commit ebd2229

5 files changed

Lines changed: 52 additions & 40 deletions

File tree

cuda_core/cuda/core/system/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
__all__ = [
1313
"CUDA_BINDINGS_NVML_IS_COMPATIBLE",
14-
"get_driver_version",
14+
"get_kernel_mode_driver_version",
15+
"get_user_mode_driver_version",
1516
"get_num_devices",
1617
"get_process_name",
1718
]

cuda_core/cuda/core/system/_system.pyx

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,41 +26,52 @@ if CUDA_BINDINGS_NVML_IS_COMPATIBLE:
2626

2727
from cuda.core.system._nvml_context import initialize
2828
else:
29-
from cuda.core._utils.cuda_utils import handle_return, runtime
29+
from cuda.core._utils.cuda_utils import driver, handle_return, runtime
3030

3131

32-
def get_driver_version() -> tuple[tuple[int, ...], tuple[int, ...]]:
32+
def get_user_mode_driver_version() -> tuple[int, ...]:
3333
"""
34-
Get the driver version.
34+
Get the user-mode (UMD / CUDA) driver version.
3535

36-
Returns both the user-mode (UMD / CUDA) driver version and the
37-
kernel-mode (KMD / GPU) driver version.
36+
This is the most commonly needed version when checking CUDA driver
37+
compatibility. It works with all ``cuda-bindings`` versions: when
38+
NVML is available it uses NVML, otherwise it falls back to the
39+
CUDA driver API.
3840

3941
Returns
4042
-------
41-
version : tuple[tuple[int, ...], tuple[int, ...]]
42-
``(umd_version, kmd_version)`` where ``umd_version`` is typically
43-
a 2-tuple ``(MAJOR, MINOR)`` and ``kmd_version`` is typically
44-
a 3-tuple ``(MAJOR, MINOR, PATCH)`` (2-tuple on WSL).
43+
version : tuple[int, ...]
44+
A 2-tuple ``(MAJOR, MINOR)``.
45+
"""
46+
cdef int v
47+
if CUDA_BINDINGS_NVML_IS_COMPATIBLE:
48+
initialize()
49+
v = nvml.system_get_cuda_driver_version()
50+
else:
51+
v = handle_return(driver.cuDriverGetVersion())
52+
return (v // 1000, (v // 10) % 100)
53+
54+
55+
def get_kernel_mode_driver_version() -> tuple[int, ...]:
56+
"""
57+
Get the kernel-mode (KMD / GPU) driver version.
58+
59+
Returns
60+
-------
61+
version : tuple[int, ...]
62+
Typically a 3-tuple ``(MAJOR, MINOR, PATCH)`` (2-tuple on WSL).
4563

4664
Raises
4765
------
4866
RuntimeError
4967
If the NVML library is not available.
5068
"""
5169
if not CUDA_BINDINGS_NVML_IS_COMPATIBLE:
52-
raise RuntimeError("get_driver_version requires NVML support")
70+
raise RuntimeError(
71+
"get_kernel_mode_driver_version requires NVML support"
72+
)
5373
initialize()
54-
55-
# UMD (user-mode / CUDA toolkit) version
56-
cdef int v
57-
v = nvml.system_get_cuda_driver_version()
58-
umd = (v // 1000, (v // 10) % 100)
59-
60-
# KMD (kernel-mode / GPU driver) version
61-
kmd = tuple(int(x) for x in nvml.system_get_driver_version().split("."))
62-
63-
return (umd, kmd)
74+
return tuple(int(x) for x in nvml.system_get_driver_version().split("."))
6475

6576

6677
def get_nvml_version() -> tuple[int, ...]:
@@ -123,7 +134,8 @@ def get_process_name(pid: int) -> str:
123134

124135
__all__ = [
125136
"get_driver_branch",
126-
"get_driver_version",
137+
"get_kernel_mode_driver_version",
138+
"get_user_mode_driver_version",
127139
"get_nvml_version",
128140
"get_num_devices",
129141
"get_process_name",

cuda_core/docs/source/api.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ Basic functions
254254
.. autosummary::
255255
:toctree: generated/
256256

257-
system.get_driver_version
257+
system.get_user_mode_driver_version
258+
system.get_kernel_mode_driver_version
258259
system.get_driver_branch
259260
system.get_num_devices
260261
system.get_nvml_version

cuda_core/docs/source/release/1.0.0-notes.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,11 @@ Breaking changes
152152
:mod:`cuda.core.utils` module.
153153
(`#2028 <https://github.com/NVIDIA/cuda-python/issues/2028>`__)
154154

155-
- Consolidated ``system.get_driver_version()`` and
156-
``system.get_driver_version_full()`` into a single
157-
:func:`system.get_driver_version` that returns
158-
``(umd_version, kmd_version)`` — a 2-tuple of version tuples
159-
(UMD is ``(MAJOR, MINOR)``, KMD is ``(MAJOR, MINOR, PATCH)``).
160-
The function now requires NVML support and raises :class:`RuntimeError`
161-
if it is not available.
155+
- Replaced ``system.get_driver_version()`` and
156+
``system.get_driver_version_full()`` with
157+
:func:`system.get_user_mode_driver_version` (works with or without
158+
NVML) and :func:`system.get_kernel_mode_driver_version` (requires
159+
NVML). Each returns a ``tuple[int, ...]``.
162160

163161
Fixes and enhancements
164162
-----------------------

cuda_core/tests/system/test_system_system.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
from .conftest import skip_if_nvml_unsupported
2020

2121

22-
@skip_if_nvml_unsupported
23-
def test_driver_version():
24-
umd, kmd = system.get_driver_version()
25-
26-
# UMD: 2-tuple (major, minor), cross-check against cuDriverGetVersion
22+
def test_user_mode_driver_version():
23+
umd = system.get_user_mode_driver_version()
2724
assert isinstance(umd, tuple)
2825
assert len(umd) == 2
2926
version = handle_return(driver.cuDriverGetVersion())
30-
expected_umd = (version // 1000, (version % 1000) // 10)
31-
assert umd == expected_umd, "UMD driver version does not match expected value"
27+
expected = (version // 1000, (version % 1000) // 10)
28+
assert umd == expected, "UMD driver version does not match expected value"
3229

33-
# KMD: 3-tuple (major, minor, patch), or 2-tuple on WSL
30+
31+
@skip_if_nvml_unsupported
32+
def test_kernel_mode_driver_version():
33+
kmd = system.get_kernel_mode_driver_version()
3434
assert isinstance(kmd, tuple)
3535
assert len(kmd) in (2, 3)
3636
ver_maj, ver_min, *ver_patch = kmd
@@ -55,11 +55,11 @@ def test_devices():
5555
assert device.device_id == expected_device.device_id, "Device ID does not match expected value"
5656

5757

58-
def test_driver_version_requires_nvml():
58+
def test_kernel_mode_driver_version_requires_nvml():
5959
if system.CUDA_BINDINGS_NVML_IS_COMPATIBLE:
6060
pytest.skip("NVML is available, cannot test the error path")
6161
with pytest.raises(RuntimeError, match="requires NVML support"):
62-
system.get_driver_version()
62+
system.get_kernel_mode_driver_version()
6363

6464

6565
@skip_if_nvml_unsupported

0 commit comments

Comments
 (0)