当前位置:   article > 正文

Ubuntu18中cuda11.6+cuDNN8.4.1+tensorRT8.4.3.1+opencv4.2.0配置(AirVO配置)(超详细)_cuda11.6对应的cudnn

cuda11.6对应的cudnn

已有cuda11.4,eigen3.3.4,ros melodic,ceres 1.14,boost 1.65

注意:我没有尝试过cuda11.4+cuDnn8.4.1+tensorRT8.4.3是否可以,但是根据cuda和cudnn的对应、tensorRT8.4.3支持列表,其实是支持的。我是重新装了cuda。如果大家装了别的cuda11,可以先尝试一下。重装了cuda和cuDnn后要删除opencv的build文件夹,重新编译和安装。

1、cuda11.6(重装cuda之前要记得看nvidia驱动是否支持,不支持要重装驱动)

CUDA 12.2 Release Notes

  1. #查看驱动版本和支持的cuda
  2. nvidia-smi

重装驱动我后续再写一篇。

卸载原来的cuda:

  1. cd /usr/local/cuda-xx.x/bin/ (进入你的cuda文件夹下)
  2. sudo ./cuda-uninstaller
  3. sudo rm -rf /usr/local/cuda-xx.x(删除cuda文件夹)

 安装新的cuda:

CUDA Toolkit Archive | NVIDIA Developer

选择x86 ubuntu 18.04和runfile

我这里使用了run的方式,你也可以使用deb的方式。

  1. wget https://developer.download.nvidia.com/compute/cuda/11.6.2/local_installers/cuda_11.6.2_510.47.03_linux.run
  2. sudo sh cuda_11.6.2_510.47.03_linux.run

"x"表示选中,不要安装附带驱动,然后其他默认即可。

添加路径:

  1. gedit ~/.bashrc
  2. #输入
  3. export PATH=$PATH:/usr/local/cuda/bin
  4. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
  5. export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda/lib64
  6. #保存退出
  7. source ~/.bashrc

完成后使用nvcc -V查看版本。

 2、cuDnn8.4.1

推荐deb安装,参考官方Installation Guide - NVIDIA Docs,下载链接:

 cuDNN Archive | NVIDIA Developer

Download cuDNN v8.4.1 (May 27th, 2022), for CUDA 11.x

Local Installer for Ubuntu18.04 x86_64 (Deb)

  1. sudo dpkg -i cudnn-local-repo-ubuntu1804-8.4.1.50_1.0-1_amd64.deb
  2. #根据提示导入KEY,不要复制
  3. sudo cp /var/cudnn-local-repo-*/cudnn-local-*-keyring.gpg /usr/share/keyrings/
  4. sudo apt-get update
  5. sudo apt-get install libcudnn8=8.4.1.50-1+cuda11.6
  6. sudo apt-get install libcudnn8-dev=8.4.1.50-1+cuda11.6
  7. sudo apt-get install libcudnn8-samples=8.4.1.50-1+cuda11.6
  8. #我有点不记得"="后面的版本号了,可以使用apt-cache查询,或者不指定
  9. sudo apt-get install libcudnn8
  10. sudo apt-get install libcudnn8-dev
  11. sudo apt-get install libcudnn8-samples
  1. sudo dpkg -l | grep cudnn
  2. #查看

3、opencv4.2(如果重装cuda,要重新编译安装)

sudo apt-get install build-essential cmake libjpeg-dev libtiff5-dev libpng-dev libavcodec-dev libavformat-dev libswscale-dev libxvidcore-dev libx264-dev libxine2-dev libv4l-dev v4l-utils libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgtk2.0-dev mesa-utils libgl1-mesa-dri libgtkgl2.0-dev libgtkglext1-dev  libatlas-base-dev gfortran libeigen3-dev

下载opencv4.2和opencv-contrib-4.2,分别解压缩,opencv-contrib文件夹放进opencv-4.2文件夹中,我的显卡是2080Ti,所以bin是7.5

  1. mkdir build && cd build
  2. cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/uestc213/data/opencv-4.2.0/opencv_contrib/modules -DOPENCV_DNN_CUDA=ON -DWITH_CUDA=ON -DCUDA_ARCH_BIN=7.5 -DBUILD_TESTS=OFF -D BUILD_SHARED_LIBS=ON -D BUILD_STATIC_LIBS=ON ..
  3. make -j8
  4. sudo make install

