Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/test-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ linux:
- { ARCH: 'amd64', PY_VER: '3.13', CUDA_VER: '13.2.1', LOCAL_CTK: '1', GPU: 'h100', GPU_COUNT: '1', DRIVER: 'latest' }
- { ARCH: 'amd64', PY_VER: '3.14', CUDA_VER: '13.2.1', LOCAL_CTK: '1', GPU: 't4', GPU_COUNT: '2', DRIVER: 'latest' }
- { ARCH: 'amd64', PY_VER: '3.14t', CUDA_VER: '13.2.1', LOCAL_CTK: '1', GPU: 'h100', GPU_COUNT: '2', DRIVER: 'latest' }
- { ARCH: 'amd64', PY_VER: '3.11', CUDA_VER: '12.9.1', LOCAL_CTK: '0', GPU: 't4', GPU_COUNT: '1', DRIVER: 'latest', FLAVOR: 'wsl' }
- { ARCH: 'amd64', PY_VER: '3.11', CUDA_VER: '12.9.1', LOCAL_CTK: '1', GPU: 't4', GPU_COUNT: '1', DRIVER: 'latest', FLAVOR: 'wsl' }
- { ARCH: 'amd64', PY_VER: '3.12', CUDA_VER: '13.2.1', LOCAL_CTK: '0', GPU: 'rtx4090', GPU_COUNT: '1', DRIVER: 'latest', FLAVOR: 'wsl' }
nightly:
# nightly-pytorch
Expand Down
19 changes: 19 additions & 0 deletions cuda_bindings/cuda/bindings/nvml.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -21638,6 +21638,25 @@ cpdef str system_get_process_name(unsigned int pid):
return cpython.PyUnicode_FromString(name)


cpdef bytes system_get_process_name_bytes(unsigned int pid):
"""Gets name of the process with provided process id.

Args:
pid (unsigned int): The identifier of the process.

Returns:
char: Reference in which to return the process name.

.. seealso:: `nvmlSystemGetProcessName`
"""
cdef unsigned int length = 1024
cdef char[1024] name
with nogil:
__status__ = nvmlSystemGetProcessName(pid, name, length)
check_status(__status__)
return bytes(name)


