记pytorch 0.4.1caffe2源码安装

记pytorch 0.4.1caffe2源码安装

  1. 下载源码

    git clone https://github.com/pytorch/pytorch.git && cd pytorch
    
image-20181022163539834
  1. 运行命令git checkout v0.4.1
记pytorch 0.4.1caffe2源码安装_第1张图片
image-20181022163849883
  1. 运行命令git submodule update —-init
记pytorch 0.4.1caffe2源码安装_第2张图片
image-20181022163952607
  1. 运行命令
mkdir build
cd build
cmake ..
make -j4

果然又是一大堆错

报错一:具体见下图

[  1%] Built target js_embed
[  1%] Performing build step for 'nccl_external'
make[3]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
Scanning dependencies of target cpuinfo
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
[  3%] Built target libprotobuf-lite
/bin/sh: 1: [: -lt: unexpected operator
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
Scanning dependencies of target pthreadpool
[  3%] Building C object confu-deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/init.c.o
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
记pytorch 0.4.1caffe2源码安装_第3张图片
image-20181022165418901

解决:

加入环境变量:

vim ~/.bashrc 
#在最后一行加入以下
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
#保存并退出
source ~/.bashrc #使.bashrc立即生效

报错二:具体见下图

make[3]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
/bin/sh: 1: [: -lt: unexpected operator
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
[  1%] Building CXX object third_party/protobuf/cmake/CMakeFiles/libprotobuf.dir/__/src/google/protobuf/arena.cc.o
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
Compiling src/libwrap.cu                      > /home/chenzhiwei/Documents/pytorch/third_party/nccl/build/obj/libwrap.o
nvcc fatal   : Unsupported gpu architecture 'compute_60'
Makefile:136: recipe for target '/home/chenzhiwei/Documents/pytorch/third_party/nccl/build/obj/libwrap.o' failed
make[3]: *** [/home/chenzhiwei/Documents/pytorch/third_party/nccl/build/obj/libwrap.o] Error 1
CMakeFiles/nccl_external.dir/build.make:110: recipe for target 'nccl_external-prefix/src/nccl_external-stamp/nccl_external-build' failed
make[2]: *** [nccl_external-prefix/src/nccl_external-stamp/nccl_external-build] Error 2
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/nccl_external.dir/all' failed
make[1]: *** [CMakeFiles/nccl_external.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
记pytorch 0.4.1caffe2源码安装_第4张图片
image-20181022170054487

解决:

还是添加环境变量吧:

记pytorch 0.4.1caffe2源码安装_第5张图片
image-20181024102455954

可以复制下面的

# CUDA
export PATH=/usr/local/cuda/bin/:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

#MKL
#export LD_LIBRARY_PATH=/opt/intel/mkl/lib/intel64:$LD_LIBRARY_PATH

#opencv
export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
export PATH=/usr/local/bin/:$PATH
export LIBRARY_PATH=/usr/local/lib/:$LIBRARY_PATH
export CPATH=/usr/local/include/:$CPATH
export PYTHONPATH=/usr/local/lib/python2.7/site-packages/:$PYTHONPATH
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

#matlab
#export MATLAB_ROOT=/usr/local/MATLAB/R2014b

#CAFFE
#export PYTHONPATH=/home/shenyunhang/Documents/caffe/python:$PYTHONPATH

# vim
export EDITOR=vim

———————————————吐血————————还是不行————————

然后我把所有文件都删了,从第一步开始安装。

这个时候检查了一下cuda啥的版本,发现使用的是cuda 9.2.148,其对应的显卡驱动版本为396.54。发现显卡驱动为不对,接下来就是安装显卡驱动了。

cuda 9.2

  • nvidia driver 396.54
  • cuda 9.2 (not install driver,install toolkit and samples)
  • cudnn 7.1.4 for cuda9.2 (for TensorRT) caffe,tensorflow, baidu anakin

cuda 8.0

  • nvidia driver 384.130
  • cuda 8.0 (not install driver,install toolkit and samples)
  • cudnn 6.0.21 for cuda8.0 caffe

安装显卡驱动nvidia driver 396.54

1)卸载原来显卡驱动:

sudo apt-get remove --purge nvidia- #这里按tab键可以看到已安装的驱动版本
sudo apt-get remove --purge nvidia-384 #本人运行的命令

2)安装nvidia driver 396.54:

安装显卡驱动推荐使用官方ppa源的方式进行安装,使用cuda_xxx_linux.run文件离线安装会导致循环登录问题。

sudo add-apt-repository ppa:graphics-drivers/ppa
sudp apt-get update

sudo apt-cache search nvidia-*
# nvidia-384
# nvidia-396
sudo apt-get -y install nvidia-396

# test #这一步需要重启后才能正常输出
sudo nvidia-smi

按照前面的步骤:

记pytorch 0.4.1caffe2源码安装_第6张图片
image-20181023154940539

终于100%了。。。。

最后,我们来测试一下是否安装成功啦:

image-20181024105000819

你可能感兴趣的:(记pytorch 0.4.1caffe2源码安装)