当前位置:网站首页>Anconda安装的pytorch依赖的cuda版本和系统cuda版本不一致问题
Anconda安装的pytorch依赖的cuda版本和系统cuda版本不一致问题
2022-07-23 05:44:00 【cg101202】
背景
- 使用Anaconda配置源码环境
- 源码需要使用
python setup.py来编译依赖cuda的torch拓展模块,如 nms,ROIPool,ROIAlign等等 - 系统的CUDA和Conda装的
cudatoolkit版本不同
问题
符合上述背景条件或者类似条件,会导致一些奇怪的错误,例如:
ImportError: ***/ATSS/atss_core/_C.cpython-36m-x86_64-linux-gnu.so: undefined symbol: __cudaRegisterFatBinaryEnd
原因分析
按照源码安装教程,conda安装pytorch时cudatoolkit版本为9.0,而编译源码时,有一个依赖CUDA的拓展模块atss_core._C,查看编译过程信息发现,使用的是系统默认CUDA,而非想象中的cudatoolkit包,这就导致拓展模块依赖的CUDA版本和Pytorch依赖的cuda版本不一,进而引发一些奇怪错误。
总结
在conda的虚拟环境中,编译依赖cuda的torch拓展模块时,并未优先使用cudatoolkit包,转而使用了系统CUDA包,如果两个CUDA包版本不一,可能会引发一些意想不到的问题。
推荐解决方案
一般出现这种问题时,源码作者可能指定了cudatoolkit,则不好去改动其版本。
推荐在系统上再安装一个对应CUDA版本,且不覆盖原有(系统默认)版本,然后使用CUDA_HOME环境变量来指出对应CUDA版本的安装目录,如 export CUDA_HOME=/usr/local/cuda-9.0,这样可以避免更改系统或用户文件。
通过这种方式,只要安装时不覆盖系统默认版本,不会影响其它用户。如果你仅在terminal中临时export,还能避免对其他依赖cuda程序的影响,很方便。
深入分析
按理说既然是在同一个虚拟环境下,编译涉及CUDA的拓展模块,应该优先搜索该虚拟环境下conda安装的cudatoolkit包,就能避免该问题。
进一步分析源码发现,cuda根目录由torch.utils.cpp_extension给出,而torch.utils.cpp_extension中的_find_cuda_home函数,只要没有设置CUDA_HOME或CUDA_PATH环境变量,就会返回默认系统路径/usr/local/cuda。
边栏推荐
猜你喜欢

输入三角形边长,求面积

《高分子合成工艺》简答题答案

Deep learning neural network

【AUTOSAR COM 1.通信协议栈介绍】

高等代数100道题及答案解析

【Autosar DEM 四.Event Memory】

Tips for using textviewdidchange of uitextview

A comprehensive and detailed summary of the basic principles of steel structure

Talent column | can't use Apache dolphin scheduler? The most complete introductory tutorial written by the boss in a month

Data analysis (II)
随机推荐
Blog building five: drawing bed selection
求矩阵的鞍点及其对应的下标。
Talent column | can't use Apache dolphin scheduler? The most complete introductory tutorial written by the boss in a month
[learning summary]
Embedded from entry to mastery (buried) - sharing of ultra detailed knowledge points 2
Upper and lower case letter conversion
Using pycaret: low code, automated machine learning framework to solve regression problems
Blog Building III: comment system selection
博客搭建一:框架选择
高分子物理考研概念及要点、考点总结
鋼結構基本原理複習
[AUTOSAR cantp 1. learn the network layer protocol of UDS diagnosis]
Installation and use of APP automated testing tool appium
【AUTOSAR COM 1.通信协议栈介绍】
Blog building 4: how to add your blog to Baidu and Google
Analysis of 100 questions and answers in Higher Algebra
Enter the triangle side length and calculate the area
[AUTOSAR DEM iv.event memory]
3.2daydayup draw inferences from one instance: three days of fishing and two days of net learning
钢结构基本原理题库