码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 【Python】pytorch,CUDA是否可用,查看显卡显存剩余容量


    CUDA可用,共有 1 个GPU设备可用。
    当前使用的GPU设备索引:0
    当前使用的GPU设备名称:NVIDIA T1000
    GPU显存总量:4.00 GB
    已使用的GPU显存:0.00 GB
    剩余GPU显存:4.00 GB
    PyTorch版本:1.10.1+cu102

    import torch
    
    # 检查CUDA是否可用
    cuda_available = torch.cuda.is_available()
    
    if cuda_available:
        # 获取GPU设备数量
        num_gpu = torch.cuda.device_count()
    
        # 获取当前使用的GPU索引
        current_gpu_index = torch.cuda.current_device()
    
        # 获取当前GPU的名称
        current_gpu_name = torch.cuda.get_device_name(current_gpu_index)
    
        # 获取GPU显存的总量和已使用量
        total_memory = torch.cuda.get_device_properties(current_gpu_index).total_memory / (1024 ** 3)  # 显存总量(GB)
        used_memory = torch.cuda.memory_allocated(current_gpu_index) / (1024 ** 3)  # 已使用显存(GB)
        free_memory = total_memory - used_memory  # 剩余显存(GB)
    
        print(f"CUDA可用,共有 {num_gpu} 个GPU设备可用。")
        print(f"当前使用的GPU设备索引:{current_gpu_index}")
        print(f"当前使用的GPU设备名称:{current_gpu_name}")
        print(f"GPU显存总量:{total_memory:.2f} GB")
        print(f"已使用的GPU显存:{used_memory:.2f} GB")
        print(f"剩余GPU显存:{free_memory:.2f} GB")
    else:
        print("CUDA不可用。")
    
    # 检查PyTorch版本
    print(f"PyTorch版本:{torch.__version__}")
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    windows先装显卡驱动,再装CUDA10.2,最后装了pytorch。

    pip install torch1.10.1+cu102 torchvision0.13.1+cu102 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu102

    在这里插入图片描述

  • 相关阅读:
    Java项目:SSM在线美食分享推荐平台网站
    宝塔部署code-server
    mulesoft Module 13 quiz 解析
    Redis 缓存预热、预热数据选取策略、缓存保温、性能边界
    cdn加速华为云obs桶文件配置过程(详细)
    Kyligence 亮相 Gartner 2022 数据与分析峰会,解锁数据智能新潜力
    携职教育:一个暑假的时间,就能拿下这本证书啦
    HTTP 协议请求头 If-Match、If-None-Match 和 ETag
    [爬虫]2.2.1 使用Selenium库模拟浏览器操作
    第一个 Shell 脚本
  • 原文地址:https://blog.csdn.net/x1131230123/article/details/132690376
  • 最新文章
  • polygon出题教程
    Manim物理模拟:别自己写欧拉了!
    AI 学习笔记:Agent 的应用演示
    分享一个CAN报文编辑器软件
    MiniCPM-V 4.6 部署实战:基于 GPUStack 与 SGLang 的端侧多模态模型部署
    用 FRP 打通云服务器与本地 Ubuntu,让 Codex 远程调试本地硬件
    软考 - 架构设计师 知识点总结
    给 FastApiAdmin 加个“会议纪要”模块,我把后端二次开发的坑踩了个遍
    聊一聊 MES系统如何实现多种标签打印并支持不同打印机
    断尺问题:戴德金分割现实悖论
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号