cpdef object system_get_hic_version():
"""Retrieves the IDs and firmware versions for any Host Interface Cards (HICs) in the system.

Expand Down
164 changes: 164 additions & 0 deletions cuda_core/tests/system/test_system_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
# SPDX-License-Identifier: Apache-2.0


import contextlib
import locale
import os
import shutil
import subprocess
import sys

import pytest

Expand All @@ -18,6 +23,152 @@
from .conftest import skip_if_nvml_unsupported


def _detect_wsl() -> bool:
if any(var in os.environ for var in ("WSL_DISTRO_NAME", "WSL_INTEROP", "WSLENV")):
return True
try:
with open("/proc/version", encoding="utf-8", errors="replace") as f:
version = f.read().lower()
except OSError:
return False
return "microsoft" in version or "wsl" in version


def _gather_wsl_host_info() -> list[str]:
info: list[str] = ["=== Windows host (via WSL interop) ==="]

cmd_exe = shutil.which("cmd.exe") or "/mnt/c/Windows/System32/cmd.exe"
powershell = shutil.which("powershell.exe") or "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"

# Active console code page via cmd.exe.
try:
result = subprocess.run( # noqa: S603
[cmd_exe, "/c", "chcp"],
capture_output=True,
text=True,
timeout=15,
cwd="/",
)
info.append(f"cmd.exe chcp rc={result.returncode}")
if result.stdout:
info.append(f" stdout: {result.stdout.strip()!r}")
if result.stderr:
info.append(f" stderr: {result.stderr.strip()!r}")
except (OSError, subprocess.SubprocessError) as e:
info.append(f"cmd.exe chcp failed: {e!r}")

# Richer culture / code page info via PowerShell.
ps_script = ";".join(
[
"$OutputEncoding=[Text.Encoding]::UTF8",
"Write-Output ('Culture=' + (Get-Culture).Name)",
"Write-Output ('UICulture=' + (Get-UICulture).Name)",
"Write-Output ('SystemLocale=' + (Get-WinSystemLocale).Name)",
"Write-Output ('ConsoleOutputCP=' + [Console]::OutputEncoding.WebName)",
"Write-Output ('ConsoleInputCP=' + [Console]::InputEncoding.WebName)",
(
"Write-Output ('ANSICodePage=' + "
"[System.Globalization.CultureInfo]::CurrentCulture.TextInfo.ANSICodePage)"
),
("Write-Output ('OEMCodePage=' + [System.Globalization.CultureInfo]::CurrentCulture.TextInfo.OEMCodePage)"),
"Write-Output ('OSVersion=' + [Environment]::OSVersion.VersionString)",
]
)
try:
result = subprocess.run( # noqa: S603
[powershell, "-NoProfile", "-NonInteractive", "-Command", ps_script],
capture_output=True,
text=True,
timeout=30,
cwd="/",
)
info.append(f"powershell.exe rc={result.returncode}")
for line in result.stdout.splitlines():
info.append(f" {line.strip()}")
if result.stderr.strip():
info.append(f" stderr: {result.stderr.strip()!r}")
except (OSError, subprocess.SubprocessError) as e:
info.append(f"powershell.exe call failed: {e!r}")

return info


def _print_locale_diagnostics() -> None:
lines: list[str] = ["=== System / locale diagnostics ==="]
lines.append(f"sys.platform: {sys.platform}")
lines.append(f"sys.version: {sys.version.splitlines()[0]}")
lines.append(f"sys.getdefaultencoding(): {sys.getdefaultencoding()!r}")
lines.append(f"sys.getfilesystemencoding(): {sys.getfilesystemencoding()!r}")
lines.append(f"sys.getfilesystemencodeerrors(): {sys.getfilesystemencodeerrors()!r}")
lines.append(f"sys.stdout.encoding: {getattr(sys.stdout, 'encoding', None)!r}")
lines.append(f"sys.stderr.encoding: {getattr(sys.stderr, 'encoding', None)!r}")
lines.append(f"sys.flags.utf8_mode: {sys.flags.utf8_mode}")

lines.append(f"locale.getpreferredencoding(False): {locale.getpreferredencoding(False)!r}")
lines.append(f"locale.getpreferredencoding(True): {locale.getpreferredencoding(True)!r}")
with contextlib.suppress(AttributeError):
lines.append(f"locale.getencoding(): {locale.getencoding()!r}")
try:
lines.append(f"locale.getlocale(): {locale.getlocale()!r}")
except (locale.Error, ValueError) as e:
lines.append(f"locale.getlocale() error: {e!r}")

for cat_name in (
"LC_ALL",
"LC_CTYPE",
"LC_COLLATE",
"LC_MESSAGES",
"LC_MONETARY",
"LC_NUMERIC",
"LC_TIME",
):
cat = getattr(locale, cat_name, None)
if cat is None:
continue
try:
lines.append(f"locale.getlocale({cat_name}): {locale.getlocale(cat)!r}")
except (locale.Error, ValueError, TypeError) as e:
lines.append(f"locale.getlocale({cat_name}) error: {e!r}")
try:
lines.append(f"locale.setlocale({cat_name}, None): {locale.setlocale(cat, None)!r}")
except (locale.Error, ValueError, TypeError) as e:
lines.append(f"locale.setlocale({cat_name}, None) error: {e!r}")

for var in (
"LANG",
"LANGUAGE",
"LC_ALL",
"LC_CTYPE",
"LC_COLLATE",
"LC_MESSAGES",
"LC_MONETARY",
"LC_NUMERIC",
"LC_TIME",
"PYTHONUTF8",
"PYTHONIOENCODING",
"PYTHONLEGACYWINDOWSFSENCODING",
):
lines.append(f"env {var}={os.environ.get(var, '<unset>')!r}")

try:
with open("/proc/version", encoding="utf-8", errors="replace") as f:
lines.append(f"/proc/version: {f.read().strip()!r}")
except OSError as e:
lines.append(f"/proc/version: <error: {e!r}>")

for var in ("WSL_DISTRO_NAME", "WSL_INTEROP", "WSLENV"):
if var in os.environ:
lines.append(f"env {var}={os.environ[var]!r}")

if _detect_wsl():
lines.extend(_gather_wsl_host_info())
else:
lines.append("WSL not detected; skipping Windows host probe")

lines.append("=== end diagnostics ===")
print("\n".join(lines), flush=True)


def test_user_mode_driver_version():
umd = system.get_user_mode_driver_version()
assert isinstance(umd, tuple)
Expand Down Expand Up @@ -62,11 +213,24 @@ def test_nvml_version():

@skip_if_nvml_unsupported
def test_get_process_name():
_print_locale_diagnostics()

from cuda.bindings import nvml

nvml.init_v2()
print("BYTES:", repr(nvml.system_get_process_name_bytes(os.getpid())))

try:
process_name = system.get_process_name(os.getpid())
except system.NotFoundError:
pytest.skip("Process not found")

print(f"process_name: {process_name!r}", flush=True)
print(
f"process_name.encode('utf-8', 'backslashreplace'): {process_name.encode('utf-8', 'backslashreplace')!r}",
flush=True,
)

assert isinstance(process_name, str)
assert "python" in process_name

Expand Down
Loading