ubuntu18.04+nvidia driver+cuda+cudnn install

Install Ubuntu18.04

according to this blog: https://blog.csdn.net/silver1225/article/details/100393719

install nvidia driver

First, disable original nvidia driver, nouveau

  1. delete the original nvidia driver
1
sudo apt-get remove nvidia-*
  1. forbid nouveau
1
sudo gedit /etc/modprobe.d/blacklist.conf

and add this in the bottom

1
2
blacklist nouveau
options nouveau modeset=0
  1. execute
1
2
sudo update-initramfs -u
reboot
  1. see the version of nouveau, if nothing returns, you succeed.
1
lsmod | grep nouveau

Second, install your nvidia driver.

  1. search your nvidia driver according to your version at https://www.nvidia.cn/Download/index.aspx?lang=cn

  2. update all

1
sudo apt-get update
  1. install gcc
1
sudo apt install build-essential
  1. show the version of your nvidia
1
lshw -numeric -C display
  1. install
1
2
sudo chmod a+x NVIDIA-Linux-x86_64-418.43.run
sudo ./NVIDIA-Linux-x86_64-418.43.run --no-opengl-files --no-x-check --no-nouveau-check
  1. check whether you succeed or not
1
nvidia-smi

Third, download cuda

download cuda at https://developer.nvidia.com/cuda-downloads

1
sudo sh cuda_10.0.130_410.48_linux.run

and select

1
2
3
4
5
6
1 accept #同意安装
2 n #不安装Driver,因为已安装最新驱动
3 y #安装CUDA Toolkit
4 <Enter> #安装到默认目录
5 y #创建安装目录的软链接
6 y #复制Samples一份到家目录

Then

1
sudo vim ~/.bashrc

Add this to the file

1
2
export PATH=/usr/local/cuda-10.1/bin${PATH:+:$PATH}} 
export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

Go back to command line

1
2
3
4
source ~/.bashrc
sudo vim /etc/profile
export PATH=/usr/local/cuda/bin:$PATH
sudo vim /etc/ld.so.conf.d/cuda.conf

Add this to the file.

Last

1
2
3
4
5
6
7
8
9
10
import torch
import torch.nn as nn
from torch.autograd import Variable, grad

SIZE=[1, 1, 171*21, 171*21]
input = Variable(torch.cuda.FloatTensor(*SIZE).uniform_(), requires_grad=True)
conv1 = nn.Conv2d(1, 1, kernel_size=3, stride=1, dilation=1, padding=1,bias=False).cuda()
output = conv1(input)
loss = output.sum()
loss.backward()

run this, if no error, you SUCCEED!