如何解析pytorch-gpu源码编译-成都快上网建站

如何解析pytorch-gpu源码编译

这篇文章给大家介绍如何解析pytorch-gpu源码编译,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

尼金平网站建设公司创新互联建站,尼金平网站设计制作,有大型网站制作公司丰富经验。已为尼金平上千提供企业网站建设服务。企业网站搭建\成都外贸网站建设要多少钱,请找那个售后服务好的尼金平做网站的公司定做!

软硬件环境

  • ubuntu 18.04 64bit
  • NVidia GTX 1070Ti
  • anaconda with python 3.7
  • CUDA 10.1
  • cuDNN 7.6
  • pytorch 1.8
 

python和gpu环境

这个就不多讲了,没装好的,可以参考下面的链接

  • anaconda基本使用
  • ubuntu安装CUDA和cuDNN
 

编译步骤

安装基础依赖

conda install numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six requests dataclasses
 

由于要使用gpu,所以还需要安装LAPACK支持,根据CUDA版本安装对应的软件包

# Add LAPACK support for the GPU if needed
conda install -c pytorch magma-cuda101  # or [ magma-cuda101 | magma-cuda100 | magma-cuda92 ] depending on your cuda version
 

接下来就可以开始克隆代码了

git clone --recursive https://github.com/pytorch/pytorch
cd pytorch
# if you are updating an existing checkout
git submodule sync
git submodule update --init --recursive
 

准备工作完成后,就可以开始编译了

export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
python setup.py install
 

CMAKE_PREFIX_PATH其实就是anaconda的安装目录,如我这里的/home/xugaoxiang/anaconda3

如何解析pytorch-gpu源码编译

pytorch

编译的时候较长,耐心等待就好

 

测试

重新开一个terminal进行测试

(base) xugaoxiang@1070Ti:~$ ipython
Python 3.7.6 (default, Jan  8 2020, 19:59:22)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import torch

In [2]: torch.__version__
Out[2]: '1.8.0a0+46d846f'

In [3]: torch.cuda.is_available()
Out[3]: True

In [4]:

说明pytorch已经安装到了anaconda的环境中,而且是gpu的版本,搞定!

整个编译过程还是非常顺利的,之前我们编译过opencvtensorflowcaffe,跟他们相比,pytorch在依赖关系的处理上做的非常好,以子项目的形式纳入到自己的工程当中,整个编译过程没出现过报错,文档也是写的简单明了,难怪它的市占率会越来越高。

关于如何解析pytorch-gpu源码编译就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


分享文章:如何解析pytorch-gpu源码编译
本文路径:http://kswjz.com/article/iheped.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流