|
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | 4 | import ctypes |
| 5 | +import os |
5 | 6 | import shutil |
| 7 | +import tempfile |
6 | 8 | import textwrap |
7 | 9 |
|
8 | 10 | import numpy as np |
|
13 | 15 | import cuda.bindings.driver as cuda |
14 | 16 | import cuda.bindings.runtime as cudart |
15 | 17 | from cuda.bindings import driver |
| 18 | +from cuda.bindings._internal.utils import FunctionNotFoundError |
16 | 19 | from cuda_python_test_helpers import driver_version_less_than |
17 | 20 |
|
18 | 21 |
|
@@ -972,6 +975,59 @@ def test_cuCheckpointProcessGetState_failure(): |
972 | 975 | assert state is None |
973 | 976 |
|
974 | 977 |
|
| 978 | +@pytest.mark.skipif( |
| 979 | + driver_version_less_than(12090), |
| 980 | + reason="cuLogs* functions were introduced in CUDA 12.9", |
| 981 | +) |
| 982 | +def test_culogs_functions_are_resolved(): |
| 983 | + """ |
| 984 | + Regression test for https://github.com/NVIDIA/cuda-python/issues/2979 |
| 985 | +
|
| 986 | + cuLogsRegisterCallback, cuLogsUnregisterCallback, cuLogsCurrent, |
| 987 | + cuLogsDumpToFile, and cuLogsDumpToMemory were introduced in CUDA 12.9, |
| 988 | + but were incorrectly requested from cuGetProcAddress_v2 with version |
| 989 | + 12080 (CUDA 12.8). On a driver that enforces the requested symbol |
| 990 | + version, that mismatch causes the internal function pointer to never |
| 991 | + be resolved, so calling the function raises FunctionNotFoundError |
| 992 | + instead of actually invoking the driver. |
| 993 | +
|
| 994 | + cuLogsRegisterCallback, cuLogsUnregisterCallback, cuLogsCurrent, and |
| 995 | + cuLogsDumpToFile are called directly below since they can be exercised |
| 996 | + safely without a real log message or a fixed-size memory buffer. We |
| 997 | + deliberately avoid calling cuLogsDumpToMemory with a real buffer here: |
| 998 | + it writes a driver-chosen amount of data into the caller-supplied |
| 999 | + buffer, which makes it unsafe to invoke blindly in a regression test. |
| 1000 | + Instead, its resolution is verified the same way |
| 1001 | + test_private_function_pointer_inspector does: by inspecting the |
| 1002 | + internal function pointer directly. |
| 1003 | + """ |
| 1004 | + from cuda.bindings._internal.driver import _inspect_function_pointer |
| 1005 | + |
| 1006 | + try: |
| 1007 | + err, callback_handle = cuda.cuLogsRegisterCallback(0, None) |
| 1008 | + assert err == cuda.CUresult.CUDA_SUCCESS |
| 1009 | + |
| 1010 | + err, _ = cuda.cuLogsCurrent(0) |
| 1011 | + assert err == cuda.CUresult.CUDA_SUCCESS |
| 1012 | + |
| 1013 | + with tempfile.NamedTemporaryFile(delete=False) as f: |
| 1014 | + log_path = f.name |
| 1015 | + try: |
| 1016 | + err, _ = cuda.cuLogsDumpToFile(None, log_path.encode(), 0) |
| 1017 | + assert err == cuda.CUresult.CUDA_SUCCESS |
| 1018 | + finally: |
| 1019 | + os.remove(log_path) |
| 1020 | + |
| 1021 | + (err,) = cuda.cuLogsUnregisterCallback(callback_handle) |
| 1022 | + assert err == cuda.CUresult.CUDA_SUCCESS |
| 1023 | + except FunctionNotFoundError as e: |
| 1024 | + pytest.fail(f"cuLogs* function unexpectedly not found on the driver: {e}") |
| 1025 | + |
| 1026 | + assert _inspect_function_pointer("__cuLogsDumpToMemory") != 0, ( |
| 1027 | + "cuLogsDumpToMemory was not resolved by cuGetProcAddress_v2" |
| 1028 | + ) |
| 1029 | + |
| 1030 | + |
975 | 1031 | def test_private_function_pointer_inspector(): |
976 | 1032 | from cuda.bindings._internal.driver import _inspect_function_pointer |
977 | 1033 |
|
|
0 commit comments