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.
- Calle Lejdfors and Lennart Ohlsson, PyGPU: A high-level language for high-speed image processing, 2006. Draft
- Calle Lejdfors and Lennart Ohlsson, Implementing an embedded GPU language by combining translation and generation, 2005. Accepted for publication: Programming Language track at SAC06.
Examples
Sobel edge-detectiondef
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 cloningSeamless 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 simulatorThis 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.
- 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 typingpython 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 is 0.2.0a-629. This 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 is a library for array computing in Python. PyGPU has been developed and tested using NumPy version 1.0b1 and later.- NumPy download page
Pygame
Pygame provide Python bindings for SDL (the Simple Direct media Library) that is required to create an OpenGL context in which to run the examples. PyGPU has been developed and tested with version 1.7.1 of Pygame and version 1.2.9 of SDL.- Pygame download page
- SDL download page
PyGLEW
PyGLEW are Python bindings for the GLEW (OpenGL Extension Wrangler library). It wraps OpenGL versions 1.1 to 2.0, including a number of additional extensions critical to the operation of PyGPU. The current version is 0.1.2:- PyGLEW-0.1.2.linux-i686.tar.gz
- PyGLEW-0.1.2.linux-i686-py2.5.tar.gz
- PyGLEW-0.1.2.win32.exe
- PyGLEW-0.1.2.tar.gz
PyCg
PyCg - Python bindings for NVIDIA's Cg library. The current version is 0.14.1 and is for Cg version 1.4.- PyCg-0.14.1.linux-i686.tar.gz
- PyCg-0.14.1.linux-i686-py2.5.tar.gz
- PyCg-0.14.1.win32.exe
- PyCg-0.14.1.tar.gz
Last modified: Thu Oct 18 12:50:21 2007