@@ -789,7 +789,7 @@ def from_gpudata(size_t data, offset, dtype, shape, GpuContext context=None,
789789 :type shape: iterable of ints
790790 :param context: context of the gpudata
791791 :type context: GpuContext
792- :param strides: strides for the results
792+ :param strides: strides for the results (C contiguous if not specified)
793793 :type strides: iterable of ints
794794 :param writable: is the data writable?
795795 :type writeable: bool
@@ -839,7 +839,7 @@ def from_gpudata(size_t data, offset, dtype, shape, GpuContext context=None,
839839 else :
840840 size = gpuarray_get_elsize(typecode)
841841 for i in range (nd- 1 , - 1 , - 1 ):
842- strides [i] = size
842+ cstrides [i] = size
843843 size *= cdims[i]
844844
845845 return pygpu_fromgpudata(< gpudata * > data, offset, typecode, nd, cdims,
@@ -1424,6 +1424,33 @@ def _concatenate(list al, unsigned int axis, int restype, object cls,
14241424 finally :
14251425 PyMem_Free(als)
14261426
1427+ cdef int (* cuda_get_ipc_handle)(gpudata * , GpuArrayIpcMemHandle * )
1428+ cdef gpudata * (* cuda_open_ipc_handle)(gpucontext * , GpuArrayIpcMemHandle * , size_t)
1429+
1430+ cuda_get_ipc_handle = < int (* )(gpudata * , GpuArrayIpcMemHandle * )> gpuarray_get_extension(" cuda_get_ipc_handle" )
1431+ cuda_open_ipc_handle = < gpudata * (* )(gpucontext * , GpuArrayIpcMemHandle * , size_t)> gpuarray_get_extension(" cuda_open_ipc_handle" )
1432+
1433+ def open_ipc_handle (GpuContext c , bytes hpy , size_t l ):
1434+ """
1435+ Open an IPC handle to get a new GpuArray from it.
1436+
1437+ :param c: context
1438+ :param hpy: binary handle data received
1439+ :param l: size of the referred memory block
1440+
1441+ """
1442+ cdef char * b
1443+ cdef GpuArrayIpcMemHandle h
1444+ cdef gpudata * d
1445+
1446+ b = hpy
1447+ memcpy(& h, b, sizeof(h))
1448+
1449+ d = cuda_open_ipc_handle(c.ctx, & h, l)
1450+ if d is NULL :
1451+ raise GpuArrayException, " could not open handle"
1452+ return < size_t> d
1453+
14271454cdef class GpuArray:
14281455 """
14291456 Device array
@@ -1561,6 +1588,19 @@ cdef class GpuArray:
15611588 raise ValueError , " GpuArray and Numpy array do not have the same size in bytes"
15621589 array_read(np.PyArray_DATA(dst), sz, self )
15631590
1591+ def get_ipc_handle (self ):
1592+ cdef GpuArrayIpcMemHandle h
1593+ cdef int err
1594+ if cuda_get_ipc_handle is NULL :
1595+ raise SystemError , " Could not get necessary extension"
1596+ if self .context.kind != b' cuda' :
1597+ raise ValueError , " Only works for cuda contexts"
1598+ err = cuda_get_ipc_handle(self .ga.data, & h)
1599+ if err != GA_NO_ERROR:
1600+ raise get_exc(err), GpuArray_error(& self .ga, err)
1601+ res = < bytes> (< char * > & h)[:sizeof(h)]
1602+ return res
1603+
15641604 def __array__ (self ):
15651605 """
15661606 __array__()
0 commit comments