support pinned array for array creation from data
@@ -2281,8 +2281,14 @@ cdef ndarray _send_object_to_gpu(obj, dtype, order, Py_ssize_t ndmin):
cdef Py_ssize_t nbytes = a.nbytes
stream = stream_module.get_current_stream()
- cdef pinned_memory.PinnedMemoryPointer mem = (
- _alloc_async_transfer_buffer(nbytes))
+ cdef pinned_memory.PinnedMemoryPointer mem
+ if isinstance(a_cpu.base, pinned_memory.PinnedMemoryPointer):
+ # NumPy arrays could be backed by pinned memory, in this case we
+ # don't need to monitor the copy using the watch list
+ mem = a_cpu.base
+ a.data.copy_from_host_async(mem.ptr, nbytes)
+ else:
+ mem = _alloc_async_transfer_buffer(nbytes)
if mem is not None:
src_cpu = numpy.frombuffer(mem, a_dtype, a_cpu.size)
src_cpu[:] = a_cpu.ravel(order)
@@ -2290,7 +2296,6 @@ cdef ndarray _send_object_to_gpu(obj, dtype, order, Py_ssize_t ndmin):
pinned_memory._add_to_watch_list(stream.record(), mem)
else:
a.data.copy_from_host(a_cpu.ctypes.data, nbytes)
-
return a
