Hi,

Following is the code that has a strange behavior. Works on GPU
(device 0 on my macbook pro), and segfaults on CPU (device 1). I
wanted to try geometric functions like "distance", only implemented on
the CPU.
Any remark regarding this dummy code will be kindly appreciated...

import numpy
import pyopencl as cl

platform = cl.get_platforms()[0]
device = platform.get_devices()[1]
print device
ctx = cl.Context([device])
queue = cl.CommandQueue(ctx)


value_array = numpy.zeros(1000, dtype=numpy.float32)
#points_array = numpy.zeros((1000, 3), dtype=numpy.float32)
points_array = numpy.random.rand(3000).astype(numpy.float32)
print points_array[0]

mf = cl.mem_flags
points_buffer = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR,
hostbuf = points_array)
value_buffer = cl.Buffer(ctx, mf.READ_WRITE, value_array.nbytes)

prg = cl.Program(ctx,
    """
    __kernel void Test(__global float3 const *points, __global float *value)
    {
        int gid = get_global_id(0);

        value[gid] = points[gid].x ;
    }
    """).build()

print "points_array shape : ",points_array.shape
prg.Test(queue, value_array.shape, None, points_buffer, value_buffer)
cl.enqueue_read_buffer(queue, value_buffer, value_array).wait()
print "%f"%value_array[0]

Regards,

David.

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

Reply via email to