Skip to main content

Prepare a Ubuntu System for Deep Learning

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*

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

Popular posts from this blog

Obfuscating Spring Boot Projects Using Maven Proguard Plugin

Introduction Obfuscation is the act of reorganizing bytecode such that it becomes hard to decompile. Many developers rely on obfuscation to save their sensitive code from undesired eyes. Publishing jars without obfuscation may hinder competitiveness because rivals may take advantage of easily decompilable nature of java binaries. Objective Spring Boot applications make use of public interfaces, annotations which makes applications harder to obfuscate. Additionally, maven Spring Boot plugin creates a fat jar which contains all dependent jars. It is not viable to obfuscate the whole fat jar. Thus obfuscating Spring Boot applications is different than obfuscating regular java applications and requires a suitable strategy. Audience Those who use Spring Boot and Maven and wish to obfuscate their application using Proguard are the target audience for this article. Sample Application As the sample application, I will use elastic search synch application from my G...

Hadoop Installation Document - Standalone Mode

This document shows my experience on following apache document titled “Hadoop:Setting up a Single Node Cluster”[1] which is for Hadoop version 3.0.0-Alpha2 [2]. A. Prepare the guest environment Install VirtualBox. Create a virtual 64 bit Linux machine. Name it “ubuntul_hadoop_master”. Give it 500MB memory. Create a VMDK disc which is dynamically allocated up to 30GB. In network settings in first tab you should see Adapter 1 enabled and attached to “NAT”. In second table enable adapter 2 and attach to “Host Only Adaptor”. First adapter is required for internet connection. Second one is required for letting outside connect to a guest service. In storage settings, attach a Linux iso file to IDE channel. Use any distribution you like. Because of small installation size, I choose minimal Ubuntu iso [1]. In package selection menu, I only left standard packages selected.  Login to system.  Setup JDK. $ sudo apt-get install openjdk-8-jdk Install ssh and pdsh, if...

Java: Cost of Volatile Variables

Introduction Use of volatile variables is common among Java developers as a way of implicit synchronization. JIT compilers may reorder program execution to increase performance. Java memory model[1] constraints reordering of volatile variables. Thus volatile variable access should has a cost which is different than a non-volatile variable access. This article will not discuss technical details on use of volatile variables. Performance impact of volatile variables is explored by using a test application. Objective Exploring volatile variable costs and comparing with alternative approaches. Audience This article is written for developers who seek to have a view about cost of volatile variables. Test Configuration Test application runs read and write actions on java variables. A non volatile primitive integer, a volatile primitive integer and an AtomicInteger is tested. Non-volatile primitive integer access is controlled with ReentrantLock and ReentrantReadWriteLock  to c...