|
3 | 3 | # SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE |
4 | 4 |
|
5 | 5 | import dataclasses |
| 6 | +import importlib |
6 | 7 |
|
7 | 8 | import pytest |
8 | 9 |
|
9 | 10 | from cuda.bindings import driver, runtime |
10 | 11 | from cuda.core._utils import cuda_utils |
11 | 12 | from cuda.core._utils.clear_error_support import assert_type_str_or_bytes_like, raise_code_path_meant_to_be_unreachable |
12 | 13 |
|
| 14 | +_EXPLANATION_MODULES = [ |
| 15 | + ("driver_cu_result_explanations", "DRIVER_CU_RESULT_EXPLANATIONS"), |
| 16 | + ("runtime_cuda_error_explanations", "RUNTIME_CUDA_ERROR_EXPLANATIONS"), |
| 17 | +] |
13 | 18 |
|
14 | | -def test_driver_cu_result_explanations_smoke(): |
15 | | - expl = cuda_utils.DRIVER_CU_RESULT_EXPLANATIONS |
| 19 | + |
| 20 | +@pytest.mark.parametrize("module_name,public_name", _EXPLANATION_MODULES) |
| 21 | +def test_explanations_smoke(module_name, public_name): |
| 22 | + expl = getattr(cuda_utils, public_name) |
16 | 23 | for code in (0, 1, 2): |
17 | 24 | assert code in expl |
18 | 25 | assert isinstance(expl[code], str) |
19 | 26 |
|
20 | 27 |
|
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) |
| 28 | +@pytest.mark.parametrize("module_name,public_name", _EXPLANATION_MODULES) |
| 29 | +def test_explanations_ctk_version(module_name, public_name): |
| 30 | + del public_name # unused |
| 31 | + core_mod = importlib.import_module(f"cuda.core._utils.{module_name}") |
| 32 | + try: |
| 33 | + bindings_mod = importlib.import_module(f"cuda.bindings._utils.{module_name}") |
| 34 | + except ModuleNotFoundError: |
| 35 | + pytest.skip("cuda.bindings._utils not available") |
| 36 | + bindings_path = f"cuda_bindings/cuda/bindings/_utils/{module_name}.py" |
| 37 | + core_path = f"cuda_core/cuda/core/_utils/{module_name}.py" |
| 38 | + if core_mod._CTK_MAJOR_MINOR_PATCH < bindings_mod._CTK_MAJOR_MINOR_PATCH: |
| 39 | + raise RuntimeError( |
| 40 | + f"cuda_core copy is older ({core_mod._CTK_MAJOR_MINOR_PATCH})" |
| 41 | + f" than cuda_bindings ({bindings_mod._CTK_MAJOR_MINOR_PATCH})." |
| 42 | + f" Please copy the _EXPLANATIONS dict from {bindings_path} to {core_path}" |
| 43 | + ) |
| 44 | + if ( |
| 45 | + core_mod._CTK_MAJOR_MINOR_PATCH == bindings_mod._CTK_MAJOR_MINOR_PATCH |
| 46 | + and core_mod._FALLBACK_EXPLANATIONS != bindings_mod._EXPLANATIONS |
| 47 | + ): |
| 48 | + raise RuntimeError( |
| 49 | + f"The cuda_core copy of the cuda_bindings _EXPLANATIONS dict is out of sync" |
| 50 | + f" (both at CTK {core_mod._CTK_MAJOR_MINOR_PATCH})." |
| 51 | + f" Please copy the _EXPLANATIONS dict from {bindings_path} to {core_path}" |
| 52 | + ) |
26 | 53 |
|
27 | 54 |
|
28 | 55 | def test_check_driver_error(): |
|
0 commit comments