Hi Alex,

Yes, that was my mistake — I was checking the type of a wrong array.
The slicing indeed returns a view of GPUArray. It introduces a
somewhat unnecessary (for my purposes) level of abstraction though,
since I just need a pointer to an  untyped memory. But in any case
your suggestion made me understand why passing integers to
Function.__call__() did not work. It seems that one has to pass some
object with 'gpudata' attribute, which can, in turn, be anything
castable to integer.

On Sun, Feb 10, 2013 at 11:56 AM, Alex Nitz <[email protected]> wrote:
> Bogdan,
>
> Strangely, I don't observe the same behavior. Slicing should produce another
> GPUArray that is not a copy of the original but just a view; the same as is
> done in numpy.
>
> Can you try the following?
>
> import pycuda.autoinit
> import numpy
> import pycuda.gpuarray
>
> N=8
>
> a = pycuda.gpuarray.to_gpu(numpy.zeros(N))
> sub_region1 = a[0:N/4]
> sub_region1 += 5
> sub_region2 = a[3*N/4:N]
> sub_region2 -= 4
>
> print type(a), type(sub_region1), type(sub_region2)
> print sub_region1
> print sub_region2
> print a
>
>
> The output that I get is:
>
> <class 'pycuda.gpuarray.GPUArray'> <class 'pycuda.gpuarray.GPUArray'> <class
> 'pycuda.gpuarray.GPUArray'>
> [ 5.  5.]
> [-4. -4.]
> [ 5.  5.  0.  0.  0.  0. -4. -4.]
>
>
>
> On Sat, Feb 9, 2013 at 7:01 PM, Bogdan Opanchuk <[email protected]> wrote:
>>
>> Moreover, I do not need the actual data to be copied. I just need a
>> view to the middle of an existing array.
>>
>> On Sun, Feb 10, 2013 at 10:53 AM, Bogdan Opanchuk <[email protected]>
>> wrote:
>> > Hi Alex,
>> >
>> >> Maybe I am misunderstanding, I am not so familiar with the buffer
>> >> terminology (having not dealt much with opencl),
>> >
>> > It is not really OpenCL-specific; basically it's just a wrapper on top
>> > of pointer arithmetic.
>> >
>> >> Would the following be sufficient?
>> >>
>> >> a = pycuda.gpuarray.to_gpu(numpy.zeros(N))
>> >>
>> >> sub_region1 = a[0:N/4]
>> >> sub_region2 = a[3N/4:N]
>> >
>> > Unfortunately, this produces numpy.ndarray, not another GPUArray.
>
>

_______________________________________________
PyCUDA mailing list
[email protected]
http://lists.tiker.net/listinfo/pycuda

Reply via email to