ubuntu18.04安装cuda、cudnn

ubuntu18.04安装cuda、cudnn

    • cuda安装
    • cudnn安装

参考链接
:参考1
:参考2
:参考3
:参考4

cuda安装

链接:cuda官网

ubuntu18.04安装cuda、cudnn_第1张图片
然后按照说明输入命令:

sudo sh cuda_10.0.130_410.48_linux.run

然后一路enter,直到:

Do you accept the previously read EULA?
accept/decline/quit: 

选择如下:

Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 410.48?
(y)es/(n)o/(q)uit: n

Install the CUDA 10.0 Toolkit?
(y)es/(n)o/(q)uit: y

Toolkit location must be an absolute path.
Enter Toolkit Location
 [ default is /usr/local/cuda-10.0 ]: 

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

Install the CUDA 10.0 Samples?
(y)es/(n)o/(q)uit: y

Enter CUDA Samples Location
 [ default is /home/scau ]: 

Installing the CUDA Toolkit in /usr/local/cuda-10.0 ...
Missing recommended library: libGLU.so
Missing recommended library: libX11.so
Missing recommended library: libXi.so
Missing recommended library: libXmu.so
Missing recommended library: libGL.so

Installing the CUDA Samples in /home/scau ...
Copying samples to /home/scau/NVIDIA_CUDA-10.0_Samples now...
Finished copying samples.

在系统文件夹进入:

vim ~/.bashrc

ps: vim后有空格, 但是这个vim编辑需要特殊的打开命令,此略

这里用下面的命令代替输入打开.bashrc文件:

sudo gedit .bashrc

ps:gedit 可以直接以文本文档的形式打开编辑

添加环境,在打开的.bashrc末端输入:

export CUDA_HOME=/usr/local/cuda 
export PATH=$PATH:$CUDA_HOME/bin 
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

验证是否安装成功,输入以下命令:

cd /usr/local/cuda/samples/1_Utilities/deviceQuery 
sudo make
./deviceQuery

ubuntu18.04安装cuda、cudnn_第2张图片
出现显卡信息和安装对应的CUDA版本,最后出现PASS,即安装成功。

cudnn安装

ubuntu18.04安装cuda、cudnn_第3张图片安装测试:
用Pycharm建立.py文件并写入:

import torch
a = torch.cuda.is_available()
print(a)

发现还没安装torch,去官网安装torch:

官网:https://pytorch.org/get-started/previous-versions/
选择合适的版本,这里CUDA为10.0,选择:

conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 -c pytorch

ubuntu18.04安装cuda、cudnn_第4张图片创建及激活虚拟环境,在anaconda虚拟环境下安装:

conda create -n yolov5 python==3.7
source activate yolov5
conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 -c pytorch

ubuntu18.04安装cuda、cudnn_第5张图片
再次输入代码,结果返回True则安装成功:

ubuntu18.04安装cuda、cudnn_第6张图片cudnn安装完成。

你可能感兴趣的:(linux,运维,服务器)