ubuntu16.10+cuda8.0+cudnn+caffe+opencv3.2+anaconda2

ubuntu我的电脑是机械革命X7TI:i7-6700+GTX1060

一、Ubuntu16.10系统安装

这一部分接触过ubuntu系统的应该比较熟悉,网上也有很多可以参考的例子,就不再赘述。另外,我是在一个SSD固态硬盘上单独安装的系统,之前在台式机上也是这么实现的,感觉这样和windows双系统故障会少些。
二、显卡驱动与cuda安装
1、显卡驱动安装

安装完ubuntu16.04系统之后,直接更新系统并重启。在多显卡的笔记本中,可能需要在BIOS系统里选择”自由选择显卡“,这样系统才能识别nvidia的显卡,并进行驱动更新。我这里是运用ppa更新的最新驱动,使用起来能够得到挺好的体验,并能够实现双显卡的自由切换。UEFI格式的没试过。直接用BIOS装的双系统。

需要输入用户密码,并确认链接源。之后刷新软件库并安装最新的驱动,在命令行输入:

sudoaptgetupdate sudo apt-get install nvidia-367

由于联想笔记本的UEFI保护,会拒绝第三方的驱动,因此需要关闭该保护,关闭之后重启能够正常驱动nvidia,并能够进行双显卡的切换。
安装完成之后,可以通过系查看系统属性,看是否是nvidia的显卡。另外,也可以通过下面命令看是否安装成功:

nvidiasettings nvidia-smi

2、cuda8.0 安装与配置

在安装之前,我想说,一定要注意GCC地版本。最好用gcc-5,g++-5。不然你将用ubuntu16.10自带的gcc-6陷入无尽的make错误之中。

$ cd /usr/bin
$ apt-get install gcc-5 g++-5
$ rm gcc
$ rm g++
$ ln -s gcc-5 gcc
$ ln -s g++-5 g++

首先下载安装文件。下载网址:https://developer.nvidia.com/cuda-downloads

有deb文件和run文件。

建议用deb文件进行安装。以下我对两种安装方式均进行介绍。

run文件安装:

下载完成cd进入目录

chmod 777 cuda_8.0.18_linux.run     #获取文件权限 sudo ./cuda_7.5.18_linux.run –override #执行文件安装

需要注意地是第一次或者是第二至让选择是否覆盖显卡驱动需要选no。

deb文件安装方法:

$ sudo dpkg -i cuda-repo.deb
$ sudo apt-get update`这里写代码片`
$ apt-get install cuda

然后修改环境变量

$ cd ~/.bashrc

在末尾加上
export PATH=/usr/local/cuda-8.0/bin PATH:+:$PATHexportLDLIBRARYPATH=/usr/local/cuda8.0/lib64 {LD_LIBRARY_PATH:+:{LD_LIBRARY_PATH}}  
export CUDA_HOME=“/usr/local/cuda:
CUDA_PATH”

$gedit /etc/ld.so.conf.d/cuda.conf

加上
/usr/local/cuda/lib64

安装完后

$ cd /usr/local/cuda/samples

makeall cd /usr/local/cuda/samples/1_Utilities/deviceQuery
$ .deviceQuery
会显示GPU相关信息:
*./deviceQuery Starting…
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: “GeForce GTX 1060”
CUDA Driver Version / Runtime Version 8.0 / 8.0
CUDA Capability Major/Minor version number: 6.1
Total amount of global memory: 6073 MBytes (6367739904 bytes)
(10) Multiprocessors, (128) CUDA Cores/MP: 1280 CUDA Cores
GPU Max Clock rate: 1671 MHz (1.67 GHz)
Memory Clock rate: 4004 Mhz
Memory Bus Width: 192-bit
L2 Cache Size: 1572864 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 2048
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 2 copy engine(s)
Run time limit on kernels: Yes
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
Device supports Unified Addressing (UVA): Yes
Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 8.0, CUDA Runtime Version = 8.0, NumDevs = 1, Device0 = GeForce GTX 1060
Result = PASS*

至此CUDA安装成功

三、安装cudnn
下载cudnn。只需要注册nvidia的帐号,然后填写问卷就可以下载了。
tarzxvfcudnn7.5tab cd cuda
cplib64/lib/usr/local/cuda/lib64/ cp include/cudnn.h /usr/local/cuda/include/

接下来更新cudnn库地软链接

cd/usr/local/cuda/lib64 sudo chmod +r libcudnn.so.5.0.10
sudolnsflibcudnn.so.5.0.10libcudnn.so.5 sudo ln -sf libcudnn.so.5 libcudnn.so
$ sudo ldconfig

接下来安装blas
$apt-get install libopenblas-dev

四、安装OPENCV3.2+opencv_contrib
下载opencv:

$git clone https://github.com/opencv/opencv.git

下载opencv_contrib:

$git clone https://github.com/opencv/opencv_contrib.git

在opencv目录里创建build文件夹
cmakeguibuildVPNbuild sudo make
$ make install

五、安装caffe
sudoaptgetinstallygit sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudoaptgetinstallynoinstallrecommendslibboostalldev sudo apt-get install -y libatlas-base-dev
sudoaptgetinstallypythondev sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev
$git clone https://github.com/bvlc/caffe.git
cdcaffe mv Makefile.config.example 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.
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 := open
# 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/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)/anaconda2
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 numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib

# Uncomment to support layers written in Python (will link against Python libs)
# WITH_PYTHON_LAYER := 1

# Whatever else you find you need goes here.
#INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
#LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial   
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial  

# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib

# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1

# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1

# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute

# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1

# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0

# enable pretty build (comment to see full commands)
Q ?= @

然后修改Makefile
改 NVCCFLAGS += -ccbin= (CXX)XcompilerfPIC (COMMON_FLAGS)
为 NVCCFLAGS += -D_FORCE_INLINES -ccbin= (CXX)XcompilerfPIC (COMMON_FLAGS)

makeall make test
$make runtest

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值