linux安裝cuda和cudnn

caozengling發表於2024-05-14

// 安裝cuda

wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/12.4.1/local_installers/cuda-repo-wsl-ubuntu-12-4-local_12.4.1-1_amd64.deb
sudo dpkg -i cuda-repo-wsl-ubuntu-12-4-local_12.4.1-1_amd64.deb
sudo cp /var/cuda-repo-wsl-ubuntu-12-4-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda-toolkit-12-4

// 編輯環境變數
sudo vim ~/.bashrc
export PATH=/usr/local/cuda-12.4/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-12.4/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

source ~/.bashrc

// 安裝 cudnn

sudo tar -xvf cudnn**

cd ./lib

sudo cp -r /lib/* /usr/local/cuda-12.4/lib64/

cd ./include

sudo cp -r /include/* /usr/local/cuda-12.4/include/

#為更改讀取許可權:
sudo chmod a+r /usr/local/cuda-12.4/include/cudnn*
sudo chmod a+r /usr/local/cuda-12.4/lib64/libcudnn*

// 檢查
cat /usr/local/cuda-12.4/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

相關文章