cupy / cupy/cupy

from_dlpack on an object not implementing DLPack protocol throws irrelevant error message

Open
#8,070 6 comments 0 reactions 0 assignees View on GitHub
cat:enhancement contribution welcome prio:low
Dominant language
Python
Stars
12.3k
Forks
1.1k
Avg merge
1d 20h
Merged PRs (30d)
45

Description

### Description

As in the title.

### To Reproduce

```py
>>> import cupy
>>> cupy.from_dlpack(object())
Traceback (most recent call last):
File "", line 1, in
File "cupy/_core/dlpack.pyx", line 344, in cupy._core.dlpack.from_dlpack
File "cupy/_core/dlpack.pyx", line 378, in cupy._core.dlpack.from_dlpack
File "cupy/_core/dlpack.pyx", line 268, in cupy._core.dlpack._dlpack_to_cupy_array
File "cupy/_core/dlpack.pyx", line 174, in cupy._core.dlpack.DLPackMemory.__init__
ValueError: A DLPack tensor object cannot be consumed multiple times
```

An expected behavior would be an exception with a message "object does not appear to implement DLPack protocol" or similar.

### Installation

Conda-Forge (`conda install ...`)

### Environment

```
>>> import cupy; cupy.show_config()
OS : Linux-5.4.0-153-generic-x86_64-with-glibc2.31
Python Version : 3.11.7
CuPy Version : 12.3.0
CuPy Platform : NVIDIA CUDA
NumPy Version : 1.26.2
SciPy Version : None
Cython Build Version : 0.29.36
Cython Runtime Version : None
CUDA Root : /tmp/arrayviews-tests/envs/arrayviews-tests_cupy-numba-cuda_19d0dab9
nvcc PATH : None
CUDA Build Version : 11080
CUDA Driver Version : 12010
CUDA Runtime Version : 11080
cuBLAS Version : (available)
cuFFT Version : 10900
cuRAND Version : 10300
cuSOLVER Version : (11, 4, 1)
cuSPARSE Version : (available)
NVRTC Version : (11, 8)
Thrust Version : 101501
CUB Build Version : 101501
Jitify Build Version : 6fc36c7
cuDNN Build Version : 8800
cuDNN Version : 8907
NCCL Build Version : None
NCCL Runtime Version : None
cuTENSOR Version : None
cuSPARSELt Build Version : None
Device 0 Name : NVIDIA GeForce RTX 2060 SUPER
Device 0 Compute Capability : 75
Device 0 PCI Bus ID : 0000:17:00.0
Device 1 Name : NVIDIA GeForce RTX 2060 SUPER
Device 1 Compute Capability : 75
Device 1 PCI Bus ID : 0000:65:00.0
```

### Additional Information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with cupy/_core/dlpack.pyx, especially the from_dlpack entry point and the DLPackMemory path shown in the traceback. Reproduce cupy.from_dlpack(object()) and trace why it reaches the multiple-consumption error; done means unsupported objects raise an error stating that they do not appear to implement the DLPack protocol.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.