Installing CUDA, OpenCL, and PyOpenCL on AWS EC2

OpenCL
Posted on Sep 18th, 2013

This post describes how to setup CUDA, OpenCL, and PyOpenCL on EC2 with Ubuntu 12.04. It took me a while to get working properly, so what follows are the steps I took to install CUDA and OpenCL on EC2. These steps should work for any machine with a CUDA capable card.

If you'd just like to create an instance with everything preinstalled, I've created a public AMI named Ubuntu-12.04-GPU-CUDA-OpenCL-PyOpenCL with the ID ami-87377cee.

You can also view the bash script to install CUDA and OpenCL.

CUDA, OpenCL, GPU Programming

OpenCL and CUDA are platforms for parallel programming. Basically, you can use it to take advantage of GPUs to solve problems quicker (e.g., drawing pixels to a screen, mining bitcoins, or looping over a large data set and doing calculations on each item). This post won't go into any more detail, but this post addresses the question "why use opencl?".

The goal of this article is to describe how to set up OpenCL and PyOpenCL using CUDA 5.5 on an AWS EC2 instance running Ubuntu 12.04.

Setup

At the time of writing, Amazon provides GPU instances Instances which are backed by two Intel Xeon X5570, quad-core with hyperthreading and two NVIDIA Tesla M2050 GPUs. Let's install CUDA, Nvidia's parallel computing platform, which includes OpenCL.

  1. First, setup a GPU instance. Select Ubuntu Server 12.04 LTS for HVM instances, which will allow us to spin up a GPU instance. Make sure to select the GPU instance type, CG1 Cluster GPU (cg1.4xlarge, 22GiB).

  2. After the instance is setup, SSH into it and we'll setup CUDA. We'll follow setting up CUDA guide, including with some extra steps to setup pyOpenCl:

    1. Setup dependencies needed to install CUDA (gcc):

       sudo apt-get update 
       sudo apt-get install gcc 

    2. Download and install CUDA. For the EC2 instance, grab the 64-bit Ubuntu 12.04 .deb file for CUDA 5.5. Run the command to download it:

      wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1204/x86_64/cuda-repo-ubuntu1204_5.5-0_amd64.deb

      (This comes from the CUDA Download Page. If this post is outdated and 5.5 is old, you can visit the CUDA toolkit archive page to download version 5.5.)

      Then run:

      sudo dpkg -i cuda-repo-ubuntu1204_5.5-0_amd64.deb 
       sudo apt-get update 
       sudo apt-get install cuda 

    3. Seutp environment; add cuda to PATH and LD_LIBRARY_PATH. Add the two following lines to ~/.bashrc

       export PATH=/usr/local/cuda-5.5/bin:$PATH 
       export LD_LIBRARY_PATH=/usr/local/cuda-5.5/lib64:$LD_LIBRARY_PATH 

    4. Install CUDA samples (optional) to some directory (. here, which will install to the current directory):

      cuda-install-samples-5.5.sh .

    5. Verify an example works (after running this, it should show two CUDA capable devices):

       cd NVIDIA_CUDA-5.5_Samples/1_Utilities/deviceQuery 
       make 
       ./deviceQuery 

  3. Now that CUDA is setup, Install opencl headers and PyOpenCL dependencies:

     sudo apt-get install opencl-headers python-pip python-dev python-numpy python-mako 

  4. Download pyopencl, then install it:

     wget https://pypi.python.org/packages/source/p/pyopencl/pyopencl-2013.1.tar.gz#md5=c506e4ec5bc56ad85bf005ec40d4783b 
     tar -vxzf pyopencl-2013.1.tar.gz 
     cd pyopencl-2013.1 
     sudo python setup.py install 

AMI and Bash Script

I've created an AMI following the steps above, named Ubuntu-12.04_GPU_CUDA-OpenCL-PyOpenCL with the ID ami-87377cee. You can select this AMI if you just want to create an instance without doing these steps yourself.

I also created a script containing all the commands, which you can view and run the bash script to setup OpenCL / PyOpenCL and CUDA.

More Resources

Now that you have OpenCL installed, the next step is learning how to use it. For a great introduction to OpenCL, check out Adventures in OpenCL by @enjalot, or a gentle introduction to OpenCL, or the PyOpenCL tutorial. In later posts, I'll go a bit more in depth why you might want to leverage OpenCL.

NEXT | Visualizing Nebulous Data
PREVIOUS | Replace a String in Multiple Files in Linux Using Grep and Sed
All Posts

Engage

Comments