Linux 查看GPU状态


Linux 查看GPU状态

nvidia-smi

nvidia-smi是NVIDIA自带的一个命令可以详细的展示显卡的运行状态。

gpustat

gpustat是github上开源的一个小工具,对于v1.0目前支持python 3.4+,对于python 2.7-3.4支持v0.x

可以直接用pip安装

pip install gpustat

如果没有root权限的话

pip install --user gpustat

如果没有root权限,安装完之后,可能需要添加环境变量。

export PATH=$PATH:/home/XXX/.local/bin
# XXX换成你的用户名

使用命令

$ gpustat -options

Options:

  • --color : Force colored output (even when stdout is not a tty)
  • --no-color : Suppress colored output
  • -u, --show-user : Display username of the process owner
  • -c, --show-cmd : Display the process name
  • -f, --show-full-cmd : Display full command and cpu stats of running process
  • -p, --show-pid : Display PID of the process
  • -F, --show-fan : Display GPU fan speed
  • -e, --show-codec : Display encoder and/or decoder utilization
  • -P, --show-power : Display GPU power usage and/or limit (draw or draw,limit)
  • -a, --show-all : Display all gpu properties above
  • --watch, -i, --interval : Run in watch mode (equivalent to watch gpustat) if given. Denotes interval between updates.
  • --json : JSON Output (Experimental)
$ gpustat

不带任何参数,会显示gpu的基本使用情况

20210405205222

$ gpustat -cp

显示具体进程号和进程名

20210405210306

输出实例解释

[0] GeForce GTX Titan X | 77'C, 96 % | 11848 / 12287 MB | python/52046(11821M)
  • [0]: GPUindex (starts from 0) as PCI_BUS_ID
  • GeForce GTX Titan `: GPU name
  • 77’C: Temperature
  • 96 %: Utilization
  • 11848 / 12287 MB: GPU Memory Usage
  • python/...: Running processes on GPU (and their memory usage)

实时动态显示

watch --color -n1 gpustat -cpu

结合watch可以动态实时的监控GPU的使用情况。