码迷,mamicode.com
首页 > 系统相关 > 详细

Caffe+Ubuntu14.04+CUDA7.5安装笔记

时间:2016-04-17 22:58:19      阅读:698      评论:0      收藏:0      [点我收藏+]

标签:

ubuntu 14.04安装




cuda7.5安装

  1. cuda7.5下载:地址 https://developer.nvidia.com/cuda-downloads
    文件: cuda_7.5.18_linux.run
  2. 登录界面前按Ctrl+Alt+F1进入命令提示符 【禁用nouveau驱动】
  3. 执行命令: sudo vi /etc/modprobe.d/blacklist-nouveau.conf
  4. 输入以下内容

    blacklist nouveau
    options nouveau modset=0
    

    最后保存退出(:wq)

  5. 执行命令: sudo update-initramfs -u
    再执行命令: lspci | grep nouveau 查看是否有内容
    如果没有内容 ,说明禁用成功,如果有内容,就重启一下再查看
    sudo reboot
    重启后,进入登录界面的时候,不要登录进入桌面,直接按Ctrl+Alt+F1进入命令提示符。

  6. 重启后,登录界面时直接按Ctrl+Alt+F1进入命令提示符

  7. 安装依赖项:
    sudo service lightdm stop
    sudo apt-get install g++
    sudo apt-get install git
    sudo apt-get install freeglut3-dev

  8. 假设cuda_7.5.18_linux.run位于 ~ 目录,切换到~目录: cd ~

  9. 执行命令: sudo sh cude_7.5.18_linux.run

  10. 安装的时候,要让你先看一堆文字(EULA),我们直接不停的按空格键到100%,然后输入一堆accept,yes,yes或回车进行安装。安装完成后,重启,然后用ls查看一下:
    ls /dev/nvidia*
    会看到/dev目录下生成多个nvidia开头文件(夹)
    或者输入命令: sudo nvcc –version 会显示类似以下信息

     dl@dl-Z170X-Gaming-3:~$ nvcc --version
    nvcc: NVIDIA (R) Cuda compiler driver
    Copyright (c) 2005-2015 NVIDIA Corporation
    Built on Tue_Aug_11_14:27:32_CDT_2015
    Cuda compilation tools, release 7.5, V7.5.17
  11. 配置环境变量
    执行命令: sudo vi /etc/profile
    文件底部添加以下内容:

    export PATH=/usr/local/cuda-7.5/bin:$PATH
    export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64:$LD_LIBRARY_PATH
  12. 编译samples
    安装成功后在~目录下可以看到一个NVIDIA_CUDA-7.5_Samples文件夹,切换到目录
    输入sudo make, 大概等个十多分钟后就会把全部的samples编译完毕。生成的可执行文件位于
    NVIDIA_CUDA-7.5_Samples/bin/x86_64/linux/release 目录下
    比如运行 ./nbody可以看到以下demo
    技术分享


cuda安装过程中遇到的问题

  1. 在执行命令: sudo apt-get install g++ 时出现以下错误
    g++ : Depends: g++-4.8 (>= 4.8.2-5~) but it is not going to be installed
  2. 是因为ubuntu 14.04的源过旧或不可访问导致,可以通过更新源解决。

  3. 首先,备份原始源文件source.list
    sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup

  4. 然后
    sudo gedit /etc/apt/source.list
    在文件尾部添加以下内容

    deb http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
    deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
    deb http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
    deb http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
    deb http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
    deb-src http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
    deb-src http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
    deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
    deb-src http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
    deb-src http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
  5. 最后 sudo apt-get update







安装caffe

  1. 下载caffe:执行命令: sudo git clone https://github.com/BVLC/caffe.git
  2. 安装依赖项:

    sudo apt-get install libatlas-base-dev
    sudo apt-get install libprotobuf-dev
    sudo apt-get install libleveldb-dev
    sudo apt-get install libsnappy-dev
    sudo apt-get install libopencv-dev
    sudo apt-get install libboost-all-dev
    sudo apt-get install libhdf5-serial-dev
    sudo apt-get install libgflags-dev
    sudo apt-get install libgoogle-glog-dev
    sudo apt-get install liblmdb-dev
    sudo apt-get install protobuf-compiler

  3. 编译caffe
    cd ~/caffe
    sudo cp Makefile.config.example Makefile.config
    make all

  4. 配置运行环境
    sudo vi /etc/ld.so.conf.d/caffe.conf
    添加内容:
    /usr/local/cuda/lib64

  5. 更新配置
    sudo ldconfig
  6. caffe测试,执行以下命令:
    cd ~/caffe
    sudo sh data/mnist/get_mnist.sh
    sudo sh examples/mnist/create_mnist.sh
    最后测试:
    sudo sh examples/mnist/train_lenet.sh

