Representation of size-0 arrays in __cuda_array_interface__
See original GitHub issueI have a design question about __cuda_array_interface__
. How (if at all) should size-0 arrays be represented? In cupy, the data field currently uses 0
as the int_ptr
.
In [7]: import cupy
In [8]: arr = cupy.random.random(0)
In [9]: arr.__cuda_array_interface__
Out[9]:
{'shape': (0,),
'typestr': '<f8',
'descr': [('', '<f8')],
'data': (0, False),
'version': 0}
Compare with numba, which uses None
In [10]: import numba.cuda
In [11]: numba.cuda.device_array(0).__cuda_array_interface__
Out[11]:
{'shape': (0,),
'strides': (8,),
'data': (None, False),
'typestr': '<f8',
'version': 0}
Currently, cupy doesn’t round-trip a size-0 array
In [12]: class Dummy:
...: def __init__(self, descr):
...: self.__cuda_array_interface__ = descr
...:
In [13]: obj = Dummy(arr.__cuda_array_interface__)
In [14]: cupy.asarray(obj)
---------------------------------------------------------------------------
CUDARuntimeError Traceback (most recent call last)
<ipython-input-14-306044f096f0> in <module>
----> 1 cupy.asarray(obj)
~/miniconda3/lib/python3.6/site-packages/cupy/creation/from_data.py in asarray(a, dtype, order)
84 """
85 if not isinstance(a, ndarray) and hasattr(a, '__cuda_array_interface__'):
---> 86 return _convert_object_with_cuda_array_interface(a)
87 return core.array(a, dtype, False, order)
88
~/miniconda3/lib/python3.6/site-packages/cupy/creation/from_data.py in _convert_object_with_cuda_array_interface(a)
56 strides = None
57 nbytes = numpy.prod(shape) * dtype.itemsize
---> 58 mem = memory.UnownedMemory(desc['data'][0], nbytes, a)
59 memptr = memory.MemoryPointer(mem, 0)
60 return ndarray(shape, dtype=dtype, memptr=memptr, strides=strides)
cupy/cuda/memory.pyx in cupy.cuda.memory.UnownedMemory.__init__()
cupy/cuda/runtime.pyx in cupy.cuda.runtime.pointerGetAttributes()
cupy/cuda/runtime.pyx in cupy.cuda.runtime.check_status()
CUDARuntimeError: cudaErrorInvalidValue: invalid argument
Info:
In [6]: cupy.show_config()
CuPy Version : 6.0.0b3
CUDA Root : /usr/local/cuda-10.0
CUDA Build Version : 9020
CUDA Driver Version : 9020
CUDA Runtime Version : 9020
cuDNN Build Version : 7402
cuDNN Version : 7402
NCCL Build Version : 2307
NCCL Runtime Version : 2307
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
CUDA Array Interface (Version 3) - Numba documentation
The CUDA Array Interface (or CAI) is created for interoperability between different implementations of CUDA array-like ... For zero-size arrays, use 0 here....
Read more >3.15. CUDA Array Interface (Version 2) - Numba
The cuda array inteface is created for interoperability between different implementation of GPU array-like objects in ... For zero-size arrays, use 0 here....
Read more >GPU Pro Tip: Fast Dynamic Indexing of Private Arrays in CUDA
Thread block size is 64 in this example. In this way we ensure that the whole virtual private array of thread 0 falls...
Read more >Introduction to Numba: CUDA Programming
NumPy arrays that are supplied as arguments to the kernel are transferred between ... By default the CUDA driver selects the fastest GPU...
Read more >GPU Arrays - pycuda 2022.2 documentation - Index of /
Return a CUDA Array Interface dict describing this array's data. __len__()#. Returns the size of the leading dimension of self. Warning.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue is resolved by #2491. The new v2 protocol specifies that the pointer to 0-size arrays should be
0
.Just trying to follow up: as I raised in numba/numba#4175, Numba’s way of representing a 0-size array with
__cuda_array_interface__['data'][0] = None
is not complying with the standard they proposed, which requires anint
. This should be considered a bug on the Numba side, not CuPy.cc: @seibert