Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ENH: Add basic dlpack testing#433

Open
ev-br wants to merge 6 commits intodata-apis:masterdata-apis/array-api-tests:masterfrom
ev-br:test_dlpackev-br/array-api-tests:test_dlpackCopy head branch name to clipboard
Open

ENH: Add basic dlpack testing#433
ev-br wants to merge 6 commits intodata-apis:masterdata-apis/array-api-tests:masterfrom
ev-br:test_dlpackev-br/array-api-tests:test_dlpackCopy head branch name to clipboard

Conversation

@ev-br
Copy link
Member

@ev-br ev-br commented Mar 23, 2026

Add a basic set of dlpack tests. The tests here are "boring":

  • no cross-library tests, only test from_dlpack for a single array library
  • only test copy=False on the same device
  • no tests for __dlpack__ yet several XXX comments to mark where I've no idea.

@ev-br
Copy link
Member Author

ev-br commented Mar 23, 2026

Issues with these "trivial" tests:

  1. torch has a weird device(type="meta") which is incompatible with DLpack. If anything, the following should raise a BufferError IIUC, not a ValueError
In [8]: device = torch.device(type="meta")

In [9]: x = torch.empty(3, device=device)

In [10]: torch.from_dlpack(x)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[10], line 1
----> 1 torch.from_dlpack(x)
...
ValueError: Unknown device type meta for Dlpack
  1. jax fails with cupy=True on CUDA where it works on CPU:
In [8]: jnp.from_dlpack(jnp.ones(3), copy=True)
---------------------------------------------------------------------------
JaxRuntimeError                           Traceback (most recent call last)
Cell In[8], line 1
----> 1 jnp.from_dlpack(jnp.ones(3), copy=True)

...

JaxRuntimeError: UNIMPLEMENTED: PJRT C API does not support HostBufferSemantics other than HostBufferSemantics::kImmutableOnlyDuringCall, HostBufferSemantics::kImmutableZeroCopy and HostBufferSemantics::kImmutableUntilTransferCompletes

  1. cupy==14.0.1 does implement copy or device arguments:
>>> x =  cupy.array([], dtype=float)
>>> cupy.from_dlpack(x, copy=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "cupy/_core/dlpack.pyx", line 568, in cupy._core.dlpack.from_dlpack
  File "cupy/_core/core.pyx", line 355, in cupy._core.core._ndarray_base.__dlpack__
BufferError: copy=True only supported for copy to CPU.

>>> cupy.from_dlpack(x, device=x.device)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "cupy/_core/dlpack.pyx", line 554, in cupy._core.dlpack.from_dlpack
NotImplementedError: from_dlpack() does not support device yet.

>>> cupy.__version__
'14.0.1'

@ev-br
Copy link
Member Author

ev-br commented Mar 23, 2026

Larger issues:

  1. How to tell if a device is dlpack-compatible. The only way I see now is to try-except call from_dlpack and catch a BufferError.

  2. How to tell if a copy=False device transfer is meant to work, given source_device and target_device. A first reaction is to create a dummy array on each device and check their __dlpack_device__ values. If they match, it should work, ok. But then what about CUDA vs CUDA_MANAGED? CPU vs CPU_PINNED? Other values? It feels like there needs to be something in the inspection capabilities to tell it.

@ev-br ev-br mentioned this pull request Mar 23, 2026
42 tasks
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.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.