Ubuntu CUDA cuDNN TensorFlow Caffe

Ubuntu

Download Desktop

Create a bootable USB stick on Windows

Requirements

  • A 2G or larger USB stick/flash drive.
  • Microsoft Windows XP or later.
  • Refus(Download), a free and open source USB stick writing tool.
  • An Ubuntu ISO file.
  • Update && Upgrade
sudo apt update
sudo apt upgrade
  • Chromium
sudo apt install chromium-browser
  • vim
sudo apt install vim
  • The easiest way to install for Debian/Ubuntu based distributions is to download and install the .deb package (64-bit) either through the graphical software center if it’s available or through the command line with:
sudo dpkg -i <file>.deb
sudo apt install -f     # Install dependencies
  • The repository and key can also be installed manually with the following script:
    Then update the package cache and install the package using:
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
sudo apt install apt-transport-https
sudo apt update
sudo apt install code       # or code-insiders
sudo apt install ./teamviewer_13.x.yyy_[arch].deb
  • pinyin
sudo apt install ibus-pinyin
sudo reboot

Installing NVIDIA Graphics Drivers

  • 1.apt install
  • 2.run install

1. apt install

1.1 [Option]Add Graphic Drivers PPA

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update

1.2 Check Graphic Drivers Version

ubuntu-drivers devices

1.3 Installing

sudo apt install nvidia-version

1.4 Reboot and check

sudo reboot
sudo nvidia-smi
sudo nvidia-setting

2.run install

2.1 NVIDIA download drivers

2.2 Installing the NVIDIA Driver

  • 2.2.1 Before you Begin

Disable Nouveau driver

lsmod | grep nouveau

If yes:
Create a new file or edit an existing one

sudo vim /etc/modprobe.d/blacklist-nouveau.conf

The following two lines will need to be added:

blacklist nouveau
options nouveau modeset=0
sudo update-initramfs -u

Reboot your system and check

  • 2.2.2 Starting the Installer
cd yourdirectory
sudo sh NVIDIA-Linux-x86_64-390.77.run

2.3 Restart your system to ensure the graphics driver takes effect.

Installing CUDA

1.Pre-installation Actions

1.1 Verify You Have a CUDA-Capable GPU

lspci | grep -i nvidia

1.2 Verify You Have a Supported Version of Linux

