欢迎大家点赞、关注集群式无人机板块(今年会全面完善仿真环境、算法、真实部署等多个部分)~
环境配置
- 操作系统版本:Ubuntu 20.04
- GPU:RTX4090
- CUDA版本:11.8
- CUDNN版本:8.9.4.25
- Pytorch:1.10.1
- Python:3.8
- gcc版本:9.4.0(g++4.8.5,c++14需要g++5.2以上)
- cmake版本:3.29.2 (3.13.2及以上)
- github链接:GitHub - traveller59/spconv: Spatial Sparse Convolution in PyTorch
在开始安装之前,需要确定自己的系统是否已经安装好cuda,和cudnn等。确认cuda版本的方法,
ctrl+t
打开你的terminal,输入:nvcc -V
注意cudnn一定要与cuda版本对应,否则安装时会报错.cudnn下载链接
spconv1.2.1安装
1. 克隆代码
git clone https://github.com/traveller59/spconv.git --recursive
由于特定版本,建议下载本地然后安装,不直接使用git获取
2. 安装依赖
sudo apt-get install cmake
#(已经安装cmake,升级一下:sudo pip install --upgrade cmake)
sudo apt-get install libboost-all-dev
sudo pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ pytest
3. 安装pybind11
github:https://github.com/pybind/pybind11
选择默认master分支
# 下载然后解压缩到spconv-1.2.1/third_party/pybind11下面
git clone https://github.com/pybind/pybind11.git
# 编译安装
cd pybind11
mkdir build
cd build
cmake ..
make check -j 4
sudo make install #(如果使用python2需要禁用/usr/bin/下的python3)
4. 运行
cd ../..
python setup.py bdist_wheel
cd ./dist
pip install spconv-2.3.6-py3-none-any.whl
5. 检查是否安装成功
python
import spconv
可以导入则安装成功。
报错
- 安装过程中可能出现的错误:
①No CMAKE_CUDA_COMPILER could be found.
可能会出现如下错误:
/home/sdb1/zyan/lulu/lib/python3.7/site-packages/setuptools/distutils_patch.py:26: UserWarning: Distutils was imported before Setuptools. This usage is discouraged and may exhibit undesirable behaviors or errors. Please use Setuptools' objects directly or at least import Setuptools first.
"Distutils was imported before Setuptools. This usage is discouraged "
running bdist_wheel
running build
running build_py
running build_ext
Release
|||||CMAKE ARGS||||| ['-DCMAKE_PREFIX_PATH=/home/sdb1/zyan/lulu/lib/python3.7/site-packages/torch', '-DPYBIND11_PYTHON_VERSION=3.7', '-DSPCONV_BuildTests=OFF', '-DPYTORCH_VERSION=10600', '-DCMAKE_CUDA_FLAGS="--expt-relaxed-constexpr" -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/home/sdb1/zyan/lulu/spconv-1.2/build/lib.linux-x86_64-3.7/spconv', '-DCMAKE_BUILD_TYPE=Release']
-- The CUDA compiler identification is unknown
CMake Error at CMakeLists.txt:6 (project):
No CMAKE_CUDA_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "CUDACXX" or the CMake cache entry CMAKE_CUDA_COMPILER to the full
path to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "/home/sdb1/zyan/lulu/spconv-1.2/build/temp.linux-x86_64-3.7/CMakeFiles/CMakeOutput.log".
See also "/home/sdb1/zyan/lulu/spconv-1.2/build/temp.linux-x86_64-3.7/CMakeFiles/CMakeError.log".
Traceback (most recent call last):
解决方法:问题还是cuda和cudnn版本不对应,从上文链接中下载cudnn对应版本(建议选择cuDNN Library for Linux (x86_64)类型)
cd 下载(下载cudnn所在的文件夹)
tar -xvf cudnn-10.0-linux-x64-v7.3.1.20.tgz(换成你的文件名字)
执行以下命令(路径是自己安装cuda的路径,根据自己的更改就好):
sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
再pip安装即可。
- Found cuDNN: v?
#可能出现以下错误
running build
running build_py
running build_ext
Release
|||||CMAKE ARGS||||| ['-DCMAKE_PREFIX_PATH=/home/zjy/anaconda3/envs/pcdet/lib/python3.6/site-packages/torch', '-DPYBIND11_PYTHON_VERSION=3.6', '-DSPCONV_BuildTests=OFF', '-DPYTORCH_VERSION=10800', '-DCMAKE_CUDA_FLAGS="--expt-relaxed-constexpr" -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/home/zjy/openpcdet/spconv-master/build/lib.linux-x86_64-3.6/spconv', '-DCMAKE_BUILD_TYPE=Release']
-- Caffe2: CUDA detected: 11.1
-- Caffe2: CUDA nvcc is: /usr/local/cuda-11.1/bin/nvcc
-- Caffe2: CUDA toolkit directory: /usr/local/cuda-11.1
-- Caffe2: Header version is: 11.1
-- Found CUDNN: /usr/local/cuda-11.1/lib64/libcudnn.so
-- Found cuDNN: v? (include: /usr/local/cuda-11.1/include, library: /usr/local/cuda-11.1/lib64/libcudnn.so)
CMake Error at /home/zjy/anaconda3/envs/pcdet/lib/python3.6/site-packages/torch/share/cmake/Caffe2/public/cuda.cmake:174 (message):
解决方法:有些cudnn的版本文件不在cudnn.h里,而在cudnn_version.h里,需要将cudnn_version.h文件复制过去
sudo cp cuda/include/cudnn_version.h /usr/local/cuda/include/
然后再pip安装即可
- nvcc fatal : Unsupported gpu architecture 'compute_89’错误
原因是conda环境下cuda编译器nvcc不支持compute_89导致安装失败,运行项目的requirement.txt安装环境往往会默认安装低版本的cuda环境。
首先通过nvcc --list-gpu-arch
查看cuda支持的编译器
- 安装时出现subprocess.CalledProcessError错误的解决方法
[ 69%] Building CUDA object src/spconv/CMakeFiles/spconv.dir/maxpool.cu.o
make[2]: *** [src/spconv/CMakeFiles/spconv.dir/build.make:76: src/spconv/CMakeFiles/spconv.dir/all.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:136: src/spconv/CMakeFiles/spconv.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
Traceback (most recent call last):
File "setup.py", line 77, in <module>
setup(
File "/home/xd/anaconda3/envs/centerformer/lib/python3.8/site-packages/setuptools/__init__.py", line 107, in setup
return distutils.core.setup(**attrs)
File "/home/xd/anaconda3/envs/centerformer/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 185, in setup
return run_commands(dist)
File "/home/xd/anaconda3/envs/centerformer/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
dist.run_commands()
File "/home/xd/anaconda3/envs/centerformer/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
self.run_command(cmd)
File "/home/xd/anaconda3/envs/centerformer/lib/python3.8/site-packages/setuptools/dist.py", line 1233, in run_command
super().run_command(command)
File "/home/xd/anaconda3/envs/centerformer/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
cmd_obj.run()
File "/home/xd/anaconda3/envs/centerformer/lib/python3.8/site-packages/wheel/bdist_wheel.py", line 299, in run
self.run_command('build')
File "/home/xd/anaconda3/envs/centerformer/lib/python3.8/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
self.distribution.run_command(command)
File "/home/xd/anaconda3/envs/centerformer/lib/python3.8/site-packages/setuptools/dist.py", line 1233, in run_command
super().run_command(command)
File "/home/xd/anaconda3/envs/centerformer/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
cmd_obj.run()
File "/home/xd/anaconda3/envs/centerformer/lib/python3.8/site-packages/setuptools/_distutils/command/build.py", line 131, in run
self.run_command(cmd_name)
File "/home/xd/anaconda3/envs/centerformer/lib/python3.8/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
self.distribution.run_command(command)
File "/home/xd/anaconda3/envs/centerformer/lib/python3.8/site-packages/setuptools/dist.py", line 1233, in run_command
super().run_command(command)
File "/home/xd/anaconda3/envs/centerformer/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
cmd_obj.run()
File "setup.py", line 40, in run
self.build_extension(ext)
File "setup.py", line 73, in build_extension
subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp)
File "/home/xd/anaconda3/envs/centerformer/lib/python3.8/subprocess.py", line 364, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--config', 'Release', '--', '-j4']' returned non-zero exit status 2.
描述: 该问题是在你安装spconv1.0/1.2.1时,执行python setup.py bdist_wheel时,编译一半出现的问题。
可能1:此问题说明spconv安装缺文件,从官方下载下来的spconv1.2.1,文件夹下的third_party/pybind11是空的,需要自己手动去下载。
pybind11链接:https://github.com/pybind/pybind11/tree/3b1dbebabc801c9cf6f0953a4c20b904d444f879
可能2:电脑是30系列显卡时,需要安装CUDA11.x,属于高版本,spconv需要安装2.x。
可能3:不乏有文件错误的可能,这里提供一个我亲测有效的文件:用于spconv1.2.1的安装,目前亲测有效
参考链接1:https://blog.csdn.net/weixin_44013732/article/details/125836795