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.
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.
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.
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).
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:
Setup dependencies needed to install CUDA (gcc):
sudo apt-get update sudo apt-get install gcc
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:
(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.)
sudo dpkg -i cuda-repo-ubuntu1204_5.5-0_amd64.deb sudo apt-get update sudo apt-get install cuda
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
Install CUDA samples (optional) to some directory (
. here, which will install to the current directory):
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
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
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
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.