当前位置: 首页 > news >正文

ubuntu20.04下配置深度学习环境GPU

卸载子系统

C:\Users\thzn>wsl --list
适用于 Linux 的 Windows 子系统分发版:
docker-desktop (默认)
docker-desktop-data
Ubuntu-18.04
Ubuntu-22.04
Ubuntu-20.04

C:\Users\thzn>wsl --unregister Ubuntu-18.04

ubuntu 换源 https://www.cnblogs.com/Horizon-asd/p/12595723.html

sudo cp /etc/apt/sources.list /etc/apt/sources.list.old
sudo vim /etc/apt/sources.list

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

更新源:sudo apt update 如果出现依赖问题-->sudo apt -f install
更新软件:sudo apt upgrade

参考网址:https://www.jianshu.com/p/be669d9359e2

0. nvidia-smi确认驱动是否正常

1. NVIDIA更新CUDA驱动 https://developer.nvidia.com/cuda-toolkit-archive

11.6.2

wget https://developer.download.nvidia.com/compute/cuda/11.6.2/local_installers/cuda_11.6.2_510.47.03_linux.run
sudo sh cuda_11.6.2_510.47.03_linux.run

($PATH:, 多个路径用:分割,查看指令 echo $PATH)

vim ~/.bashrc
export PATH=$PATH:/usr/local/cuda-11.6/bin/
export LD_LIBRARY_PATH=/usr/local/cuda-11.6/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
更新环境变量:source ~/.bashrc
检查是否成功:nvcc --version

问题1:

root@DESKTOP-9LGEL90:/home/chen# sudo sh cuda_11.6.0_510.39.01_linux.run
Failed to verify gcc version. See log at /var/log/cuda-installer.log for details.
root@DESKTOP-9LGEL90:/home/chen# sudo apt install build-essential

问题2:如果出现环境变量编辑错误导致的问题

root@DESKTOP-9LGEL90:/home/chen# ls
Command 'ls' is available in the following places
* /bin/ls
* /usr/bin/ls
The command could not be located because '/bin:/usr/bin' is not included in the PATH environment variable.
ls: command not found
root@DESKTOP-9LGEL90:/home/chen# export PATH=/usr/bin:/bin

2. cudnn下载配置 https://developer.nvidia.com/zh-cn/cudnn

其他版本下载:https://developer.nvidia.com/rdp/cudnn-archive

将cudnn-linux-x86_64-8.4.0.27_cuda11.6-archive.tar.xz拷贝到D盘
root@DESKTOP-9LGEL90:/mnt/d# cp /mnt/d/cudnn-linux-x86_64-8.4.0.27_cuda11.6-archive.tar.xz /home/chen/
root@DESKTOP-9LGEL90:/mnt/d# cd /home/chen/
root@DESKTOP-9LGEL90:/home/chen# tar -xvf cudnn-linux-x86_64-8.4.0.27_cuda11.6-archive.tar.xz
root@DESKTOP-9LGEL90:/home/chen# sudo cp cudnn-linux-x86_64-8.4.0.27_cuda11.6-archive/include/* /usr/local/cuda-11.6/include/
root@DESKTOP-9LGEL90:/home/chen# sudo cp cudnn-linux-x86_64-8.4.0.27_cuda11.6-archive/lib/* /usr/local/cuda-11.6/lib64/

sudo chmod a+r /usr/local/cuda-11.6/include/cudnn.h
sudo chmod a+r /usr/local/cuda-11.6/lib64/libcudnn*

是否安装成功:cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

3. Anaconda下载安装 https://www.anaconda.com/download
将Anaconda3-2022.10-Linux-x86_64.sh拷贝到D盘
root@DESKTOP-9LGEL90:/home/chen# cp /mnt/d/Anaconda3-2022.10-Linux-x86_64.sh /home/chen
root@DESKTOP-9LGEL90:/home/chen# ./Anaconda3-2022.10-Linux-x86_64.sh

安装日志输出
eval "$(/root/anaconda3/bin/conda shell.YOUR_SHELL_NAME hook)"

To install conda's shell functions for easier access, first activate, then:

