Repository navigation
[no-ci] fix(driver): correct cuLogs* introduced version to 12.9 in cuda_bindings_12 (backport #2978) #3395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[no-ci] fix(driver): correct cuLogs* introduced version to 12.9 in cuda_bindings_12 (backport #2978) #3395
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,15 +2,18 @@ | |
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import ctypes | ||
| import os | ||
| import platform | ||
| import shutil | ||
| import tempfile | ||
| import textwrap | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
|
|
||
| import cuda.cuda as cuda | ||
| from cuda.bindings import driver | ||
| from cuda.bindings._internal.utils import FunctionNotFoundError | ||
| from cuda_python_test_helpers import driver_version_less_than | ||
| from cuda_python_test_helpers.memory import ( | ||
| POOL_SIZE, | ||
|
|
@@ -1153,6 +1156,39 @@ def test_cuCheckpointProcessGetState_failure(): | |
| assert state is None | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| driver_version_less_than(12090), | ||
| reason="cuLogs* functions were introduced in CUDA 12.9", | ||
| ) | ||
| def test_culogs_functions(): | ||
| try: | ||
| err, callback_handle = cuda.cuLogsRegisterCallback(0, None) | ||
| assert err == cuda.CUresult.CUDA_SUCCESS | ||
|
|
||
| err, _ = cuda.cuLogsCurrent(0) | ||
| assert err == cuda.CUresult.CUDA_SUCCESS | ||
|
|
||
| with tempfile.NamedTemporaryFile(delete=False) as f: | ||
| log_path = f.name | ||
| try: | ||
| err, _ = cuda.cuLogsDumpToFile(None, log_path.encode(), 0) | ||
| assert err == cuda.CUresult.CUDA_SUCCESS | ||
| finally: | ||
| os.remove(log_path) | ||
|
|
||
| # cuLogsDumpToMemory's own docstring states the driver's internal log | ||
| # buffer is capped at 25600 bytes, so a buffer of that size is always | ||
| # large enough to hold the dump without risking a buffer overrun. | ||
| buf = bytearray(25600) | ||
| err, _, _ = cuda.cuLogsDumpToMemory(None, buf, len(buf), 0) | ||
| assert err == cuda.CUresult.CUDA_SUCCESS | ||
|
|
||
| (err,) = cuda.cuLogsUnregisterCallback(callback_handle) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. important: Unregister the callback on failure. If a later cuLogs call raises
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's ok to crash because this is a test case not core code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lijinf2 suggestion: Understood. I will leave callback cleanup to your discretion. The concern is test isolation, not core-code safety. You are interacting with an AI system.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to match existing code on the 12.9.x branch in this PR. This isn't significant enough I think to track as a follow-on. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| assert err == cuda.CUresult.CUDA_SUCCESS | ||
| except FunctionNotFoundError as e: | ||
| pytest.fail(f"cuLogs* function unexpectedly not found on the driver: {e}") | ||
|
|
||
|
|
||
| def test_private_function_pointer_inspector(): | ||
| from cuda.bindings._internal.driver import _inspect_function_pointer | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: NVIDIA/cuda-python
Length of output: 2131
Script executed:
Repository: NVIDIA/cuda-python
Length of output: 3871
important: Register a live callback, not
None.cuLogsRegisterCallback(0, None)stores a NULL user callback. The binding always registerscuLogsCallbackWrapperwith the driver, and that wrapper calls the stored callback without a NULL check (cuda_bindings_12/cuda/bindings/driver.pyx:50976). If the driver delivers a log message while this callback is registered, the wrapper calls a NULL function pointer and can crash the test process.Register a no-op callback instead:
Suggested fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the test case crashes we will catch that in CI. Adding no-op will make the test case complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lijinf2 important: Understood. I won’t press for the no-op callback. The reported crash risk depends on the driver delivering a log message, so CI can pass without exercising that path.
You are interacting with an AI system.