超详细保姆级Ubuntu 20.04 LTS+RTX4090部署AI环境(CUDA、TensorRT、Pytorch、torchnvjpeg、torch2trt、pycuda)

环境安装

下面教程是完整的环境安装流程,采用Ubuntu 20.04LTS桌面版

一、Ubuntu基础配置

1、更新系统apt数据源

sudo vim /etc/apt/sources.list 

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse 
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse 
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse 
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse 
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse 
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse 
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse 
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse 
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse 
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse 

然后更新源

sudo apt-get update 

2、安装ssh、ifcnofnig、screen、htop、nvidia-cuda-toolkit等

sudo apt install -y openssh-server       SSH服务
sudo apt install -y net-tools            网络工具包,如ifconfig
sudo apt install -y nvidia-cuda-toolkit  CUDA工具包
sudo apt install -y screen               多用户会话
sudo apt install -y -y htop              系统监测,如CPU、内存
sudo apt install -y gcc+                 编译
sudo apt install -y make                 编译

3、安装pip3

sudo apt install python3-pip

#设置为国内源
pip3 install pip -U
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

4、安装torch CUDA 11.8

下载地址:Start Locally | PyTorch

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

5、安装其他依赖库

将下面的依赖保存为pip.txt,然后进行执行

gitpython
ipython  # interactive notebook
matplotlib>=3.2.2
numpy>=1.18.5
opencv-python>=4.1.1
Pillow>=7.1.2
psutil  # system resources
PyYAML>=5.3.1
requests>=2.23.0
scipy>=1.4.1
thop>=0.1.1  # FLOPs computation
tqdm>=4.64.0
tensorboard>=2.4.1
pandas>=1.1.4
seaborn>=0.11.0
easydict
gdown
lap
filterpy
onnx>=1.9.0
export
tensorrt
pycuda
jwt
python-multipart
uvicorn
pyqt5
loguru
xlrd >= 2.0.1

执行命令,安装以上全部依赖

pip3 install -r pip.txt

二、安装驱动、CUDA、CUDNN、Tensort

1、安装RTX4090驱动

下载地址:Linux x64 (AMD64/EM64T) Display Driver | 525.125.06 | Linux 64-bit | NVIDIA
执行命令安装:

sudo sh NVIDIA-Linux-x86_64-535.54.03.run

2、安装CUDA 12.2

下载地址:https://developer.nvidia.com/cuda-toolkit-archive

执行命令,下载本地安装包

wget https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run
sudo sh cuda_12.2.0_535.54.03_linux.run

如果报错:请先切换为命令行,然后重启reboot系统后再执行即可

sudo systemctl set-default multi-user.target    命令行模式
sudo systemctl set-default graphical.target     图形化模式

安装完毕后,默认的路径为

export CUDA_INC_DIR=/usr/local/cuda/include
export LD_LIBRARY_PATH=/usr/local/cuda/lib64
export PATH=/usr/local/cuda/bin:$PATH 

3、安装CUDNN v8.9.2 for CUDA 12.X

下载地址:https://developer.nvidia.com/rdp/cudnn-archive#a-collapse51b
下载DEB安装包

sudo dpkg -i cudnn-local-repo-ubuntu2004-8.9.2.26_1.0-1_amd64.deb

报错:key,则需要先拷贝key到指定目录“cp .... key",然后再执行安装包

4、安装Tensort TensorRT 8.6 GA for x86_64

下载地址:Log in | NVIDIA Developer
https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/secure/8.6.1/local_repos/nv-tensorrt-local-repo-ubuntu2204-8.6.1-cuda-12.0_1.0-1_amd64.deb
下载DEB安装包

sudo dpkg -i nv-tensorrt-local-repo-ubuntu2004-8.6.1-cuda-12.0_1.0-1_amd64.deb

报错:key,则需要先拷贝key到指定目录“cp .... key",然后再执行安装包

三、安装torchnvjpeg、torch2trt、pycuda

1、安装torchnvjpeg

下载地址:GitHub - itsliupeng/torchnvjpeg: Decode JPEG image on GPU using PyTorch

git clone https://github.com/itsliupeng/torchnvjpeg.git
#先编译wheel成安装包,然后再安装whl文件 
python3 setup.py bdist_wheel
cd dist
pip3 install torchnvjpeg.xxxxx
#或者
pip3 install 5.torchnvjpeg-0.1.0-cp38-cp38-linux_x86_64.whl

2、安装torch2trt

下载地址:GitHub - NVIDIA-AI-IOT/torch2trt: An easy to use PyTorch to TensorRT converter

git clone https://github.com/NVIDIA-AI-IOT/torch2trt.git
#先编译wheel成安装包,然后再安装whl文件
python3 setup.py bdist_wheel
cd dist
pip3 install torch2trt.xxxxx
#或者
pip3 install 6.torch2trt-0.4.0-py3-none-any.whl

3、安装pycuda

下载地址:GitHub - inducer/pycuda: CUDA integration for Python, plus shiny features

git clone https://github.com/inducer/pycuda.git
python3 setup.py bdist_wheel
cd dist
pip3 install pycuda.xxxxx
#或者
pip3 install 7.pycuda-2022.2.2-cp38-cp38-linux_x86_64.whl
#或者
pip3 install pycuda

报错:提示g++等编译错误、nvcc错误等

sudo apt install nvidia-cuda-toolkit

设置正确的环境变量 export CPATH=:/usr/local/cuda-12.2/bin:/usr/local/cuda-12.2/include:/usr/local/cuda-12.2/

安装完毕!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值