conda init

If you'd prefer that conda's base environment not be activated on startup,
set the auto_activate_base parameter to false:

conda config --set auto_activate_base false

Thank you for installing Anaconda3!

添加到环境变量在($PATH:, 多个路径用:分割)
sudo vim ~/.bashrc

export PATH=$PATH:/usr/local/cuda-11.6/bin/:/root/anaconda3/bin
export LD_LIBRARY_PATH=/usr/local/cuda-11.6/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

source ~/.bashrc

检查是否成功:conda list 或 conda env list 或 conda list:查看安装了哪些包 或 conda env list 或 conda deactivate 或 conda remove -n testGPU --all 或 

4. 配置源

pip 配置清华源

常见的国内源有以下几种:
清华:https://pypi.tuna.tsinghua.edu.cn/simple/
阿里云:http://mirrors.aliyun.com/pypi/simple/
豆瓣:http://pypi.douban.com/simple/
中国科学技术大学 :https://pypi.mirrors.ustc.edu.cn/simple/

C:\Users\thzn>pip config list # 查看
global.index-url='https://pypi.tuna.tsinghua.edu.cn/simple'

C:\Users\thzn>pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/ # 配置
Writing to C:\Users\thzn\AppData\Roaming\pip\pip.ini

C:\Users\thzn>pip config list
global.index-url='http://mirrors.aliyun.com/pypi/simple/'

C:\Users\thzn>python -m pip install --upgrade pip # 升级

换回默认源:pip config unset global.index-url

conda 配置清华源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud//pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --set show_channel_urls yes

conda remove -n yolov5GPU --all

5. 安装pytorch https://pytorch.org/get-started/locally

conda create -n mmlabGPU python=3.7 -y
conda activate  mmlabGPU

GPU:pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116
CPU:pip3 install torch torchvision torchaudio

测试
python

>>> import torch
>>> torch.__version__
'1.13.1+cu116'
>>> torch.version.cuda
'11.6'

>> torch.cuda.is_available() #检查cuda是否可以使用 True
>> torch.cuda.current_device() #查看当前gpu索引号
>> torch.cuda.current_stream(device=0)#查看当前cuda流
>> torch.cuda.device(1) #选择device
>> torch.cuda.device_count() #查看有多少个GPU设备
>> torch.cuda.get_device_capability(device=0) #查看gpu的容量

http://www.lryc.cn/news/6025.html

相关文章:

  • 用egg.js来写一个api管理系统(一)
  • 企业数字化转型和升级:架构设计方法与实践
  • 【LeetCode】环形链表 II [M](链表)
  • Unity之如何实现一个VR任务(剧情)系统
  • k8s核心概念与kubectl命令行工具的使用
  • 【零基础入门前端系列】—无序列表、有序列表、定义列表(四)
  • 为什么重写equals还要重写hashcode方法
  • 电子技术——电流镜负载的差分放大器
  • go面试题
  • 攻防世界-Confusion1
  • 机器学习实战--梯度下降法进行波士顿房价预测
  • 黑马】后台管理-项目优化和上线
  • Web 框架 Flask 快速入门(三)数据库-MySQL
  • 牛客网Python篇数据分析习题(六)
  • Ansible的安装及部署
  • 链表题目总结 -- 递归
  • 重写-linux内存管理-伙伴分配器(一)
  • 为什么要用springboot进行开发呢?
  • 设备树信息解析相关函数
  • LeetCode-1124. 表现良好的最长时间段【哈希表,前缀和,单调栈】
  • vue-router路由配置
  • 中国计算机设计大赛来啦!用飞桨驱动智慧救援机器狗
  • 嘉定区2022年高新技术企业认定资助申报指南
  • 【C++】关键字、命名空间、输入和输出、缺省参数、函数重载
  • 【一道面试题】关于HashMap的一系列问题
  • 论文笔记: Monocular Depth Estimation: a Review of the 2022 State of the Art
  • Springmvc补充配置
  • MySQL 的 datetime等日期和时间处理SQL函数及格式化显示
  • 基于微信云开发的防诈反诈宣传教育答题小程序
  • Map和Set