4、g2o    20230223

  1. sudo apt install libsuitesparse-dev qtdeclarative5-dev qt5-qmake libqglviewer-dev-qt5
  2. git clone https://github.com/RainerKuemmerle/g2o.git
  3. cd g2o
  4. mkdir build
  5. cd build
  6. cmake ..
  7. make -j8
  8. sudo make install

5、tensorRT8.4.2

Log in | NVIDIA Developer

下载需要注册账号

以下方法安装成功,但是我的c++项目编译不通过,找不到tensorRT。

  1. sudo gedit ~/.bashrc
  2. 输入
  3. export LD_LIBRARY_PATH=/home/213/TensorRT-8.4.3.1/lib:$LD_LIBRARY_PATH
  4. export LIBRARY_PATH=/home/213/TensorRT-8.4.3.1/lib::$LIBRARY_PATH
  5. 保存退出
  6. source ~/.bashrc
  1. # 安装后可使用python调用TensorRT
  2. cd TensorRT- 8.4.3.1/python
  3. pip3 install tensorrt-8.4.3.1-cp36-none-linux_x86_64.whl
  4. # 安装UFF,支持tensorflow模型转化,若使用pytorch可以不装
  5. cd TensorRT- 8.4.3.1/uff
  6. pip3 install uff-0.6.9-py2.py3-none-any.whl
  7. # 安装graphsurgeon,支持自定义结构
  8. cd TensorRT- 8.4.3.1/graphsurgeon
  9. pip3 install graphsurgeon-0.4.6-py2.py3-none-any.whl

用deb的方式:参考Installation Guide :: NVIDIA Deep Learning TensorRT DocumentationThis NVIDIA TensorRT 8.4.3 Installation Guide provides the installation requirements, a list of what is included in the TensorRT package, and step-by-step instructions for installing TensorRT.https://docs.nvidia.com/deeplearning/tensorrt/archives/tensorrt-843/install-guide/index.html#installing-debian首先要加入cuda11.6的deb(network),保证依赖验证通过

  1. wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
  2. sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
  3. sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
  4. sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
  5. sudo apt-get update
  6. #如果安装过了cuda,这里就不要安装了。
  7. #sudo apt-get -y install cuda

