PyGPU - Python for the GPU

Haven't you ever dreamt of writing code in a very high level language and have that code execute at speeds rivaling that of lower-level languages? PyGPU is a compiler that lets you write image processing programs in Python that execute on the graphics processing unit (GPU) present in modern graphics cards. This enables image processing algorithms to take advantage of the performance of the GPU. In some applications, performance increases approach an order of magnitude, compared to CPUs.

Existing methods for programming the GPU uses either specialised languages (such as Cg, HLSL, or GLSL) or an embedded language in C++ (Sh) or C# (Accelerator). The specialised languages are generally very low-level (on the level of C with some simple C++ constructs). Furthermore, they require intimate knowledge of advanced graphics programming concepts, as well as quite a bit of glue-code to handle parameter passing and render pipeline setup.

The embedded approaches admit a higher level of abstraction (being embedded in somewhat higher level languages) and also does away with a lot of the glue code necessary with using specialised languages. However, neither C++ or C# come close to the simple, direct flexibility and expressive power of more dynamic languages such as Python or Ruby.

PyGPU is an embedded language in Python, that allow most of Python features (list-comprehensions, higher-order functions, iterators) to be used for constructing GPU algorithms. It uses a image abstraction to abstract away implementation details of the GPU, while still allowing translation to very efficient GPU native-code.

News

As of 2007-10-16 the support libraries PyCg and PyGLEW to PyGPU are hosted on launchpad.net. Please submit bug-reports and feature requests there.

As of 2006-10-17 PyGPU is hosted at Google Code. There you'll find an issue tracking system, discussion groups, as well as anonymous read-only access to the development versions of PyGPU.

Papers

PyGPU is a research project for exploring the possibilities of using very high level languages for writing GPU programs.

Examples

Sobel edge-detection

def sobelEdgeDetect(im=DImage, p=Position):

wX = outerproduct([1,2,1],[-1,0,1])

wY = transpose(wX)



Gx = convolve(wX,im,p)

Gy = convolve(wY,im,p)



return sqrt(Gx**2 + Gy**2) Seamless cloning Seamless cloning works by solving a Laplace equation to optimally match the edges of two images allowing seamless pasting of one image into another.



The multigrid Laplace solver and pasting operations are implemented in PyGPU and run exclusively on the GPU.



The example is based on the SIGGRAPH 2003 paper Poisson Image Editing by Pérez, Gangnet, and Blake. The test images are from http://www.cs.tau.ac.il/~tommer/adv-graphics/ex1.htm.



2D Fluid simulator This example implements a PyGPU program that solves Navier-Stokes equations for incompressible flow. It executes on the GPU and the solver runs at interactive rates.



The example is based on the GPU Gems article available here (PDF).



Download and installation

PyGPU is written completely in Python but, in order to interface with the graphics card and GPU, requires a couple of extension packages. Links to the respective extension packages are provided below.

Installation instructions

Install NumPy and Pygame. For instructions see their respective webpages. Install PyGLEW and PyCg. Windows : Simply run the executable files provided below. The Windows distribution if PyGLEW and PyCg is for Python 2.4 only .

: Simply run the executable files provided below. The Windows distribution if PyGLEW and PyCg is for . Linux: Download the tar.gz-archives, unpack them, and run python setup.py install as root, to install.

Note: if you use a modern Linux distribution (Ubuntu 7.0 e.g.) you should use the Python 2.5 versions (indicated by the -py2.5 suffix). Otherwise, use the ordinary, Python 2.4 packages. Download PyGPU, unpack it and run the main.py program to verify that your installation works correctly. Start it by either double-clicking on the icon, or by firing up a terminal and typing python main.py while in the appropriate directory.

Download links

PyGPU runs on both Linux and Windows and under both NVIDIA and ATI graphics cards. Previous version have been reported to work on Mac OS as well. The current version isThis is alpha software, you should expect missing functionality, performance issues, etc. If you find bugs please report them in the issue-tracker

For direct SVN access to the source repository please see the Google code page.

NumPy

NumPy download page

Pygame

PyGLEW

PyCg