daily pastebin goal
49%
SHARE
TWEET

Untitled

a guest Feb 14th, 2013 40 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. import pyopencl as cl
  3. import numpy
  4.  
  5. KERNEL = """
  6. __kernel void test(__global const int *a,
  7.                    __global const int *b,
  8.                    __global int *c
  9.                   )
  10. {
  11.        int agid = get_global_id(0);
  12.        for (int g=0; g < %(bsize)d; g++)
  13.            c[agid] = popcount(a[agid] ^ b[g]);
  14. }
  15. """
  16. for ASIZE in [29120, 29122]:
  17.     BSIZE = 29097
  18.     a = numpy.random.randint(-1595081346, 1595081346, ASIZE).astype(numpy.int32)
  19.     b = numpy.random.randint(-1595081346, 1595081346, BSIZE).astype(numpy.int32)
  20.     c_result = numpy.zeros(ASIZE, numpy.int32)
  21.     for platform in cl.get_platforms():
  22.         for device in platform.get_devices():
  23.             ctx = cl.Context([device])
  24.             queue = cl.CommandQueue(ctx,
  25.                                     properties=cl.command_queue_properties.PROFILING_ENABLE)
  26.  
  27.             mf = cl.mem_flags
  28.             a_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a)
  29.             b_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=b)
  30.             dest_buf = cl.Buffer(ctx, mf.WRITE_ONLY | mf.COPY_HOST_PTR, hostbuf=c_result)
  31.             prg = cl.Program(ctx, KERNEL % {'bsize' : BSIZE}).build()
  32.             exec_evt = prg.test(queue, a.shape, None, a_buf, b_buf, dest_buf)
  33.             exec_evt.wait()
  34.             elapsed = 1e-9*(exec_evt.profile.end - exec_evt.profile.start)
  35.             print "Time for ASIZE: %s [%s]: %g s" % (ASIZE,
  36.                                                      cl.device_type.to_string(device.type),
  37.                                                      elapsed)
  38.             cl.enqueue_read_buffer(queue, dest_buf, c_result).wait()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top