參考 https://www.pugetsystems.com/labs/hpc/How-to-install-CUDA-9-2
-on-Ubuntu-18-04-1184/
下載Ubuntu18.04 desktop, 制作USB啟動,安裝
在Software & Updates"中檢查 nvidia驅(qū)動,必須是396版
如果驅(qū)動的版本號不對:
apt purge nvidia*
add-apt-repository ppa:graphics-drivers/ppa
sudo apt install nvidia-kernel-source-396
sudo apt install nvidia-driver-396
重啟電腦-
sudo apt-get install freeglut3 freeglut3-dev libxi-dev libxmu-dev
4.下載17.10的CUDA "run" file installer 然后安裝sudo sh cuda_9.2.88_396.26_linux.runYou are attempting to install on an unsupported configuration. Do you wish to continue?
(y)es/(n)o [ default is no ]: yInstall NVIDIA Accelerated Graphics Driver for Linux-x86_64 396.26? (y)es/(n)o/(q)uit: n !?。。。。。。?!重要?。。。。?! Install the CUDA 9.2 Toolkit? (y)es/(n)o/(q)uit: y Enter Toolkit Location [ default is /usr/local/cuda-9.2 ]:Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: yInstall the CUDA 9.2 Samples?
(y)es/(n)o/(q)uit: yEnter CUDA Samples Location
[ default is /home/kinghorn ]: /usr/local/cuda-9.2 Install the cuBLAS patch
wget https://developer.nvidia.com/compute/cuda/9.2/Prod/patches/1/cuda_9.2.88.1_linux
sudo chmod +x cuda_9.2.88.1_linux.run
sudo ./cuda_9.2.88.1_linux.run --silent --accept-eula-
Setup your environment variables
To configure the CUDA environment for all users (and applications) on your system create the file (use sudo and a text editor of your choice)
/etc/profile.d/cuda.sh
with the following content,
export PATH=$PATH:/usr/local/cuda/bin
export CUDADIR=/usr/local/cudaAlso create the file, /etc/ld.so.conf.d/cuda.conf
and add the line, /usr/local/cuda/lib64
Then run: sudo ldconfig
7 重啟電腦
- Test CUDA by building the "samples"
編譯和運行測試代碼 - 安裝和運行pytorch, gpu 運行
import torch
torch.cuda.current_device()
In [3]: torch.cuda.device(0)
In [4]: torch.cuda.device_count()
In [5]: torch.cuda.get_device_name(0)