<p dir="ltr"><br>
On Aug 29, 2014 8:26 PM, "Zhigang Gong" <<a href="mailto:zhigang.gong@gmail.com">zhigang.gong@gmail.com</a>> wrote:<br>
><br>
> I guess you may only change the kernel. Please also replace all the double with float in the cl-demo.c.Then rebuild and run it again. I just tried, and it works well.<br>
><br>
><br>
> _______________________________________________<br>
> Beignet mailing list<br>
> <a href="mailto:Beignet@lists.freedesktop.org">Beignet@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/beignet">http://lists.freedesktop.org/mailman/listinfo/beignet</a><br>
><br>
How about this program? It has no double. C always prints zero. It's pyopencl. </p>
<p dir="ltr">import pyopencl as cl<br>
import numpy<br>
import sys<br>
import time<br>
<br>
class CL(object):<br>
def __init__(self, size=10):<br>
self.size = size<br>
self.ctx = cl.create_some_context()<br>
self.queue = cl.CommandQueue(self.ctx)<br>
<br>
def load_program(self):<br>
fstr="""<br>
__kernel void part1(__global float* a, __global float* b, __global float* c)<br>
{<br>
unsigned int i = get_global_id(0);<br>
<br>
c[i] = a[i] + b[i];<br>
}<br>
"""<br>
self.program = cl.Program(self.ctx, fstr).build()<br>
<br>
def popCorn(self):<br>
mf = cl.mem_flags<br>
<br>
self.a = numpy.array(range(self.size), dtype=numpy.float32)<br>
self.b = numpy.array(range(self.size), dtype=numpy.float32)<br>
<br>
self.a_buf = cl.Buffer(self.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR,<br>
hostbuf=self.a)<br>
self.b_buf = cl.Buffer(self.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR,<br>
hostbuf=self.b)<br>
self.dest_buf = cl.Buffer(self.ctx, mf.WRITE_ONLY, self.b.nbytes)<br>
<br>
def execute(self):<br>
self.program.part1(self.queue, self.a.shape, None, self.a_buf, self.b_buf, self.dest_buf)<br>
c = numpy.empty_like(self.a)<br>
cl.enqueue_read_buffer(self.queue, self.dest_buf, c).wait()<br>
print ( "a", self.a)<br>
print ( "b", self.b)<br>
print ( "c", c )<br>
<br>
def add(s=10) :<br>
starttime = time.clock()<br>
matrixmul = CL(s)<br>
matrixmul.load_program()<br>
matrixmul.popCorn()<br>
matrixmul.execute()<br>
endtime = time.clock()<br>
print s, endtime - starttime <br>
<br>
if __name__ == '__main__':<br>
#add(1)<br>
#add(2)<br>
#add(3)<br>
#add(4)<br>
#add(5)<br>
add(50)<br>
add(500)<br>
add(5000)<br>
add(50000)<br>
add(500000)<br>
<br>
#add(10000000)<br>
</p>