如果您是一位技术爱好者,或者是一位希望密切关注 GPU 性能的 Linux 用户,那您就来对地方了。 在这篇文章中,我们将探索 GPU 监控软件的世界,尤其是 Ubuntu/Debian Linux。 无论您是游戏玩家、数据科学家,还是从事 GPU 密集型任务的开发人员,拥有一个可靠的 GPU 监控软件对于优化性能和确保系统在压力下保持冷静都至关重要。 我们将深入探讨 GPUStat、NVTOP 和 NVITOP 等流行工具,讨论它们的功能和安装方法,让你拥有全面的 CPU 和 GPU 监控能力。 GPUStat 和 NVTOP 是一款花哨但非常实用的 GPU 监控工具,是基于 ncurses 的英伟达™(NVIDIA®)GPU 状态查看器,类似于 htop 命令或 top 命令。 我们可以在 Debian 或 Ubuntu Linux 上使用 pip/apt 命令按如下步骤安装它。 那么,让我们开始在 Linux 上使用 GPU 监控功能吧!
Top 1. GPUStat
GPUStat 是一款用于查询和监控 GPU 状态的简单命令行实用程序。 它仅适用于英伟达™(NVIDIA®)图形设备。 不支持 AMD GPU。 这是一款免费开源软件。
从 PyPI 安装 GPUStat Install。 更多信息,请访问 Github 上的 GPUStat: https://github.com/wookayin/gpustat
$ pip install gpustat
如果您没有 root (sudo) 权限,请尝试在用户名空间安装 gpustat:
$ pip install --user gpustat
GPUStat使用示例
常用的 gupstat 命令如下:
# To periodically watch
$ gpustat --watch
# If something goes wrong, try
$ gpustat --debug
# Monitor gpu
$ gpustat -cp
更多使用信息,请查阅使用帮助。
# See help details
$ gpustat --help
usage: gpustat [-h] [--force-color | --no-color] [--id ID] [-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] [--no-processes] [-v]
options:
-h, --help show this help message and exit
--force-color, --color
Force to output with colors
--no-color Suppress colored output
--id ID Target a specific GPU (index).
-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.
--no-processes Do not display running process information (memory, user, etc.)
-v, --version show program's version number and exit
Top 2. NVTOP
Nvtop 是 Neat Video card TOP 的缩写,类似于 AMD、Intel 和 NVIDIA GPU 的任务监视器。 它可以处理多个 GPU,并以 htop 熟悉的方式打印它们的相关信息。
将 Nvtop 安装在 Ubuntu Impish (21.10)、Debian buster(稳定版)及更新版本上。 更多信息,请访问 Github 上的 Nvtop: https://github.com/Syllo/nvtop
install nvtop
$ sudo apt install nvtop
在 Ubuntu 20.04、22.04 及更新版本上
$ sudo add-apt-repository ppa:flexiondotorg/nvtop
$ sudo apt install nvtop
NVTOP 使用示例
## RUN the tool ##
$ nvtop
快速命令行参数帮助。
$ nvtop --help
nvtop version 1.0.0
Available options:
-d --delay : Select the refresh rate (1 == 0.1s)
-v --version : Print the version and exit
-s --gpu-select : Column separated list of GPU IDs to monitor
-i --gpu-ignore : Column separated list of GPU IDs to ignore
-p --no-plot : Disable bar plot
-C --no-color : No colors
-N --no-cache : Always query the system for user names and command line information
-f --freedom-unit : Use fahrenheit
-E --encode-hide : Set encode/decode auto hide time in seconds (default 30s, negative = always on screen)
-h --help : Print help and exit
Top 3. NVITOP
Nvitop 是一款交互式英伟达™(NVIDIA®)GPU 进程查看器,也是 GPU 进程管理的一站式解决方案。 Nvitop 可以轻松集成到其他应用程序中。 您可以使用 Nvitop 制作自己的监控工具。 完整的 A PI 主机参考文献请访问 https://nvitop.readthedocs.io。
安装 NVITOP
从 PyPI 安装。 更多信息,请访问 Github 上的 Nvitop: https://github.com/XuehaiPan/nvitop
# Install nvitop
$ pip3 install --upgrade nvitop
强烈建议在隔离的虚拟环境中安装 nvitop。 通过 pipx 简单安装和运行
从 conda-forge 安装
conda install -c conda-forge nvitop
NVITOP 使用示例
# Query the status of all devices
$ nvitop -1 # or use `python3 -m nvitop -1`
# Specify query devices (by integer indices)
$ nvitop -1 -o 0 1 # only show <GPU 0> and <GPU 1>
# Run as a resource monitor
$ nvitop
按 h 键会显示帮助屏幕,或输入 nvitop --help 查看更多命令选项: