ubuntu18.04配置cuda+cudnn+tensorrt+anconda+pytorch-gpu+pycharm

一、显卡驱动安装
ubuntu18.04配置cuda+cudnn+tensorrt+anconda+pytorch-gpu+pycharm_第1张图片
执行nvidia-smi查看安装情况
ubuntu18.04配置cuda+cudnn+tensorrt+anconda+pytorch-gpu+pycharm_第2张图片
二、cuda安装
cuda官网下载cuda_11.6.2_510.47.03_linux.run,安装执行

sudo sh cuda_11.6.2_510.47.03_linux.run

提升安装项,驱动不用安装,即第一项(Driver),按空格键取消,接下选在Install进行安装
修改环境变量

sudo gedit ~/.bashrc

在最后添加

# Add the related bin and lib for cuda toolkit
export PATH="/usr/local/cuda-11.6/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda-11.6/lib64:$LD_LIBRARY_PATH"

更新环境

source ~/.bashrc

查看安装情况

nvcc -V

ubuntu18.04配置cuda+cudnn+tensorrt+anconda+pytorch-gpu+pycharm_第3张图片

三、安装cudnn
cudnn官网下载cudnn-local-repo-ubuntu1804-8.9.5.30_1.0-1_amd64.deb,官网安装教程

sudo dpkg -i cudnn-local-repo-ubuntu1804-8.9.5.30_1.0-1_amd64.deb

cd /var/cudnn-local-repo-ubuntu1804-8.9.5.30
sudo apt-get install '/var/cudnn-local-repo-ubuntu1804-8.9.5.30/libcudnn8_8.9.5.30-1+cuda11.8_amd64.deb'
sudo apt-get install '/var/cudnn-local-repo-ubuntu1804-8.9.5.30/libcudnn8-dev_8.9.5.30-1+cuda11.8_amd64.deb'
sudo apt-get install '/var/cudnn-local-repo-ubuntu1804-8.9.5.30/libcudnn8-samples_8.9.5.30-1+cuda11.8_amd64.deb'

四、安装tensorrt
官网下载TensorRT-8.5.1.7.Linux.x86_64-gnu.cuda-11.8.cudnn8.6.tar.gz
ubuntu18.04配置cuda+cudnn+tensorrt+anconda+pytorch-gpu+pycharm_第4张图片
解压文件,拷贝到对应文件下

sudo mv TensorRT-8.5.1.7/ /opt/
sudo gedit ~/.bashrc

bashrc文件最下方添加

export PATH="/opt/TensorRT-8.5.1.7/bin:$PATH"
export LD_LIBRARY_PATH="/opt/TensorRT-8.5.1.7/lib:$LD_LIBRARY_PATH"

激活环境

source .bashrc

测试

cd /opt/TensorRT-8.5.1.7/samples/sampleOnnxMNIST
make -j2
cd /opt/TensorRT-8.5.1.7/bin
./sample_onnx_mnist

如果出现预测结果,说明安装成功

五、anconda安装
下载Anaconda3-2021.04-Linux-x86_64.sh进行安装

sudo sh Anaconda3-2021.04-Linux-x86_64.sh

如果想关闭默认环境,执行

If you'd prefer that conda's base environment not be activated on startup, 
   set the auto_activate_base parameter to false: 

conda config --set auto_activate_base false
sudo chmod a+w /home/ubuntu/.conda

六、pytorch-gpu安装
安装链接,执行

pip install torch==1.13.0+cu116 torchvision==0.14.0+cu116 torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/cu116

七、pycharm安装
下载并安装
添加快捷方式

sudo gedit /usr/share/applications/pycharm.desktop
[Desktop Entry]
Version=1.0
Name=Pycharm Community Edition
Comment=Python IDE for Professional Developers
Exec=/xxx/pycharm/bin/pycharm.sh
Icon=/xxx/pycharm/bin/pycharm.png
Terminal=false
StartupNotify=true
StartupWMClass=jetbrains-pycharm-ce
Type=Application
Categories=Development;IDE;Python;

执行

sh /xxx/pycharm/bin/pycharm.sh

运行pycharm应用

环境添加选在python3.xx

你可能感兴趣的:(pytorch,pycharm,人工智能)