tensorRT安装

官方指导文档:Installation Guide :: NVIDIA Deep Learning TensorRT Documentation

适配很重要!!!! 需要cuda, cuDNN, tensorRT三者匹配。我的cuda11.3 所以对应的cuDNN和tensorRT下载的是如下版本:

cudnn-linux-x86_64-8.9.4.25_cuda11-archive.tar.xz

TensorRT-8.0.3.4.Linux.x86_64-gnu.cuda-11.3.cudnn8.2.tar.gz

服务器直接下载,用wget下,但是我没有成功,下了30多k的啥东西我也不知道,所以我是直接本地下载,然后scp传上去的。

解压cuDNN和tensorRT:

tar -xvf cudnn-linux-x86_64-8.9.4.25_cuda11-archive.tar.xz
tar -xvf TensorRT-8.0.3.4.Linux.x86_64-gnu.cuda-11.3.cudnn8.2.tar.gz

依次执行下面三行代码:

$ sudo cp cudnn-*-archive/include/cudnn*.h /usr/local/cuda/include 
$ sudo cp -P cudnn-*-archive/lib/libcudnn* /usr/local/cuda/lib64 
$ sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*

第一行: 将 cuDNN 库的头文件复制到 CUDA 的包含目录下

第二行:将 cuDNN 库的动态链接库复制到 CUDA 的库目录下

第三行:赋予读取权限给头文件和库文件。

cuDNN就算完事了,查看cuDNN版本:

因为是最新的,所以版本信息在cudnn_version.h里面,不在cudnn.h里

cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2 这个什么也不会输出

cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

tensorRT安装_第1张图片

下面就是安装tensorRT了。 

查看文件夹:

ls TensorRT-8.0.3.4

先添加环境变量 ,运行成功就ok:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/TensorRT-8.0.3.4/lib

然后进入Python文件夹,我的python是3.8.10:

:~/autodl-tmp/datav/TensorRT-8.0.3.4/python# ls
tensorrt-8.0.3.4-cp35-none-linux_x86_64.whl  tensorrt-8.0.3.4-cp38-none-linux_x86_64.whl
tensorrt-8.0.3.4-cp36-none-linux_x86_64.whl  tensorrt-8.0.3.4-cp39-none-linux_x86_64.whl
tensorrt-8.0.3.4-cp37-none-linux_x86_64.whl

查看对应的文件夹下内置的python文件,cp38就是3.8的 复制对应的文件名:

:~/autodl-tmp/datav/TensorRT-8.0.3.4/python# python3 -m pip install tensorrt-8.0.3.4-cp38-none-linux_x86_64.whl
Looking in indexes: http://mirrors.aliyun.com/pypi/simple
Processing ./tensorrt-8.0.3.4-cp38-none-linux_x86_64.whl
Installing collected packages: tensorrt
Successfully installed tensorrt-8.0.3.4

因为我用pytorch,不用tensorflow 所以不用安装uff里面的东西

进入graphsurgeon文件夹安装对应的文件:

(base) root@autodl-container-8f5011bc52-3422f594:~/autodl-tmp/datav/TensorRT-8.0.3.4/graphsurgeon# ls
graphsurgeon-0.4.5-py2.py3-none-any.whl
(base) root@autodl-container-8f5011bc52-3422f594:~/autodl-tmp/datav/TensorRT-8.0.3.4/graphsurgeon# python3 -m pip install graphsurgeon-0.4.5-py2.py3-none-any.whl
Looking in indexes: http://mirrors.aliyun.com/pypi/simple
Processing ./graphsurgeon-0.4.5-py2.py3-none-any.whl
Installing collected packages: graphsurgeon
Successfully installed graphsurgeon-0.4.5

进入onnx_graphsurgeon文件夹安装对应的文件:

(base) root@autodl-container-8f5011bc52-3422f594:~/autodl-tmp/datav/TensorRT-8.0.3.4/onnx_graphsurgeon# ls
onnx_graphsurgeon-0.3.10-py2.py3-none-any.whl
(base) root@autodl-container-8f5011bc52-3422f594:~/autodl-tmp/datav/TensorRT-8.0.3.4/onnx_graphsurgeon# python3 -m pip install onnx_graphsurgeon-0.3.10-py2.py3-none-any.whl
Looking in indexes: http://mirrors.aliyun.com/pypi/simple
Processing ./onnx_graphsurgeon-0.3.10-py2.py3-none-any.whl
Requirement already satisfied: numpy in /root/miniconda3/lib/python3.8/site-packages (from onnx-graphsurgeon==0.3.10) (1.22.4)
Collecting onnx
  Downloading http://mirrors.aliyun.com/pypi/packages/c4/4a/cb138cbffe65c7c6a4c650e01fbc1c1e1c143797252fc128e4694276c2cc/onnx-1.14.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.6 MB)
     |████████████████████████████████| 14.6 MB 5.5 MB/s 
Collecting protobuf>=3.20.2
  Downloading http://mirrors.aliyun.com/pypi/packages/4c/87/59648989ad7f5ba6fe3c7f8abc555183f28559b6f6cd14ad17a3f0d3094f/protobuf-4.24.1-cp37-abi3-manylinux2014_x86_64.whl (311 kB)
     |████████████████████████████████| 311 kB 94.7 MB/s 
Requirement already satisfied: typing-extensions>=3.6.2.1 in /root/miniconda3/lib/python3.8/site-packages (from onnx->onnx-graphsurgeon==0.3.10) (4.2.0)
Installing collected packages: protobuf, onnx, onnx-graphsurgeon
  Attempting uninstall: protobuf
    Found existing installation: protobuf 3.19.4
    Uninstalling protobuf-3.19.4:
      Successfully uninstalled protobuf-3.19.4

这就完事了。测试一下:

将头文件路径添加进配置文件去:

"includePath": [
          "${workspaceFolder}/**",
          "/usr/local/cuda-11.3/targets/x86_64-linux/include/**",
          "/usr/include/opencv4/**",
          "/root/autodl-tmp/datav/TensorRT-8.0.3.4/include/**"  // 添加路径到这里
        ],

头文件和库文件添加到makefile文件的头文件和库文件里去:

include_paths := /usr/local/cuda-11.3/targets/x86_64-linux/include \
				 /usr/include/opencv4 /usr/include/opencv4/opencv \
				 /root/autodl-tmp/datav/TensorRT-8.0.3.4/include/

library_paths := /usr/local/cuda-11.3/targets/x86_64-linux/lib \
				 /root/autodl-tmp/datav/TensorRT-8.0.3.4/lib
	

简单写一下:

#include 
#include 
#include 
#include 

int main(){

    
    std::cout << "搞定收工!!" << std::endl;
    return 0;
}

make一波:

tensorRT安装_第2张图片

完美。搞定了 直接起飞 

你可能感兴趣的:(人工智能,深度学习,c++)