Install Tensorflow GPU (CUDA 10.0) on Ubuntu 18.04

This article is mainly used to record my own installation process. It is not recommended to use in a production environment. For your convenience, please use those mature methods.

 

Please make sure that the 64-bit version of python is installed. TensorFlow does not support the 32-bit version.

 

1,Update and Upgrade your system:

sudo apt-get update 
sudo apt-get upgrade

2,Verify You Have a CUDA-Capable GPU:

lspci | grep -i nvidia

Please verify on Nvidia official website.

3,Verify You Have a Supported Version of Linux:

uname -m && cat /etc/*release

The x86_64 line indicates you are running on a 64-bit system which is supported by cuda 9.1

4,Install Dependencies:

sudo apt-get install build-essential 
sudo apt-get install cmake git unzip zip
sudo apt-get install python-dev python3-dev python-pip python3-pip

5,Install linux kernel header:

sudo apt-get install linux-headers-$(uname -r)

6,Install CUDA 10.0

Remove previous cuda installation:

sudo apt-get purge nvidia*
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /usr/local/cuda*

Install cuda :

Recommended reference to Nvidia official installation method

Official method:Nvidia official website (recommended use deb(network))

 

For Ubuntu 18.04:

sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" | sudo tee /etc/apt/sources.list.d/cuda.list

or

sudo apt-get update 
sudo apt-get -o Dpkg::Options::="--force-overwrite" install cuda-10-0 cuda-drivers

 

7,Reboot the system to load the NVIDIA drivers.

8,Open terminal

echo 'export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}' >> ~/.bashr
source ~/.bashrc
sudo ldconfig
nvidia-smi

Check driver version

Probably Driver Version:396.26

 

If you got nvidia-smi is not found then you have unsupported linux kernel installed.

 

You can check your cuda installation using following sample:

cuda-install-samples-10.0.sh ~
cd ~/NVIDIA_CUDA-10.0_Samples/5_Simulations/nbody
make
./nbody

9, Install cuDNN

Goto https://developer.nvidia.com/cudnn and download Login and agreement required.

I use this version: cuDNN v7.4.2 Library for Linux [ cuda 10.0]

Goto downloaded folder and in terminal perform following:

tar -xf cudnn-10.0-linux-x64-v7.4.2.20.tgz 
sudo cp -R cuda/include/* /usr/local/cuda-10.0/include
sudo cp -R cuda/lib64/* /usr/local/cuda-10.0/lib64

10,Install NCCL 2.3.5

Goto https://developer.nvidia.com/nccl/nccl-download and download Login and agreement required.

Goto downloaded folder and in terminal perform following:

tar -xf nccl_2.3.5-2+cuda10.0_x86_64.txz
cd nccl_2.3.5-2+cuda10.0_x86_64
sudo cp -R * /usr/local/cuda-10.0/targets/x86_64-linux/
sudo ldconfig

11,Install Dependencies

 

Use following if not in active virtual environment.

pip install -U --user pip six numpy wheel mock

pip3 install -U --user pip six numpy wheel mock
pip install -U --user keras_applications==1.0.5 --no-deps

pip3 install -U --user keras_applications==1.0.5 --no-deps
pip install -U --user keras_preprocessing==1.0.3 --no-deps

pip3 install -U --user keras_preprocessing==1.0.3 --no-deps

Use following if  in active virtual environment.

pip install -U pip six numpy wheel mock
pip install -U keras_applications==1.0.5 --no-deps
pip install -U keras_preprocessing==1.0.3 --no-deps
12,Configure Tensorflow from source:
Download bazel:
cd ~/
wget https://github.com/bazelbuild/bazel/releases/download/0.17.2/bazel-0.17.2-installer-linux-x86_64.sh
chmod +x bazel-0.17.2-installer-linux-x86_64.sh
./bazel-0.17.2-installer-linux-x86_64.sh --user
echo 'export PATH="$PATH:$HOME/bin"' >> ~/.bashrc

note:Only 0.17.2 version works in my enviorment.

Reload environment variables
source ~/.bashrc
sudo ldconfig
Start the process of building TensorFlow
cd ~/
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout r1.12
./configure
Give python path in
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3
Do you wish to build TensorFlow with Apache Ignite support? [Y/n]: Y

Do you wish to build TensorFlow with XLA JIT support? [Y/n]: Y

Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: N

Do you wish to build TensorFlow with ROCm support? [y/N]: N

Do you wish to build TensorFlow with CUDA support? [y/N]: Y

Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 9.0]: 10.0
Please specify the location where CUDA 10.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-10.0
Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7]: 7.4.2
Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-10.0]: /usr/local/cuda-10.0
Do you wish to build TensorFlow with TensorRT support? [y/N]: N
Please specify the NCCL version you want to use. If NCCL 2.2 is not installed, then you can use version 1.3 that can be fetched automatically but it may have worse performance with multiple GPUs. [Default is 2.2]: 2.3.5
Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 5.0] 5.0
Do you want to use clang as CUDA compiler? [y/N]: N
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: /usr/bin/gcc
Do you wish to build TensorFlow with MPI support? [y/N]: N
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: -march=native
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]:N

13, Build Tensorflow using bazel

bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

 

bazel-bin/tensorflow/tools/pip_package/build_pip_package tensorflow_pkg
Install TensorFlow
cd tensorflow_pkg

Use following if  in active virtual environment.

pip install tensorflow*.whl
Or you need to creative a virtual enviorment

 

14,Verify Tensorflow installation

python

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

 

ReferenceHow to install Tensorflow GPU with CUDA 10.0 for python on Ubuntu

Install TensorFlow(CPU) and Keras with anaconda on macOS Mojave(10.14)

According to the official website recommended install tensorflow with Anaconda.

1, Install anaconda

Anaconda official website

 

2, Create a virtual enviorment with anaconda

Open TensorFlow official website,Find Create a virtual environment (recommended) ,choose the third section conda

conda create -n venv pip python=3.6 # select python version

(You can omit pip python=3.6 here. Anaconda has already support 3.7 version)

source activate venv

pip install –ignore-installed –upgrade packageURL

(You can find packageURL here)

The code is:

pip install https://github.com/lakshayg/tensorflow-build/releases/download/tf1.12.0-macOS-mojave-ubuntu16.04-py2-py3/tensorflow-1.12.0-cp37-cp37m-macosx_10_13_x86_64.whl

 

3, Install Keras

pip install keras

 

Keras is now installed.

 

 

About CDN

Two years ago, I used Ali’s CDN service for a short time. After all, Ali’s advertising has never stopped. Because the implementation of the real-name system since last year, and Ali’s series of vices, I have moved all related services overseas. Since special situation of the domestic network, the response time more than 200ms.  It is natural to think of using the CDN service to optimize the speed of access, but there will be new problems. If you want to use the CN CDN, the website must have a record domestically, and the site can only use HTTP. Therefore, I start considering the foreign CDN service. For the same reason, foreign CDN do not have nodes in the main land, or they have to cooperates with a domestic service provider to provide nodes.

I recently chatted with a friend about the speed of access, so I consider to use free CDN, which is better than nothing, not to mention the security of the website itself. After the CDN is set, I test the response speed of each place is detected. The speed of foreign countries is obviously improved a lot. The basic response time will not exceed 5ms, and the slowest Sydney is only about 10ms. Unexpected domestically, although it is still very slow, the response is mostly around 150ms, but at least there are probably tens of ms improvement compared to before.

Establishing Guest Network Traffic Control with OpenWrt on Netgear R6300v2

This post is based on the NETGEAR router R6300 V2. It is not guaranteed to be feasible in other environments.

1, Flush OpenWrt firmware

Goto OpenWrt official website

Search Netgear R6300 v2ow1

Check support firmware

ow2

After downloading the firmware, log in to the router management page. Select “Advanced” – “Management” – “Firmware Upgrade”, upload the firmware and wait for about 5 minutes.

Note: The 5G drive of R6300 V2  is not open although Openwrt supports 802.11ac 5G network.

After the firmware is installed, log in to the router management page select Network-Interfaces.

Modify WAN parameters connection to the Internet.

Other wireless settings under the Network-Wifi option.

ow3

 

2, Configure the guest network and limit its bandwidth

Required package:

luci-app-sqm

sqm-scripts

You can find them in luci.

ow11

Configure the guest network after installation

 

Create a new interface

 

log in to the router management page-Network-Interfaces-Add new interface

I renamed it ‘GUEST’

Change the protocol to a static address

Protocol-Static address

Filling subnet mask

ipv4-netmask:255.255.255.0

ow12

Open DHCP service at the bottom of the page

ow13

Firewall settings choose lan

ow14

 

Configuring wireless for the guest network

 

Network-wifi

Choose the appropriate frequency band Add

Network settings choose Guest

ow15

 

Limit guest network bandwidth

Network-SQM QoS

Select the corresponding guest network name under the interface name option

 

Attention here

 

Download speed actually is upload speed

Upload speed is download speed

Enabled after configuration

 

Finally, go to Network-Wifi to open the guest network.