0

I would like to copy a numpy array on an existing, pre-allocated, gpu array.

I've seen that cupy offers the functions copy and copyto, however the former does not allow to specify the destination array, while the latter works only between device arrays.

Is there any way to achieve copying a numpy array to the device making usage of pre-allocated memory?

1
  • 1
    Not sure if there is any way of doing this in the high-level API, but it is certainly possible using the low-level API. See e.g. cupy.cuda.runtime.memcpy() Commented May 30, 2024 at 12:40

1 Answer 1

3

What paleonix commented indeed works fine, i.e. something like this:

cupy.cuda.runtime.memcpy(cupy_array.data.ptr, numpy_array.ctypes.data, numpy_array.nbytes, cupy.cuda.runtime.memcpyHostToDevice)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.