Skip to content

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

Merged
rluo8 merged 3 commits into
NVIDIA:mainfrom
rluo8:fix/dlpack-exchange-error-propagation
Sep 30, 2026
Merged

rluo8 merged 3 commits 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

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor
Doc Preview CI
Preview removed because the pull request was closed or merged.

@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.

rluo8 and others added 2 commits September 29, 2026 09:22
Declare the exchange API callbacks and their typedefs `except -1`, the
contract dlpack.h documents, and raise instead of setting the error
indicator by hand. KeyboardInterrupt and other BaseExceptions now also
reach the consumer as -1 with the exception set.

Co-authored-by: Andy Jost <ajost@nvidia.com>
Signed-off-by: Rui Luo <ruluo@nvidia.com>
@rluo8

rluo8 commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Andy-Jost for the review, that's cleaner. I've taken your change in 3e7c139 (with you as co-author), and the existing tests pass unchanged.

@Andy-Jost Andy-Jost left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks @rluo8!

@rluo8
rluo8 merged commit 8845a79 into NVIDIA:main Sep 30, 2026
220 of 222 checks passed
github-actions Bot pushed a commit that referenced this pull request Oct 1, 2026
Removed preview folders for the following PRs:
- PR #2939
- PR #2953
- PR #2962
- PR #2966
- PR #2968
- PR #2969
- PR #2972
- PR #2974
- PR #2976
- PR #2977
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