运行结果如下:
技术分享





其他依赖项

我们查看caffe目录下 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 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_50,code=compute_50

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := mkl
# 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)/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 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

# 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

# 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

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 ?= @


可以看到诸如

# cuDNN acceleration switch (uncomment to build with cuDNN).
# USE_CUDNN := 1

# Uncomment if you‘re using OpenCV 3
# OPENCV_VERSION := 3

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas

都是使用默认的设置,我们可以安装其他依赖项提高caffe运行效率



opencv3.0安装

  1. github上有人写好完整的运行脚本自动下载opencv,编译,安装,配置等

  2. Caffe + Ubuntu 15.04 + CUDA 7.5 新手安装配置指南 作者 Xin-Yu Ou(欧新宇) 可以到他的网盘中下载
    PS:为了方便大家使用,我提供一个百度云盘,用于分享部分安装过程中需要用到的软件包和链接地址(所有软件包仅供学术交流使用,请大家尽量去官网下载。)。百度云盘链接: http://pan.baidu.com/s/1qX1uFHa 密码:wysa

  3. 在Install-OpenCV-master文件夹中包含安装各个版本opencv脚本

  4. 切换到目录执行:
    sudo sh Ubuntu/dependencies.sh
    安装依赖项

  5. 执行opencv3.0安装脚本
    sudo sh Ubuntu/3.0/opencv3_0_0.sh
    等待安装完成即可

  6. 修改Makefile.config

    
    # Uncomment if you‘re using OpenCV 3
    
    OPENCV_VERSION := 3
  7. (可选)opencv3.1已经发布,如果要安装最新的opencv3.1,我们可以先执行
    sudo sh get_latest_version_download_file.sh
    获取最新的地址,然后更新opencv3_0_0.sh中的下载地址,同时需要修正文件名等

    arch=$(uname -m)
    if [ "$arch" == "i686" -o "$arch" == "i386" -o "$arch" == "i486" -o "$arch" == "i586" ]; then
    flag=1
    else
    flag=0
    fi
    echo "Installing OpenCV 3.0.0"
    mkdir OpenCV
    cd OpenCV
    echo "Removing any pre-installed ffmpeg and x264"
    sudo apt-get -y remove ffmpeg x264 libx264-dev
    echo "Installing Dependenices"
    sudo apt-get -y install libopencv-dev
    sudo apt-get -y install build-essential checkinstall cmake pkg-config yasm
    sudo apt-get -y install libtiff4-dev libjpeg-dev libjasper-dev
    sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev
    sudo apt-get -y install python-dev python-numpy
    sudo apt-get -y install libtbb-dev
    sudo apt-get -y install libqt4-dev libgtk2.0-dev
    sudo apt-get -y install libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev
    sudo apt-get -y install x264 v4l-utils ffmpeg
    sudo apt-get -y install libgtk2.0-dev
    echo "Downloading OpenCV 3.0.0"
    wget -O opencv-3.0.0.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/3.0.0/opencv-3.0.0.zip/download
    echo "Installing OpenCV 3.0.0"
    unzip opencv-3.0.0.zip
    cd opencv-3.0.0
    mkdir build
    cd build
    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
    make -j8
    sudo make install
    sudo sh -c ‘echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf‘
    sudo ldconfig
    echo "OpenCV 3.0.0 ready to be used"

安装opencv3遇到的问题

  1. 在执行
    sudo sh Ubuntu/3.0/opencv3_0_0.sh
    出现有个地方一直卡住了,显示在下载一个文件: ippicv_linux_20141027.tgz
    因为墙的原因,这个文件无法下载下来
  2. [其他文档] ippicv_linux_20141027.tgz 处下载文件 ippicv_linux_20141027.tgz

  3. 下载后拷贝到opencv/3rdparty/ippicv/downloads/linux-8b449a536a2157bcad08a2b9f266828b/ 目录下即

  4. http://stackoverflow.com/questions/25726768/opencv-3-0-trouble-with-installation



