Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GPGPU programming in Python

Tags:

python

opencl

I want to start GPGPU programming in Python. Should I start with pyopencl or clyther? What's the difference?

like image 750
r00kie Avatar asked Dec 12 '22 20:12

r00kie


1 Answers

OpenCL consists of two parts. There is a host-side which is typically written in C, and a device-side which is written in a derivative of C defined by OpenCL. This code is compiled to the device (typically a GPU) at run-time.

CLyther attempts to abstract everything out. You write the host-side code in Python. You write the device-side code in a subset of Python (in a similar way to Cython). This is very high level and easy-to-use.

PyOpenCL is a comparatively low-level binding to the OpenCL API from Python. Device-side code is written in OpenCL's subset of C99. It gives you full access to and full control of OpenCL. Very little is abstracted away.

I have limited experience with both, but my impression is that, once both are mature, I would prefer to use Clyther for most projects. It is more user-friendly, which means you're more likely to use it, and to use it more. It is also easier to shift code back and forth between Clyther and Python than PyOpenCL and Python, so code maintenance and refactoring should be easier. For very performance-critical projects, I would prefer PyOpenCL. It gives better low-level control, and fewer layers between you and the hardware. The ultimate possible performance should be better with PyOpenCL than with Clyther.

I do not know if this will continue to be the case forever. It is likely that PyOpenCL will, eventually, add higher-level constructs, and that Clyther will, eventually, add lower-level control. In an ideal world, the Clyther developers would move the core such that it was built on top of PyOpenCL, so we wouldn't have to choose, and to avoid duplication of labor. I doubt that will ever happen, though.

At present, PyOpenCL appears to be more mature than Clyther. It was started first, and is less ambitious in scope. It has better documentation than Clyther, and appears to have a bigger user community. Both are fairly similar in code size -- Clyther is about 4KLOCs of Python and 4KLOCs of C. PyOpenCL is about 7KLOCs of Python code, and 9KLOCs of C++ code. This is approximate (includes build systems, examples, etc), so should not be treated as implying anything beyond approximate equality.

like image 81
user274045 Avatar answered Jan 12 '23 00:01

user274045