centos 7 安装caffe

我已经编辑了在centos 7 兼容atblas和opencv 3的caffe版本,点击这里下载。

centos 6.5安装caffe中介绍了一下安装caffe的过程,但是总体上比较麻烦,由于一些原因需要再次安装caffe,这次是在centos 7上,其中发现了一种快速的方法,这里记录一下。

一、服务器配置

操作系统:centos 7
GPU:

[root@localhost ~]# lspci | grep -i nvidia
02:00.0 3D controller: NVIDIA Corporation GK110GL [Tesla K20c] (rev a1)
04:00.0 3D controller: NVIDIA Corporation GK110GL [Tesla K20c] (rev a1)
83:00.0 3D controller: NVIDIA Corporation GK110GL [Tesla K20c] (rev a1)
84:00.0 3D controller: NVIDIA Corporation GK110GL [Tesla K20c] (rev a1)

注意:这里使用的是命令行版的centos,如果是图形界面,需要另外配置。

二、安装过程

0.安装软件源

$ yum install epel-release

1.安装cuda

nvidia官网提供了yum源,因此只需安装yum源,便可轻松安装cuda,省去编译的复杂过程。需要注意的是一定要根据直接的操作系统选择合适的版本,详情点这里

$ wget http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-repo-rhel7-7.0-28.x86_64.rpm 
$ rpm -iv cuda-repo-rhel7-7.0-28.x86_64.rpm
$ yum search cuda
$ yum install cuda

2.安装依赖软件

$ yum install atlas-devel snappy-devel boost-devel leveldb leveldb-devel hdf5 hdf5-devel  glog glog-devel gflags gflags-devel protobuf protobuf-devel opencv opencv-devel lmdb lmdb-devel

3.安装caffe

$ unzip caffe-master.zip 
$ cd caffe-master 
$ cp Makefile.config.example Makefile.config
$ vim Makefile
# 将 LIBRARIES += cblas atlas 改为 LIBRARIES += satlas tatlas
$ vim Makefile.config
# 修改内容为:
#   LIBRARY_DIRS 加上 /usr/lib64/atlas
$ make all

4. 配置环境

$ vim /etc/ld.so.conf.d/caffe.conf
# 添加/usr/local/cuda/lib64 /usr/local/lib64 /usr/local/lib
# 注意换行
$ ldconfig

5. 运行

$ reboot
$ ./data/mnist/get_mnist.sh 
$ ./examples/mnist/create_mnist.sh 
$ vim examples/mnist/lenet_solver.prototxt
# 修改 ~/caffe/caffe-master/examples/mnist/lenet_solver.prototxt 文件设定运行 CPU 版本或者 GPU 版本。
# 修改最后一行: solver_mode: CPU 或者 solver_mode: GPU
$ time ./examples/mnist/train_lenet.sh

6. make pycaffe

$ for req in $(cat requirements.txt); do pip install $req; done
$ make pycaffe

7. 安装ipython notebook

$ pip install ipython[notebook]

首先,需要建立一个server的config:

$ ipython profile create nbserver

修改新建的profile,即ipython_notebook_config.py(命令行会有输出,告诉你生成的文件在哪里):

c = get_config()

# Kernel config
c.IPKernelApp.pylab = 'inline'  # if you want plotting support always

# Notebook config
c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:bcd259ccf...your hashed password here'
# It's a good idea to put it on a known, fixed port
c.NotebookApp.port = 9999

这里需要mycert.pem,使用openssl生成一个:

$ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem

接着,需要生成一串哈希后的密钥:

$ ipython
$ In [1]: from IPython.lib import passwd
$ In [2]: passwd()

启动IPython notebook:

$ ipython notebook --profile=nbserver

最后就可以在浏览器里远程访问了。

如果发现没有生成ipython_notebook_config.py文件,则有可能是新版本的ipython,新版本有了比较大的变化,notebook的启动命令改成了jupyter:

#产生配置文件
$ jupyter notebook --generate-config

将产生一个~/.jupyter/jupyter_notebook_config.py,修改此文件如下,mycert.pem和密钥如上,不在赘述:

# Notebook config
c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:bcd259ccf...your hashed password here'
# It's a good idea to put it on a known, fixed port
c.NotebookApp.port = 9999

启动notebook:

$ jupyter notebook

记得访问https://ip:port

8. 异常

有些情况下,安装完成后运行caffe会提示:Check failed: error == cudaSuccess (38 vs. 0) no CUDA-capable device is detected,原因可能是nvidia驱动未安装成功,而驱动是随着cuda一起安装的,期间要用到linux内核文件,默认在目录/lib/modules/

$ ll
total 8
drwxr-xr-x. 7 root root 4096 Sep  9 12:18 3.10.0-229.11.1.el7.x86_64
drwxr-xr-x. 7 root root 4096 Sep  9 12:19 3.10.0-229.el7.x86_64

如果你更新过系统的话yum update,这里可能出现两个内核,如上。查看现在的内核版本:

$ uname -a
Linux localhost.localdomain 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

到3.10.0-229.el7.x86_64目录下:

