1、nvidia驱动
-
1.1 ubuntu禁用nouveau:
sudo gedit /etc/modprobe.d/blacklist.conf
最后一行添加:
blacklist nouveau
options nouveau modeset=0
然后:
sudo update-initramfs -u
#需要重启生效
reboot
重启后:
lsmod | grep nouveau #没有输出,即说明禁用成功
进入blos关闭secure boot
1.2安装nvidia驱动
安装可能需要的依赖
#其实很多你的环境已经安装了,所以一般并没有多少时间。
sudo apt-get update
sudo apt-get install dkms build-essential linux-headers-generic
sudo apt-get install gcc-multilib xorg-dev
sudo apt-get install freeglut3-dev libx11-dev libxmu-dev install libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
卸载nvidia驱动
#for case1: original driver installed by apt-get: 如果原驱动是用apt-get安装的,就用第1种方法卸载
sudo apt-get remove --purge nvidia*
#for case2: original driver installed by runfile:
#如果原驱动是用runfile安装的,就用–#uninstall命令卸载。其实,用runfile安装的时候也会卸载掉之前#的驱动,所以不手动卸载亦可
sudo chmod +x NVIDIA-Linux*.run
sudo ./NVIDIA-Linux-x86_64-384.59.run --uninstall
简单固定的安装:
参考网址https://blog.csdn.net/wf19930209/article/details/81877822 方法二
sudo add-apt-repository ppa:xorg-edgers/ppa
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
查看可安装的驱动版本列表
ubuntu-drivers devices
sudo apt install nvidia-430
重启
sudo shutdown -r now
但是只能安装系统驱动推荐的nvidia版本,如果中间出问题需要依赖则:
sudo apt install aptitude
sudo aptitude install 软件包名
根据提供的解决方案选择 y 或者 n即可
去官网下载驱动安装自己想要的版本(NVIDIA-Linux-x86_64-430.34):
https://www.geforce.cn/drivers
第二个选项中:选择时需看清楚是(notebooks)或者非notebook
下载好放到自己的英文目录下,因为切换非图形化界面时中文显示为乱码
/home/用户名/down/
接着按ctrl
+ alt
+ F1(F2~F6)中一个进入图形化界面
# 关闭ctrl alt F7
$sudo service lightdm stop
# 进入驱动目录 ---- 第三步的作用
# username是你自己的用户名/down是上面建立的,放我们下载的驱动文件
$cd /home/username/down
# 更改权限,tab补全名字
$sudo chmod a+x NVIDIA-Linux-x86_64-*.run --dkms --no-opengl-files
''' 安装 非常重要*****'''
|||||||||||||||||||||||||||||||||||||||||||||||||||||
$sudo ./NVIDIA-Linux-x86_64-390.77.run
'''这里开始就很骚了,大概率会提示你'''
dkms 安装最好 选yes
32位兼容 安装最好 选yes
x-org 最好别安,选no,有的电脑可能导致登录界面黑屏
the distribution-provided pre-install scipt failed,是否继续安装?
'''如果你从来没有安装过nvidia驱动,甚至方法一都没有安装过'''
#dkms 安装最好 选yes
# 1.按“continue”;
# 问你装32-bit库吗?按'Yes' ,32位兼容 安装最好 选yes
# 问你“would you like to run the nvidia-xconfig ...” 按'NO'有的电脑可能导致登录界
# 面黑屏
# 一般会让你确认细节,点`ok`
|||BUT||BUT|||||BUT|||||BUT||||BUT||||BUT||||||BUT||||
'''如果你安装过驱动,请按'取消安装',输入以下代码'''
$sudo apt-get remove --purge nvidia* #删除以前安装的文件
$sudo ./Nvidiaxxxx你下载的驱动具体名字.run -uninstall # 卸载文件内容
'''回到上面的第六步和第七步,重新弄一遍'''
$sudo reboot # 重启
# 再回到安装步骤
$sudo ./NVIDIA-Linux-x86_64-390.77.run
# 还是会提醒的,遇到警告也不怕
# 1.按“continue”;
# 问你装32-bit库吗?按'NO'
# 问你“would you like to run the nvidia-xconfig .......” 按'NO'
# 开机~
$sudo service lightdm start
重启之后查看nvidia
nvidia-smi
2、安装CUDA10.0和CUDNN7.5.1
2.1下载位置:
cuda(cuda_10.0.130_410.48_linux):https://developer.nvidia.com/cuda-toolkit-archive
cudnn(cudnn-10.0-linux-x64-v7.5.0.56):https://developer.nvidia.com/rdp/cudnn-archive#a-collapse751-10
2.2 CUDA10.0安装:
sudo sh cuda_10.0.130_410.48_linux.run
安装过程:
在安装过程中会询问是否安装显卡驱动,由于我们在第一步中已经安装,所以我们选择no(不安装)
Do you accept the previously read EULA? (accept/decline/quit): accept
You are attempting to install on an unsupported configuration. Do you wish to continue? ((y)es/(n)o) [ default is no ]: y
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 352.39? ((y)es/(n)o/(q)uit): n
Install the CUDA 10.0 Toolkit? ((y)es/(n)o/(q)uit): y
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 8.0 Samples? ((y)es/(n)o/(q)uit): y
Enter CUDA Samples Location [ default is /home/ls ]:
添加系统环境变量:
gedit ~/.bashrc
# add cuda
export PATH=/usr/local/cuda-10.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH
source ~/.bashrc #立即生效
测试是否安装成功
查看CUDA版本:
nvcc -V
2.3cudnn安装
cuDNN v7.5.1 Library for Linux for CUDA 10.0
cd ~
tar -zxf cudnn-10.0-linux-x64-v7.5.1.10.tgz
cd cuda
sudo cp lib64/* /usr/local/cuda/lib64/
sudo cp include/* /usr/local/cuda/include/
3.pytorch安装(都在超级用户下进行 su)
参考 https://blog.csdn.net/abc13526222160/article/details/86497684
3.1 Anaconda3-5.3.1-Linux-x86_64.sh 下载
安装参考:https://blog.csdn.net/u012243626/article/details/82469174
可以自己选择安装位置(放在下载等文件夹里重装时可以选择一定程度保留文件)
3.2 配置环境
添加下载源:
conda config --prepend channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
#cat ~/.condarc #可以查看下载源
gedit ~/.condarc #可以编辑下载源删除default
把连接超时的时间设置成40s,读取超时的时间修改成100s,不然安装pytorch的时候容易失败
conda config --set remote_connect_timeout_secs 40
conda config --set remote_read_timeout_secs 100
打开安装的环境命令:
conda create -n dl python=3.7 #创建环境
source activate dl #启动环境
安装pytorch1.1.0命令:
conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=10.0
测试:
import torch
import time
print(torch.__version__)
print(torch.cuda.is_available())
# print('hello, world.')
a = torch.randn(10000, 1000)
b = torch.randn(1000, 2000)
t0 = time.time()
c = torch.matmul(a, b)
t1 = time.time()
print(a.device, t1 - t0, c.norm(2))
device = torch.device('cuda')
a = a.to(device)
b = b.to(device)
t0 = time.time()
c = torch.matmul(a, b)
t2 = time.time()
print(a.device, t2 - t0, c.norm(2))
t0 = time.time()
c = torch.matmul(a, b)
t2 = time.time()
print(a.device, t2 - t0, c.norm(2))
1.1.0
True
cpu 0.06677007675170898 tensor(141467.7188)
cuda:0 0.002493143081665039 tensor(141467.7188, device='cuda:0')
cuda:0 0.0007426738739013672 tensor(141467.7188, device='cuda:0')
更新pip源
#都在su 超级用户的命令下运行
mkdir ~/.pip
cd ~/.pip
touch pip.conf
sudo gedit ~/.pip/pip.conf
#粘贴下面的
[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host=mirrors.aliyun.com
安装spyder(有错误,决定安装pycharm)
pip show spyder #查看安装的spyder位置
pip check #利用它来查看不匹配的依赖
apt-get remove spyder #删除之前的spyder
pip install spyder==3.3 #ubuntu16.10 适合装这个版本
安装pycharm
参考:
https://blog.csdn.net/shuiyixin/article/details/89530415
添加codna环境进入pycharm:
https://www.cnblogs.com/yuxuefeng/articles/9235431.html