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

news2024/10/5 19:15:57

卸载子系统

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.coloradmin.cn/o/344323.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【编程基础之Python】4、安装Python开发工具

【编程基础之Python】4、安装Python开发工具安装Python开发工具为什么需要开发工具Anaconda自带的开发工具PyCharm安装PyCharm运行PyCharm并创建项目总结安装Python开发工具 为什么需要开发工具 通常情况下,为了提高开发效率,需要使用相应的开发工具&a…

Three.js 无限平面快速教程【Plane】

Three.js 提供了 Plane 概念来表示在 3d 空间中无限延伸的二维表面。 这对于光标交互很有用,因此你可能需要了解如何设置此平面、将其可视化并根据需要进行调整。 推荐:使用 NSDT场景设计器 快速搭建 3D场景。 Three.js 的 Plane 文档很好而且准确&…

Locust初次体验【解决webUI没数据】

官方文档:What is Locust? — Locust 2.14.2 documentation webUI模式跑起来没有数据。。。。???; E:\T_Work\other\WB_Locust\my_locustfiles>locust [2023-02-14 09:57:44,530] PC-20190108TSZQ/INFO/locust.m…

Java 基础面试题——基本数据类型与包装类

目录1.Java 有哪几种基本数据类型?分别对应哪些包装类?2.Java 中为什么要保留基本数据类型?为什么要使用包装类?3.基本数据类型的转换规则有哪些?4.基本数据类型与包装类有什么区别?5.什么是装箱&#xff1…

MongoDB--》索引的了解及具体操作

目录 索引—index 索引的类型 索引的管理操作 索引的使用 索引—index 使用索引的原因:索引支持在MongoDB中高效地执行查询。如果没有索引,MongoDB必须执行全集合扫描,即扫描集合中的每个文档,以选择与查询语句匹配的文档。这…

基于android的即时通讯APP 聊天APP

基于android的即时通讯APP 或者 聊天APP 一 项目概述 该项目是基于Android 的聊天APP系统,该APP包含前台,后台管理系统,前台包含用户通讯录,用户详情,用户聊天服务,用户二维码,发现功能,发现详情 , 个人中心, 个人信…

【RSTP的原理和配置】

一、RSTP 概述 RSTP使用了IEEE 802.1W协议,视为STP的改进版本,收敛速度快,兼容STP。 RSTP可以兼容STP,但是会丧失快速收敛等优势; 1、RSTP对STP的改进; 1.1、端口角色的增补、简化了生成树协议的理解及部…

【基于transform和CNN的多级蒸馏:超分】

A hybrid of transformer and CNN for efficient single image super-resolution via multi-level distillation (基于transform和CNN的多级蒸馏单幅图像超分辨率算法) 近年来,基于卷积神经网络(CNN)的单幅图像超分辨…

Boost库的编译

废话就不多说了,直接上boost编译的方法。 1、下载boost库源码 https://github.com/missionlove/boost 2、使用vs命令行工具,选择对应的Command工具 3、切换目录到Boost源码 bootstrap.bat 文件所在的目录下 4、运行bootstrap.bat 脚本 start bootst…

CSS单位之vw、vh、vmin、vmax、%

CSS单位之vw、vh、vmin、vmax、% vm/vh:相对于视窗(Viewport)的高度和宽度。 1vh 等于1/100的视窗高度,1vw 等于1/100的视窗宽度。 视窗(Viewport)是指浏览器内部的可视区域大小,即window.innerWidth/window.innerHei…

研报精选230213

目录 【行业230213西南证券】医疗创新器械-内窥镜行业专题:核心三问,内窥镜技术趋势图谱和投资机会【行业230213国金证券】基础化工行业研究:成长接力,继续看好有边际变化的新材料【行业230213民生证券】有色金属周报:…

Hazel游戏引擎(004)

本人菜鸟,文中若有代码、术语等错误,欢迎指正 我写的项目地址:https://github.com/liujianjie/GameEngineLightWeight(中文的注释适合中国人的你) 文章目录前言操作步骤讲解GitHubHazel项目此项目定位项目属性修改Sand…

【蓝桥集训】第一天——前缀和

作者:指针不指南吗 专栏:Acwing 蓝桥集训每日一题 🐾输出的时候,注意数据类型🐾 文章目录1.截断数组2.前缀和3.子矩阵的和4.k倍区间1.截断数组 给定一个长度为 n 的数组 a1a_1a1​,a2a_2a2​,…,ana_nan​。 现在&…

Windows提权流程及手法

Windows提权一、信息收集二、WinSystemHelper三、Sherlock四、MSF提权五、参考链接一、信息收集 收集本机systeminfo中补丁信息 在提权辅助平台 https://i.hacking8.com/tiquan/ 中查询可利用exp 查询exp,选择对应的Exp下载运行 https://i.hacking8.com/ https:/…

在google设置静态页面 CDN加速

一、 创建bucket,设置bucket 链接:https://console.cloud.google.com/storage/browser 创建bucket 设置bucket公开访问 在bucket列表中,进入刚创建的bucket。 选择页面顶部附近的权限标签。 在权限部分中,点击 person_add 授…

Linux操作系统学习(了解环境变量)

文章目录环境变量初识除了上述介绍的PATH&#xff0c;还有一些常见的环境变量如&#xff1a;查看环境变量方法 &#xff1a;环境变量的基本概念&#xff1a;本地变量&#xff1a;环境变量初识 环境变量解释起来比较抽象&#xff0c;先看示例&#xff1a; #include <stdio.…

如果你是O型血的准妈妈,新生儿溶血症一定要提前了解,有备无患

婚姻&#xff0c;最重要的是同理心&#xff0c;合适的家庭&#xff0c;但一个刚刚分娩的宝贝妈妈认为&#xff0c;爱也可能需要血型匹配。原因是宝马刚出生的宝宝在医院治疗黄疸&#xff0c;因为宝马是O型血&#xff0c;而丈夫不是O型血&#xff0c;医院治疗黄疸的宝宝很多。这…

完美解决:重新安装VMware Tools灰色。以及共享文件夹的创建(centos8)

解决&#xff1a;重新安装VMware Tools灰色问题&#xff1a;重新安装VMware Tools灰色解决方案-挂载VMware中的linux.iso1. vmtools的linux.iso挂载及安装2. 共享文件夹的创建及配置问题&#xff1a;重新安装VMware Tools灰色 发现一个小问题&#xff0c;我的vm虚拟机安装后发…

前后端一些下载与配置(第二篇 第10天过后)nuxt banner redis 短信服务

NUXT 应该是不用怎么装&#xff1f; 有现成的 axios 还需要在npm吗 好像已经有现成的了 banner banner 笔记汇总P396 Redis Linux安装redis tar -xzvf redis-6.2.6.tar.gz cd redis-6.2.6 照着他做 然后 cd /usr/local/redis/bin ./redis-server /usr/local/redis…

微信小程序 事件传参,参数同步显示 button提交内容,读取input内容

我们先来回顾一下之前学的内容 我们可以在button组件中加入bindtap参数进行事件绑定 <button type"primary" bindtap"onbutton">按钮</button> onbutton(e){console.log(按钮被按下)}, 然后我们也能在input组件中加入bindinput参数进行事件绑…