Skip to content

fix(cuda.core): preserve DLPack C exchange errors - #2939

Open
rluo8 wants to merge 1 commit into
NVIDIA:mainfrom
rluo8:fix/dlpack-exchange-error-propagation
Open

rluo8 wants to merge 1 commit into
NVIDIA:mainfrom
rluo8:fix/dlpack-exchange-error-propagation

Conversation

@rluo8

@rluo8 rluo8 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Description

The DLPack C exchange API requires export/import callbacks to return -1
with a Python exception set
(dlpack.h;BufferError when the data cannot be described).
StridedMemoryView returned -1 without restoring the exception.

This PR restores the exception with PyErr_SetObject before returning -1,
adds regression tests for both export entry points and unsupported-
device import, and add a release note.

Signed-off-by: Rui Luo <ruluo@nvidia.com>
@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Sep 23, 2026
@rluo8 rluo8 self-assigned this Sep 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@rluo8
rluo8 requested review from Andy-Jost and mdboom September 23, 2026 09:31
@Andy-Jost Andy-Jost added this to the cuda.core 1.3.0 milestone Sep 23, 2026
@Andy-Jost Andy-Jost added bug Something isn't working P1 Medium priority - Should do labels Sep 23, 2026
@Andy-Jost

Copy link
Copy Markdown
Contributor

Thanks for the fix, and I confirmed it works. I think we can avoid adjusting the exception state by hand through CPython calls if we declare the Cython entry points except -1. The typedefs in _dlpack.pxd need the same annotation, or the assignment into the API table does not compile. That also covers KeyboardInterrupt, which except Exception lets through. I worked up an example in Andy-Jost@dbc22cf, and your tests pass unchanged on it. Take it or leave it, and I will approve either way.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cuda.core Everything related to the cuda.core module P1 Medium priority - Should do

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants