Thursday, October 25, 2012

Exploring OpenCL: Setup PyOpenCL

Preparing your computer for OpenCL development apparently isn't as simple as installing a few packages.

To do OpenCL development with Python, you'll need:

- Proprietary GPU drivers (for AMD/nVidia GPUs) if you want to use the GPU.
- Vendor libraries (AMD APP SDK, for example).
- Installable Client Driver.
- OpenCL ICD loader.
- PyOpenCL (for using OpenCL in Python).

Since I have a Radeon HD 7750, I'll be using AMD Catalyst. I'm using the driver provided through Ubuntu's additional drivers tool. It's easier to manage and shouldn't require manual removal after a kernel update.

From the looks of things, nVidia's SDK only supports running OpenCL on nVidia GPUs. AMD's SDK allows running on any x86 CPU as well as on AMD GPUs so it makes sense to use AMD APP SDK if you don't have nVidia hardware. This way you'll be able to run your OpenCL software even on Intel CPUs.

Here's how to install 64-bit AMD APP SDK (v2.7 at this time).

~$ wget http://developer.amd.com/Downloads/AMD-APP-SDK-v2.7-lnx64.tgz
~$ tar zxvf AMD-APP-SDK-v2.7-lnx64.tgz
~$ sudo sh Install-AMD-APP.sh 


There's an open source ICD loader that's recommended over the vendor specific loaders. It's in the Ubuntu repositories already. You'll also need the OpenCL ICD which is available from a 3rd party repository (unfortunately).

You'll need to add the following using Software Sources.

deb ftp://ftp.MIRROR.debian.org/debian/ unstable main contrib non-free
deb-src ftp://ftp.MIRROR.debian.org/debian/ unstable main contrib non-free


Replace MIRROR with your country code. If it's not available in your country, just try a different country. After that, it's a simple install away.

~$ sudo apt-get update
~$ sudo apt-get install amd-opencl-icd
~$ sudo apt-get install ocl-icd-libopencl1

You'll probably want to disable the repository in Software Sources after installing the opencl-icd package unless you want to run the risk of breakage when non-Ubuntu packages get mixed in with Ubuntu packages.

Finally, you'll want to install PyOpenCL to access the OpenCL API in Python.

~$ sudo apt-get install python-pyopencl

Now you should be ready to start OpenCL development on your computer using Python.

Good Luck.


2 comments:

  1. Greetings!

    Is it necessary to load the SDK if you are only using OpenCL to crunch BOINC project applications?

    I have AMD 64 CPU and Radeon HD7750 GPU.

    Thanks in advance,
    Jay

    ReplyDelete
    Replies
    1. If you're just running a OpenCL app and not coding one I think you just need the ICD.

      That also depends on whether the app you're running was compiled with the newer SDK. Older versions may require the SDK installed.

      Delete