Hi Loic,

gouarin <[email protected]> writes:
> I would like to exchange 2 pointer addresses of gpuarray. Here, this is 
> an example of what I want to do
>
> """
> __global__ void computation(float *a, float *b)
> {
>       // compute something with a and put the result in b
> }
>
> __global__ void exchange(float **a, float **b)
> {
>      float *tmp;
>      tmp = *a;
>      *a = *b;
>      *b = tmp;
> }
> """
>
> Then I construct 2 gpuarrays and I call my first kernel easily.
>
> kernel1 = mod.get_function("computation")
> kernel2 = mod.get_function("exchange")
>
> a_gpu = gpuarray.to_gpu(a)
> b_gpu = gpuarray.to_gpu(b)
>
> kernel1(a_gpu.gpudata, b_gpu.gpudata, ...)
> kernel2( ????, ????, ...)
>
> But I don't understand how to call the second kernel "exchange" to 
> change the addresses of my gpuarrays.
> How can I get the address of a gpuarray and then how can I change it ?

Just do this:

a_gpu.gpudata, b_gpu.gpudata = b_gpu.gpudata, a_gpu.gpudata 

Note that gpudata is documented as read-only, so this is moderately
illegitimate in the strict sense (i.e. I don't promise this will keep
working forever), but I don't see any good reasons for it breaking
either.

More importantly--why do you need to swap pointers in arrays? Swapping
arrays should do the same thing, right?

Andreas

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

Reply via email to