python nvidia 显卡信息 格式数据

python nvidia 显卡信息 格式数据.

python 复制代码
def get_gpu_memory():
    result = subprocess.check_output(['nvidia-smi', '--query-gpu=pci.bus_id,memory.used,memory.total,memory.free', '--format=csv'])
    # 返回 GPU 的显存使用情况,单位为 M
    info = []
    for t in csv.DictReader(result.decode().splitlines()):
        info.append({'id':t['pci.bus_id'],
         'used':int(t[' memory.used [MiB]'].split()[0]),
         'total':int(t[' memory.total [MiB]'].split()[0]),
         'free':int(t[' memory.free [MiB]'].split()[0])})
    return info

参考

相关推荐
曲幽17 小时前
FastAPI + PostgreSQL 实战:从入门到不踩坑,一次讲透
python·sql·postgresql·fastapi·web·postgres·db·asyncpg
用户8356290780511 天前
使用 C# 在 Excel 中创建数据透视表
后端·python
码路飞1 天前
FastMCP 实战:一个 .py 文件,给 Claude Code 装上 3 个超实用工具
python·ai编程·mcp
dev派1 天前
AI Agent 系统中的常用 Workflow 模式(2) Evaluator-Optimizer模式
python·langchain
前端付豪1 天前
AI 数学辅导老师项目构想和初始化
前端·后端·python
用户0332126663671 天前
将 PDF 文档转换为图片【Python 教程】
python
悟空爬虫1 天前
UV实战教程,我啥要从Anaconda切换到uv来管理包?
python
dev派1 天前
AI Agent 系统中的常用 Workflow 模式(1)
python·langchain
明月_清风1 天前
从“能用”到“专业”:构建生产级装饰器与三层逻辑拆解
后端·python
曲幽2 天前
数据库实战:FastAPI + SQLAlchemy 2.0 + Alembic 从零搭建,踩坑实录
python·fastapi·web·sqlalchemy·db·asyncio·alembic