GPU+Cuda8.0+cudnn8+OpenCv2.4.13+Caffee 安装教程嘎嘎

来源:互联网 发布:淘宝保存的图片找不到 编辑:程序博客网 时间:2024/05/21 07:50

 

1 安装CUDA准备工作

1.1.检查自己的GPU是否是CUDA-capable
在终端中输入:

lspci| grep -i nvidia

,会显示自己的NVIDIA GPU版本信息
去CUDA的官网查看自己的GPU版本是否在CUDA的支持列表中
https://developer.nvidia.com/cuda-gpus

 

2、查看Linux发行版本,x86_64(64)??

  # uname--help         /**  uname -m && cat/etc/*release   **/

3、检查gcc是否安装

  # gcc -version

 如果没有安装需要  # yum install gccgcc-c++

4、检查是否正确安装kernel headers

  #uname -r  /**这是Kernelheaders的版本,必须在安装cuda驱动之前安装完成**/

  #yum install kernel-devel-$(uname -r) kernel-headers-$(uname -r)

 

在安装之前。注意:安装过程需要root用户权限

 

1.2, 安装

下载run 文件

chmod +x  XX.run

init 3 

sh  ./xx.run

 

选择
Do you accept the previously read EULA?
accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64
361.62?
(y)es/(n)o/(q)uit: y

Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: y
Enter Toolkit Location
[ default is /usr/local/cuda-8.0 ]:
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y
Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: y
Enter CUDA Samples Location

 

 

安装完成,但是缺少一些库。

2) 安装所缺少的库
sudo apt-get install freeglut3-dev build-essential libx11-dev
libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa
libglu1-mesa-dev

安装完成。

Missingrecommended library: libGLU.so

yum install freeglut-devel
Missing recommended library: libX11.so

yum install libXqq-devel--nogpg
Missing recommended library: libXi.so

yum install libXi-devel.x86_64
Missing recommended library: libXmu.so

yum install libXmu-devel

libXilibXmu 安装失败, 可忽略

查询网址:

http://rpmfind.net/linux/rpm2html/search.php?query=libXmu&submit=Search+...&system=&arch=

 

 

Issue1  Onno!Something has gone wrong!

解决:安装run时没有选Install NVIDIA AcceleratedGraphics Driver for Linux-x86_64      Y

1.检查路径 ~/dev下 有无存在名为 nvidia*(以nvidia开头)的多个文件(device files)
若无,安装错误,见解决篇。
2.检查 CUDA Toolkit是否安装成功
终端输入 :

nvcc -V

会输出CUDA的版本信息(V要大写)
3.编译samples例子
进入到Samples安装目录,然后在该目录下终端输入make,等待十来分钟。
4.编译完成后测试
可以在Samples里面找到bin/x86_64/linux/release/目录,并切换到该目录
运行deviceQuery程序,sudo./deviceQuery
查看输出结果,重点关注最后一行,Pass表示通过测试

 

1.3安装后设置环境变量 PATH与添加库

echo 'export PATH=/usr/local/cuda/bin:$PATH' >>   /etc/bashrc

echo 'exportLD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >>  /etc/bashrc

source  /etc/bashrc

 

 

 

2安装cudnn6.5/8.0

·        安装cudnn比较简单,简单地说,就是复制几个文件:库文件和头文件。将cudnn的头文件复制到cuda安装路径的include路径下,将cudnn的库文件复制到cuda安装路径的lib64路径下。

#解压文件 tar -zxvf cudnn-6.5-linux-x64-v2.tgz 
#切换路径 cd cudnn-6.5-linux-x64-v2 
#复制lib文件到cuda安装路径下的lib64/ sudo cp lib* /usr/local/cuda/lib64/ 
#复制头文件 sudo cp cudnn.h /usr/local/cuda/include/ 
#更新软连接 cd /usr/local/cuda/lib64/ 
sudo rm -rf libcudnn.so libcudnn.so.6.5 
sudo ln -s libcudnn.so.6.5.48 libcudnn.so.6.5 
sudo ln -s libcudnn.so.6.5 libcudnn.so 

·        到目前为止,cudnn已经安装完了

文件位置

·        https://developer.nvidia.com/rdp/cudnn-archive页面中搜索 cuDNN v2 Library for Linux, 点击该链接下载

 

·        测试

·        #运行cudnn-sample-v2 tar –zxvf cudnn-sample-v2.tgz

·         cd cudnn-sample-v2

·        make

·        ./mnistCUDNN

·        #改程序运行成功,说明cudnn安装成功。

·         

·        

·         

文件位置

·        https://developer.nvidia.com/rdp/cudnn-archive页面中搜索 cuDNN v2 Code Samples, 点击该链接下载

 

 

注意:  有可能cudnn caffe版本出现不兼容,表现为编译caffe时出现未声明的变量

查看/usr/local/cudn/include/cudnn.h 检查

 

 

3 centos7 opencv2.4.13安装

 

 

以管理员身份运行
su root
输入密码

安装依赖包

yum install gcc gcc-c++ gtk2-devel cmakegimp-devel gimp-devel-tools gimp-help-browser zlib-devel libtiff-devellibjpeg-devel libpng-devel gstreamer-devel libavc1394-devel libraw1394-devellibdc1394-devel jasper-devel jasper-utils swig python libtool nasm

官网下载opencv2.4.13.zipusr/local
cd /usr/local
unzip opencv-2.4.13.zip
cd opencv-2.4.13/
cmake CMakeLists.txt
make
make install
cp /usr/local/opencv-2.4.13/unix-install/opencv.pc/usr/lib64/pkgconfig/
gedit /etc/ld.so.conf.d/opencv.conf

