Skip to content

Commit 44eb27e

Browse files
committed
Merge branch 'path_finder_search_priority_v2' into path_finder_search_priority_v2_use_in_bindings
2 parents 7d8ab70 + 5977b9d commit 44eb27e

File tree

8 files changed

+116
-19
lines changed

8 files changed

+116
-19
lines changed

cuda_bindings/cuda/bindings/_path_finder/load_dl_common.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# Copyright 2025 NVIDIA Corporation. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

4-
import subprocess # nosec B404
5-
import sys
64
from dataclasses import dataclass
75
from typing import Callable, Optional
86

7+
from cuda.bindings._path_finder.run_python_code_safely import run_python_code_safely
98
from cuda.bindings._path_finder.supported_libs import DIRECT_DEPENDENCIES
109

1110

@@ -44,12 +43,7 @@ def load_dependencies(libname: str, load_func: Callable[[str], LoadedDL]) -> Non
4443

4544
def load_in_subprocess(python_code, timeout=30):
4645
# This is to avoid loading libraries into the parent process.
47-
return subprocess.run( # nosec B603
48-
[sys.executable, "-c", python_code],
49-
capture_output=True,
50-
encoding="utf-8",
51-
timeout=timeout, # Ensure this does not hang for an excessive amount of time.
52-
)
46+
return run_python_code_safely(python_code, timeout=timeout)
5347

5448

5549
def build_subprocess_failed_for_libname_message(libname, result):
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import multiprocessing
2+
import subprocess # nosec B404
3+
import sys
4+
import traceback
5+
from io import StringIO
6+
7+
8+
class Worker:
9+
def __init__(self, python_code, result_queue):
10+
self.python_code = python_code
11+
self.result_queue = result_queue
12+
13+
def __call__(self):
14+
# Capture stdout/stderr
15+
old_stdout = sys.stdout
16+
old_stderr = sys.stderr
17+
sys.stdout = StringIO()
18+
sys.stderr = StringIO()
19+
20+
try:
21+
exec(self.python_code, {"__name__": "__main__"}) # nosec B102
22+
returncode = 0
23+
except SystemExit as e: # Handle sys.exit()
24+
returncode = e.code if isinstance(e.code, int) else 0
25+
except BaseException:
26+
traceback.print_exc()
27+
returncode = 1
28+
finally:
29+
# Collect outputs and restore streams
30+
stdout = sys.stdout.getvalue()
31+
stderr = sys.stderr.getvalue()
32+
sys.stdout = old_stdout
33+
sys.stderr = old_stderr
34+
try: # noqa: SIM105
35+
self.result_queue.put((returncode, stdout, stderr))
36+
except Exception: # nosec B110
37+
# If the queue is broken (e.g., parent gone), best effort logging
38+
pass
39+
40+
41+
def run_python_code_safely(python_code, *, timeout=None):
42+
"""Run Python code in a spawned subprocess, capturing stdout/stderr/output."""
43+
ctx = multiprocessing.get_context("spawn")
44+
result_queue = ctx.SimpleQueue()
45+
process = ctx.Process(target=Worker(python_code, result_queue))
46+
process.start()
47+
48+
try:
49+
process.join(timeout)
50+
if process.is_alive():
51+
process.terminate()
52+
process.join()
53+
return subprocess.CompletedProcess(
54+
args=[sys.executable, "-c", python_code],
55+
returncode=-9,
56+
stdout="",
57+
stderr=f"Process timed out after {timeout} seconds and was terminated.",
58+
)
59+
60+
if result_queue.empty():
61+
return subprocess.CompletedProcess(
62+
args=[sys.executable, "-c", python_code],
63+
returncode=-999,
64+
stdout="",
65+
stderr="Process exited without returning results.",
66+
)
67+
68+
returncode, stdout, stderr = result_queue.get()
69+
return subprocess.CompletedProcess(
70+
args=[sys.executable, "-c", python_code],
71+
returncode=returncode,
72+
stdout=stdout,
73+
stderr=stderr,
74+
)
75+
76+
finally:
77+
try:
78+
result_queue.close()
79+
result_queue.join_thread()
80+
except Exception: # nosec B110
81+
pass
82+
if process.is_alive():
83+
process.kill()
84+
process.join()

