ubuntu20.04安装tensorRT

仅做记录,自用

官网安装教程连接:Installation Guide :: NVIDIA Deep Learning TensorRT Documentation

本机环境:CUDA11.3、cuDNN8.2、python3

下载安装包TensorRT-8.2.5.1.Linux.x86_64-gnu.cuda-11.4.cudnn8.2.tar.gz

version="8.2.5.1"
arch=$(uname -m)
cuda="cuda-11.4"
cudnn="cudnn8.2"
tar -xzvf TensorRT-${version}.Linux.${arch}-gnu.${cuda}.${cudnn}.tar.gz # 在安装包目录下解压

ls TensorRT-${version} # 检查文件下目录
bin  data  doc  graphsurgeon  include  lib  onnx_graphsurgeon  python 
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:TensorRT-${version}/lib # 添加环境变量

cd TensorRT-${version}/python

python3 -m pip install tensorrt-*-cp3x-none-linux_x86_64.whl # 在虚拟环境内安装,cp3x对应环境python版本
cd ../..
cd TensorRT-${version}/uff
python3 -m pip install uff-0.6.9-py2.py3-none-any.whl
which convert-to-uff # 检查
cd ../..
cd TensorRT-${version}/graphsurgeon
python3 -m pip install graphsurgeon-0.4.6-py2.py3-none-any.whl 

cd ../..
cd TensorRT-${version}/onnx_graphsurgeon
python3 -m pip install onnx_graphsurgeon-0.3.12-py2.py3-none-any.whl

# python # 验证trt

>>> import tensorrt

>>> trt.__version__

'8.2.5.1'

 安装pyCUDA,官网连接:https://docs.nvidia.com/deeplearning/tensorrt/archives/tensorrt-840-ea/install-guide/index.html#installing-pycuda

 

python3 -m pip install 'pycuda<2021.1'

 常见错误:

 src/cpp/cuda.hpp:14:10: fatal error: cuda.h: No such file or directory
         14 | #include
            |          ^~~~~~~~
      compilation terminated.
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]

原因:cuda环境变量未添加

echo  $PATH

检查输出:/home/zhangqi/anaconda3/bin:/opt/ros/noetic/bin:/home/zhangqi/anaconda3/bin:/home/zhangqi/anaconda3/bin:/home/zhangqi/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

里面无cuda路径

cd ~
gedit gedit ./.bashrc

在文件的最后一行加上该语句:

export PATH=/usr/local/cuda-11.3/bin${PATH:+:${PATH}} # 加完后保存关闭

source ./.bashrc # 使路径生效

echo  $PATH # 验证,显示有cuda路径

你可能感兴趣的:(ubuntu,linux,运维)