Skip to content

Commit 5417ea7

Browse files
Andy-Jostclaude
andcommitted
Address review: restore the cuda-core pin; re-deliver KeyboardInterrupt from the table fill; yq via apt; nits (NVIDIA#2783)
- cuda_python/setup.py pins cuda-core~=1.2.0 again. The bump at each cuda-core release, followed by a cuda-python release, is documented in .github/RELEASE-core.md, cuda_python/AGENTS.md and cuda_core/AGENTS.md. - A KeyboardInterrupt raised inside the function-table fill is no longer swallowed. The fill re-arms it with PyErr_SetInterrupt() after its warning, and report_message() does the same when an interrupt fires inside the warnings machinery, so the user sees the interrupt at the next bytecode boundary and the warning survives. Empty exception text falls back to the type name. Test: cuda_core/tests/test_driver_table.py, through the NVRTC table, CPU-only. - The Linux GPU test containers get yq from apt (the Python jq wrapper, which accepts the same command); the composite action is removed. - DeviceArch is a FastEnum again (present at both floors). - support.rst: the driver bullet states what the floor does not change and what an older driver means. Small comment and release-note fixes. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent f53077f commit 5417ea7

18 files changed

Lines changed: 161 additions & 107 deletions

File tree

‎.github/RELEASE-core.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ platforms as appropriate for each release.
6262
## Check (or update if needed) the dependency requirements
6363

6464
Review `cuda_core/pyproject.toml` and verify that all dependency
65-
requirements are current.
66-
67-
Update the cuda_core dependency in `cuda_python/setup.py`.
65+
requirements are current. The `cu12`/`cu13` extras declare the
66+
`cuda-bindings` floors; see "Bumping the cuda-bindings floor" in
67+
`cuda_core/AGENTS.md`.
68+
69+
Update the `cuda-core` pin in `cuda_python/setup.py` to the new minor
70+
series (`cuda-core~=X.Y.0`), and plan a `cuda-python` release right after
71+
this one. Until that release, `pip install cuda-python` resolves to the
72+
previous `cuda-core`.
6873

6974
---
7075

‎.github/actions/setup_yq_linux/action.yml‎

Lines changed: 0 additions & 41 deletions
This file was deleted.

‎.github/workflows/coverage.yml‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,8 @@ jobs:
8080
uses: ./.github/actions/install_unix_deps
8181
continue-on-error: false
8282
with:
83-
dependencies: "tree rsync libsqlite3-0 g++ jq wget libgl1 libegl1"
84-
dependent_exes: "tree rsync libsqlite3-0 g++ jq wget libgl1 libegl1"
85-
86-
- name: Set up yq
87-
# The container image has no yq; ci/tools/env-vars reads ci/versions.yml with it.
88-
uses: ./.github/actions/setup_yq_linux
89-
with:
90-
arch: amd64
83+
dependencies: "tree rsync libsqlite3-0 g++ jq wget libgl1 libegl1 yq"
84+
dependent_exes: "tree rsync libsqlite3-0 g++ jq wget libgl1 libegl1 yq"
9185

9286
- name: Setup proxy cache
9387
uses: nv-gha-runners/setup-proxy-cache@main

‎.github/workflows/test-wheel-linux.yml‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,9 @@ jobs:
140140
# for artifact fetching, graphics libs, g++ required for cffi in
141141
# example; util-linux for `nsenter` (custom-DRIVER rows re-exec
142142
# install_gpu_driver.sh onto the host through nsenter)
143-
dependencies: "jq wget libgl1 libegl1 g++ util-linux"
144-
dependent_exes: "jq wget"
145-
146-
- name: Set up yq
147-
# The container image has no yq; ci/tools/env-vars reads ci/versions.yml with it.
148-
uses: ./.github/actions/setup_yq_linux
149-
with:
150-
arch: ${{ matrix.ARCH }}
143+
# yq: ci/tools/env-vars reads ci/versions.yml with it
144+
dependencies: "jq wget libgl1 libegl1 g++ util-linux yq"
145+
dependent_exes: "jq wget yq"
151146

152147
- name: Install GPU driver
153148
if: ${{ matrix.DRIVER != 'latest' && matrix.DRIVER != 'earliest' }}

‎cuda_bindings/docs/source/release/13.5.0-notes.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ Enhancements
301301
- ``nvvm.add_module_to_program``, ``nvvm.lazy_add_module_to_program``, ``nvvm.get_compiled_result``, ``nvvm.get_program_log`` (``buffer``)
302302
- For all ``cuda-bindings`` APIs, functions that accept a struct wrapper will accept the struct wrapper directly, rather than requiring getting the ``.ptr`` property.
303303
- Creating class instances in ``cuda-bindings`` should now be faster in most cases, because it requires 1 heap allocation rather than 2.
304-
- Before a source build compiles anything, it now checks that the CUDA Toolkit's ``cuda.h`` has the major.minor this source tree was generated from. A mismatch stops the build with a message that names the header found and the version needed. Previously a mismatch surfaced as a long list of C++ redefinition errors.
304+
- Before a source build compiles anything, it now checks that the CUDA Toolkit's ``cuda.h`` has the major.minor the source tree was generated from. A mismatch stops the build with a message that names the header found and the version needed. Previously a mismatch surfaced as a long list of C++ redefinition errors.
305305

306306
Behavior changes
307307
----------------

‎cuda_core/AGENTS.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ a bump. To bump:
6666
5. Pin `cuda-bindings` to match in the conda-forge `cuda-core` feedstock. The
6767
feedstock lives outside this repository.
6868

69+
A `cuda-core` release also bumps the `cuda-core~=X.Y.0` pin in
70+
`cuda_python/setup.py`, followed by a `cuda-python` release (see
71+
`.github/RELEASE-core.md`).
72+
6973
### CUDA Toolkit minor bumps
7074

7175
The build compares the toolkit's `cuda.h` with the header that the installed

‎cuda_core/cuda/core/_cpp/rt/DESIGN.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,13 @@ which a thread holding a C++ lock can deadlock (see "GIL Management").
440440

441441
Python exceptions raised by that code never become C++ exceptions: the C API
442442
reports them as return codes, and `report_message` hands them to
443-
`sys.unraisablehook`. Nothing on the report path may allocate or throw, since a
444-
deleter is `noexcept`.
443+
`sys.unraisablehook`. The one exception is `KeyboardInterrupt`: a SIGINT that
444+
fires inside the warnings machinery is not swallowed. `report_message` emits
445+
the warning again and re-arms the interrupt with `PyErr_SetInterrupt()`, so
446+
Python raises it at the next bytecode boundary in the caller's code. The
447+
function-table fill does the same when its Python calls are interrupted
448+
(`take_python_error` in `py_driver_fns.cpp`). Nothing on the report path may
449+
allocate or throw, since a deleter is `noexcept`.
445450

446451
So: use `pw_` only in deleters and cleanup paths that hold no C++ lock and have
447452
finished updating the layer's own state. Where a lock must stay held, call

‎cuda_core/cuda/core/_cpp/rt/py_driver_fns.cpp‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,19 @@ const char* library_name(FnTable table) noexcept {
107107
// true when the exception says nothing about cuda-bindings or the driver: an
108108
// interruption such as KeyboardInterrupt or SystemExit, or exhaustion such as
109109
// MemoryError or RecursionError. The fill reports such a failure but does not
110-
// latch it, so the next call tries again.
111-
bool take_python_error(char* buf, std::size_t size) noexcept {
110+
// latch the table as failed, so the next call tries again.
111+
//
112+
// Sets *interrupted when the exception was a KeyboardInterrupt. The fill runs
113+
// in noexcept code reached from deleters and nogil blocks, so it cannot
114+
// propagate the exception, but the caller re-arms the interrupt with
115+
// PyErr_SetInterrupt() once its own Python work (the warning) is done. Python
116+
// then raises KeyboardInterrupt at the next bytecode boundary, so the user
117+
// sees the interrupt, not the CUDAError from the failed call.
118+
bool take_python_error(char* buf, std::size_t size, bool* interrupted) noexcept {
112119
const bool transient = PyErr_Occurred()
113120
&& (!PyErr_ExceptionMatches(PyExc_Exception) || PyErr_ExceptionMatches(PyExc_MemoryError)
114121
|| PyErr_ExceptionMatches(PyExc_RecursionError));
122+
*interrupted = PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_KeyboardInterrupt);
115123
#if PY_VERSION_HEX >= 0x030C0000
116124
PyObject* exc = PyErr_GetRaisedException();
117125
#else
@@ -124,7 +132,10 @@ bool take_python_error(char* buf, std::size_t size) noexcept {
124132
#endif
125133
PyObject* text = exc ? PyObject_Str(exc) : nullptr;
126134
const char* utf8 = text ? PyUnicode_AsUTF8(text) : nullptr;
127-
std::snprintf(buf, size, "%s", utf8 ? utf8 : "unknown error");
135+
if (utf8 == nullptr || *utf8 == '\0') {
136+
utf8 = exc ? Py_TYPE(exc)->tp_name : "unknown error"; // str(KeyboardInterrupt()) is empty
137+
}
138+
std::snprintf(buf, size, "%s", utf8);
128139
Py_XDECREF(text);
129140
Py_XDECREF(exc);
130141
PyErr_Clear();
@@ -188,20 +199,27 @@ bool ensure_fn_table(FnTable table) noexcept {
188199
}
189200
PendingExceptionGuard pending;
190201

202+
bool interrupted = false;
191203
PyObject* module = PyImport_ImportModule(module_name(table));
192204
if (module == nullptr) {
193-
const bool transient = take_python_error(cause, sizeof(cause));
205+
const bool transient = take_python_error(cause, sizeof(cause), &interrupted);
194206
std::snprintf(message, sizeof(message),
195207
"cuda.core cannot import %s from the installed cuda-bindings: %s", module_name(table), cause);
196208
record_failure(table, message, !transient);
209+
if (interrupted) {
210+
PyErr_SetInterrupt(); // after the warning: the handler must not consume the interrupt
211+
}
197212
return false;
198213
}
199214
PyObject* pointers = PyObject_CallMethod(module, "_inspect_function_pointers", nullptr);
200215
Py_DECREF(module);
201216
if (pointers == nullptr) {
202-
const bool transient = take_python_error(cause, sizeof(cause));
217+
const bool transient = take_python_error(cause, sizeof(cause), &interrupted);
203218
std::snprintf(message, sizeof(message), "cuda-bindings could not load the %s: %s", library_name(table), cause);
204219
record_failure(table, message, !transient);
220+
if (interrupted) {
221+
PyErr_SetInterrupt(); // after the warning: the handler must not consume the interrupt
222+
}
205223
return false;
206224
}
207225
if (!PyDict_Check(pointers)) {
@@ -227,7 +245,7 @@ bool ensure_fn_table(FnTable table) noexcept {
227245
void* address = PyLong_AsVoidPtr(item);
228246
if (address == nullptr && PyErr_Occurred()) {
229247
Py_DECREF(pointers);
230-
take_python_error(cause, sizeof(cause));
248+
take_python_error(cause, sizeof(cause), &interrupted);
231249
std::snprintf(message, sizeof(message),
232250
"internal cuda.core error, please report: the entry for %s in %s is not an address: %s",
233251
entries[i].key, module_name(table), cause);

‎cuda_core/cuda/core/_cpp/rt/py_report.cpp‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ std::atomic<PyObject*> warning_category{nullptr};
2222
// warning was promoted to an error), the failure is written as an unraisable
2323
// exception, the CPython convention for exceptions in destructors. Falls back
2424
// to stderr when the interpreter cannot be used.
25+
//
26+
// A KeyboardInterrupt is never swallowed here. The warnings machinery runs
27+
// Python code, so a pending SIGINT (one the user typed, or one that a failed
28+
// table fill re-armed; see py_driver_fns.cpp) can fire inside it. The warning
29+
// is then emitted again and the interrupt re-armed with PyErr_SetInterrupt(),
30+
// so Python raises it at the next bytecode boundary in the caller's code.
2531
void report_message(const char* message) noexcept {
2632
PyObject* category = warning_category.load(std::memory_order_acquire);
2733
if (category && Py_IsInitialized() && !py_is_finalizing()) {
@@ -34,16 +40,26 @@ void report_message(const char* message) noexcept {
3440
PyObject *pending_type, *pending_value, *pending_tb;
3541
PyErr_Fetch(&pending_type, &pending_value, &pending_tb);
3642
#endif
43+
bool interrupted = false;
3744
if (PyErr_WarnEx(category, message, 1) != 0) {
38-
PyObject* subject = PyUnicode_FromString(message);
39-
PyErr_WriteUnraisable(subject);
40-
Py_XDECREF(subject);
45+
interrupted = PyErr_ExceptionMatches(PyExc_KeyboardInterrupt);
46+
if (interrupted) {
47+
PyErr_Clear();
48+
}
49+
if (!interrupted || PyErr_WarnEx(category, message, 1) != 0) {
50+
PyObject* subject = PyUnicode_FromString(message);
51+
PyErr_WriteUnraisable(subject);
52+
Py_XDECREF(subject);
53+
}
4154
}
4255
#if PY_VERSION_HEX >= 0x030C0000
4356
PyErr_SetRaisedException(pending);
4457
#else
4558
PyErr_Restore(pending_type, pending_value, pending_tb);
4659
#endif
60+
if (interrupted) {
61+
PyErr_SetInterrupt();
62+
}
4763
return;
4864
}
4965
}

‎cuda_core/cuda/core/_memory/_copy_enums.py‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,8 @@ def _to_driver_flags(self) -> int:
124124

125125

126126
# CUDA 12.8 added CUmemcpySrcAccessOrder and CUmemcpyFlags. Every
127-
# cuda-bindings that cuda.core accepts has them. Keyed by ``str``: under
128-
# ``python_version = "3.10"`` mypy resolves StrEnum to the unstubbed backports
129-
# shim and so infers the members as plain ``str``. StrEnum members are ``str``
130-
# instances, so this holds on every version. The values are wrapped in
131-
# ``int()`` because the driver enums are untyped.
127+
# cuda-bindings that cuda.core accepts has them. Keyed by ``str`` (StrEnum
128+
# members are ``str``; mypy on 3.10 cannot see the enum) and valued as ``int``.
132129
_src_order = driver.CUmemcpySrcAccessOrder
133130
_flags = driver.CUmemcpyFlags
134131
_SRC_ACCESS_ORDER_TO_DRIVER: dict[str, int] = {

0 commit comments

Comments
 (0)