Trying to convert between VPI, cupy, jetson_utils cudaImage, which all support cuda_array_interface, except it is easy to go into VPI but not out because VPI’s is slightly different. VPI’s ‘shape’ and ‘strides’ are a list and the others are as a tuple.
On VPI 2.2.7 with AGX Orin 32gb Jetpack 5.1.1-b56
import vpi
import cupy
from jetson_utils import cudaImage
vpi_image = vpi.Image((320,256), format=vpi.Format.RGB8)
vpi_image.cuda().__cuda_array_interface__
# Note 'shape' and 'strides' are lists
#{'shape': [256, 320, 3], 'strides': [1024, 3, 1], 'typestr': 'B', 'data': (8796327936, False), 'version': 2}
cuArr = cupy.zeros((256,320,3), dtype=cupy.uint8)
cuArr.__cuda_array_interface__
#{'shape': (256, 320, 3), 'typestr': '|u1', 'descr': [('', '|u1')], 'stream': 1, 'version': 3, 'strides': None, 'data': (8796082176, False)}
cuImg = cudaImage(320,256, "rgb8")
cuImg.__cuda_array_interface__
# {'shape': (256, 320, 3), 'typestr': '<u1', 'data': (8774062080, False), 'version': 3}
# cupy to VPI
vpi_image2 = vpi.asimage(cuArr) #OK
# cudaImage to VPI
vpi_image3 = vpi.asimage(cuImg) #OK
# cudaImage to cupy
cuArr2 = cupy.asarray(cuImg) # OK
# vpi to cupy
cuImg = cupy.asarray(vpi_image.cuda()) #ERROR
#Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# File "/usr/local/lib/python3.8/dist-packages/cupy/_creation/from_data.py", line 75, in asarray
# return _core.array(a, dtype, False, order)
# File "cupy/_core/core.pyx", line 2376, in cupy._core.core.array
# File "cupy/_core/core.pyx", line 2388, in cupy._core.core.array
# File "cupy/_core/core.pyx", line 2431, in cupy._core.core._array_from_cuda_array_interface
# File "cupy/_core/core.pyx", line 2741, in cupy._core.core._convert_object_with_cuda_array_interface
# TypeError: Expected tuple, got list
Is there way to resolve this discrepancy so it is easier to go out from VPI?