参考 https://www.pugetsystems.com/labs/hpc/How-to-install-CUDA-9-2
-on-Ubuntu-18-04-1184/
下载Ubuntu18.04 desktop, 制作USB启动,安装
在Software & Updates"中检查 nvidia驱动,必须是396版
如果驱动的版本号不对:
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.run
You 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)