Amazon <a href="http://aws.amazon.com/about-aws/whats-new/2010/11/15/announcing-cluster-gpu-instances-for-amazon-ec2/" target="_blank">recently added</a> GPUs to their Elastic Compute Cloud. We decided to throw <a href="http://www.accelereyes.com/products/libjacket" target="_blank">LIBJACKET</a> into this GPU cloud to see how it would fare. The $2/hr pay-on-demand pricing is a great option for many Jacket programmers.

This post is full of screenshots detailing the steps we took to get going with GPU computing in Amazon's cloud:
<div>
<ol>
	<li>Sign up with Amazon EC2</li>
	<li>Launch a GPU instance</li>
	<li>Login to the instance using ssh</li>
	<li>Setup the environment</li>
	<li>Download, build, and test LIBJACKET!</li>
</ol>
</div>
Everything in this post applies equally well to running Jacket for MATLAB® on EC2. Simply install MATLAB + Jacket in your Amazon GPU instance and start working over ssh.

<!--more-->

<em>Note: Simply click on the images to make them larger as needed.</em>

1) <strong>Sign up with Amazon EC2</strong>
<ul>
	<li>Go to <a href="http://aws.amazon.com/ec2/" target="_blank">http://aws.amazon.com/ec2/</a> and sign up.</li>
	<li>Once you are done, you will get multiple email notifications from Amazon.</li>
	<li>Open the email with "Amazon Elastic Compute Cloud Sign-Up Confirmation".</li>
	<li>Navigate to the first link, create the Access keys, and store them in a safe place.</li>
	<li>Now go to <a href="https://console.aws.amazon.com/ec2/home" target="_blank">https://console.aws.amazon.com/ec2/home</a>.</li>
	<li>This is where you will be doing most of your work.</li>
	<li>If you had not created key pairs already, you can create a new key pair as shown below:</li>
</ul>
<p style="text-align: center;"><a href="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/key01.png"><img class="aligncenter size-medium wp-image-908" title="key01" alt="" src="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/key01.png" width="666" height="520" /></a></p>
<p style="text-align: center;"><a href="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/key02.png"><img class="aligncenter size-medium wp-image-909" title="key02" alt="" src="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/key02.png" width="666" height="520" /></a></p>
<p style="text-align: center;"><a href="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/key03.png"><img class="aligncenter size-medium wp-image-910" title="key03" alt="" src="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/key03.png" width="666" height="520" /></a></p>

<ul>
	<li>At this point you will be prompted to download a .pem key that you will need to use for all future logins.</li>
</ul>
2) <strong>Launch a GPU instance</strong>
<ul>
	<li>You begin by clicking launch instances in your management console.</li>
</ul>
<p style="text-align: center;"><a href="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/instance01.png"><img class="aligncenter size-full wp-image-916" title="instance01" alt="" src="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/instance01.png" width="666" height="520" /></a></p>

<ul>
	<li>Be careful to choose the correct type of instance.</li>
	<li>To create the GPU cluster, choose the Centos 5.5 instance  (AMI ID: aa30c7c3).</li>
	<li>Verify that CUDA 3.1 is included.</li>
</ul>
<p style="text-align: center;"><a href="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/instance02.png"><img class="aligncenter size-full wp-image-916" title="instance01" alt="" src="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/instance02.png" width="666" height="520" /></a></p>

<ul>
	<li>Next in instance details, choose "Cluster GPU" as the instance type.</li>
</ul>
<p style="text-align: center;"><a href="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/instance03.png"><img class="aligncenter size-full wp-image-916" title="instance01" alt="" src="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/instance03.png" width="666" height="520" /></a></p>

<ul>
	<li>Use default values for the rest of the fields in Instance details.</li>
	<li>When prompted to choose the key pair, use the one that you had already downloaded.</li>
	<li>For the rest of the tutorial, we use "test_key.pem" as our key.</li>
	<li>Replace test_key with the appropriate key name whenever necessary.</li>
</ul>
<p style="text-align: center;"><a href="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/instance04.png"><img class="aligncenter size-full wp-image-916" title="instance01" alt="" src="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/instance04.png" width="666" height="520" /></a></p>

<ul>
	<li>Choose default values for the rest. The final review page should look like this:</li>
</ul>
<p style="text-align: center;"><a href="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/instance05.png"><img class="aligncenter size-full wp-image-916" title="instance01" alt="" src="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/instance05.png" width="666" height="520" /></a></p>

<ul>
	<li>Congratulations, you now have a GPU instance!</li>
	<li>Your instance also starts running immediately, So does your billing cycle :)</li>
</ul>
3) <strong>Login to the instance using ssh</strong>
<ul>
	<li>To connect to your instance, you need to know the IP address associated with your account.</li>
	<li>For this, click on your instance, choose connect.</li>
	<li>A popup window opens up giving you the required details.</li>
