You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
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'
numpy cannot consume a capsule created by __dlpack__, while torch happily does. Which one is correct?
>>> import numpy as np
>>> import torch
>>> x = np.ones(3)
>>> capsule = x.__dlpack__()
>>> torch.from_dlpack(capsule) # works fine
tensor([1., 1., 1.], dtype=torch.float64)
>>> np.from_dlpack(capsule) # ouch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'PyCapsule' object has no attribute '__dlpack__'
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.
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.
How to tell a supported max_version in __dlpack__. Should max_version=(-111, 42) raise? What about reasonable version values: max_version=(3, 0) if a library only supports (2,0).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a basic set of
dlpacktests. The tests here are "boring":from_dlpackfor a single array librarycopy=Falseon the same deviceno tests forseveral__dlpack__yetXXXcomments to mark where I've no idea.