@@ -1424,6 +1424,28 @@ 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+ cdef char * b
1438+ cdef GpuArrayIpcMemHandle h
1439+ cdef gpudata * d
1440+
1441+ b = hpy
1442+ memcpy(& h, b, sizeof(h))
1443+
1444+ d = cuda_open_ipc_handle(c.ctx, & h, l)
1445+ if d is NULL :
1446+ raise GpuArrayException, " could not open handle"
1447+ return < size_t> d
1448+
14271449cdef class GpuArray:
14281450 """
14291451 Device array
@@ -1561,6 +1583,19 @@ cdef class GpuArray:
15611583 raise ValueError , " GpuArray and Numpy array do not have the same size in bytes"
15621584 array_read(np.PyArray_DATA(dst), sz, self )
15631585
1586+ def get_ipc_handle (self ):
1587+ cdef GpuArrayIpcMemHandle h
1588+ cdef int err
1589+ if cuda_get_ipc_handle is NULL :
1590+ raise SystemError , " Could not get necessary extension"
1591+ if self .context.kind == ' cuda' :
1592+ raise ValueError , " Only works for cuda contexts"
1593+ err = cuda_get_ipc_handle(self .ga.data, & h)
1594+ if err != GA_NO_ERROR:
1595+ raise get_exc(err), GpuArray_error(& self .ga, err)
1596+ res = < bytes> (< char * > & h)[:sizeof(h)]
1597+ return res
1598+
15641599 def __array__ (self ):
15651600 """
15661601 __array__()
0 commit comments