Hi Alex, all,
Andreas Kloeckner <lists(a)informa.tiker.net> writes:
Alex Nitz <alex.nitz(a)ligo.org> writes:
> I am mostly a pycuda user, but am investigating trying to use some of my
> codes with pyopencl. My codes make heavy use of the numpy-like array. I
> noticed that there doesn't seem to yet be a "__getitem__" function yet
> defined, although the buffer objects themselves have one.
> My needs are basically met by the version that is in pycuda, so I have
> created a short patch to add the same behavior to pyopencl. It is fairly
> limited in that it only supports 1-dimensional, non-strided slices. Is a
> more comprehensive functionality already in the works? If not, would it be
> possible to get this patch applied?
First of all, thanks for your contribution! I'm a bit hesitant to apply
this patch, because sub-buffers (which your patch implicitly uses, see
clCreateSubBuffer in the CL spec) are allowed to have alignment
requirements that make this routine fail. The better way to implement
this is to use the original buffer and store an offset to the intended
beginning of the data. I'll introduce this after the 2013.1 release,
which is due soon. (as soon as I sort out the current Mac trouble)
pyopencl git has just learned to support __getitem__ and arrays with
offsets. Specifically, arrays now have .data, which returns a buffer and
asserts that the array has no offset, and .base_data, which you'll want
to use in conjunction with .offset to find the base in relation to the
buffer returned by .base_data.
For now, only element-wise operations are aware of this. More support
will come later, patches always welcome.
It'd be great if you could give this a shot and provide feedback.