步骤简述:
1.安装GPU驱动(系统适配,不采取手动安装的方式)
2.安装依赖(cuda依赖库,caffe依赖)
3.安装cuda
4.安装cudnn(只是复制文件加链接,不需要编译安装的过程)
5.安装caffe
6.安装pycaffe
7.安装matcaffe
获取资源
cuda8.0 , cudnn ,caffe-master (暂未提供,网上下载)
caffe-master:
git clone https://github.com/BVLC/caffe.git
1.安装GPU(系统适配,不采取手动安装的方式)
(通过下载nvidia驱动后手动安装,禁核显驱动的方式容易导致重启后循环登录,不建议采用该方式。)
关闭bios里的secure boot(否则无法使用显卡驱动)
设置----软件和更新----附加驱动----使用NVIDIA....(专有)----应用更改----(之后为半小时的等待)-----提示重新启动
终端中输入
nvidia-smi
返回以下结果则说明显卡安装完毕。
2.安装依赖(GPU依赖库,caffe依赖)(opencv不用编译安装,apt-get安装即可)
sudo apt-get install vim python-pip git build-essential python-opencv libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler libopenblas-dev liblapack-dev libatlas-base-dev libgflags-dev libgoogle-glog-dev liblmdb-dev libboost-all-devfreeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
3.安装cuda
进入到有cuda安装文件的目录,执行安装文件(确定该目录下有cuda_8.0.61_375.26_linux.run文件)
sudo sh ./cuda_8.0.61_375.26_linux.run
之后会有安装提示,第一步选择n,即不安装nvidia驱动(因为之前已经安装过了),其他选项都选y以及默认安装目录就行了。
如果安装完成后还提示有缺失的库,就用apt-get安装相应的库,具体库的名字在网上能找到。
安装结束后,终端输入
sudo nvcc -V
显示如下结果则表示安装完成
测试cuda sample
cd /usr/local/cuda-7.5/samples/1_Utilities/deviceQuery
make -j4
./deviceQuery
显示如下结果则表示cuda安装已经完成
4.安装cudnn(只是复制文件加链接,不需要编译安装的过程)
tar -zxvf cudnn-8.0-linux-x64-v5.1.tgz
cd cuda
sudo cp lib64/lib* /usr/local/cuda/lib64/
sudo cp include/cudnn.h /usr/local/cuda/include/
cd /usr/local/cuda/lib64/
sudo chmod +r libcudnn.so.x.x.x # x替换为自己查看.so的版本 ,如libcudnn.so.5.1.10
sudo ln -sf libcudnn.so.x.x.x libcudnn.so.x
sudo ln -sf libcudnn.so.x libcudnn.so
sudo ldconfig
sudo vim /etc/profile
添加环境变量如下:
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
5.安装caffe
cd ~/caffe-master #进入到caffe-master的目录,路径根据你的caffe-master的实际路径而改变
cp Makefile.config.example Makefile.config
vim Makefile.config
Makefile.config 注意修改红色部分
## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!
# cuDNN acceleration switch (uncomment to build with cuDNN).
# USE_CUDNN := 1
# CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := 1
# uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0
# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
# You should not set this flag if you will be reading LMDBs with any
# possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1
# Uncomment if you're using OpenCV 3
# OPENCV_VERSION := 3
# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++
# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr
# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
# For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
-gencode arch=compute_20,code=sm_21 \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 \
-gencode arch=compute_61,code=compute_61
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas
# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib
# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app
# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
# ANACONDA_HOME := $(HOME)/anaconda
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
# $(ANACONDA_HOME)/include/python2.7 \
# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include
# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
# /usr/lib/python3.5/dist-packages/numpy/core/include
# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib
# PYTHON_LIB := $(ANACONDA_HOME)/lib
# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import