Linux 监控服务器GPU状态

1 前言

深度学习需要使用GPU进行训练学习,在训练我们的模型时,我们需要直到GPU的状态,以帮助我们监控程序的运行。下面就介绍几种简单的方式来展示GPU的状态

2 监控GPU状态

2.1 使用nvidia-smi

nvidia-smi

在这里插入图片描述

这种方式最常用,基本展示了GPU的信息,为了起到实时的作用,可以使用watch命令

watch -n 3 nvidia-smi

此时每隔3秒,就会更新一次数据

$ watch --help
用法:
 watch [options] command

选项:
  -b, --beep             如果命令以非零返回值退出的话则发出哔声
  -c, --color            interpret ANSI color and style sequences
  -d, --differences[=<permanent>]
                         highlight changes between updates
  -e, --errexit          exit if command has a non-zero exit
  -g, --chgexit          exit when output from command changes
  -n, --interval <secs>  seconds to wait between updates
  -p, --precise          尝试以精确的间隔运行命令
  -t, --no-title         关闭头部显示
  -x, --exec             将命令传给 exec 而非“sh -c”

 -h, --help     显示此帮助然后离开
 -v, --version  output version information and exit

2.2 使用gpustat

gpustatpython中的一个包,这里我们使用anaconda中的环境进行安装和使用

  1. 进入base环境
conda activate
  1. 下载gpustat
pip install gpustat
  1. 在conda环境中执行命令
gpustat

在这里插入图片描述

查看帮助

gpustat -h

usage: gpustat [-h] [--force-color | --no-color] [-a] [-c] [-f] [-u] [-p] [-F] [-e [{,enc,dec,enc,dec}]]
               [-P [{,draw,limit,draw,limit,limit,draw}]] [--json] [-i [INTERVAL]] [--no-header]
               [--gpuname-width GPUNAME_WIDTH] [--debug] [-v]

optional arguments:
  -h, --help            show this help message and exit
  --force-color, --color
                        Force to output with colors
  --no-color            Suppress colored output
  -a, --show-all        Display all gpu properties above
  -c, --show-cmd        Display cmd name of running process
  -f, --show-full-cmd   Display full command and cpu stats of running process
  -u, --show-user       Display username of running process
  -p, --show-pid        Display PID of running process
  -F, --show-fan-speed, --show-fan
                        Display GPU fan speed
  -e [{,enc,dec,enc,dec}], --show-codec [{,enc,dec,enc,dec}]
                        Show encoder/decoder utilization
  -P [{,draw,limit,draw,limit,limit,draw}], --show-power [{,draw,limit,draw,limit,limit,draw}]
                        Show GPU power usage or draw (and/or limit)
  --json                Print all the information in JSON format
  -i [INTERVAL], --interval [INTERVAL], --watch [INTERVAL]
                        Use watch mode if given; seconds to wait between updates
  --no-header           Suppress header message
  --gpuname-width GPUNAME_WIDTH
                        The width at which GPU names will be displayed.
  --debug               Allow to print additional informations for debugging.
  -v, --version         show program's version number and exit

每个1秒展示状态,并展示使用GPU的PID

gpustat -i 1 -p

在这里插入图片描述

此时会单独占用一个终端,并按照要求展示状态


  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值