Build an environment where Tensorflow and Keras run on GPU on AWS GPU instance.
I know that these articles are the nth room, but even so, there are scattered materials on the net that are written at each timing and I do not know whether they are the latest or not, so I will write the current situation by dividing it into such articles. .. It seems that it has been released from the manual installation of Nouveau and CUDA Toolkit, although there is still some manual work.
Basically, refer to the contents of the following URL. Detailed versions etc. have been changed.
The OS to be selected is Ubuntu 16.04, and the detailed settings will be omitted. The caveat here is that the CUDA Toolkit files are huge, so it's a good idea to set the storage size a bit larger than the default 8GB.
$ sudo add-apt-repository ppa:graphics-drivers/ppa -y
$ sudo apt-get update
$ sudo apt-get install -y nvidia-375 nvidia-settings
Install the CUDA Toolkit. This time I will use 8.0. Here, it is obtained by wget, but it is the same as the installer obtained by "Linux> x86_64> Ubuntu> 16.04> deb (local)" from the following URL.
CUDA Toolkit Download | NVIDIA Developer
$ wget https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64-deb
$ sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64-deb
$ sudo apt-get update
$ sudo apt-get install -y cuda nvidia-cuda-toolkit
Now make sure you have successfully installed with nvidia-smi
and nvcc --version
.
** Addition: It seems that you can download it directly from the URL below. ** **
$ wget http://developer.download.nvidia.com/compute/redist/cudnn/v5.1/cudnn-8.0-linux-x64-v5.1.tgz
~~ cuDNN must be downloaded from the NVIDIA site and transferred to your AWS instance. ~~
~~ Click the download button at the URL below to agree to the "cuDNN Software License Agreement", and then "Download cuDNN v5.1 (Jan 20, 2017), for CUDA 8.0" "cuDNN v5.1 Library for Linux" (file name: Download cudnn-8.0-linux-x64-v5.1.tgz
). Login required. ~~
NVIDIA cuDNN | NVIDIA Developer
~~ Copy the downloaded file to your AWS GPU instance. ~~
# local
$ scp cudnn-8.0-linux-x64-v5.1.tgz aws-gpu-instance:
Unzip and place the files inside.
$ tar zxvf cudnn-8.0-linux-x64-v5.1.tgz
$ sudo mv cuda/lib64/* /usr/local/cuda/lib64/
$ sudo mv cuda/include/* /usr/local/cuda/include/
Add the following settings to the configuration file of the shell you are using. This time I added it to .bashrc
.
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"
export CUDA_HOME=/usr/local/cuda
Now it's time to set up Tensorflow and Keras. I will omit building the Python environment, but if you follow this article, you can build a Python3 environment using pyenv / virtualenv.
$ pip install tensorflow-gpu
$ pip install keras
I will download the Keras source code and run some examples inside.
$ git clone https://github.com/fchollet/keras.git
$ cd keras/examples
$ python mnist_cnn.py
If you try to move something appropriately, GPU-Util goes up with nvidia-smi
, or it is obviously faster than the local or CPU usage version, it will be OK. Thank you for your hard work.
One of the reference URL If you install according to, an error will occur due to the version difference of cuDNN. Use v5.1 instead of v5.0.
Loaded runtime CuDNN library: 5005 (compatibility version 5000) but source was compiled with 5110 (compatibility version 5100)
Recommended Posts