python开发环境配置,conda,cuda,cudnn

anaconda安装:

官网下载地址: https://www.anaconda.com/products/distribution#Downloads

下载.sh文件到本地,运行:sh 文件.sh,注意最后要添加环境变量

创建需要的python环境:conda create -n env_name python=x.x

pip install 安装需要的python三方件:安装torch 1.12.0 cuda 11.6版本

pip install torch==1.12.0 torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116

安装cuda 11.6:官网 https://developer.nvidia.com/cuda-toolkit-archive

选择需要的版本

python开发环境配置,conda,cuda,cudnn_第1张图片

根据安装环境选择,选择安装方式:

python开发环境配置,conda,cuda,cudnn_第2张图片

官网会根据选择情况提供安装命令,可直接使用:

python开发环境配置,conda,cuda,cudnn_第3张图片
wget https://developer.download.nvidia.com/compute/cuda/11.6.0/local_installers/cuda_11.6.0_510.39.01_linux.runsudo
sh cuda_11.6.0_510.39.01_linux.run

安装完成后会打印如下内容:

===========
= Summary =
===========

Driver:   Installed
Toolkit:  Installed in /usr/local/cuda-11.6/

Please make sure that
 -   PATH includes /usr/local/cuda-11.6/bin
 -   LD_LIBRARY_PATH includes /usr/local/cuda-11.6/lib64, or, add /usr/local/cuda-11.6/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-11.6/bin
To uninstall the NVIDIA Driver, run nvidia-uninstall
Logfile is /var/log/cuda-installer.log

添加环境变量:vim ~/.bashrc 在文件末尾添加下面内容

export CUDA_HOME=/usr/local/cuda 
export PATH=$PATH:$CUDA_HOME/bin 
export LD_LIBRARY_PATH=/usr/local/cuda-11.6/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
source ~/.bashrc

使用命令查看安装的CUDA版本:

nvcc -V
会返回如下内容:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Fri_Dec_17_18:16:03_PST_2021
Cuda compilation tools, release 11.6, V11.6.55
Build cuda_11.6.r11.6/compiler.30794723_0

CUDA 11.6无自带sample测试用例了,可以通过自己的项目来测试安装是否正确

例如:print(torch.cuda.is_available()),如果返回True,则说明cuda安装好了

cuDNN配置

CUDA与cuDNN配套关系查看:https://docs.nvidia.com/deeplearning/cudnn/support-matrix/index.html#cudnn-cuda-hardware-versions,CUDA 11.6配的是cuDNN 8.7.0

cuDNN下载,需要注册用户登录才能下载:https://developer.nvidia.com/rdp/cudnn-download

文件:cudnn-linux-x86_64-8.7.0.84_cuda11-archive.tar.xz

解压:

tar -xvf cudnn-linux-x86_64-8.7.0.84_cuda11-archive.tar.xz

解压后进入文件夹,root用户可以不加sudo:

cp include/cudnn*.h /usr/local/cuda/include/
cp -P lib64/libcudnn* /usr/local/cuda/lib64/
chmod a+r /usr/local/cuda/include/cudnn*.h
chmod a+r /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 7
#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 */

你可能感兴趣的:(python,人工智能,ubuntu,linux)