然后下载tensorRT的deb

  1. #安装deb,这里的文件名,改为自己下载下来的,也可以tab补全
  2. sudo dpkg -i nv-tensorrt-repo-${os}-${tag}_1-1_amd64.deb
  3. sudo apt-key add /var/nv-tensorrt-repo-${os}-${tag}/*.pub
  4. sudo apt-get update
  5. sudo apt-get install tensorrt
  6. #我这里不与tensorflow使用,只安装我需要的
  7. python3 -m pip install numpy
  8. sudo apt-get install python3-libnvinfer-dev
  9. sudo apt-get install onnx-graphsurgeon
  10. sudo apt-get install tensorrt-libs
  11. sudo apt-get install tensorrt-dev
  12. #维持旧版cuda与tensorrt关联
  13. sudo apt-mark hold tensorrt-dev
  14. #可以取消
  15. sudo apt-mark unhold tensorrt-dev

6、glog

  1. git clone https://github.com/google/glog.git
  2. cd glog
  3. cmake -S . -B build -G "Unix Makefiles"
  4. cmake --build build
  5. cmake --build build --target test
  6. sudo cmake --build build --target install

7、ceres 2.0.0

可以直接去github下载压缩包,也可以

  1. git clone --branch 2.0.0 https://github.com/ceres-solver/ceres-solver.git
  2. cd ceres-solver
  3. mkdir build
  4. cd build
  5. #因为我已经装了一个ceres1.14,防止冲突,我重新设置路径
  6. sudo mkdir /usr/local/ceres2.0.0
  7. cmake -D CMAKE_INSTALL_PREFIX=/usr/local/ceres2.0.0 ..
  8. make -j8
  9. sudo make install

8、编译AIRVO

  1. mkdir -p airvo_ws/src
  2. cd airvo_ws/src/
  3. git clone https://github.com/sair-lab/AirVO.git
  4. cd ..
  5. catkin_make
  6. source devel/setup.bash

9、遇到的错误和修改

1......

  1. In file included from /usr/local/include/g2o/core/base_fixed_sized_edge.h:39:0,
  2. from /usr/local/include/g2o/core/base_binary_edge.h:30,
  3. from /usr/local/include/g2o/types/slam3d/types_slam3d.h:31,
  4. from /home/uestc213/data/airvio_ws/src/AirVO/include/utils.h:25,
  5. from /home/uestc213/data/airvio_ws/src/AirVO/src/camera.cc:4:
  6. /usr/local/include/g2o/stuff/tuple_tools.h: In function ‘void g2o::tuple_apply_i(F&&, T&, int)’:
  7. /usr/local/include/g2o/stuff/tuple_tools.h:45:35: error: ‘tuple_size_v’ is not a member of ‘std’
  8. std::make_index_sequence<std::tuple_size_v<std::decay_t<T>>>());
  9. ^~~~~~~~~~~~
  10. /usr/local/include/g2o/stuff/tuple_tools.h:45:35: note: suggested alternative: ‘tuple_size’

修改cmakelist中
set(CMAKE_CXX_STANDARD 14)

set(CMAKE_CXX_STANDARD 17)

2.......

error: ‘make_unique’ is not a member of ‘g2o’
   auto linear_solver = g2o::make_unique<SlamLinearSolver>();

使用20230223版本的g2o

3.......

  1. /usr/local/include/g2o/core/base_variable_sized_edge.hpp:90:12: error: ‘class ceres::internal::FixedArray’ has no member named ‘fill’
  2. add_vi.fill(0.);

单独安装ceres2.0.0在/usr/local/ceres2.0.0中
cmakelist中指定
set(Ceres_DIR /usr/local/ceres2.0.0/lib/cmake/Ceres)
find_package(Ceres 2.0.0 REQUIRED)
include_directories( ${CERES_INCLUDE_DIRS} )
target_link_libraries( ${CERES_LIBRARIES} )

4.....

如果是ubuntu18.04,还需要编译一个cv_bridge,否则容易运行报错

可以参考最后一部分,opencv4的cv_bridge部分

Ubuntu18.04 ROS Melodic的cv_bridge指向问题(四种方式,包括opencv4)_XiangrongZ的博客-CSDN博客大概就是找不到ros的cv_bridgehttps://blog.csdn.net/llllldm/article/details/126334841

5....

编译可以通过,但是在运行时崩溃,提示libg2o_opengl_helper.so找不到,

用ldd devel/lib/libair_vo_lib.so | grep g2o,可以看到这个动态链接库找不到。

此时如果你的g2o安装路径是默认的,在/usr/local中,则使用sudo ldconfig,然后重新编译airvo即可。如果有不一样的安装路径,如多版本共存,则需要修改FindG2O.cmake文件,在AirVO的cmake文件夹中。添加上你的安装路径中的include和lib,然后在/etc/ld.so.conf.d/libc.conf文件中增加你的安装路径。再执行sudo ldconfig,再重新编译AirVO。

10、运行

  1. source devel/setup.bash
  2. roslaunch air_vo oivio.launch
  3. roslaunch air_vo uma_bumblebee_indoor.launch
  4. roslaunch air_vo euroc.launch
  5. roslaunch air_vo euroc_ros.launch

附、onnxruntime 1.12.1

这个我没有安装,但是可以运行。

根据NVIDIA - TensorRT | onnxruntimeNVIDIA - CUDA | onnxruntime

  1. https://github.com/microsoft/onnxruntime.git
  2. cd onnxruntime
  3. git checkout v1.12.1
  4. git submodule update --init --recursive
  5. ./build.sh --skip_tests --config Release --build_shared_lib
  6. ./build.sh --skip_tests --use_cuda --config Release --build_shared_lib --parallel --cuda_home /usr/local/cuda --cudnn_home /usr/local/cuda
  7. ./build.sh --build_shared_lib --skip_tests --config Release --use_cuda --cudnn_home /usr/local/cuda --cuda_home /usr/local/cuda --use_tensorrt --tensorrt_home /home/213/TensorRT-8.4.3.1
  1. 进入
  2. /home/uestc213/onnxruntime/build/Linux/Release
  3. 然后sudo make install

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/185096
推荐阅读
相关标签
  

闽ICP备14008679号