安装 NVIDIA 显卡驱动
进入Ctrl+Alt+F1 终端界面
sudo service lightdm stop
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get -y install nvidia-375
sudo apt-get -y install mesa-common-dev freeglut3-dev
sudo service lightdm start
sudo reboot
离线安装
先下载NVIDIA显卡驱动,再安装
//这里需要注意,自己的显卡类型
我的GTX770
选择 GeForce–700Series–GTX770–Linux64bit
下载到 NVIDIA-Linux-x86_64-384.98.run
sudo vim /etc/modprobe.d/blacklist-nouveau.conf
在文件的结尾添加 blacklist nouveau
sudo apt-get -y update
sudo apt-get -y upgrade
sudo reboot
在Ctrl+Alt+F1
sudo service lightdm stop
sudo chomd 777 NVIDIA-Linux-x86_64-384.98.run
./NVIDIA-Linux-x86_64-384.98.run
sudo service lightdm start
sudo reboot
查看是否安装成功
lsmod | grep nouveau 没有输出说明已经禁用系统的nouveau
nvidia-settings
nvidia-smi 出现信息,说明已经安装成功
安装CUDA
2、安装
sudo sh cuda_8.0.61_375.26_linux.run
出现文字后,文字很多,直接一次Ctrl+C 然后输入accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26? 输入 n ,因为刚才已经安装过了
其他的安装都选择默认和是就可以了
3、配置环境变量
在 .bashrc文件结尾添加
export PATH="$PATH:/usr/local/cuda-8.0/bin"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib64/"
source ~/.bashrc && sudo ldconfig
4、测试CUDA
cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
sudo make
sudo ./deviceQuery
如果显示一些关于 GPU 的信息,则说明安装成功
安装cuDNN
下载 cuDNN https://developer.nvidia.com/cudnn
sudo tar -zxvf ./cudnn-8.0-linux-x64-v6.0.tgz
cd cuda
sudo cp include/cudnn.h /usr/local/cuda/include
sudo cp lib64/lib* /usr/local/cuda/lib64/
安装 OpenCV3.2
安装依赖
sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff4-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine-dev libgstreamer0.10-dev libgstreamer-pluginsbase0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip创建工作目录
mkdir -p ~/src/opencv && cd ~/src/opencv
下载 opencv3.2.0 并解压
wget
mv 3.2.0 opencv-3.2.0.zip && unzip opencv-3.2.0.zip
下载 opencv_contrib3.2.0 并解压(这是一些附加的模块,两个版本要一致)
wget
mv 3.2.0 opencv_contrib-3.2.0.zip && unzip opencv_contrib-3.2.0.zip
配置编译和安装
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-3.2.0/modules/ ../opencv-3.2.0
make -j8
sudo make install
配置环境变量:
(1)打开文件/etc/ld.so.conf.d/opencv.conf 加入: /usr/local/lib
(2)更新库目录 sudo ldconfig
(3)打开文件/etc/bash.bashrc 加入:
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
安装NCCL (多GPU情况)
git clone https://github.com/NVIDIA/nccl.git
cd nccl
make CUDA_HOME=/usr/local/cuda-8.0/ test
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./build/lib
./build/test/single/all_reduce_test 10000000
sudo make PREFIX=/usr/local/nccl install
添加环境变量到 ~/.bashrc
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/nccl/lib/"
使环境变量生效:
source ~/.bashrc && sudo ldconfig
安装OpenBLAS 默认配置
git clone https://github.com/xianyi/OpenBLAS.git
cd OpenBLAS/
(注意 make 不要断网,需要下载安装包)
make
sudo make PREFIX=/usr/local/OpenBLAS install
添加环境变量到 ~/.bashrc
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/OpenBLAS/lib/"
使环境变量生效:
source ~/.bashrc && sudo ldconfig
安装NVcaffe
(1)下载 Caffe:
git clone https://github.com/NVIDIA/caffe.git ./NVcaffe
(2)拷贝 Makefile.config:
cp Makefile.config.example Makefile.config
(3)修改 Makefile.config 文件:
sudo gedit Makefile.configa. 若使用 cudnn,则将#USE_CUDNN := 1 的#去掉
b. 若使用 nccl,则将#USE_NCCL := 1 的#去掉,并且在下面添加
NCCL_INCLUDE := /usr/local/nccl/include
NCCL_LIB := /usr/local/nccl/lib
并将$(NCCL_INCLUDE)
和$(NCCL_LIB)
分别加入 INCLUDE_DIRS 和 LIBRARY_DIRS
c. 若使用的 opencv 版本是 3 的,则将#OPENCV_VERSION := 3 的#去掉,并修改数字为 3
d. 默认使用 blas 修改 BLAS_INCLUDE 和 BLAS_LIB 为上一步的安装目录
e. 若要使用 python 来编写 layer,则将#WITH_PYTHON_LAYER := 1 前#去掉,我们需要 Python(4)安装相关依赖项:
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install –no-install-recommends libboost-all-dev
sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev(5)**Ubuntu16.04 的 **gcc 版本 是 5.4 过高,解决办法:
sudo gedit /usr/local/cuda/include/host_config.h
搜索:
error – unsupported GNU version! gcc versions later than 5 are not supported!
修改为:
//#error – unsupported GNU version! gcc versions later than 5 are not supported!
(6)直接编译可能会报错,atal error: caffe/proto/caffe.pb.h: No such file
解决办法如下:
首先进入 caffe 目录,执行下面命令
protoc src/caffe/proto/caffe.proto –cpp_out=.
mkdir include/caffe/proto
mv src/caffe/proto/caffe.pb.h include/caffe/proto
(7)编译 Caffe:
make all –j4
make test –j4
make runtest –j4(8)最后编译 Python 接口
l 安装 Python 依赖库
sudo apt-get install python-numpy python-scipy python-matplotlib python-sklearn python-skimage python-h5py python-protobuf python-leveldb python-networkx python-nose python-pandas python-gflags cython ipython python-yaml python-pipsudo pip install –upgrade pip
for req in $(cat python/requirements.txt); do sudo pip install $req; done
l 修改环境变量:
将 caffe 目录下的 Python 目录加入 ~/.bashrc 文件 ,如下:
export PYTHONPATH=”$PYTHONPATH:/home/username/work/NVcaffe/python”
使环境变量生效:
source ~/.bashrc && sudo ldconfig
l 编译 python 接口
在 NVcaffe 目录下执行命令:
make pycaffe
make distribute
make pytest
l 查看 python 接口是否编译成功
输入 python 进入 python shell 输入 import sys 和 import caffe 没有报错就成功了。
参考文档
Ubuntu16.04+双TitanX+CUDA8.0+CUDNN5.1
error
在编译NVcaffe时,make all make test通过了,make runtest出错了
电脑的显卡太弱,CUDA Capability是2.1,而官方的cudnn加速是不支持3.0以下的版本的,因此只能在Makefile.config中注释掉USE_CUDNN这行,重新执行以下 make clean make all -j12 make test -j12 make runtest -j12