uname -m && cat /etc/*release

You should see output similar to the following:

x86_64

1.3 Verify the System Has gcc Installed

gcc --version

If not:

sudo apt install gcc

1.4 Verify the System has the Correct Kernel Headers and Development Packages Installed

The version of the kernel your system is running can be found by running the following command:

uname -r

The kernel headers and development packages for the currently running kernel can be installed with:

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

1.5 Choose an Installation Method

The CUDA Toolkit can be installed using either of two different installation mechanisms: distribution-specific packages (RPM and Deb packages), or a distribution-independent package (runfile packages).
The distribution-independent package has the advantage of working across a wider set of Linux distributions, but does not update the distribution’s native package management system. The distribution-specific packages interface with the distribution’s native package management system.
It is recommended to use the distribution-specific packages, where possible.

1.6 Download the NVIDIA CUDA Toolkit

1.7 Handle Conflicting Installation Methods

  • Use the following command to uninstall a Toolkit runfile installation:
sudo /usr/local/cuda-X.Y/bin/uninstall_cuda_X.Y.pl
  • Use the following command to uninstall a Driver runfile installation:
sudo /usr/bin/nvidia-uninstall
  • Use the following commands to uninstall a RPM/Deb installation:
sudo apt --purge remove <package_name>
  • 2.Package Manager Installation(deb)
  • 3.Runfile Installation

2.Package Manager Installation

Ubuntu 16.04 x86_64 deb(local) Download

  • Install repository meta-data
sudo dpkg -i cuda-repo-ubuntu1604-9-2-local_9.2.148-1_amd64.deb
  • Installing the CUDA public GPG key
sudo apt-key add /var/cuda-repo-<version>/7fa2af80.pub
  • Update the Apt repository cache
sudo apt update
  • Install CUDA
sudo apt install cuda

3.Runfile Installation

3.1 Disable the Nouveau drivers

3.2 Reboot into text mode

Ctrl+Alt+F1
Stop the graphical interface

sudo service lightdm stop

3.3 Run the installer

sudo sh cuda_<version>_linux.run

3.4 Reboot the system to reload the graphical interface.

4.Post-installation Actions

4.1 Mandatory Actions

Environment Setup
The PATH variable needs to include /usr/local/cuda-9.2/bin
To add this path to the PATH variable:

sudo vim /etc/profile       # System variable
export PATH=/usr/local/cuda-9.2/bin${PATH:+:${PATH}}
source /etc/profile

In addition, when using the runfile installation method, the LD_LIBRARY_PATH variable needs to contain /usr/local/cuda-9.2/lib64 on a 64-bit system, or /usr/local/cuda-9.2/lib on a 32-bit system

export LD_LIBRARY_PATH=/usr/local/cuda-9.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

Tips:

  • Temporary variable
export PATH=/usr/local/cuda-9.2/bin${PATH:+:${PATH}}
  • User variable
sudo vim ./bashrc
source ./bashrc
  • System variable
sudo vim /etc/profile
source profile

4.2.1 Verify the Installation

  • 1 Verify the Driver Version
cat /proc/driver/nvidia/version
  • 2 Compiling the Examples

The version of the CUDA Toolkit can be checked

nvcc -V
cd ~/NVIDIA_CUDA-9.2_Samples
make

The resulting binaries will be placed under ~/NVIDIA_CUDA-9.2_Samples/bin.

  • 3 Running the Binaries
cd bin/x86_64/linux/release
./deviceQuery

ensures that the system and the CUDA-capable device are able to communicate correctly.

./bandwidthTest

cuDNN

1.Prerequisites

Ensure you meet the following requirements before you install cuDNN.

  • A GPU of compute capability 3.0 or higher. To understand the compute capability of the GPU on your system, see: CUDA GPUs.
  • If you are using cuDNN with a Volta GPU, version 7 or later is required.
  • One of the following supported Architecture - OS combinations:

    • On x86_64 (for installing cuDNN with debian files) - Ubuntu 14.04 or Ubuntu 16.04
    • On x86_64 (for installing tgz files) - Any Linux distribution
    • On POWER8/POWER9 - RHEL7.4
  • One of the following supported CUDA versions and NVIDIA graphics driver:

    • NVIDIA graphics driver R375 or newer for CUDA 8
    • NVIDIA graphics driver R384 or newer for CUDA 9
    • NVIDIA graphics driver R390 or newer for CUDA 9.2

1.1 Installing NVIDIA Graphics Drivers

1.2 Installing CUDA

2.Downloading cuDNN

3.Installing cuDNN on Linux

  • 3.1 Installing from a Tar File
  • 3.2 Installing from a Debian File

3.1 Installing from a Tar File

  • 1.Unzip the cuDNN package.
tar -xzvf cudnn-<version>-linux-x64-v7.tgz
  • 2.Copy the following files into the CUDA Toolkit directory.
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

3.2 Installing from a Debian File

  • 1.Install the runtime library, for example:
sudo dpkg -i libcudnn<version>amd64.deb
  • 2.Install the developer library, for example:
sudo dpkg -i libcudnn7-dev_7.0.3.11-1+cuda9.0_amd64.deb
  • 3.Install the code samples and the cuDNN Library User Guide, for example:
sudo dpkg -i libcudnn7-doc_7.0.3.11-1+cuda9.0_amd64.deb

4.Verifying

To verify that cuDNN is installed and is running properly, compile the mnistCUDNN sample located in the /usr/src/cudnn_samples_v7 directory in the debian file.
* 1.Copy the cuDNN sample to a writable path.

cp -r /usr/src/cudnn_samples_v7/ $HOME
  • 2.Go to the writable path.
cd  $HOME/cudnn_samples_v7/mnistCUDNN
  • 3.Compile the mnistCUDNN sample.
make clean && make
  • 4.Run the mnistCUDNN sample.
./mnistCUDNN

If cuDNN is properly installed and running on your Linux system, you will see a message similar to the following:

Test passed!

Tensorflow

pip3 install tensorflow-gpu

Caffe

1.Prerequisites

Caffe has several dependencies:

sudo apt install build-essential
  • CUDA is required for GPU mode.

    • library version 7+ and the latest driver version are recommended, but 6.* is fine too. 5.5, and 5.0 are compatible but considered legacy
  • BLAS via ATLAS, MKL, or OpenBLAS.

  • Boost >= 1.55
  • protobuf, glog, gflags, hdf5
sudo apt install libboost-all-dev
sudo apt install libprotobuf-dev libprotobuf-all-dev libprotobuf-compiler libgoogle-glog-dev libgflags-dev libhdf5-serial-dev

Optional dependencies:

  • OpenCV >= 2.4 including 3.0
  • IO libraries: lmdb, leveldb (note: leveldb requires snappy)
  • cuDNN for GPU acceleration (v6)
sudo apt install libopencv-dev
sudo apt install libsnappy-dev
sudo apt install liblmdb-dev libleveldb-dev

Pycaffe interfaces have their own natural needs.

  • For Python Caffe: Python 2.7 or Python 3.3+, numpy (>= 1.7), boost-provided boost.python

cuDNN Caffe: for fastest operation Caffe is accelerated by drop-in integration of NVIDIA cuDNN. To speed up your Caffe models, install cuDNN then uncomment the USE_CUDNN := 1 flag in Makefile.config when installing Caffe. Acceleration is automatic. The current version is cuDNN v6; older versions are supported in older Caffe.

CPU-only Caffe: for cold-brewed CPU-only Caffe uncomment the CPU_ONLY := 1 flag in Makefile.config to configure and build Caffe without CUDA. This is helpful for cloud or cluster deployment.

2.CUDA and BLAS

Caffe requires the CUDA nvcc compiler to compile its GPU code and CUDA driver for GPU operation. To install CUDA, go to the NVIDIA CUDA website and follow installation instructions there. Install the library and the latest standalone driver separately; the driver bundled with the library is usually out-of-date. Warning! The 331.* CUDA driver series has a critical performance issue: do not use it.

For best performance, Caffe can be accelerated by NVIDIA cuDNN. Register for free at the cuDNN site, install it, then continue with these installation instructions. To compile with cuDNN set the USE_CUDNN := 1 flag set in your Makefile.config.

Caffe requires BLAS as the backend of its matrix and vector computations. There are several implementations of this library. The choice is yours:

  • ATLAS: free, open source, and so the default for Caffe.
  • Intel MKL: commercial and optimized for Intel CPUs, with free licenses.

    1.Install MKL.
    2.Set up MKL environment (Details: Linux, OS X). Example: source /opt/intel/mkl/bin/mklvars.sh intel64
    3.Set BLAS := mkl in Makefile.config

  • OpenBLAS: free and open source; this optimized and parallel BLAS could require more effort to install, although it might offer a speedup.

    1.Install OpenBLAS
    2.Set BLAS := open in Makefile.config

sudo apt install libopenblas-dev

3.Python Caffe (optional)

The main requirements are numpy and boost.python (provided by boost). pandas is useful too and needed for some examples. You can install the dependencies with

for req in $(cat requirements.txt); do pip install $req; done

but we suggest first installing the Anaconda Python distribution, which provides most of the necessary packages, as well as the hdf5 library dependency.

To import the caffe Python module after completing the installation, add the module directory to you $PYTHONPATH by export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH or the like. You should not import the module in the caffe/python/caffe directory!

sudo vim /etc/profile
export PYTHONPATH=/home/user_name/caffe/python:$PYTHONPATH
source /etc/profile

Caffe’s Python interface works with Python 2.7. Python 3.3+ should work out of the box without protobuf support. For protobuf support please install protobuf 3.0 alpha (https://developers.google.com/protocol-buffers/). Earlier Pythons are your own adventure.

4.Compilation

Caffe can be compiled with either Make or CMake. Make is officially supported while CMake is supported by the community.

4.1 Compilation with Make

Configure the build by copying and modifying the example Makefile.config for your setup. The defaults should work, but uncomment the relevant lines if using Anaconda Python.

cp Makefile.config.example Makefile.config
# Adjust Makefile.config (for example, if using Anaconda Python, or if cuDNN is desired)
make all
make test
make runtest
  • For CPU & GPU accelerated Caffe, no changes are needed.
  • For cuDNN acceleration using NVIDIA’s proprietary cuDNN software, uncomment the USE_CUDNN := 1 switch in Makefile.config. cuDNN is sometimes but not always faster than Caffe’s GPU acceleration.
  • For CPU-only Caffe, uncomment CPU_ONLY := 1 in Makefile.config.

To compile the Python and MATLAB wrappers do make pycaffe and make matcaffe respectively. Be sure to set your MATLAB and Python paths in Makefile.config first!

Distribution: run make distribute to create a distribute directory with all the Caffe headers, compiled libraries, binaries, etc. needed for distribution to other machines.

Speed: for a faster build, compile in parallel by doing make all -j8 where 8 is the number of parallel threads for compilation (a good choice for the number of threads is the number of cores in your machine).

Now that you have installed Caffe, check out the MNIST tutorial and the reference ImageNet model tutorial.

4.2 CMake Build

In lieu of manually editing Makefile.config to configure the build, Caffe offers an unofficial CMake build thanks to @Nerei, @akosiorek, and other members of the community. It requires CMake version >= 2.8.7. The basic steps are as follows:

mkdir build
cd build
cmake ..
make all
make install
make runtest

猜你喜欢

转载自blog.csdn.net/XingpengLu/article/details/81878317