GPU Computing with Python

by pavan on December 15, 2011

in Announcements,CUDA,Parallel computing,Python

One of the biggest areas where GPUs are providing benefit is with scientific computing. With libraries like Sage and SciPy providing a huge collection of functions and algorithms for free, Python has become one of the favorite tools for developers around the world. Even though these libraries have C/C++ back-ends, performance on large problems quickly becomes an issue and can kill productivity.

On the heals of our free release of Arrayfire C/C++, we’re excited to release ArrayFire Python. All of this is FREE for most users (see below for clarification)!

The structure of ArrayFire/Python is loosely based on NumPy in that it uses a single array object that can contain multiple data types. You can convert NumPy arrays to ArrayFire arrays and vice versa. If you already have your application using NumPy arrays, this is a quick way to jump in and tweak critical sections.

import numpy as np
import arrayfire as af
a = np.random.rand(5,5)
b = af.array(a)
c = b.host() # c is the same as a

Alternatively, you can generate data on the device:

r = af.randu(5, 5)
o = af.ones(5,5)
z = af.zeros(5,5)

Once you have the data you need, you can utilize hundreds of functions to convert your code entirely onto the GPU. You’ll find much of the API follows directly from NumPy itself.

Screenshot taken while running raindrop example

Jumping right in, here is an example showing the Monte-Carlo calculation of pi

from arrayfire import *
def pi(samples=20000000):
    x = randu(samples, 1)
    y = randu(samples, 1)
    return 4 * sum(mul(x, x) + mul(y, y) < 1) / samples

You can visit our website to download the latest version of ArrayFire. You can find the Python wrapper in arrayfire/python directory. Installation instructions are in README, and a few examples are included that show off both compute and visualizations.

Our Forums are the best place to get the latest info and help.

AccelerEyes provides this software for free in the hope that some of you might be interested in hiring us to port your code to the GPU.  If that is interesting, let us know!

* ArrayFire is free for use on a single GPU.  To run ArrayFire on larger hardware systems, contact sales@accelereyes.com.

Previous post:

Next post: