根据文档:https://docs.nvidia.com/deeplearning/tensorrt/archives/tensorrt-861/install-guide/index.html
TensorRT 8.6.1 支持:cuda11.8, cuDNN v8.9.0
1. 安装 cuda11.8
nvidia-smi
可以看到显示CUDA Version为 12.2,说明该显卡最高支持到 12.2, 我们安装 11.8
参考:https://developer.nvidia.com/cuda-11-8-0-download-archive?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=runfile_local
cd /home/h/programs
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
sudo sh cuda_11.8.0_520.61.05_linux.run
直接继续,因为我们已经装过 nvidia 显卡 驱动了。
我们保留了 Demo
!!! 我的根目录 / 分小了,空间不足。。。
# 删除 cuda-11.8
cd /usr/local
sudo rm -r cuda-11.8
# 删除软链接
unlink cuda
安装 cuda 到 指定目录,如:/home/h/programs
参考:https://blog.csdn.net/kxqt233/article/details/113825524
sudo sh cuda_11.8.0_520.61.05_linux.run --help
sudo sh cuda_11.8.0_520.61.05_linux.run --toolkitpath=/home/h/programs/cuda-11.8 --toolkit --silent
安装完成后,/usr/local 下的 cuda 软链接指向:/home/h/programs/cuda-11.8
sudo vim ~/.bashrc # 配置系统环境:打开系统环境配置文件
# 将cuda的头文件和库文件路径加入系统环境,因为有软链接,我们直接使用 /usr/local/cuda
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
source ~/.bashrc # 更新配置
nvcc -V # 检查安装是否成功
cat /usr/local/cuda/version.json
我使用的是 zsh,遇到以下问题:https://blog.csdn.net/qq_36148847/article/details/79261067
解决:修改 ~/.zshrc,source ~/.zshrc 即可。
2. 安装 cuDNN v8.9.0 (July 11th, 2023), for CUDA 11.x
参考:https://developer.nvidia.com/rdp/cudnn-archive
https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html
cd /home/h/programs
# 手动下载 Local Installer for Linux x86_64 (Tar)
# https://developer.nvidia.com/downloads/compute/cudnn/secure/8.9.0/local_installers/11.8/cudnn-linux-x86_64-8.9.0.131_cuda11-archive.tar.xz/
tar -xvf cudnn-linux-x86_64-8.9.0.131_cuda11-archive.tar.xz
# Copy the following files into the CUDA toolkit directory.
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 版本
cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
#define CUDNN_MAJOR 8
#define CUDNN_MINOR 9
#define CUDNN_PATCHLEVEL 0
–
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
/* cannot use constexpr here since this is a C-only file */
3. 安装 TensorRT 8.6 GA
EA 版本代表抢先体验(在正式发布之前)。
GA 代表通用性。 表示稳定版,经过全面测试。
参考:https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html#installing-tar
# 下载 https://developer.nvidia.com/nvidia-tensorrt-8x-download
# 手动下载
tar -xzvf TensorRT-8.6.1.6.Linux.x86_64-gnu.cuda-11.8.tar.gz
vim ~/.zshrc
# tensorrt-8.6.1.6
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/h/programs/TensorRT-8.6.1.6/libexport PATH=/home/h/programs/TensorRT-8.6.1.6/bin:$PATH # 保证 trtexec 可用
source ~/.zshrc
验证安装:
cd /home/h/programs/TensorRT-8.6.1.6/samples/sampleOnnxMNIST
# 编译
make
# 运行
cd /home/h/programs/TensorRT-8.6.1.6/bin
./sample_onnx_mnist
预测为 8,正确!
4. 安装 protobuf-3.19.4
参考:https://github.com/protocolbuffers/protobuf/blob/v3.19.4/src/README.md
sudo apt-get install autoconf automake libtool curl make g++ unzip
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protobuf-all-3.19.4.tar.gz --no-check-certificate
tar zxvf protobuf-all-3.19.4.tar.gz
cd protobuf-3.19.4
./autogen.sh
./configure --prefix=/home/h/programs/protobuf # 安装到的路径,否则默认安装到 /usr/local/
make -j 8
make check
sudo make install
sudo ldconfig # refresh shared library cache.
添加环境变量:
vim ~/.zshrc
加入以下内容:
####### add protobuf lib path ########
#(动态库搜索路径) 程序加载运行期间查找动态链接库时指定除了系统默认路径之外的
其他路径
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/h/programs/protobuf/lib/
#(静态库搜索路径) 程序编译期间查找动态链接库时指定查找共享库的路径
export LIBRARY_PATH=$LIBRARY_PATH:/home/h/programs/protobuf/lib/
#执行程序搜索路径
export PATH=$PATH:/home/h/programs/protobuf/bin/
#c程序头文件搜索路径
export C_INCLUDE_PATH=$C_INCLUDE_PATH:/home/h/programs/protobuf/include/
#c++程序头文件搜索路径
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/home/h/programs/protobuf/incl ude/
#pkg-config 路径
export PKG_CONFIG_PATH=/home/h/programs/protobuf/lib/pkgconfig/
######################################
激活环境变量:
source ~/.zshrc
查看版本:
protoc --version
# libprotoc 3.19.4