$ cd 3.10.0-229.el7.x86_64/
$ ll
total 2604
lrwxrwxrwx.  1 root root     38 Sep  8 21:08 build -> /usr/src/kernels/3.10.0-229.el7.x86_64
drwxr-xr-x.  2 root root     42 Sep  9 12:18 extra
drwxr-xr-x. 11 root root   4096 Sep  8 21:08 kernel
-rw-r--r--.  1 root root 683375 Sep  9 12:19 modules.alias
-rw-r--r--.  1 root root 658870 Sep  9 12:19 modules.alias.bin
-rw-r--r--.  1 root root   1291 Mar  6  2015 modules.block
-rw-r--r--.  1 root root   5900 Mar  6  2015 modules.builtin
-rw-r--r--.  1 root root   7652 Sep  9 12:19 modules.builtin.bin
-rw-r--r--.  1 root root 214016 Sep  9 12:19 modules.dep
-rw-r--r--.  1 root root 310732 Sep  9 12:19 modules.dep.bin
-rw-r--r--.  1 root root    339 Sep  9 12:19 modules.devname
-rw-r--r--.  1 root root    108 Mar  6  2015 modules.drm
-rw-r--r--.  1 root root    108 Mar  6  2015 modules.modesetting
-rw-r--r--.  1 root root   1482 Mar  6  2015 modules.networking
-rw-r--r--.  1 root root  83514 Mar  6  2015 modules.order
-rw-r--r--.  1 root root    165 Sep  9 12:19 modules.softdep
-rw-r--r--.  1 root root 293202 Sep  9 12:19 modules.symbols
-rw-r--r--.  1 root root 365868 Sep  9 12:19 modules.symbols.bin
lrwxrwxrwx.  1 root root      5 Sep  8 21:08 source -> build
drwxr-xr-x.  2 root root      6 Mar  6  2015 updates
drwxr-xr-x.  2 root root     91 Sep  8 21:08 vdso
drwxr-xr-x.  2 root root      6 Mar  6  2015 weak-updates

你或许发现build文件夹是个软连接文件,而且不停的闪烁,说明软连接已经被破坏了。原因是更新系统时内核也更新了,但是启动时还是旧内核,但旧内核的/usr/src/kernels/3.10.0-229.el7.x86_64已经被删除了。解决办法是:1.用新内核启动;2.将build文件夹连接到新内核, 如下:

$ rm -fr build
$ ln -s /usr/src/kernels/3.10.0-229.11.1.el7.x86_64/ build

然后执行以下步骤:

#uninstall
#cuda-7.5
$ yum remove cuda cuda-7-5 cuda-command-line-tools-7-5 cuda-core-7-5 cuda-cudart-7-5 cuda-cudart-dev-7-5 cuda-cusolver-7-5 cuda-cusolver-dev-7-5 cuda-documentation-7-5 cuda-driver-dev-7-5 cuda-drivers cuda-gdb-src-7-5 cuda-license-7-5 cuda-minimal-build-7-5 cuda-misc-headers-7-5 cuda-nvidia-kmod-common cuda-repo-rhel7 cuda-repo-rhel7-7-5-local cuda-runtime-7-5 cuda-samples-7-5 cuda-toolkit-7-5 cuda-visual-tools-7-5 cuda-cublas-7-5 cuda-cublas-dev-7-5 cuda-cufft-7-5 cuda-cufft-dev-7-5 cuda-curand-7-5 cuda-curand-dev-7-5 cuda-cusparse-7-5 cuda-cusparse-dev-7-5 cuda-npp-7-5 cuda-npp-dev-7-5 cuda-nvrtc-7-5 cuda-nvrtc-dev-7-5
#cuda-7.0
$ yum remove cuda cuda-7-0 cuda-command-line-tools-7-0 cuda-core-7-0 cuda-cudart-7-0 cuda-cudart-dev-7-0 cuda-cusolver-7-0 cuda-cusolver-dev-7-0 cuda-documentation-7-0 cuda-driver-dev-7-0 cuda-drivers cuda-gdb-src-7-0 cuda-license-7-0 cuda-minimal-build-7-0 cuda-misc-headers-7-0 cuda-nvidia-kmod-common cuda-repo-rhel7 cuda-repo-rhel7-7-0-local cuda-runtime-7-0 cuda-samples-7-0 cuda-toolkit-7-0 cuda-visual-tools-7-0 cuda-cublas-7-0 cuda-cublas-dev-7-0 cuda-cufft-7-0 cuda-cufft-dev-7-0 cuda-curand-7-0 cuda-curand-dev-7-0 cuda-cusparse-7-0 cuda-cusparse-dev-7-0 cuda-npp-7-0 cuda-npp-dev-7-0 cuda-nvrtc-7-0 cuda-nvrtc-dev-7-0
#reinstall runfile方式
$ wget http://developer.download.nvidia.com/compute/cuda/7.5/Prod/local_installers/cuda_7.5.18_linux.run
$ ./cuda_7.5.18_linux.run
  1. https://devtalk.nvidia.com/default/topic/915640/unix-graphics-announcements-and-news/multiple-glx-client-libraries-in-the-nvidia-linux-driver-installer-package/
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值