www.allitebooks.com

Learning%20Data%20Mining%20with%20Python Learning%20Data%20Mining%20with%20Python

24.07.2016 Views

Chapter 11 Getting your code to run on a GPU can be a frustrating experience. It depends greatly on what type of GPU you have, how it is configured, your operating system, and whether you are prepared to make some low-level changes to your computer. There are three main avenues to take: • The first is to look at your computer, search for tools and drivers for your GPU and operating system, explore some of the many tutorials out there, and find one that fits your scenario. Whether this works depends on what your system is like. That said, this scenario is much easier than it was a few years ago, with better tools and drivers available to perform GPU-enabled computation. • The second avenue is to choose a system, find good documentation on setting it up, and buy a system to match. This will work better, but can be fairly expensive—in most modern computers, the GPU is one of the most expensive parts. This is especially true if you want to get great performance out of the system—you'll need a really good GPU, which can be very expensive. • The third avenue is to use a virtual machine, which is already configured for such a purpose. For example, Markus Beissinger has created such a system that runs on Amazon's Web Services. The system will cost you money to run, but the price is much less than that of a new computer. Depending on your location, the exact system you get and how much you use it, you are probably looking at less than $1 an hour, and often much, much less. If you use spot instances in Amazon's Web Services, you can run them for just a few cents per hour (although, you will need to develop your code to run on spot instances separately). If you aren't able to afford the running costs of a virtual machine, I recommend that you look into the first avenue, with your current system. You may also be able to pick up a good secondhand GPU from family or a friend who constantly updates their computer (gamer friends are great for this!). Running our code on a GPU We are going to take the third avenue in this chapter and create a virtual machine based on Markus Beissinger's base system. This will run on an Amazon's EC2 service. There are many other Web services to use, and the procedure will be slightly different for each. In this section, I'll outline the procedure for Amazon. [ 259 ]

Classifying Objects in Images Using Deep Learning If you want to use your own computer and have it configured to run GPU-enabled computation, feel free to skip this section. You can get more information on how this was set up, which may also provide information on setting it up on another computer, at http://markus.com/install-theano-on-aws/. To start with, go to the AWS console at: https://console.aws.amazon.com/console/home?region=us-east-1 Log in with your Amazon account. If you don't have one, you will be prompted to create one, which you will need to do in order to continue. Next, go to the EC2 service console at: https://console.aws.amazon.com/ec2/v2/ home?region=us-east-1. Click on Launch Instance and choose N. California as your location in the dropdown menu at the top-right. Click on Community AMIs and search for ami-b141a2f5, which is the machine created by Markus Beissinger. Then, click on Select. On the next screen, choose g2.2xlarge as the machine type and click on Review and Launch. On the next screen, click on Launch. At this point, you will be charged, so please remember to shut down your machines when you are done with them. You can go to the EC2 service, select the machine, and stop it. You won't be charged for machines that are not running. You'll be prompted with some information on how to connect to your instance. If you haven't used AWS before, you will probably need to create a new key pair to securely connect to your instance. In this case, give your key pair a name, download the pem file, and store it in a safe place—if lost, you will not be able to connect to your instance again! Click on Connect for information on using the pem file to connect to your instance. The most likely scenario is that you will use ssh with the following command: ssh -i .pem ubuntu@ [ 260 ]

Chapter 11<br />

Getting your code to run on a GPU can be a frustrating experience. It depends<br />

greatly on what type of GPU you have, how it is configured, your operating system,<br />

and whether you are prepared to make some low-level changes to your <strong>com</strong>puter.<br />

There are three main avenues to take:<br />

• The first is to look at your <strong>com</strong>puter, search for tools and drivers for your<br />

GPU and operating system, explore some of the many tutorials out there,<br />

and find one that fits your scenario. Whether this works depends on what<br />

your system is like. That said, this scenario is much easier than it was a few<br />

years ago, with better tools and drivers available to perform GPU-enabled<br />

<strong>com</strong>putation.<br />

• The second avenue is to choose a system, find good documentation on<br />

setting it up, and buy a system to match. This will work better, but can be<br />

fairly expensive—in most modern <strong>com</strong>puters, the GPU is one of the most<br />

expensive parts. This is especially true if you want to get great performance<br />

out of the system—you'll need a really good GPU, which can be very<br />

expensive.<br />

• The third avenue is to use a virtual machine, which is already configured for<br />

such a purpose. For example, Markus Beissinger has created such a system<br />

that runs on Amazon's Web Services. The system will cost you money to<br />

run, but the price is much less than that of a new <strong>com</strong>puter. Depending on<br />

your location, the exact system you get and how much you use it, you are<br />

probably looking at less than $1 an hour, and often much, much less. If you<br />

use spot instances in Amazon's Web Services, you can run them for just a few<br />

cents per hour (although, you will need to develop your code to run on spot<br />

instances separately).<br />

If you aren't able to afford the running costs of a virtual machine, I re<strong>com</strong>mend that<br />

you look into the first avenue, with your current system. You may also be able to<br />

pick up a good secondhand GPU from family or a friend who constantly updates<br />

their <strong>com</strong>puter (gamer friends are great for this!).<br />

Running our code on a GPU<br />

We are going to take the third avenue in this chapter and create a virtual machine<br />

based on Markus Beissinger's base system. This will run on an Amazon's EC2 service.<br />

There are many other Web services to use, and the procedure will be slightly<br />

different for each. In this section, I'll outline the procedure for Amazon.<br />

[ 259 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!