An Ubuntu Deep Learning System
A. Install latest Nvidia drivers
1- Run following commands to add latest drivers from PPA.
sudo add-apt-repository ppa:graphics-drivers/ppa sudo apt update
2- Then use Ubuntu Software&Updates Additional Drivers application to update your driver.
For my GTX-1070 I chose driver with version 384.69.
3- After installation Restart your PC. You may need to disable safe boot using bios menu.
4- Run following command to ensure that drivers are installed correctly.
lsmod | grep nvidia
5- İf you have issue with the new driver remove it with following command.
sudo apt-get purge nvidia*
For more information see:
B. Install Cuda Toolkit
1- Download Cuda Toolkit from following url:
or for version 8 simply run following command:
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
2- Run following commands for installation
sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64-deb sudo apt-get update sudo apt-get install cuda
To Install “cuBLAS Patch Update to CUDA 8” follow the same way.
wget https://developer.nvidia.com/compute/cuda/8.0/Prod2/patches/2/cuda-repo-ubuntu1604-8-0-local-cublas-performance-update_8.0.61-1_amd64-deb sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-cublas-performance-update_8.0.61-1_amd64.deb sudo apt-get update sudo apt-get install cuda
3- Edit /etc/environment file and modify path variable.
sudo vi /etc/environment
Now add ‘/usr/local/cuda-8.0/bin’ to end. Load the file again so that changes take effect.
source /etc/environment
Run following commands to create required variables.
echo 'export LD_LIBRARY_PATH=”$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64' >> ~/.bashrc echo 'export CUDA_HOME=/usr/local/cuda' >> ~/.bashrc source ~/.bashrc
4- Test CUDA with following commands:
cd /usr/local/cuda-8.0/samples/5_Simulations/nbody
sudo make
./nbody
If it fails to find gpu, make sure you are using correct driver version.
C. Install cuDNN
1- Download cudnn tar file from url:
It requires registration. Chose version 5.1 which is recommended, in August 2017.
2- Install by running following commands:
tar -zxvf cudnn-8.0-linux-x64-v5.1.tgz
cd cuda
sudo cp include/* /usr/cuda-8.0/include/
sudo cp lib64/* /usr/local/cuda-8.0/lib64
D. Install libcupti
Run the following command.
sudo apt-get install libcupti-dev
E. Install GIT
1- Run command:
sudo apt install git
F. Install MKL
1- Install dependencies
sudo apt install cmake sudo apt install doxygen
2- Download and build sources
git clone https://github.com/01org/mkl-dnn.git cd mkl-dnn cd scripts && ./prepare_mkl.sh && cd .. mkdir -p build && cd build && cmake .. && make
3- Validate the build
make test
4- Install the library
sudo make install
For my case I need to add /usr/local/lib directory to library path to prevent the error “error while loading shared libraries: libmkldnn.so.0: cannot open shared object file: No such file or directory”:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
For details see:
G. Build Tensorflow
1- Install curl:
sudo apt install curl
2- Install BAZEL by running commands below. For further reference see: https://docs.bazel.build/versions/master/install-ubuntu.html#install-on-ubuntu
sudo apt-get install openjdk-8-jdk echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add - sudo apt-get update && sudo apt-get install bazel sudo apt-get upgrade bazel
3- Install required python packages
sudo apt-get install python-numpy python-dev python-pip python-wheel
4- Clone tensorflow repository
git clone https://github.com/tensorflow/tensorflow
5- Configure the installation
cd tensorflow
./configure
As guideline to configuration:
- Use default python installation
- Use default python library path
- Enable jemallaoc
- Enable cuda
- Use default CUDA version which should be 8.0
- Use default cuda installation path which should be /usr/local/cuda
- Specify cudnn version . I specified as 5.1.10
- Use default cudnn library path which should be /usr/local/cuda
- Specify cuda compute capability. For my gtx 1070 it is 6.1. For list of them see https://developer.nvidia.com/cuda-gpus
- Do not use clang compiler
- Use default gcc compiler
- Use default optimization option which is “-march=native”. It is said to be doing optimization according to CPU. Still during build I added more optimization flags.
6- Build tensorflow
bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.2 --config=cuda --config=mkl //tensorflow/tools/pip_package:build_pip_package
Now we can build the wheel.
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
7- Install Tensorflow
sudo pip install /tmp/tensorflow_pkg/tensorflow-1.3.0-cp27-cp27mu-linux_x86_64.whl
8- Verify the installation
Start python and run following command:
import tensorflow as tf
For more information see:
Alternative Installation instructions for tensorflow:
H. Install Keras
1- Install Dependencies
pip install numpy pip install pandas pip install matplotlib pip install tqdm pip install h5py pip install Pillow
2- Install Keras 2
pip install keras
I. Install FFMPEG
FFMEG is needed for video related tasks. Install by using following apt command.
sudo apt install ffmpeg
Comments
Post a Comment