works fine, thanks.

====================

import pyopencl as cl
import numpy
import numpy.linalg as la

sizeX=4
sizeY=2
sizeZ=5
a = numpy.random.rand(sizeX,sizeY,sizeZ).astype(numpy.float32)

ctx = cl.Context()
queue = cl.CommandQueue(ctx)

mf = cl.mem_flags
a_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a)
dest_buf = cl.Buffer(ctx, mf.WRITE_ONLY, a.nbytes)

prg = cl.Program(ctx, """
    __kernel void sum(__global const float *a, __global float *b)
    {
      int x = get_global_id(0);
      int y = get_global_id(1);
      int z = get_global_id(2);

      int idx = z * %d * %d + y * %d + x;

      b[idx] = a[idx] * x + 3 * y + 5 * z;
    }
    """ % (sizeY, sizeX, sizeX) ).build()

prg.sum(queue, a.shape, a_buf, dest_buf)
cl.enqueue_read_buffer(queue, dest_buf, a).wait()
print a

2009/10/17, Andreas Klöckner <[email protected]>:
> On Samstag 17 Oktober 2009, Darcoux Christine wrote:
>> 1) How do upload the "a" array ?
>
> Same as the 1D arrays in the examples.
>
>> 2) How I get the x y and z coordinates for the current index in the
>> volume?
>
> Try get_global_id(0), get_global_id(1), get_global_id(2). In general, the CL
> spec is your friend here.
>
> Andreas
>

_______________________________________________
PyOpenCL mailing list
[email protected]
http://tiker.net/mailman/listinfo/pyopencl_tiker.net

Reply via email to