cuda_bindings/docs/source/release/12.9.0-notes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ Highlights
1515
* Statically link CUDA Runtime instead of reimplementing it
1616
* Move stream callback wrappers to the Python layer
1717
* Return code construction is made faster
18-
* Failed API calls return None for non error code tuple elements
1918

2019

2120
Bug fixes
2221
---------
2322

2423
* Fix segfault when converting char* NULL to bytes
24+
* Failed API calls return None for non error code tuple elements
2525
* Compute-sanitizer may report ``CUDA_ERROR_INVALID_CONTEXT`` when calling certain CUDA
2626
runtime APIs such as ``cudaGetDevice()``
2727

cuda_bindings/docs/versions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"latest" : "latest",
3+
"12.9.0" : "12.9.0",
34
"12.8.0" : "12.8.0",
45
"12.6.2" : "12.6.2",
56
"12.6.1" : "12.6.1"

cuda_core/docs/source/install.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ dependencies are as follows:
77

88
| | CUDA 11 | CUDA 12 |
99
|------------------ | ------------ | ----------- |
10-
| CUDA Toolkit [^1] | 11.2 - 11.8 | 12.0 - 12.6 |
10+
| CUDA Toolkit [^1] | 11.2 - 11.8 | 12.x |
1111
| Driver | 450.80.02+ (Linux), 452.39+ (Windows) | 525.60.13+ (Linux), 527.41+ (Windows) |
1212

1313
[^1]: Including `cuda-python`.
1414

1515
`cuda.core` supports Python 3.9 - 3.13, on Linux (x86-64, arm64) and Windows (x86-64).
1616

17+
1718
## Installing from PyPI
1819

1920
`cuda.core` works with `cuda.bindings` (part of `cuda-python`) 11 or 12. For example with CUDA 12:
@@ -22,8 +23,9 @@ $ pip install cuda-core[cu12]
2223
```
2324
and likewise use `[cu11]` for CUDA 11.
2425

25-
Note that using `cuda.core` with NVRTC or nvJitLink installed from PyPI via `pip install` requires
26-
`cuda.bindings` 12.8.0+ or 11.8.6+.
26+
Note that using `cuda.core` with NVRTC installed from PyPI via `pip install` requires
27+
`cuda.bindings` 12.8.0+ or 11.8.6+. Likewise, with nvJitLink it requires 12.8.0+.
28+
2729

2830
## Installing from Conda (conda-forge)
2931

@@ -33,12 +35,8 @@ $ conda install -c conda-forge cuda-core cuda-version=12
3335
```
3436
and likewise use `cuda-version=11` for CUDA 11.
3537

36-
Note that to use `cuda.core` with nvJitLink installed from conda-forge currently requires it to
37-
be separately installed:
38-
```console
39-
$ conda install -c conda-forge libnvjitlink
40-
```
41-
(can be combined with the command above). This extra step will be removed in a future release.
38+
Note that to use `cuda.core` with nvJitLink installed from conda-forge requires `cuda.bindings` 12.8.0+.
39+
4240

4341
## Installing from Source
4442

@@ -47,4 +45,4 @@ $ git clone https://github.com/NVIDIA/cuda-python
4745
$ cd cuda-python/cuda_core
4846
$ pip install .
4947
```
50-
For now `cuda-python` (`cuda-bindings` later) 11.x or 12.x is a required dependency.
48+
`cuda-bindings` 11.x or 12.x is a required dependency.

cuda_python/docs/source/release.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
maxdepth: 3
66
---
77
8+
12.9.0 <release/12.9.0-notes>
89
12.8.0 <release/12.8.0-notes>
910
12.6.2 <release/12.6.2-notes>
1011
12.6.1 <release/12.6.1-notes>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.. SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
2+
3+
# CUDA Python 12.9.0 Release notes
4+
==================================
5+
6+
Released on May 5, 2025.
7+
8+
9+
Included components
10+
-------------------
11+
12+
* `cuda.bindings 12.9.0 <https://nvidia.github.io/cuda-python/cuda-bindings/12.9.0/release/12.9.0-notes.html>`_
13+
14+
15+
Highlights
16+
----------
17+
18+
* Add bindings for libNVVM

cuda_python/docs/versions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"latest" : "latest",
3+
"12.9.0" : "12.9.0",
34
"12.8.0" : "12.8.0",
45
"12.6.2" : "12.6.2",
56
"12.6.1" : "12.6.1"

0 commit comments

Comments
 (0)