返回顶部
首页 > 资讯 > 后端开发 > Python >报错解决:RuntimeError: Error compiling objects for extension和nvcc fatal: Unsupported gpu architecture
  • 540
分享到

报错解决:RuntimeError: Error compiling objects for extension和nvcc fatal: Unsupported gpu architecture

pythonCUDAPytorchUbuntu 2023-09-02 17:09:33 540人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

报错解决:RuntimeError: Error compiling objects for extension和nvcc fatal: Unsupported gpu architecture

报错解决:RuntimeError: Error compiling objects for extension和nvcc fatal: Unsupported gpu architecture

报错

博主在配置mmdetection3D环境时,运行pip install -v -e .会有如下报错:

nvcc fatal : Unsupported gpu architecture 'compute_86'error: command '/usr/bin/nvcc' failed with exit code 1
ninja: build stopped: subcommand failed.Traceback (most recent call last):File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1717, in _run_ninja_buildsubprocess.run(File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/subprocess.py", line 516, in runraise CalledProcessError(retcode, process.args,subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.The above exception was the direct cause of the following exception:Traceback (most recent call last):File "setup.py", line 197, insetup(File "/home/user/anaconda3/envs/open_mmlab/lib/Python3.8/site-packages/setuptools/init.py", line 155, in setupreturn distutils.core.setup(**attrs)File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 148, in setupreturn run_commands(dist)File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 163, in run_commandsdist.run_commands()File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 967, in run_commandsself.run_command(cmd)File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 986, in run_commandcmd_obj.run()File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/command/develop.py", line 34, in runself.install_for_development()File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/command/develop.py", line 114, in install_for_developmentself.run_command('build_ext')File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/_distutils/cmd.py", line 313, in run_commandself.distribution.run_command(command)File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 986, in run_commandcmd_obj.run()File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/command/build_ext.py", line 79, in run_build_ext.run(self)File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run_build_ext.build_ext.run(self)File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/_distutils/command/build_ext.py", line 339, in runself.build_extensions()File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 735, in build_extensionsbuild_ext.build_extensions(self)File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/Cython/Distutils/old_build_ext.py", line 195, in build_extensions_build_ext.build_ext.build_extensions(self)File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/_distutils/command/build_ext.py", line 448, in build_extensionsself._build_extensions_serial()File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/_distutils/command/build_ext.py", line 473, in _build_extensions_serialself.build_extension(ext)File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/command/build_ext.py", line 202, in build_extension_build_ext.build_extension(self, ext)File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/_distutils/command/build_ext.py", line 528, in build_extensionobjects = self.compiler.compile(sources,File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 556, in unix_wrap_ninja_compile_write_ninja_file_and_compile_objects(File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1399, in _write_ninja_file_and_compile_objects_run_ninja_build(File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1733, in _run_ninja_buildraise RuntimeError(message) from eRuntimeError: Error compiling objects for extension

原因与解决

大概率的原因是安装的PyTorch和cuda版本不匹配,解决办法是安装想匹配的cuda或pytorch。

首先查看cuda版本

nvcc -V

输出如下,可以看出当前cuda版本是10.2:

nvcc: NVIDIA (R) Cuda compiler driverCopyright (c) 2005-2019 NVIDIA CorporationBuilt on Wed_Oct_23_19:24:38_PDT_2019Cuda compilation tools, release 10.2, V10.2.89

接着查看pytorch版本

python -c "import torch; print(torch.__version__)"

输出1.10.0+cu102

查看pytorch对应的cuda版本

python -c "import torch; print(torch.version.cuda)"

输出10.2

注意,上述输出的 cuda 的版本并不一定是 Pytorch 在实际系统上运行时使用的 cuda 版本,而是编译该 Pytorch release 版本时使用的 cuda 版本。

想要查看 Pytorch 实际使用的运行时的 cuda 目录,可以直接输出 cpp_extension.py 中的 CUDA_HOME 变量。

python -c "import torch; import torch.utils; import torch.utils.cpp_extension;  print(torch.utils.cpp_extension.CUDA_HOME)"

输出/usr/local/cuda-11.3

一般最好pytorch对应的cuda版本与安装版本相同,若不相同,版本相差比较大,就有可能出现上述报错,解决方法就是安装相匹配的cuda驱动,安装教程可以查看博主的另一篇博客博客,若已安装多版本CUDA,可以在bashrc文件中,添加以下代码指定CUDA版本:

# 根据自身情况修改cuda版本export PATH=/usr/local/cuda-10.2/bin:$PATHexport CUDA_PATH=/usr/local/cuda-10.2export CUDA_HOME=/usr/local/cuda-10.2export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64:$LD_LIBRARY_PATH

参考文献

Pytorch与CUDA的版本

来源地址:https://blog.csdn.net/weixin_43603658/article/details/131271511

--结束END--

本文标题: 报错解决:RuntimeError: Error compiling objects for extension和nvcc fatal: Unsupported gpu architecture

本文链接: https://lsjlt.com/news/391138.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作