Skip to content

Commit 632bdc4

Browse files
committed
test(driver): add regression test for cuLogs* version pinning
Adds test_culogs_functions_are_resolved to confirm cuLogsRegisterCallback, cuLogsUnregisterCallback, cuLogsCurrent, cuLogsDumpToFile, and cuLogsDumpToMemory are resolved by cuGetProcAddress_v2 and do not raise FunctionNotFoundError, guarding against the version mismatch fixed in this PR. Addresses review feedback on NVIDIA#2978, closes NVIDIA#2979.
1 parent 3d0bccd commit 632bdc4

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

‎cuda_bindings/tests/test_cuda.py‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
import ctypes
5+
import os
56
import shutil
7+
import tempfile
68
import textwrap
79

810
import numpy as np
@@ -13,6 +15,7 @@
1315
import cuda.bindings.driver as cuda
1416
import cuda.bindings.runtime as cudart
1517
from cuda.bindings import driver
18+
from cuda.bindings._internal.utils import FunctionNotFoundError
1619
from cuda_python_test_helpers import driver_version_less_than
1720

1821

@@ -972,6 +975,59 @@ def test_cuCheckpointProcessGetState_failure():
972975
assert state is None
973976

974977

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+
9751031
def test_private_function_pointer_inspector():
9761032
from cuda.bindings._internal.driver import _inspect_function_pointer
9771033

0 commit comments

Comments
 (0)