码农知识堂 - 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

    在这里插入图片描述

  • 相关阅读:
    目标检测算法——工业缺陷数据集汇总2(附下载链接)
    js:对于JavaScript数字对象的初步认知
    android Leakcanary/Studio Profiler/MAT 处理内存问题(泄漏和Big超大内存对象)
    外包干了三年,快要废了。。。
    世界前沿技术发展报告2023《世界航天技术发展报告》(四)载人航天技术
    信用卡使用雷区大揭秘:为何你贷款被拒?
    信息学奥赛一本通:1156:求π的值
    c++ || 位运算
    力扣452-用最少数量的箭引爆气球——贪心算法
    为何海量计算机系毕业生“负债”报IT培训班?高校IT教育该如何变革?
  • 原文地址:https://blog.csdn.net/x1131230123/article/details/132690376
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号