Discussion:
[PyCUDA] question about memcpy_atod
Paul Mullowney
2014-12-04 22:06:48 UTC
Permalink
Hi,

I've been using PyCuda quite a bit recently. Very nice!
I'm trying to use memcpy_atod to message a chunk of CPU data to the GPU
where the size/shapes of the input and output arrays don't match (though
the size of the data transfer certain does).

In the C/C++ world, I would think of this as a cudaMemcpy with some pointer
arithmetic on the host buffer. Here's an example of what I'm trying to do:

import numpy as np
import pycuda.autoinit
import pycuda.driver as cuda
import pycuda.gpuarray as gpuarray

x = np.ones((40),dtype="float32")
xgpu = gpuarray.zeros((10),dtype="float32")
print xgpu.get()

cuda.memcpy_atod(xgpu.gpudata,x[20:30],0,10)
print xgpu.get()

I see the error:

Boost.Python.ArgumentError: Python argument types in
pycuda._driver.memcpy_atod(DeviceAllocation, numpy.ndarray, int, int)
did not match C++ signature:
memcpy_atod(unsigned long long dest, pycuda::array ary, unsigned int
index, unsigned int len)

Can memcpy_atod be used for my purposes? If so, what do I need to change in
order to make this work?

Thanks in advance!
-Paul
Andreas Kloeckner
2014-12-12 05:44:11 UTC
Permalink
Post by Paul Mullowney
I've been using PyCuda quite a bit recently. Very nice!
I'm trying to use memcpy_atod to message a chunk of CPU data to the GPU
where the size/shapes of the input and output arrays don't match (though
the size of the data transfer certain does).
memcpy_atod applies to CUDA arrays, not numpy arrays.

The equivalent of pointer arithmetic can be achieved by slicing the
numpy array.

Hope that helps,
Andreas

Loading...