Hi Andreas,

This is great ! I am a novice user of Python and I did not use numpy before, this makes things really simple.

Thanks,

Andrea

On 4/25/12 12:56 PM, Andreas Kloeckner wrote:
On Wed, 25 Apr 2012 12:17:33 -0400, Andrea Borsic<[email protected]>  
wrote:
Hi Andreas,

I'd like to ask you a question (but I don't plan to bother you in the
future with PyOpnCL questions), I hope you don't mind.

I am at a stage where I am trying to figure out whether I can use
PyOpenCL for my work, and wanted to ask you one information regarding
copying only parts of a buffer from host to device.

In most of the problems in medical imaging I am dealing with I need to
copy data from a 3D array to the GPU in a slice by slice fashion. Whole
3D volumes do not fit on the GPU, but fortunately many algorithms can
work in "sliding slice" way, where only a certain thickness of the
volume is copied to the GPU, and as the algorithm proceeds a new slice
is added and one is discarded from the back of the stack. The bottom
line is that I need to copy only one 2D slice at a time from host to
device, from a 3D array.

I currently use, in C, clEnqueueWriteBuffer pointing to the base of the
3D buffer, specifying the current slice offset and numbers of bytes to copy.

I am looking to do the same with PyOpenCL, I did various searches on the
internet, but I am not quite sure that I understand how to specify an
offset and num_bytes in a memory transfer operation.

  From the documentation of pyopencl.enqueue_copy and it seems that for
host<->  Buffer copies the supported parameter is "device_offset", but I
would need actually to specify a host_offset, to address the single
slice, and a byte_count, to read only 1 slice. These parameters seem to
be available only for Buffer<->  Buffer transfers (which I assume is a
GPU<->  GPU transfer ?)

What's the correct way of copying only a subset of a host memory buffer
to device and vice-versa (writing back from device to host to a
particular range within a buffer ?)
(cc'ing pyopencl list)

I assume your data is sitting in a numpy array on the host. Then all you
need to do is enqueue_copy(dev_buf, host[1000:2000]), i.e. pass the
desired slice of the numpy array to enqueue_copy, instead of the whole
array. Obviously, this will only work if the numpy array resulting from
the slice access is contiguous in host memory.

Hope this helps!

Andreas



_______________________________________________
PyOpenCL mailing list
[email protected]
http://lists.tiker.net/listinfo/pyopencl

Reply via email to