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

这篇具有很好参考价值的文章主要介绍了报错解决:RuntimeError: Error compiling objects for extension和nvcc fatal: Unsupported gpu architecture。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

报错

博主的软硬件环境(供参考):

  • Linux
  • NVIDIA GeForce RTX 3090
  • CUDA Driver version 515.76
  • CUDA 10.2
  • gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
  • Pytorch 1.10.0+cu102

博主在配置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_build
subprocess.run(
File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/subprocess.py", line 516, in run
raise 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, in
setup(
File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/init.py", line 155, in setup
return distutils.core.setup(**attrs)
File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 148, in setup
return run_commands(dist)
File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 163, in run_commands
dist.run_commands()
File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 967, in run_commands
self.run_command(cmd)
File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 986, in run_command
cmd_obj.run()
File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/command/develop.py", line 34, in run
self.install_for_development()
File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/command/develop.py", line 114, in install_for_development
self.run_command('build_ext')
File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/_distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 986, in run_command
cmd_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 run
self.build_extensions()
File "/home/user/anaconda3/envs/open_mmlab/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 735, in build_extensions
build_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_extensions
self._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_serial
self.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_extension
objects = 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_build
raise RuntimeError(message) from e
RuntimeError: Error compiling objects for extension

原因与解决

可能的原因和解决方法如下:

GPU硬件架构不支持,查询你的GPU型号和架构,使用合适的硬件

查看GPU的型号:

nvidia-smi

安装的Pytorch和CUDA版本不匹配,解决办法是安装相匹配的CUDA或Pytorch

首先查看cuda版本

nvcc -V

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

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda 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

如果依然有问题,尝试刷新一下环境或重启一下source ~/.bashrc

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

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

总结

安装mmdetection3d的时候,一定要注意各版本之间的依赖关系,以及软硬件版本的匹配,例如Pytorch版本、CUDA版本等等。

参考文献

Pytorch与CUDA的版本文章来源地址https://www.toymoban.com/news/detail-639758.html

到了这里,关于报错解决:RuntimeError: Error compiling objects for extension和nvcc fatal: Unsupported gpu architecture的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包