Skip to content
Chandan Maruthi edited this page Jul 23, 2017 · 21 revisions

GPU Computing on the cloud for 1 dollar

Computing complex models for AI and ML projects requires extensive resources and training takes forever. GPUs allow for faster computations and makes training practical. In this talk we will look at how to use GPUs on the cloud specifically with Tensorflow on Amazon EC2 .

What is a GPU

Architecturally, the CPU is composed of just few cores with lots of cache memory that can handle a few software threads at a time. In contrast, a GPU is composed of hundreds of cores that can handle thousands of threads simultaneously. The ability of a GPU with 100+ cores to process thousands of threads can accelerate some software by 100x over a CPU alone. What’s more, the GPU achieves this acceleration while being more power- and cost-efficient than a CPU.

So why dont we all have more of them

Dedicated GPUs re large , need lots of cooling and power and are just too expensive.

Some people have such setups ,like this guy/gal

or

These Guys

Using GPUs for RNNs and CNNs for NLP

P2 Instances on Amazon

Amazon recently launched Nvidia GPU instances on the AWS EC2 service. These instances allow access to GPU's with the ease of EC2. You have the ability to launch several instances of few based on your needs.

Login to Amazon AWS

Select Ec2 Launch Center

Select a P2 Instance

Whats the difference between P2 vs G2

Select an Ubuntu Linus AMI

sss

Instance Details

Storage

Inbound Settings

Instance Tags

Security Keys

First Login

Check Hardware

$ lspci -nnk

What is a GPU

http://expressionflow.com/2016/10/09/installing-tensorflow-on-an-aws-ec2-p2-gpu-instance/

Install Prerequisites

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential git python-pip libfreetype6-dev libxft-dev libncurses-dev libopenblas-dev gfortran python-matplotlib libblas-dev liblapack-dev libatlas-base-dev python-dev python-pydot linux-headers-generic linux-image-extra-virtual unzip python-numpy swig python-pandas python-sklearn unzip wget pkg-config zip g++ zlib1g-dev libcurl3-dev
sudo pip install -U pip

Installing CUDA 8

CUDA is a parallel computing platform and application programming interface (API) model created by Nvidia.[1] It allows software developers and software engineers to use a CUDA-enabled graphics processing unit (GPU) for general purpose processing – an approach termed GPGPU (General-Purpose computing on Graphics Processing Units). The CUDA platform is a software layer that gives direct access to the GPU's virtual instruction set and parallel computational elements, for the execution of compute kernels.[2] https://en.wikipedia.org/wiki/CUDA

Second we wish to use the latest version of the CUDA library with the instance type. The latest version at the date of writing this post is 8.0. To install CUDA download the package from NVIDIA and install it.

wget https://developer.nvidia.com/compute/cuda/8.0/prod/local_installers/cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64-deb
sudo dpkg -i cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64-deb
rm cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64-deb
sudo apt-get update
sudo apt-get install -y cuda

Installing cuDNN

The NVIDIA CUDA® Deep Neural Network library (cuDNN) is a GPU-accelerated library of primitives for deep neural networks. cuDNN provides highly tuned implementations for standard routines such as forward and backward convolution, pooling, normalization, and activation layers. cuDNN is part of the NVIDIA Deep Learning SDK. https://developer.nvidia.com/cudnn

Visit Nvidia Developer Portal

Login/Create an Account

Look for Cudnn

Cudnn Download

Pick the right Cudnn Important

Find_Right_CUDnn

Third we want to download and install latest version of cuDNN. Downloading cuDNN requires logging into NVIDIA developer site, so we can’t use wget to fetch the files. Download the following files from NVIDIA and upload them to your AWS instance.

cuDNN v5.1 Runtime Library for Ubuntu14.04 (Deb)
cuDNN v5.1 Developer Library for Ubuntu14.04 (Deb)

After having uploaded the files to your server, install them using the following commands.

sudo dpkg -i libcudnn5_5.1.5-1+cuda8.0_amd64.deb
sudo dpkg -i libcudnn5-dev_5.1.5-1+cuda8.0_amd64.deb

Configure the Environment Finally we need to configure the environment to work with CUDA and cuDNN. Add to the following lines to your ~/.profile file.

export CUDA_HOME=/usr/local/cuda
export CUDA_ROOT=/usr/local/cuda
export PATH=$PATH:$CUDA_ROOT/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDA_ROOT/lib64

Installing TensorFlow

https://www.tensorflow.org/install/install_linux

Install pip and virtualenv by issuing one of the following commands

sudo apt-get install python-pip python-dev python-virtualenv # for Python 2.7
sudo apt-get install python3-pip python3-dev python-virtualenv # for Python 3.n

Create a virtualenv environment by issuing one of the following commands

virtualenv --system-site-packages targetDirectory # for Python 2.7
virtualenv --system-site-packages -p python3 targetDirectory # for Python 3.n

where targetDirectory specifies the top of the virtualenv tree. Our instructions assume that targetDirectory is ~/tensorflow, but you may choose any directory.

Activate the virtualenv environment by issuing one of the following commands:

source ~/tensorflow/bin/activate # bash, sh, ksh, or zsh
source ~/tensorflow/bin/activate.csh  # csh or tcsh

The preceding source command should change your prompt to the following: (tensorflow)$

Install TensorFlow :

(tensorflow)$ pip install --upgrade tensorflow      # for Python 2.7
(tensorflow)$ pip3 install --upgrade tensorflow     # for Python 3.n
(tensorflow)$ pip install --upgrade tensorflow-gpu  # for Python 2.7 and GPU
(tensorflow)$ pip3 install --upgrade tensorflow-gpu # for Python 3.n and GPU

Validate The Installation

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

Matrix Additions with GPUs

Matrix Multiplication with GPUs

Clone this wiki locally