Skip to content

Commit 474b3b6

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 aeef8df commit 474b3b6

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

@@ -974,6 +977,59 @@ def test_cuCheckpointProcessGetState_failure():
974977
assert state is None
975978

976979

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

0 commit comments

Comments
 (0)