ubuntu 16.04 caffe2安装及运行问题总结

安装问题

1、将caffe2安装到个人目录

为了不影响服务器上其他用户的使用(其实是不想被其他人影响),可能也有人会跟我一样选择将caffe2安装到个人目录。在没有用命令指定的情况下,caffe2安装的位置就是当前使用的python的位置,所以可以在个人目录下安装一个python或者anaconda,当然我建议的是安装一个anaconda,在conda虚拟环境中装caffe2也避免了环境冲突的困扰。

创建conda虚拟环境:conda create -n some_env python=2.7

此时按官网教程https://caffe2.ai/docs/getting-started.html?platform=ubuntu&configuration=compile执行python setup.py就不需要权限了。

如果安装方式采用的是cmake和make指令,在安装后依赖并下载完安装包之后,参考https://blog.csdn.net/yan_joy/article/details/73659566 执行以下步骤

cd pytorch
mkdir build
cd build
cmake ..
export DESTDIR=$HOME && make -j20 install ##指令安装路径并安装

 

2、undefined reference to symbol '_ZN3MPI8Datatype4FreeEv'

/usr/bin/ld: CMakeFiles/mpi_test.dir/mpi/mpi_test.cc.o: undefined reference to symbol '_ZN3MPI8Datatype4FreeEv'
//usr/lib/libmpi_cxx.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
caffe2/CMakeFiles/mpi_test.dir/build.make:110: recipe for target 'bin/mpi_test' failed
make[2]: *** [bin/mpi_test] Error 1
CMakeFiles/Makefile2:3796: recipe for target 'caffe2/CMakeFiles/mpi_test.dir/all' failed
make[1]: *** [caffe2/CMakeFiles/mpi_test.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

解决:参考https://github.com/caffe2/caffe2/issues/2144

将CMakeLists.txt中的USE_MPI "Use MPI" ON改为OFF

 

3、在使用官网的caffe2安装包时,如果采用python setup.py的方式安装,cmake summary中的USE_OPENCV一直是OFF,虽然可以成功安装caffe2,但是运行代码时会报opencv相关的问题,可是opencv的安装验证无误,如果执行USE_OPENCV=1 python setup.py,虽然cmake summary中USE_OPENCV变为了ON,但安装会出问题;如果采用cmake,make的方式安装,cmake summary中USE_OPENCV是ON,安装过程也不报错,但是在运行

cd ~ && python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"

 验证时会返回failure,为了查看具体原因,在python中输入

from caffe2.python import core

将返回

WARNING:root:This caffe2 python run does not have GPU support. Will run in CPU only mode.
segmentation fault (core dumped)

查了网上很多帖子,有说是NCCL的问题,有说是glibc的问题,我每个都试了,但依然报错。

最后,没有用官网的caffe2安装包,而是用了GitHub上一位答主提供的安装包,其他所有操作一模一样,就顺利安装了。万万没想到挣扎了这么久的问题错在了源头上。安装包我上传在了百度云,分享给跟我同样问题的朋友。https://pan.baidu.com/s/1YdJTlzcSYQuzacao3FoZiA

 

4、cmake ..的步骤之后出现了很多CMake Warning

CMake Warning at caffe2/CMakeLists.txt:199 (add_executable):
  Cannot generate a safe runtime search path for target net_gpu_test because
  there is a cycle in the constraint graph:

    dir 0 is [/usr/local/cuda/lib64]
      dir 4 must precede it due to runtime library [libnvrtc.so.8.0]
    dir 1 is [/home/xiongcx/pytorch/build/lib]
    dir 2 is [/home/xiongcx/anaconda2/envs/r21d/lib]
    dir 3 is [/home/xiongcx/cuda-8.0/lib64/stubs]
    dir 4 is [/home/xiongcx/cuda-8.0/lib64]
      dir 0 must precede it due to runtime library [libcurand.so.8.0]

  Some of these libraries may not be found correctly.

解决:报错原因是系统中安装了多个cuda,服务器不知道该用哪个,因此在cmake那步指定cuda和cudnn路径:

cmake -DCUDA_TOOLKIT_ROOT_DIR=/home/xiongcx/cuda-8.0/ -DCUDNN_ROOT_DIR=/home/xiongcx/cuda-8.0/lib64 ..

运行问题

. Encountered CUDA error: invalid device function Error from operator: 
output: "gpu_3/conv1_middle_w" name: "" type: "MSRAFill" arg { name: "shape" ints: 45 ints: 3 ints: 1 ints: 7 ints: 7 } device_option { device_type: 1 cuda_gpu_id: 3 }

原因:网上很多情况是cuda和cudnn的安装问题,就我个人而言,是因为原本用的服务器GPU是Tesla K20c和GeForce GT 610,现在的服务器是1080 Ti,caffe2源码编译是用前者编译的,在用不同GPU的时候就出了问题,因此重新编译caffe2,然后就可以了。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值