Skip to content

Conversation

@tqchen
Copy link
Member

@tqchen tqchen commented Dec 5, 2025

This PR updates the exchange API to be capsule following the new convention. Note that the exchange API python recommendation is not yet updated on the array-api side and so far there hasn't yet been downstream implementation, so this change should be safe in generally.

@tqchen
Copy link
Member Author

tqchen commented Dec 5, 2025

cc @Kathryn-cat

@tqchen
Copy link
Member Author

tqchen commented Dec 5, 2025

RFC thread #179

This PR updates the exchange API to be capsule following the new convention.
Note that the exchange API python recommendation is not yet updated on the array-api
side and so far there hasn't yet been downstream implementation, so this change
should be safe in generally.
@tqchen
Copy link
Member Author

tqchen commented Dec 12, 2025

cc @leofang @rgommers also updated python_spec.rst here

@tqchen
Copy link
Member Author

tqchen commented Dec 12, 2025

Array api spec PR data-apis/array-api#984

@leofang leofang self-requested a review December 23, 2025 06:28
@leofang
Copy link
Collaborator

leofang commented Dec 23, 2025

Sorry for delay, will try to finish my review in a day or two!

Copy link
Collaborator

@leofang leofang left a comment

Choose a reason for hiding this comment

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

Thanks, @tqchen! LGTM overall, left some questions that we should address before merging.

direct interaction between the array framework PyObject* and DLPack,
as a result it is harder to implement the C Exchange API through ctypes (because
ctypes releases GIL by default and sometimes in non-free-threading environment,
GIL is needed to interact with the Python C API).
Copy link
Collaborator

Choose a reason for hiding this comment

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

@dalcinl or @seberg to comment. I am aware that this is to capture the meeting discussion on why ctypes does not work for our purposes, but I am a bit confused by the mention of GIL.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm, this flew past me. Honestly, I am not sure what this note is getting at. The mention of the GIL seems wrong either way. I think I said it in the meeting too, but don't quite remember.

"Releasing the GIL" actually should be thought of "releases the thread-state". And that affects both free-threaded and non-free threaded python just the same.
The difference is that with the GIL a Python thread must own the thread state (and thus the GIL).

I would be fine with just dropping the note, because I am not sure which functions this affects how right now.
The interesting point to make is that some functions are expected to be called without the thread-state (GIL) held, so they need to grab it (like the note that we have for the deallocator).

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks a lot for the note, updated to replace thread state to GIL

@tqchen
Copy link
Member Author

tqchen commented Jan 10, 2026

@leofang please take another look, all comments are addressed

Copy link
Collaborator

@leofang leofang left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @tqchen!

Maybe let's merge this in a few days? Not sure if @seberg or others wants to take another look.

@tqchen
Copy link
Member Author

tqchen commented Jan 17, 2026

sounds good, we can wait for a few days

@seberg
Copy link
Collaborator

seberg commented Jan 18, 2026

Yeah, I don't mind (or very slightly prefer) going towards a capsule.

@tqchen
Copy link
Member Author

tqchen commented Jan 21, 2026

Seems we are close to merge, planning to merge this in incoming week. but happy to also see comments

@leofang leofang merged commit 84d107b into dmlc:main Jan 24, 2026
3 checks passed
@leofang
Copy link
Collaborator

leofang commented Jan 24, 2026

Thanks, Tianqi & all! Let's get this in!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants