如何解析pytorch-gpu源码编译

发布时间:2021-12-04 18:47:49 作者:柒染
来源:亿速云 阅读:165

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

软硬件环境

 

python和gpu环境

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

 

编译步骤

安装基础依赖

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源码编译就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. indent 源码编译
  2. bison yacc 源码编译

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

pytorch gpu

上一篇:PyTorch发布原型功能以执行机器学习模型设备上硬件引擎的示例分析

下一篇:如何深度解析Pytorch中的UNet模型

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》