将以下内容添加到最后:
/usr/local/lib
保存关闭

ldconfig
gedit /etc/bash.bashrc

在文件后添加:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
保存关闭

重启终端

【测试】

cd/usr/local/opencv-2.4.13/samples/c
chmod +x build_all.sh
./build_all.sh
./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml"--scale=1.5lena.jpg

 

 

 

 

4 centos7 caffe安装

我是从github  下载最新的

 

安装依赖库

http://caffe.berkeleyvision.org/installation.html

 

·        CUDA is required for GPUmode.

o    libraryversion 7+ and the latest driver version are recommended, but 6.* is fine too

o    5.5,and 5.0 are compatible but considered legacy

·        BLASvia ATLAS, MKL, or OpenBLAS.

·        Boost>= 1.55

·        protobuf,glog,gflags,hdf5

Optionaldependencies:

·        OpenCV>= 2.4 including 3.0

·        IO libraries:lmdb,leveldb (note:leveldb requiressnappy)

·        cuDNN for GPU acceleration (v6)

Pycaffeand Matcaffe interfaces have their own natural needs.

·        For Python Caffe:Python2.7 orPython 3.3+,numpy (>= 1.7),boost-providedboost.python

·        For MATLAB Caffe: MATLAB with themexcompiler.

 

 

General dependencies

sudo yum install protobuf-develleveldb-devel snappy-devel opencv-devel python-devel boost-devel hdf5-devel

Remaining dependencies, recent OS

sudo yum install gflags-devel glog-devellmdb-devel

 

注意:

如果自带低版本boost,卸载它, yum remove boost再用rpm -qa boost不会输出任何信息,说明卸载成功.

发现安装的boost版本是1.53,要求>=1.55  所以卸载后安装1.55

 

CentOS 7.2安装Boost 1.55.0

boost安装

wget http://www.mirrorservice.org/sites/dl.sourceforge.net/pub/sourceforge/b/bo/boost/boost/1.55.0/boost_1_55_0.tar.bz2

1.  源博客中的链接地址一直出错,所以在网上找了上面的地址  

2. $ tar jxvf  boost_1_55_0.tar.bz2  

3.  $ cd boost_1_55_0  

4. $ ./bootstrap.sh  

5.  $ ./b2  

6. $ sudo ./b2 install  

 

注意

Boost 前确认安装了Python

yum install python-devel

 

1、查看python版本

方法一:

python –V

 

2、查看Numpy版本

python -c"import numpy; print numpy.version.version"

 

3. 问题:

libs/iostreams/src/bzip2.cpp:20:56:致命错误:bzlib.h:没有那个文件或目录

yum -y install bzip2-devel

 

 

//验证开发环境
1.
测试代码
$ cat test_boost.cpp
#include <boost/version.hpp>
#include <boost/config.hpp>
#include <boost/lexical_cast.hpp>
#include <iostream>

using namespace std;

int main()
{
  using boost::lexical_cast;
  int a= lexical_cast<int>("123456");
  double b = lexical_cast<double>("123.456");
  std::cout << a << std::endl;
  std::cout << b << std::endl;
  return 0;
}

2.
编译,运行
$ g++ -Wall -o test_boost test_boost.cpp
$ ls
test_boost  test_boost.cpp

$ ./test_boost 
123456
123.456

 

 

[root@localhostAIRelated]# cmake --version

cmakeversion 2.8.12.

 

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

mkdir build

cd build

cmake ..

make all

make install

make runtest

 

还要安装blas 

sudoyum install atlas-devel
这里需要注意的是,在caffeMakefile.config中需要加入altas的路径,因为我在这里遇到了路径找不到的错误,配置之后就没有了:

BLAS_INCLUDE :=/usr/include/atlas
BLAS_LIB := /usr/lib64/atlas

如果还是有这个问题是因为 ATLAS现在的名称变了,要新建一下软链接

Cd /usr/lib64/atlas

 

     sudo ln -svlibsatlas.so.3.10 libcblas.so

     sudo ln -svlibsatlas.so.3.10 libatlas.so

 

问题:

1.        Cudnn caffe版本不兼容   cudnn 头文件与库文件

2.       

/bin/ld: cannot find -lcblas

/bin/ld: cannot find –latlas

 

解决方案

1,

     先确定Makefile.config里面是否有配置了BLAS_LIB BLAS_INCLUDE,去掉前面的#号。

     如果还是有这个问题是因为 ATLAS现在的名称变了,要新建一下软连

     sudo ln -svlibsatlas.so.3.10 libcblas.so

     sudo ln -svlibsatlas.so.3.10 libatlas.so

2,

改用openblas

yum install  openblas-devel

MakeFile.config配置如下:

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 := /usr/include/atlas
#BLAS_LIB := /usr/lib64/atlas

后续一切成功。 done

 

 

Cmake 时出错:

 

CMakeError at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:108(message):

 Could NOT find Atlas (missing:Atlas_LAPACK_LIBRARY)Call Stack (most recent call first):

/usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:315(_FPHSA_FAILURE_MESSAGE)cmake/Modules/FindAtlas.cmake:43 (find_package_handle_standard_args)

 cmake/Dependencies.cmake:113

 

 

1安装lapack

 [root@s011805161450~]#yum install lapack lapack-develblas blas-devel

 

2//改变BLAS库名称

cmake -DBLAS=open ..

阅读全文
0 0
原创粉丝点击