cupy and ctypes

122 views
Skip to first unread message

David Grote

unread,
Jan 28, 2021, 8:15:43 PM1/28/21
to CuPy User Group

Hi - I'm interested in finding a Python package that will allow working with an existing C++ code base, giving access to device resident memory. On a CPU, I use ctypes.pythonapi.PyMemoryView_FromMemory to handle the pointers to memory (passed up from C++) and pass them to numpy.frombuffer to create numpy arrays allowing access to the data. Is there something comparable in CuPy? I notice that implementing frombuffer is listed as a TODO.
   Thanks!
        Dave

Leo Fang

unread,
Feb 25, 2021, 1:49:29 AM2/25/21
to CuPy User Group
Hello,

CuPy currently does not support the Python buffer protocol, and I am not aware of any plan for it. For zero-copy exchange with other GPU applications, we recommend using the CUDA Array Interface or DLPack, see https://docs.cupy.dev/en/latest/reference/interoperability.html

A while ago I have tested implementing the buffer protocol for cupy.ndarray, and the problem I encountered was it segfaults at consume time. I concluded that the protocol is incompatible with device arrays, but I could be mistaken...

David Grote 在 2021年1月28日 星期四下午8:15:43 [UTC-5] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages