TensorRT输入网络和参数,然后生成一个优化后的运行时引擎,用于对该网络执行推理。
TensorRT有C++和python的接口。
TensorRT应用了graph optimizations图优化、layer fusion层融合以及other optimizations其他优化,同时还利用各种hily optimized kernels高度优化的内核来寻找该模型的最快实现。
TensorRT支持混合精度。
安装TensorRT之前需要安装以下内容:
需要安装CUDA和CUDNN
1、下载与ubuntu和CPU对应的tensorrt版本
2、修改以下命令以执
os="ubuntuxx04"
tag="cudax.x-trt8.x.x.x-yyyymmdd"
sudo dpkg -i nv-tensorrt-repo-${os}-${tag}_1-1_amd64.deb
sudo apt-key add /var/nv-tensorrt-repo-${os}-${tag}/7fa2af80.pub
sudo apt-get update
sudo apt-get install tensorrt
如果使用python中使用的话
python3 -m pip install numpy
sudo apt-get install python3-libnvinfer-dev
python3-libnvinfer
python3 -m pip install protobuf
sudo apt-get install uff-converter-tf
python中查看例子
python3 -m pip install numpy onnx
sudo apt-get install onnx-graphsurgeon
3、查看安装的tensorrt版本信息
dpkg -l | grep TensorRT
2、安装tensorrt
仅运行tensorrt c++应用
sudo yum install libnvinfer8 libnvparsers8 libnvonnxparsers8 libnvinfer-plugin8
还需要构建tensorrt c++ 应用
sudo yum install libnvinfer-devel libnvparsers-devel libnvonnxparsers-devel
libnvinfer-plugin-devel
在python中运行tensorrt
sudo yum install python3-libnvinfer
3、安装libnvinfer8
version="8.x.x-1.cudax.x"
sudo yum downgrade libnvinfer8-${version} libnvparsers8-${version} libnvonnxparsers8-${version} libnvinfer-plugin8-${version} libnvinfer-devel-${version} libnvparsers-devel-${version} libnvonnxparsers-devel-${version} libnvinfer-plugin-devel-${version} python3-libnvinfer-${version}
sudo yum install yum-plugin-versionlock
sudo yum versionlock libnvinfer8 libnvparsers8 libnvonnxparsers8 libnvinfer-plugin8
libnvinfer-devel libnvparsers-devel libnvonnxparsers-devel libnvinfer-plugin-devel
python3-libnvinfer
假如想要升级tensorrt或者CUDA,就需要先对libnvinfer8解除绑定。
sudo yum versionlock delete libnvinfer8 libnvparsers8 libnvonnxparsers8 libnvinferplugin8 libnvinfer-devel libnvparsers-devel libnvonnxparsers-devel libnvinfer-plugindevel python3-libnvinfer
pip-installable nvidia-tensorrt
nvidia-tensorrt支持python3.6~3.9 和CUDA 11.x。Linux系统和x86_64 CPUx架构,wheel文件支持centos 7、ubuntu 18.04。
在安装之前先安装NVIDIA -pyindex,也许还需要更新一下python里面的安装包
python3 -m pip install --upgrade setuptools pip
python3 -m pip install nvidia-pyindex
如果使用requirements.txt,需要在requirements.txt中添加。
--extra-index-url https://pypi.ngc.nvidia.com
步骤
1、安装tensorrt
python3 -m pip install --upgrade nvidia-tensorrt
2、验tensorrt是否安装成功
python3
>>> import tensorrt
>>> print(tensorrt.__version__)
>>> assert tensorrt.Builder(tensorrt.Logger())
4.6. tar文件压缩
version="8.x.x.x"
arch=$(uname -m)
cuda="cuda-x.x"
cudnn="cudnn8.x"
tar xzvf TensorRT-${version}.Linux.${arch}-gnu.${cuda}.${cudnn}.tar.gz
ls TensorRT-${version}
bin data doc graphsurgeon include lib onnx_graphsurgeon python samples targets
TensorRT-Release-Notes.pdf uff
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:
cd TensorRT-${version}/python
python3 -m pip install tensorrt-*-cp3x-none-linux_x86_64.whl
cd TensorRT-${version}/uff
python3 -m pip install uff-0.6.9-py2.py3-none-any.whl
which convert-to-uff
cd TensorRT-${version}/graphsurgeon
python3 -m pip install graphsurgeon-0.4.5-py2.py3-none-any.whl
开始安装之前:cuda、cuDNN
步骤:
a)、加入到解压的
假如CUDNN没有拷贝到CUDA中,那么也需要将CUDNN的bin路径加入环境变量。
b)、将TensorRT中
python.exe -m pip install tensorrt-*-cp3x-none-win_amd64.whl
python3 -m pip install \graphsurgeon\graphsurgeon-0.4.5-py2.py3-none-any.whl
python3 -m pip install \uff\uff-0.6.9-py2.py3-none-any.whl
python3 -m pip install \onnx_graphsurgeon\onnx_graphsurgeon-0.3.12-py2.py3-
none-any.whl
TensorRT container、NVIDIA JetPack™、NVIDIA DRIVE®
使用一个Debian文件
os="ubuntuxx04"
tag="cudax.x-trt8.x.x.x-yyyymmdd"
sudo dpkg -i nv-tensorrt-repo-${os}-${tag}_1-1_amd64.deb
sudo apt-get update
sudo apt-get install tensorrt libcudnn8
sudo apt-get install python3-libnvinfer-dev
sudo apt-get install uff-converter-tf graphsurgeon-tf onnx-graphsurgeon
version="8.4.x.x-1+cudax.x"
sudo apt-get install libcudnn8=${version} libcudnn8-dev=${version}
sudo apt-mark hold libcudnn8 libcudnn8-dev
使用tar文件
使用zip文件
关于这个任务
步骤
sudo apt-get purge "libnvinfer*"
sudo apt-get purge "nv-tensorrt-repo*"
sudo yum erase "libnvinfer*"
sudo yum erase "nv-tensorrt-repo*"
sudo apt-get purge graphsurgeon-tf onnx-graphsurgeon
sudo yum erase graphsurgeon-tf onnx-graphsurgeon
上面的命令会将uff-converter-tf一起删除掉,如果希望仅删除uff-converter-tf,则
sudo apt-get purge uff-converter-tf
sudo yum erase uff-converter-tf
如果想只删除graphsurgeon-tf
sudo apt-get autoremove
sudo yum autoremove
sudo pip3 uninstall tensorrt
sudo pip3 uninstall uff
sudo pip3 uninstall graphsurgeon
sudo pip3 uninstall onnx-graphsurgeon
要记得首先升级CUDA,然后在安装PyCUDA。NumPy已经安装了。
PyCUDA不是必须安装的,它通过python调用CUDA接口,并且某些例子中可能用到。
PyCUDA的特性包括
安装pycuda之前首先确保nvcc在环境变量中
python -m pip install 'pycuda<2021.1'
需要在CUDA安装或者更新之后再安装pycuda。
pip install 'pycuda<2021.1'