Skip to content

Commit d6b3e78

Browse files
committed
cuda_core: prefer enum explanations from cuda.bindings, keep local fallback (#1712)
Each explanation module now tries to import the authoritative dict from cuda.bindings._utils (ModuleNotFoundError-guarded) and falls back to its own copy for older cuda-bindings that don't ship it yet. Smoke tests added for both dicts. Made-with: Cursor
1 parent f35670a commit d6b3e78

3 files changed

Lines changed: 32 additions & 10 deletions

File tree

cuda_core/cuda/core/_utils/driver_cu_result_explanations.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

4-
# To regenerate the dictionary below run:
5-
# ../../../../../toolshed/reformat_cuda_enums_as_py.py /usr/local/cuda/include/cuda.h
6-
# Replace the dictionary below with the output.
7-
# Also update the CUDA Toolkit version number below.
8-
4+
# Fallback copy -- overridden from cuda.bindings below when available.
95
# CUDA Toolkit v13.2.0
106
DRIVER_CU_RESULT_EXPLANATIONS = {
117
0: (
@@ -356,3 +352,11 @@
356352
),
357353
999: "This indicates that an unknown internal error has occurred.",
358354
}
355+
356+
# Prefer the authoritative copy from cuda.bindings when available.
357+
try:
358+
import cuda.bindings._utils.driver_cu_result_explanations as _authoritative
359+
except ModuleNotFoundError:
360+
pass
361+
else:
362+
DRIVER_CU_RESULT_EXPLANATIONS = _authoritative.DRIVER_CU_RESULT_EXPLANATIONS

cuda_core/cuda/core/_utils/runtime_cuda_error_explanations.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

4-
# To regenerate the dictionary below run:
5-
# ../../../../../toolshed/reformat_cuda_enums_as_py.py /usr/local/cuda/include/driver_types.h
6-
# Replace the dictionary below with the output.
7-
# Also update the CUDA Toolkit version number below.
8-
4+
# Fallback copy -- overridden from cuda.bindings below when available.
95
# CUDA Toolkit v13.2.0
106
RUNTIME_CUDA_ERROR_EXPLANATIONS = {
117
0: (
@@ -549,3 +545,11 @@
549545
" This error return is deprecated as of CUDA 4.1."
550546
),
551547
}
548+
549+
# Prefer the authoritative copy from cuda.bindings when available.
550+
try:
551+
import cuda.bindings._utils.runtime_cuda_error_explanations as _authoritative
552+
except ModuleNotFoundError:
553+
pass
554+
else:
555+
RUNTIME_CUDA_ERROR_EXPLANATIONS = _authoritative.RUNTIME_CUDA_ERROR_EXPLANATIONS

cuda_core/tests/test_cuda_utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
1111
from cuda.core._utils.clear_error_support import assert_type_str_or_bytes_like, raise_code_path_meant_to_be_unreachable
1212

1313

14+
def test_driver_cu_result_explanations_smoke():
15+
expl = cuda_utils.DRIVER_CU_RESULT_EXPLANATIONS
16+
for code in (0, 1, 2):
17+
assert code in expl
18+
assert isinstance(expl[code], str)
19+
20+
21+
def test_runtime_cuda_error_explanations_smoke():
22+
expl = cuda_utils.RUNTIME_CUDA_ERROR_EXPLANATIONS
23+
for code in (0, 1, 2):
24+
assert code in expl
25+
assert isinstance(expl[code], str)
26+
27+
1428
def test_check_driver_error():
1529
num_unexpected = 0
1630
for error in driver.CUresult:

0 commit comments

Comments
 (0)