0. 卸载环境
1、卸载显卡驱动的命令:
假如安装的是NVIDIA-Linux-x86_64-390.116.run:
则运行如下命令:sh NVIDIA-Linux-x86_64-390.116.run --uninstall
2、卸载cuda和cudnn
cd /usr/local/cuda-9.2/bin/
./uninstall_cuda_9.2.pl
rm -rf /usr/local/cuda-9.2/
rm -rf /usr/local/cuda/include/cudnn.h
rm -rf /usr/local/cuda/lib64/libcudnn*
卸载完后需要reboot。
1. 安装GPU驱动
如果是更早版本,可以在阿里云进行下载,命令为
wget http://mirrors.cloud.aliyuncs.com/opsx/ecs/linux/binary/nvidia/driver/NVIDIA-Linux-x86_64-390.116.run
sh NVIDIA-Linux-x86_64-390.116.run
如果是比较新的版本,需要去官网查询下载https://cn.download.nvidia.cn/tesla:
wget http://cn.download.nvidia.com/tesla/396.82/NVIDIA-Linux-x86_64-396.82.run
sh NVIDIA-Linux-x86_64-396.82.run
使用nvidia-smi查看驱动是否安装成功。
2. 安装cuda和cudnn
由于最终安装的是pytorch-1.4.0-py3.6_cuda9.2.148_cudnn7.6.3_0.tar.bz2(https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64/py3.6_cuda9.2.148_cudnn7.6.3_0.tar.bz2)
wget http://mirrors.cloud.aliyuncs.com/opsx/ecs/linux/binary/nvidia/cuda/9.2.148/
cuda_9.2.148.1_linux cuda_9.2.148_396.37_linux
wget http://mirrors.cloud.aliyuncs.com/opsx/ecs/linux/binary/nvidia/cuda/9.2.148/cuda_9.2.148.1_linux
wget https://developer.download.nvidia.com/compute/machine-learning/cudn /secure/7.6.3.30/Production/9.2_20190822/cudnn-9.2-linux-x64-v7.6.3.30.tgz?vcg3oGnO2NK5a53HqN1zGD14tDO3RkB0jFuHdq6lAsg_7rX-sM-CAi6OW2_bV7tbCpNprKdqRmW8gtsd3ERtCytItX4p6G-WjxkSYOpEkeiVxxpBe9HCijmQSNkOrcQ7NhbXbyo3udR1CKbihWzNKFgn4k7WMvYq86cJVGVWiErtg-1kX_q5UqW5kiL8Pm9TDVwT1qG010_lSt_2Lv-L9nH_vZBWMy0 -O cudnn.tgz
其中cuda_9.2.148_396.37_linux为cuda文件,cuda_9.2.148.1_linux为cuda补丁,cudnn-9.2-linux-x64-v7.5.0.tgz为cudnn文件。
sh cuda_9.2.148_396.37_linux
sh cuda_9.2.148.1_linux
tar -zxvf cudnn.tgz
cp cuda/include/cudnn.h /usr/local/cuda/include
cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
使用nvcc --version查看cuda版本
使用cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
3. 安装Pytorch
conda install pytorch torchvision cudatoolkit=9.2 -c pytorch
如果安装比较慢,可以设成清华镜像,或者直接下载pytorch压缩包,conda install安装。
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64/pytorch-1.4.0-py3.6_cuda9.2.148_cudnn7.6.3_0.tar.bz2
实验代码,如果不出错,说明安装成功。
# Code in file tensor/two_layer_net_tensor.py
import torch
device = torch.device('cuda') # Uncomment this to run on GPU
# N is batch size; D_in is input dimension;
# H is hidden dimension; D_out is output dimension.
N, D_in, H, D_out = 64, 1000, 100, 10
# Create random input and output data
x = torch.randn(N, D_in, device=device)
4. 安装Tensorflow
pip3 install tensorflow-gpu==1.12.0
来源:CSDN
作者:herosunly
链接:https://blog.csdn.net/herosunly/article/details/104051863