安装BLAS——选择MKL

  1. 首先下载 MKL(Intel(R) Parallel Studio XE Cluster Edition for Linux 2016)
    网址: https://software.intel.com/en-us/intel-education-offerings
    Caffe + Ubuntu 15.04 + CUDA 7.5 新手安装配置指南 作者 Xin-Yu Ou(欧新宇) 可以到他的网盘中下载, 需要自己申请序列号
  2. 下载完成后: parallel_studio_xe_2016.tgz

  3. 执行以下命令:
    $ tar zxvf parallel_studio_xe_2016.tar.gz

    $ chmod a+x parallel_studio_xe_2016 -R

    $ sh install_GUI.sh

  4. 环境配置:
    $ sudo gedit /etc/ld.so.conf.d/intel_mkl.conf
    然后添加以下内容

    /opt/intel/lib/intel64
    /opt/intel/mkl/lib/intel64
    

    配置生效: sudo ldconfig -v
    安装MKL完成

  5. 修改Makefile.config

        # BLAS choice:
        # atlas for ATLAS (default)
        # mkl for MKL
        # open for OpenBlas
        BLAS := mkl





cuDNN安装

  1. cudnn下载
    下载地址:https://developer.nvidia.com/cudnn
    或者到网盘: http://pan.baidu.com/s/1bnOKBO 下载
    下载相应文件cudnn-7.0-linux-x64-v4.0-rc.tgz, 放到~根目录下

  2. 切换到~目录,执行命令

    sudo tar xvf cudnn-7.0-linux-x64-v4.0-rc.tgz
    cd cuda/include
    sudo cp *.h /usr/local/include/
    cd ../lib64
    sudo cp lib* /usr/local/lib/
    cd /usr/local/lib
    sudo chmod +r libcudnn.so.4.0.4
    sudo ln -sf libcudnn.so.4.0.4 libcudnn.so.4
    sudo ln -sf libcudnn.so.4 libcudnn.so
    sudo ldconfig
  3. 修改Makefile.config

    
    # cuDNN acceleration switch (uncomment to build with cuDNN).
    
    USE_CUDNN := 1



重新编译测试caffe

  1. 编译

    sudo make clean
    sudo make all

  2. sample测试: ( 比不使用cudnn快很多)
    sh data/mnist/get_mnist.sh
    sh examples/mnist/create_mnist.sh

  3. 我们可以将迭代次数增加到50000次
    sudo gedit examples/mnist/lenet_solver.prototxt
    修改max_iter: 50000
    最后:
    sh examples/mnist/train_lenet.sh
    技术分享










其他

  1. Vi编辑命令 常用vi编辑器命令行
A:当前行的尾部追加内容

i:游标前插入内容

I:游标后插入内容

o:在鼠标所在行的下面添加内容

O:在鼠标所在行的上面添加内容

ESC:退出编辑模式

Ctrl-T:移动到下一个tab

Backspace:向后移动一个字符

Ctrl-U:删除当前

cw:删除游标所在的字符,然后进入编辑模式

cc:删除游标所在的行,然后进入编辑模式

C:删除从游标所在的位置到行尾的字符,然后进入编辑模式

dd:删除当前行

ndd:删除第n行

D:删除当前行游标所在的位置后面的字符

dw:删除邮编所在的字符

d}:删除当前段剩余的字符

d^:删除游标前到行首的字符

c/pat:删除游标后面到第一次匹配字符间的内容

dn:删除游标后面到下一个匹配字符间的内容

dfa:删除当前行游标到匹配字符间的内容(匹配的字符也将被删)

dta:删除当前行游标到匹配字符间的内容(匹配的字符不被删)

dL:删除从游标到屏幕的最后一行之间的内容

dG:删除从游标到文件末尾之间的内容
J:连结上下两行的内容

p:在游标后面插入buffer中的内容

P:在游标前面插入buffer中的内容

rx:用x替换字符

Rtext:用text从游标开始处进行替换

u:撤销最后的改变

U:还原当前行的内容

x:向后删除游标所在位置的字符

X:向前删除游标前面的字符

nX:删除前面的n个字符,游标所在的字符将不会被删

.:还原最后的改变

~:反转字母的大小写

y:拷贝当前行到新的buffer

yy:拷贝当前行

"xyy:拷贝当前行的buffer名为x的buffer

ye:拷贝当单词的末尾



  1. 搜狗输入法安装
    Ubuntu14.04安装搜狗输入法

  2. im-config 然后 ibus选取fcitx

  3. fcitx-config-gtk3




参考资料

  1. Caffe学习系列(1):安装配置ubuntu14.04+cuda7.5+caffe+cudnn
  2. Caffe + Ubuntu 15.04 + CUDA 7.5 新手安装配置指南
  3. ubuntu 14.04 install g++问题"g++:Depends:g++-4.8(>= 4.8.2-5
  4. ippicv_linux_20141027.tgz
  5. http://stackoverflow.com/questions/25726768/opencv-3-0-trouble-with-installation

Caffe+Ubuntu14.04+CUDA7.5安装笔记

标签:

原文地址:http://blog.csdn.net/zengdong_1991/article/details/51174044

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!