[PYTHON] Build a Chainer environment using CUDA and cuDNN on a p2 instance

What i did

I created a Chainer environment that can use CUDA and cuDNN on p2.xlarge of AWS.

Premise

I used the following version. (At the time of implementation)

version
OS Ubuntu14.04
pyenv 1.0.8
Anaconda 4.3.0
python 3.6.2
CUDA 8.0
cuDNN v5.1
Chainer 1.2.21

Installation of required libraries

sudo apt-get install -y git gcc make openssl libssl-dev libbz2-dev libreadline-dev libsqlite3-dev

Install pyenv

For the installation of pyenv, refer to the following. http://qiita.com/y__sama/items/5b62d31cb7e6ed50f02c

git clone https://github.com/yyuu/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
source ~/.bashrc

Installation of Anaconda

For the installation of Anaconda, refer to the following. http://qiita.com/y__sama/items/5b62d31cb7e6ed50f02c

pyenv install -l | grep anaconda
pyenv install anaconda3-4.3.0
pyenv rehash
pyenv global anaconda3-4.3.0
echo 'export PATH="$PYENV_ROOT/versions/anaconda3-4.3.0/bin/:$PATH"' >> ~/.bashrc
source ~/.bashrc
conda update conda
python --version

CUDA installation

wget https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64-deb
sudo dpkg -i cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64-deb
sudo apt-get update
sudo apt-get install cuda -y
echo 'export CUDA_HOME=/usr/local/cuda' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${CUDA_HOME}/lib64' >> ~/.bashrc
echo 'export PATH=$PATH:${CUDA_HOME}/bin' >> ~/.bashrc

cuDNN installation

Obtained separately from the nvidia site.

mkdir .cudnn
tar xvzf ./cudnn-8.0-linux-x64-v5.1.tgz
mv ./cuda ./.cudnn
mv ./.cudnn/cuda ./.cudnn/5.1
sudo ln -s ~/.cudnn/5.1/include/cudnn.h /usr/local/cuda/include/cudnn.h
sudo ln -s ~/.cudnn/5.1/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

Install Chainer

pip install chainer

Operation check

mkdir mnist
wget https://raw.githubusercontent.com/pfnet/chainer/master/examples/mnist/train_mnist.py ./mnist
#GPU usage
time python ./mnist/train_mnist.py -g 0 -e 10
#GPU not used
time python ./mnist/train_mnist.py -g -1 -e 10

If there is a difference in execution time, it is successful.

Recommended Posts

Build a Chainer environment using CUDA and cuDNN on a p2 instance
Build a Django development environment using pyenv-virtualenv on Mac
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
Build a Python environment on your Mac using pyenv
Build a Python development environment using pyenv on MacOS
Building a Python environment on a Mac and using Jupyter lab
Build a go environment using Docker
Install CUDA 8.0 and Chainer on Ubuntu 16.04
Build a python3 environment on CentOS7
How to build a LAMP environment using Vagrant and VirtulBox Note
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
Build a game leaderboard on Alibaba cloud using Python and Redis
Build a Python environment on your Mac with Anaconda and PyCharm
# 3 Build a Python (Django) environment on AWS EC2 instance (ubuntu18.04) part2
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
Build Python3 and OpenCV environment on Ubuntu 18.04
Build a python environment on MacOS (Catallina)
Build a Python + OpenCV environment on Cloud9
Build Linux on a Windows environment. Steps to install Laradock and migrate
Build a WardPress environment on AWS with pulumi
Build Python3.5 + matplotlib environment on Ubuntu 12 using Anaconda
Simply build a Python 3 execution environment on Windows
Build a Django environment on Raspberry Pi (MySQL)
Build a python environment with ansible on centos6
Build a Python environment on Mac (Mountain Lion)
Build a Python development environment on your Mac
Build a virtual environment with pyenv and venv
Build a Kubernetes environment for development on Ubuntu
Try using tensorflow ① Build python environment and introduce tensorflow
Build a Python development environment on Raspberry Pi
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Trial and error]
Build a PYNQ environment on Ultra96 V2 and log in to Jupyter Notebook
Build a TensorFlow development environment on Amazon EC2 with command copy and paste
Build a machine learning environment using PyCharm on Ubuntu environment (TensorFlow will also be introduced!)
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Build an OpenCV4 environment on Raspberry Pi using Poetry
Install Python3 on Mac and build environment [Definitive Edition]
How to build a beautiful Python environment on a new Mac and install Jupter Notebook
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a local development environment for Laravel6.X on Mac
Build a machine learning Python environment on Mac OS
Build a GVim-based Python development environment on Windows 10 (1) Installation
How to build a Django (python) environment on docker
Build a Python development environment on Mac OS X
Build a Python virtual environment using venv (Django + MySQL ①)
Build a python virtual environment with virtualenv and virtualenvwrapper
Create a decent shell and python environment on Windows
Memo A beginner tried to build a Java environment and Japaneseize it on Ubuntu 18.04.2 LTS.
How to build a Python environment on amazon linux 2
Build a machine learning environment natively on Windows 10 (x64)
Build a lightweight Fast API development environment using Docker
Build a numerical calculation environment with pyenv and miniconda3
How to build a Python virtual execution environment using Visual Studio Code and pipenv on a Windows machine (also Jupyter notebook)
When I tried to build a Rails environment on WSL2 (Ubuntu 20.04LTS), I stumbled and fell.
Build a python machine learning study environment on macOS sierra
Build a machine learning environment on mac (pyenv, deeplearning, opencv)
Build an environment for machine learning using Python on MacOSX
How to build a new python virtual environment on Ubuntu
Build a Docker environment that can use PyTorch and JupyterLab
Build a machine learning scikit-learn environment with VirtualBox and Ubuntu
Building a Jupyter Lab development environment on WSL2 using Anaconda3