部分文章内容为公开资料查询整理,原文出处可能未标注,如有侵权,请联系我,谢谢。邮箱地址:gnivor@163.com ►►►需要气球么?请点击我吧!

TensorRT源码编译

参考资料

tensorrt编译 https://zhuanlan.zhihu.com/p/346307138
tensorrt相关指南 https://zhuanlan.zhihu.com/p/382728131
使用 TensorRT 加速深度学习推理 https://developer.nvidia.com/zh-cn/blog/speeding-up-deep-learning-inference-using-tensorrt/

1. 背景

TensorRT是NVIDIA推出的用于高性能深度学习推理的 SDK,其以 NVIDIA 的并行编程模型 CUDA 为基础构建而成,可以显著的优化在线推理的性能和吞吐。TensorRT 针对多种深度学习推理应用的生产部署提供 INT8 和 FP16 优化,并支持算子融合,减少cuda kernal launches次数。本文主要对tensorrt的源码编译整个过程进行整理和介绍。

2.源码编译

2.1.下载TensorRT

直接从官网获取 https://developer.nvidia.com/tensorrt

这里给出下载的目录,可自行按需选择
tensorrt download
https://developer.nvidia.com/nvidia-tensorrt-download
https://developer.nvidia.com/nvidia-tensorrt-8x-download

注意这里EA/GA的区别 EA: 抢先体验, GA:稳定版。建议使用GA

这里我们使用8.2.2.1
https://developer.nvidia.com/compute/machine-learning/tensorrt/secure/8.2.2.1/tars/tensorrt-8.2.2.1.linux.x86_64-gnu.cuda-10.2.cudnn8.2.tar.gz
解压

tar -zxvf tensorrt-8.2.2.1.http://linux.x86_64-gnu.cuda-10.2.cudnn8.2.tar.gz -C ./
mv TensorRT-8.2.1.8/ /TensorRT

2.2.TensorRT OSS编译

github: https://github.com/NVIDIA/TensorRT/tree/release/8.2
OSS 是 Open Source Software的缩写,该存储库包含 NVIDIA TensorRT 的开源软件 (OSS) 组件。 其中包括 TensorRT plugins和parsers(Caffe 和 ONNX)的源代码,以及演示 TensorRT 平台的用法和功能的示例应用程序。 这些开源软件组件是 TensorRT 通用版 (GA) 版本的子集,包括了一些扩展和bug修复

2.2.1.clone指定分支

git clone -b release/8.2 https://github.com/nvidia/TensorRT TensorRT
cd TensorRT
git submodule update --init --recursive

2.2.2.环境依赖

生成编译容器 https://github.com/NVIDIA/TensorRT/tree/release/8.2#setting-up-the-build-environment
准备与2.1下载TensorRT GA相同的资源依赖,包括
cuda-10.2 + cuDNN-8.2 (安装方式见附1、附2)
其余版本详见 https://github.com/NVIDIA/TensorRT/tree/release/8.2#prerequisites
这里注意TensorRT在2.1已经下载完成

export TRT_LIBPATH=/TensorRT/

2.2.3.编译

mkdir build && cd build
cmake .. -DTRT_LIB_DIR=/TensorRT/lib/ -DTRT_INC_DIR=/TensorRT/include -DCUDA_VERSION=10.2
# cmake CMAKE_CUDA_COMPILER="/usr/local/cuda/bin/nvcc"  .. -DTRT_LIB_DIR=/TensorRT/lib/ -DTRT_INC_DIR=/TensorRT/include -DCUDA_VERSION=10.2
make nvinfer_plugin -j$(nproc)
# make -j$(nproc)

1.安装指定版本的cuda toolkit

https://developer.nvidia.com/cuda-toolkit
https://developer.nvidia.com/cuda-10.2-download-archive?target_os=Linux&target_arch=x86_64&target_distro=CentOS&target_version=8&target_type=rpmlocal
使用rpc安装

wget https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda-repo-rhel8-10-2-local-10.2.89-440.33.01-1.0-1.x86_64.rpm
sudo rpm -i cuda-repo-rhel8-10-2-local-10.2.89-440.33.01-1.0-1.x86_64.rpm
sudo dnf clean all
sudo dnf -y module install nvidia-driver:latest-dkms
#sudo dnf -y install cuda
sudo dnf -y install cuda-10.2.89-1 --nogpgcheck #加上 --nogpgcheck,即可绕过GPG验证成功安装

使用runfile安装

wget https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_440.33.01_linux.run
sudo sh cuda_10.2.89_440.33.01_linux.run

注意:补丁
使用TensorRT version >= 7.2时,cuda10.2中可能有cublas报错,安装补丁可解决,下载:
https://developer.nvidia.com/cuda-10.2-download-archive?target_os=Linux&target_arch=x86_64&target_distro=CentOS&target_version=7&target_type=rpmlocal

2.安装指定版本的cudnn

cudnn入口:https://developer.nvidia.com/cudnn
所有版本:https://developer.nvidia.com/rdp/cudnn-archive
8.2版本:https://developer.nvidia.com/compute/machine-learning/cudnn/secure/8.2.4/10.2_20210831/cudnn-10.2-linux-x64-v8.2.4.15.tgz

posted @ 2023-07-05 18:14  流了个火  阅读(485)  评论(0编辑  收藏  举报
►►►需要气球么?请点击我吧!►►►
View My Stats