Add CUDA Array Interface consumer support - #19233
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Thanks for the contribution – it's not clear to me that |
@jakevdp Yes, I agree. I'll update the PR accordingly. |
|
Similar to |
While array-api does not mention CUDA Array Interface nor NumPy Array Interface, these are kind of legacy buffer protocols and objects implementing the Buffer Protocol are allowed inputs to Here's a summary how the objects implementing CUDA Array Interface protocol are resolved elsewhere:
Considering the above, my first choice would be to resolve CAI objects in the |
|
That sounds good, we can do it in |
Currently, jax, numpy, and cupy implement this using the following principle: if Your concern corresponds to the case where
Considering the numpy FutureWarning, the answer might be affirmative, but notice that https://data-apis.org/array-api/latest/API_specification/generated/array_api.asarray.html#array_api.asarray does not support this nor does it support the current behavior where input list items are native array objects. |
|
Thanks - before we proceed with the review, can you sign the CLA? |
I'm not 100% sure about this one. DLPack should provide a superset of functionality of There's something to be said for this either way of course, given that not all libraries today have support that's fully equivalent between the two protocols. But there isn't too much traffic on gh-1100 in 3+ years. And we have too many different protocols in Python that are overlapping - with DLPack being the most viable one long-term, as the only one that has multi-device support. |
|
Circling back here: after chatting with @hawkinsp a bit, I think this is probably the right approach. We'll have to wait on openxla/xla#8237 before we can do anything here, but once that's in let's plan to proceed with this review. |
f0200cd to
db93119
Compare
|
OK, looks good! Last thing: could you please squash the changes into a single commit? Thanks! |
1296a90 to
9cba1c0
Compare
Done. |
|
I guess before merging this PR, openxla/xla#8237 needs to land soon. |
493b249 to
8cfd04b
Compare
Imported from GitHub PR openxla/xla#8237 As in the title. Required by jax-ml/jax#19233 Copybara import of the project: -- b2f5fdc973f50426ff3dbc9c73e860582c69c0d3 by Pearu Peterson <pearu.peterson@gmail.com>: Add CudaArrayInterfaceToBuffer Merging this change closes #8237 PiperOrigin-RevId: 603666956
Imported from GitHub PR #8237 As in the title. Required by jax-ml/jax#19233 Copybara import of the project: -- b2f5fdc by Pearu Peterson <pearu.peterson@gmail.com>: Add CudaArrayInterfaceToBuffer Merging this change closes #8237 COPYBARA_INTEGRATE_REVIEW=#8237 from pearu:pearu/cuda_array_interface-importer b2f5fdc PiperOrigin-RevId: 603666956
8cfd04b to
d68182d
Compare
|
@jakevdp I think we can move forward with this PR as openxla/xla#8237 has landed |
jakevdp
left a comment
There was a problem hiding this comment.
Looks good - we also should add a CHANGELOG entry.
d68182d to
c9fcfe9
Compare
c9fcfe9 to
0dcab27
Compare
|
Sorry for the delay in mergind: we're running into some test failures when testing this against PJRT runtimes; I'm trying to debug internally. |
| dtype=jtu.dtypes.supported(cuda_array_interface_dtypes), | ||
| ) | ||
| @jtu.run_on_devices("cuda") | ||
| def testCaiToJax(self, shape, dtype): |
There was a problem hiding this comment.
We need a skip condition here for PJRT runtimes, similar to others in this file. Something like this should work:
| def testCaiToJax(self, shape, dtype): | |
| def testCaiToJax(self, shape, dtype): | |
| if xb.using_pjrt_c_api(): | |
| self.skipTest("cuda_array_interface support is incomplete in the PJRT C API") # TODO(jakevdp) |
There was a problem hiding this comment.
Applied.
IIUC, PJRT is about running code on Intel GPUs but this test is decorated with jtu.run_on_devices("cuda") that would imply that the test ought to be skipped anyway when using a non-CUDA device. Is there an explanation why this test is still executed for PJRT runtimes?
Another question is if CAI support can ever be used within PJRT because CUDA is Nvidia device-specific?
0dcab27 to
82b2ae2
Compare
This PR adds CUDA Array Interface (versions 2 and 3) consumer support to JAX.
In addition, the PR enables constructing JAX arrays from objects that implement dlpack provider support.
Fixes #1100
Requires openxla/xla#8237