</ul>
<p style="text-align: center;"><a href="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/instance06.png"><img class="aligncenter size-full wp-image-916" title="instance01" alt="" src="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/instance06.png" width="666" height="520" /></a></p>
<p style="text-align: center;"><a href="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/instance07.png"><img class="aligncenter size-full wp-image-916" title="instance01" alt="" src="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/instance07.png" width="666" height="520" /></a></p>
<p style="text-align: center;"><a href="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/instance08.png"><img class="aligncenter size-full wp-image-916" title="instance01" alt="" src="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/instance08.png" width="666" height="520" /></a></p>

<ul>
	<li>Take note that you have set the permissions of test_key.pem to be readable only by you.</li>
	<li>cd to the directory test_key.pem is located in and use the following commands to ssh into Amazon EC2:</li>
</ul>
<pre class="lang:default decode:true">$ chmod 400 test_key.pem
$ ssh -i test_pem root@ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com</pre>
4) <strong>Setup the environment</strong>
<ul>
	<li>Once you are logged in poke around a little to get to know a bit about the environment.</li>
	<li>You could verify if the cuda toolkit and nvidia drivers have been installed:</li>
</ul>
<pre class="lang:default decode:true">$ ls /usr/local/cuda
$ cat /proc/driver/nvidia/version</pre>
<ul>
	<li>Now coming to setting up the environment, you will have to install a few things.</li>
	<li>Centos 5.5 comes with gcc 4.1 by default, and libjacket currently has compatibility issues with it.</li>
	<li>Hence we will be installing gcc 44 and g++ libraries:</li>
</ul>
<pre class="lang:default decode:true">$ yum install -y gcc-c++ gcc44 gcc44-c++</pre>
<ul>
	<li>Now you need to set up the system to use gcc44 , g++44 by default:</li>
</ul>
<pre class="lang:default decode:true">$ cp /usr/bin/gcc /usr/bin/gcc41; cp /usr/bin/g++ /usr/bin/g++41
$ rm /usr/bin/gcc /usr/bin/g++
$ alternatives --install /usr/bin/gcc gcc /usr/bin/gcc44 40
$ alternatives --install /usr/bin/gcc gcc /usr/bin/gcc41 50
$ alternatives --install /usr/bin/g++ g++ /usr/bin/g++44 40
$ alternatives --install /usr/bin/g++ g++ /usr/bin/g++41 50</pre>
<ul>
	<li>Now that the alternatives have been set up, you will need to choose the correct version:</li>
</ul>
<pre class="lang:default decode:true">$ alternatives --config gcc</pre>
<ul>
	<li>This will print out a menu on the console. Choose the option that points to gcc44.</li>
	<li>Repeat the procedure for g++.</li>
</ul>
<pre class="lang:default decode:true">$ alternatives --config g++</pre>
<ul>
	<li>Now you can verify the gcc and g++ versions by using the following commands:</li>
</ul>
<pre class="lang:default decode:true">$ gcc --version
$ g++ --version</pre>
<ul>
	<li>Make sure the version is 4.4.x.</li>
	<li>Now that gcc is setup, we need to put /usr/local/cuda/bin in .bashrc:</li>
</ul>
<pre class="lang:default decode:true">$echo "export PATH=$PATH:/usr/local/cuda/bin" &gt;&gt; ~/.bashrc</pre>
<ul>
	<li>Now you are all set and can begin working with LIBJACKET!</li>
</ul>
<strong>5.  Download, build, and test LIBJACKET!</strong>
<ul>
	<li>Download LIBJACKET</li>
</ul>
<pre class="lang:default decode:true">$wget -c http://www.accelereyes.com/nightly/libjacket-linux-DEV.tgz</pre>
<ul>
	<li>Extract it:</li>
</ul>
<pre class="lang:default decode:true">$tar xvzf libjacket-linux-DEV.tgz</pre>
<ul>
	<li>Test it!</li>
</ul>
&nbsp;
<pre class="lang:default decode:true">$cd libjacket/examples/pi
$make run</pre>
<p style="text-align: center;"><a href="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/final1.png"><img class="aligncenter size-full wp-image-935" title="final" alt="" src="http://blog.accelereyes.com/blog/wp-content/uploads/2010/12/final1.png" width="666" height="520" /></a></p>

<ul>
	<li>LIBJACKET yielded a <span style="color: #ff0000;">44X speedup</span> for this example!</li>
</ul>
<!--more-->Notes:
<ul>
	<li>Do not forget to go back to the management console to stop the instance once you are done working with it.</li>
	<li>You will be assigned a new IP every time you stop and start an instance. There may be ways around it, we have not explored it yet.</li>
	<li>Setting up the whole thing took about one hour's work. Most of the time being spent to figure out gcc issues.</li>
	<li><a href="http://kenneth.kufluk.com/blog/2010/03/getting-started-with-amazon-ec2/" target="_blank">Here</a> is a nice post that was really helpful to us in about getting started with EC2</li>
</ul>