Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can pycuda.driver.memcpy_htod_async add a "size" parameter? #300

Open
so2bin opened this issue Jul 10, 2021 · 2 comments
Open

Can pycuda.driver.memcpy_htod_async add a "size" parameter? #300

so2bin opened this issue Jul 10, 2021 · 2 comments

Comments

@so2bin
Copy link

so2bin commented Jul 10, 2021

Hello, now "memcpy_htod_async" function only support paramter: pycuda.driver.memcpy_htod_async(dest, src, stream=None). Can you extends this api with additional paramter: size? Here size means how many bytes will be copyed. Or is there any other
already exist function has the similay effect.

Thank you.

@so2bin
Copy link
Author

so2bin commented Jul 10, 2021

I found the definition of memcpy_htod_async as here, you passed a fixed size of buf: buf_wrapper.m_buf.len:

void py_memcpy_dtoh_async(py::object dest, CUdeviceptr src, py::object stream_py)

  void py_memcpy_dtoh_async(py::object dest, CUdeviceptr src, py::object stream_py)
  {
    py_buffer_wrapper buf_wrapper;
    buf_wrapper.get(dest.ptr(), PyBUF_ANY_CONTIGUOUS | PyBUF_WRITABLE);

    PYCUDA_PARSE_STREAM_PY;

    CUDAPP_CALL_GUARDED_THREADED(cuMemcpyDtoHAsync,
        (buf_wrapper.m_buf.buf, src, buf_wrapper.m_buf.len, s_handle));
  }

Cuda API has exported the parameter: size_t ByteCount, this paramter is very important in some scene as we may only want to transfer partial bytes from buffer:
https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__MEM.html#group__CUDA__MEM_1g56f30236c7c5247f8e061b59d3268362

Thank you.

@inducer
Copy link
Owner

inducer commented Jul 11, 2021

If you're copying to a numpy array, you can determine the transfer size simply by creating a view of the array, like a[0:100] to only copy the first 100 entries (assuming a 1D array).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants