ubuntu18.04安装显卡驱动和CUDA9.0

1、硬件与软件版本

显卡:GeForce GTX 750

系统:Ubuntu 18.04

cuda:9.0版本

cuDNN:cuDnn v7

2、英伟达显卡安装(.run方式安装容易出错,我使用的是ppa源方式安装。)

2.1删除旧的驱动

Linux默认安装的驱动不是英伟达的驱动,所以先把旧的驱动删除。

# 删除
sudo apt-get purge nvidia*

2.2禁止自带的nouveau nvidia驱动

# 打开配置文件,网上说打开blacklist-nouveau.conf,我是没找到,所以如下操作的
sudo vim /etc/modprobe.d/blacklist.conf

填写禁用的内容:

blacklist nouveau
options nouveau modeset=0

更新配置文件:

sudo update-initramfs -u

重启reboot系统。

2.3添加ppa源

  • 首先,将ppa:graphics-drivers/ppa存储库添加到系统中
$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt update
  • 接下来,识别图形卡模型和推荐的驱动程序: 

ubuntu18.04安装显卡驱动和CUDA9.0_第1张图片

如上图,可以看到推荐的是最大的nvida-driver-415.

# 安装
sudo apt-get install nvidia-driver-415
# 重启
sudo reboot

3、安装cuda9.0

如下步骤:

英伟达开发者专区有详细的安装前操作指南。最重要的是,您应该验证您的系统具有cuda支持的GPU。您可以使用以下命令验证正在检测的GPU:

$ lspci | grep -i nvidia

如下是我的机器。GTX750

 

This command should return one GPU per line, in my case: 02:00.0 VGA compatible controller: NVIDIA Corporation GM200 [GeForce GTX TITAN X].

#!/bin/bash
## This gist contains step by step instructions to install cuda v9.0 and cudnn 7.2 in ubuntu 18.04
### steps ####
# verify the system has a cuda-capable gpu
# download and install the nvidia cuda toolkit and cudnn
# setup environmental variables
# verify the installation
# CUDA 9.0 requires NVIDIA driver version 384 or above
###
### to verify your gpu is cuda enable check
lspci | grep -i nvidia
### gcc compiler is required for development using the cuda toolkit. to verify the version of gcc install enter
gcc --version
# first get the PPA repository driver
sudo add-apt-repository ppa:graphics-drivers/ppa
# install nvidia driver 
sudo apt install nvidia-384 nvidia-384-dev
# install other import packages
sudo apt-get install g++ freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev
# CUDA 9 requires gcc 6
sudo apt install gcc-6
sudo apt install g++-6
#此处要替换原来的gcc、g++
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 60
# downoad one of the "runfile (local)" installation packages from cuda toolkit archive 
wget https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda_9.0.176_384.81_linux-run
# make the download file executable
chmod +x cuda_9.0.176_384.81_linux-run 
sudo ./cuda_9.0.176_384.81_linux-run --override
# answer following questions while installation begin
# You are attempting to install on an unsupported configuration. Do you wish to continue? y
# Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81? n
# Install the CUDA 9.0 Toolkit? y
# set up symlinks for gcc/g++
sudo ln -s /usr/bin/gcc-6 /usr/local/cuda/bin/gcc
sudo ln -s /usr/bin/g++-6 /usr/local/cuda/bin/g++
# setup your paths
echo 'export PATH=/usr/local/cuda-9.0/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
# install cuDNN v7.2
# in order to download cuDNN you have to regeistered here https://developer.nvidia.com/developer-program/signup
# then download cuDNN v7.2 form https://developer.nvidia.com/cudnn
CUDNN_TAR_FILE="cudnn-9.0-linux-x64-v7.2.1.38"
wget https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v7.2.1/prod/9.0_20180806/${CUDNN_TAR_FILE}
tar -xzvf ${CUDNN_TAR_FILE}
# copy the following files into the cuda toolkit directory.
sudo cp -P cuda/include/cudnn.h /usr/local/cuda-9.0/include
sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda-9.0/lib64/
sudo chmod a+r /usr/local/cuda-9.0/lib64/libcudnn*
# finally, to verify the installation, check
nvidia-smi
nvcc -V

 

你可能感兴趣的:(深度学习)