Results 1 to 3 of 3

Thread: PyOpenCL: OpenCL Python Bindings

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    6

    PyOpenCL: OpenCL Python Bindings

    I'm pleased to announce the release of PyOpenCL 0.90, a complete, functional Python wrapper around OpenCL.

    Its home page is at http://mathema.tician.de/software/pyopencl.

    PyOpenCL has complete documentation and a Wiki available.

    Download PyOpenCL here from its page in the Python package index.

    Since there are a few competing efforts, what sets PyOpenCL apart?

    • Object cleanup tied to lifetime of objects. This idiom, often called RAII in C++, makes it much easier to write correct, leak- and crash-free code.[/*:m:20t6iq6e]
    • Completeness. PyOpenCL puts the full power of OpenCL’s API at your disposal, if you wish. Every obscure get_info() query and all CL calls are accessible.[/*:m:20t6iq6e]
    • Automatic Error Checking. All errors are automatically translated into Python exceptions.[/*:m:20t6iq6e]
    • Speed. PyOpenCL’s base layer is written in C++, so all the niceties above are virtually free.[/*:m:20t6iq6e]
    • Helpful, complete Documentation[/*:m:20t6iq6e]
    • Liberal license. PyOpenCL is open-source and free for commercial, academic, and private use under the MIT/X11 license.[/*:m:20t6iq6e]


    Here's some sample code to give you an impression:

    Code :
    import pyopencl as cl
    import numpy
    import numpy.linalg as la
     
    a = numpy.random.rand(50000).astype(numpy.float32)
    b = numpy.random.rand(50000).astype(numpy.float32)
     
    ctx = cl.create_context_from_type(cl.device_type.ALL)
    queue = cl.CommandQueue(ctx)
     
    mf = cl.mem_flags
    a_buf = cl.create_host_buffer(
            ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, a)
    b_buf = cl.create_host_buffer(
            ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, b)
    dest_buf = cl.create_buffer(ctx, mf.WRITE_ONLY, b.nbytes)
     
    prg = cl.create_program_with_source(ctx, """
        __kernel void sum(__global const float *a,
        __global const float *b, __global float *c)
        {
          int gid = get_global_id(0);
          c[gid] = a[gid] + b[gid];
        }
        """).build()
     
    prg.sum(queue, a.shape, a_buf, b_buf, dest_buf)
     
    a_plus_b = numpy.empty_like(a)
    cl.enqueue_read_buffer(queue, dest_buf, a_plus_b).wait()
     
    print la.norm(a_plus_b - (a+b))

  2. #2
    Junior Member
    Join Date
    Aug 2009
    Posts
    6

    Re: PyOpenCL: OpenCL Python Bindings

    Whoops--the above post has the wrong download link.

    Correct download link

  3. #3

    Re: PyOpenCL: OpenCL Python Bindings

    Thanks for the detailed reply!! That helped me to fix my problem. You are my life saver!!!

Similar Threads

  1. OpenCL + Python
    By ffelagund in forum Interoperability issues
    Replies: 0
    Last Post: 07-17-2012, 10:25 AM
  2. OpenGL ES python bindings for S60
    By flame in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 12-15-2006, 01:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •