16
2024
06
00:06:07

nvidia-smi:控制您的GPU



推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

翻译 https://www.microway.com/hpc-tech-tips/nvidia-smi_control-your-gpus/

大多数用户知道如何检查其CPU的状态,查看多少系统内存可用或找出多少磁盘空间可用。相反,从历史上看,保持GPU的运行状况和状态更加困难。如果您不知道在哪里看,甚至可能很难确定系统中GPU的类型和功能。值得庆幸的是,NVIDIA最新的硬件和软件工具在这方面取得了不错的改进。

该工具是NVIDIA的系统管理界面(nvidia-smi)。根据卡的生成方式,可以收集各种级别的信息。此外,可以启用和禁用GPU配置选项(例如ECC内存功能)。

顺便说一句,如果您发现在使NVIDIA GPU运行GPGPU代码方面遇到困难,这nvidia-smi会很方便。例如,在某些系统上/dev,启动时未创建正确的NVIDIA设备。nvidia-smi以root身份运行简单查询将初始化所有卡,并在中创建合适的设备/dev。在其他时候,确保所有GPU卡可见并正确通信非常有用。这是带有四个Tesla V100 GPU卡的最新版本的默认输出:

复制代码
nvidia-smi

±----------------------------------------------------------------------------+
| NVIDIA-SMI 410.48 Driver Version: 410.48 |
|-------------------------------±---------------------±---------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|=++==============|
| 0 Tesla V100-PCIE… Off | 00000000:18:00.0 Off | 0 |
| N/A 40C P0 55W / 250W | 31194MiB / 32480MiB | 44% Default |
±------------------------------±---------------------±---------------------+
| 1 Tesla V100-PCIE… Off | 00000000:3B:00.0 Off | 0 |
| N/A 40C P0 36W / 250W | 30884MiB / 32480MiB | 0% Default |
±------------------------------±---------------------±---------------------+
| 2 Tesla V100-PCIE… Off | 00000000:86:00.0 Off | 0 |
| N/A 41C P0 39W / 250W | 30884MiB / 32480MiB | 0% Default |
±------------------------------±---------------------±---------------------+
| 3 Tesla V100-PCIE… Off | 00000000:AF:00.0 Off | 0 |
| N/A 39C P0 37W / 250W | 30884MiB / 32480MiB | 0% Default |
±------------------------------±---------------------±---------------------+

±----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 305892 C /usr/bin/python 31181MiB |
±----------------------------------------------------------------------------+
复制代码
持续模式
在Linux上,您可以将GPU设置为持久模式,以使NVIDIA驱动程序加载,即使没有应用程序在访问这些卡也是如此。 当您要运行一系列短期作业时,此功能特别有用。 持久模式每个闲置的GPU使用更多的功率,但是可以防止每次启动GPU应用程序时出现相当长的延迟。 如果您已为GPU分配了特定的时钟速度或功率限制,则也很有必要(因为在卸载NVIDIA驱动程序时这些更改会丢失)。 通过运行以下命令在所有GPU上启用持久性模式:

nvidia-smi -pm 1
在Windows上,nvidia-smi无法设置持久性模式。 相反,您需要将计算GPU设置为TCC模式。 这应该通过NVIDIA的图形GPU设备管理面板来完成。

nvidia-smi支持的GPU
NVIDIA的SMI工具基本上支持自2011年以来发布的所有NVIDIA GPU。这些工具包括Fermi和更高架构家族(Kepler,Maxwell,Pascal,Volta等)的Tesla,Quadro和GeForce设备。

支持的产品包括:
Tesla:S1070,S2050,C1060,C2050 / 70,M2050 / 70/90,X2070 / 90,K10,K20,K20X,K40,K80,M40,P40,P100,V100
Quadro:4000、5000、6000、7000,M2070-Q,K系列,M系列,P系列,RTX系列
GeForce:支持级别不同,可用指标少于特斯拉和Quadro产品

查询GPU状态
我们为客户提供基准测试服务的Microway的GPU Test Drive集群包含一组NVIDIA最新的Tesla GPU。 这些是NVIDIA的高性能计算GPU,可提供大量的运行状况和状态信息。 以下示例摘自该内部群集。

要列出所有可用的NVIDIA设备,请运行:

nvidia-smi -L

GPU 0: Tesla K40m (UUID: GPU-d0e093a0-c3b3-f458-5a55-6eb69fxxxxxx)
GPU 1: Tesla K40m (UUID: GPU-d105b085-7239-3871-43ef-975ecaxxxxxx)
要列出有关每个GPU的某些详细信息,请尝试:

nvidia-smi --query-gpu=index,name,uuid,serial --format=csv

0, Tesla K40m, GPU-d0e093a0-c3b3-f458-5a55-6eb69fxxxxxx, 0323913xxxxxx
1, Tesla K40m, GPU-d105b085-7239-3871-43ef-975ecaxxxxxx, 0324214xxxxxx
要以1秒的更新间隔监视总体GPU使用情况:

复制代码
nvidia-smi dmon

gpu pwr gtemp mtemp sm mem enc dec mclk pclk

Idx W C C % % % % MHz MHz

0    43    35     -     0     0     0     0  2505  1075
1    42    31     -    97     9     0     0  2505  107512

(in this example, one GPU is idle and one GPU has 97% of the CUDA sm “cores” in use)
复制代码
要以1秒的更新间隔监视每个进程的GPU使用情况:

复制代码
nvidia-smi pmon

gpu pid type sm mem enc dec command

Idx # C/G % % % % name

0      14835     C    45    15     0     0   python         
1      14945     C    64    50     0     0   python12

(in this case, two different python processes are running; one on each GPU)
复制代码
监控和管理GPU Boost
NVIDIA在较新的GPU中包含的GPU Boost功能允许GPU时钟根据负载而变化(只要有可用的功率和散热空间,就可以实现最佳性能)。 但是,可用空间的大小会因应用程序(甚至是输入文件!)而异,因此用户和管理员应密切注意GPU的状态。

可以显示每个GPU(在本例中为Tesla V100)的可用时钟速度列表:

复制代码
nvidia-smi -q -d SUPPORTED_CLOCKS

GPU 00000000:18:00.0
Supported Clocks
Memory : 877 MHz
Graphics : 1380 MHz
Graphics : 1372 MHz
Graphics : 1365 MHz
Graphics : 1357 MHz
[…159 additional clock speeds omitted…]
Graphics : 157 MHz
Graphics : 150 MHz
Graphics : 142 MHz
Graphics : 135 MHz
复制代码
如图所示,Tesla V100 GPU支持167种不同的时钟速度(从135 MHz到1380 MHz)。 但是,仅支持一种内存时钟速度(877 MHz)。 某些GPU支持两种不同的内存时钟速度(一种高速和一种省电速度)。 通常,当内存处于省电速度(空闲GPU状态)时,此类GPU仅支持单个GPU时钟速度。 在所有最新的Tesla和Quadro GPU上,GPU Boost会自动管理这些速度并尽可能快地运行时钟(在热量/功率限制以及管理员设置的任何限制范围内)。

要查看当前的GPU时钟速度,默认时钟速度和最大可能的时钟速度,请运行:

复制代码
nvidia-smi -q -d CLOCK

GPU 00000000:18:00.0
Clocks
Graphics : 1230 MHz
SM : 1230 MHz
Memory : 877 MHz
Video : 1110 MHz
Applications Clocks
Graphics : 1230 MHz
Memory : 877 MHz
Default Applications Clocks
Graphics : 1230 MHz
Memory : 877 MHz
Max Clocks
Graphics : 1380 MHz
SM : 1380 MHz
Memory : 877 MHz
Video : 1237 MHz
Max Customer Boost Clocks
Graphics : 1380 MHz
SM Clock Samples
Duration : 0.01 sec
Number of Samples : 4
Max : 1230 MHz
Min : 135 MHz
Avg : 944 MHz
Memory Clock Samples
Duration : 0.01 sec
Number of Samples : 4
Max : 877 MHz
Min : 877 MHz
Avg : 877 MHz
Clock Policy
Auto Boost : N/A
Auto Boost Default : N/A
复制代码
理想情况下,您希望所有时钟始终以最高速度运行。 但是,这并非对所有应用程序都可行。 要查看每个GPU的当前状态以及时钟变慢的任何原因,请使用PERFORMANCE标志:

复制代码
nvidia-smi -q -d PERFORMANCE

GPU 00000000:18:00.0
Performance State : P0
Clocks Throttle Reasons
Idle : Not Active
Applications Clocks Setting : Not Active
SW Power Cap : Not Active
HW Slowdown : Not Active
HW Thermal Slowdown : Not Active
HW Power Brake Slowdown : Not Active
Sync Boost : Not Active
SW Thermal Slowdown : Not Active
Display Clock Setting : Not Active
复制代码
如果任何GPU时钟运行速度较慢,则上述“时钟节流原因”中的一个或多个将被标记为活动。 最令人担忧的情况是硬件减速是否处于活动状态,因为这很可能表明电源或散热问题。 其余条件通常表明该卡处于空闲状态或已由系统管理员手动设置为较慢的模式。

使用nvidia-smi查看系统/ GPU拓扑和NVLink
为了正确利用更高级的NVIDIA GPU功能(例如GPU Direct),正确配置系统拓扑至关重要。 拓扑结构是指各种系统设备(GPU,InfiniBand HCA,存储控制器等)如何相互连接以及如何与系统的CPU连接。 某些拓扑类型将降低性能,甚至导致某些功能不可用。 为了帮助解决此类问题,nvidia-smi支持系统拓扑和连接性查询:

复制代码
nvidia-smi topo --matrix

    GPU0    GPU1    GPU2    GPU3    mlx4_0  CPU Affinity1

GPU0 X PIX PHB PHB PHB 0-11
GPU1 PIX X PHB PHB PHB 0-11
GPU2 PHB PHB X PIX PHB 0-11
GPU3 PHB PHB PIX X PHB 0-11
mlx4_0 PHB PHB PHB PHB X

Legend:

X = Self
SOC = Path traverses a socket-level link (e.g. QPI)
PHB = Path traverses a PCIe host bridge
PXB = Path traverses multiple PCIe internal switches
PIX = Path traverses a PCIe internal switch
复制代码
复习本节将需要一些时间来适应,但可能非常有价值。 上面的配置显示了两个Tesla K80 GPU和一个Mellanox FDR InfiniBand HCA(mlx4_0),它们都连接到服务器的第一个CPU。 由于CPU是12核Xeon,因此拓扑工具建议将作业分配给前12个CPU核(尽管具体情况因应用程序而异)。

更高复杂性的系统在检查其配置和功能时需要格外小心。 以下是NVIDIA DGX-1系统的nvidia-smi拓扑的输出,其中包括两个20核CPU,八个连接NVLink的GPU和四个Mellanox InfiniBand适配器:

复制代码
GPU0 GPU1 GPU2 GPU3 GPU4 GPU5 GPU6 GPU7 mlx5_0 mlx5_2 mlx5_1 mlx5_3 CPU Affinity
GPU0 X NV1 NV1 NV2 NV2 SYS SYS SYS PIX SYS PHB SYS 0-19,40-59
GPU1 NV1 X NV2 NV1 SYS NV2 SYS SYS PIX SYS PHB SYS 0-19,40-59
GPU2 NV1 NV2 X NV2 SYS SYS NV1 SYS PHB SYS PIX SYS 0-19,40-59
GPU3 NV2 NV1 NV2 X SYS SYS SYS NV1 PHB SYS PIX SYS 0-19,40-59
GPU4 NV2 SYS SYS SYS X NV1 NV1 NV2 SYS PIX SYS PHB 20-39,60-79
GPU5 SYS NV2 SYS SYS NV1 X NV2 NV1 SYS PIX SYS PHB 20-39,60-79
GPU6 SYS SYS NV1 SYS NV1 NV2 X NV2 SYS PHB SYS PIX 20-39,60-79
GPU7 SYS SYS SYS NV1 NV2 NV1 NV2 X SYS PHB SYS PIX 20-39,60-79
mlx5_0 PIX PIX PHB PHB SYS SYS SYS SYS X SYS PHB SYS
mlx5_2 SYS SYS SYS SYS PIX PIX PHB PHB SYS X SYS PHB
mlx5_1 PHB PHB PIX PIX SYS SYS SYS SYS PHB SYS X SYS
mlx5_3 SYS SYS SYS SYS PHB PHB PIX PIX SYS PHB SYS X

Legend:

X = Self
SYS = Connection traversing PCIe as well as the SMP interconnect between NUMA nodes (e.g., QPI/UPI)
NODE = Connection traversing PCIe as well as the interconnect between PCIe Host Bridges within a NUMA node
PHB = Connection traversing PCIe as well as a PCIe Host Bridge (typically the CPU)
PXB = Connection traversing multiple PCIe switches (without traversing the PCIe Host Bridge)
PIX = Connection traversing a single PCIe switch
NV# = Connection traversing a bonded set of # NVLinks
复制代码
还可以查询NVLink连接本身,以确保状态,功能和运行状况。 鼓励读者查阅NVIDIA文档,以更好地了解细节。 DGX-1上nvidia-smi的简短摘要如下所示。

复制代码
nvidia-smi nvlink --status

GPU 0: Tesla V100-SXM2-32GB
Link 0: 25.781 GB/s
Link 1: 25.781 GB/s
Link 2: 25.781 GB/s
Link 3: 25.781 GB/s
Link 4: 25.781 GB/s
Link 5: 25.781 GB/s

     [snip]1

GPU 7: Tesla V100-SXM2-32GB
Link 0: 25.781 GB/s
Link 1: 25.781 GB/s
Link 2: 25.781 GB/s
Link 3: 25.781 GB/s
Link 4: 25.781 GB/s
Link 5: 25.781 GB/s
复制代码
打印所有GPU详细信息
要列出特定GPU上的所有可用数据,请使用-i指定卡的ID。 这是旧版Tesla GPU卡的输出:

复制代码
NVSMI LOG
Timestamp : Mon Nov 5 14:50:59 2018
Driver Version : 410.48

Attached GPUs : 4
GPU 00000000:18:00.0
Product Name : Tesla V100-PCIE-32GB
Product Brand : Tesla
Display Mode : Enabled
Display Active : Disabled
Persistence Mode : Disabled
Accounting Mode : Disabled
Accounting Mode Buffer Size : 4000
Driver Model
Current : N/A
Pending : N/A
Serial Number : 032161808xxxx
GPU UUID : GPU-4965xxxx-79e3-7941-12cb-1dfe9c53xxxx
Minor Number : 0
VBIOS Version : 88.00.48.00.02
MultiGPU Board : No
Board ID : 0x1800
GPU Part Number : 900-2G500-0010-000
Inforom Version
Image Version : G500.0202.00.02
OEM Object : 1.1
ECC Object : 5.0
Power Management Object : N/A
GPU Operation Mode
Current : N/A
Pending : N/A
GPU Virtualization Mode
Virtualization mode : None
IBMNPU
Relaxed Ordering Mode : N/A
PCI
Bus : 0x18
Device : 0x00
Domain : 0x0000
Device Id : 0x1DB610DE
Bus Id : 00000000:18:00.0
Sub System Id : 0x124A10DE
GPU Link Info
PCIe Generation
Max : 3
Current : 3
Link Width
Max : 16x
Current : 16x
Bridge Chip
Type : N/A
Firmware : N/A
Replays since reset : 0
Tx Throughput : 31000 KB/s
Rx Throughput : 155000 KB/s
Fan Speed : N/A
Performance State : P0
Clocks Throttle Reasons
Idle : Not Active
Applications Clocks Setting : Not Active
SW Power Cap : Not Active
HW Slowdown : Not Active
HW Thermal Slowdown : Not Active
HW Power Brake Slowdown : Not Active
Sync Boost : Not Active
SW Thermal Slowdown : Not Active
Display Clock Setting : Not Active
FB Memory Usage
Total : 32480 MiB
Used : 31194 MiB
Free : 1286 MiB
BAR1 Memory Usage
Total : 32768 MiB
Used : 8 MiB
Free : 32760 MiB
Compute Mode : Default
Utilization
Gpu : 44 %
Memory : 4 %
Encoder : 0 %
Decoder : 0 %
Encoder Stats
Active Sessions : 0
Average FPS : 0
Average Latency : 0
FBC Stats
Active Sessions : 0
Average FPS : 0
Average Latency : 0
Ecc Mode
Current : Enabled
Pending : Enabled
ECC Errors
Volatile
Single Bit
Device Memory : 0
Register File : 0
L1 Cache : 0
L2 Cache : 0
Texture Memory : N/A
Texture Shared : N/A
CBU : N/A
Total : 0
Double Bit
Device Memory : 0
Register File : 0
L1 Cache : 0
L2 Cache : 0
Texture Memory : N/A
Texture Shared : N/A
CBU : 0
Total : 0
Aggregate
Single Bit
Device Memory : 0
Register File : 0
L1 Cache : 0
L2 Cache : 0
Texture Memory : N/A
Texture Shared : N/A
CBU : N/A
Total : 0
Double Bit
Device Memory : 0
Register File : 0
L1 Cache : 0
L2 Cache : 0
Texture Memory : N/A
Texture Shared : N/A
CBU : 0
Total : 0
Retired Pages
Single Bit ECC : 0
Double Bit ECC : 0
Pending : No
Temperature
GPU Current Temp : 40 C
GPU Shutdown Temp : 90 C
GPU Slowdown Temp : 87 C
GPU Max Operating Temp : 83 C
Memory Current Temp : 39 C
Memory Max Operating Temp : 85 C
Power Readings
Power Management : Supported
Power Draw : 58.81 W
Power Limit : 250.00 W
Default Power Limit : 250.00 W
Enforced Power Limit : 250.00 W
Min Power Limit : 100.00 W
Max Power Limit : 250.00 W
Clocks
Graphics : 1380 MHz
SM : 1380 MHz
Memory : 877 MHz
Video : 1237 MHz
Applications Clocks
Graphics : 1230 MHz
Memory : 877 MHz
Default Applications Clocks
Graphics : 1230 MHz
Memory : 877 MHz
Max Clocks
Graphics : 1380 MHz
SM : 1380 MHz
Memory : 877 MHz
Video : 1237 MHz
Max Customer Boost Clocks
Graphics : 1380 MHz
Clock Policy
Auto Boost : N/A
Auto Boost Default : N/A
Processes
Process ID : 315406
Type : C
Name : /usr/bin/python
Used GPU Memory : 31181 MiB
复制代码
额外的nvidia-smi选项
当然,我们还没有介绍nvidia-smi工具的所有可能用途。 要阅读选项的完整列表,请运行nvidia-smi -h(相当长)。 一些子命令具有自己的帮助部分。 如果您需要更改卡上的设置,则需要查看设备修改部分:

复制代码
-pm, --persistence-mode= Set persistence mode: 0/DISABLED, 1/ENABLED
-e, --ecc-config= Toggle ECC support: 0/DISABLED, 1/ENABLED
-p, --reset-ecc-errors= Reset ECC error counts: 0/VOLATILE, 1/AGGREGATE
-c, --compute-mode= Set MODE for compute applications:
0/DEFAULT, 1/EXCLUSIVE_PROCESS,
2/PROHIBITED
–gom= Set GPU Operation Mode:
0/ALL_ON, 1/COMPUTE, 2/LOW_DP
-r --gpu-reset Trigger reset of the GPU.
Can be used to reset the GPU HW state in situations
that would otherwise require a machine reboot.
Typically useful if a double bit ECC error has
occurred.
Reset operations are not guarenteed to work in
all cases and should be used with caution.
-vm --virt-mode= Switch GPU Virtualization Mode:
Sets GPU virtualization mode to 3/VGPU or 4/VSGA
Virtualization mode of a GPU can only be set when
it is running on a hypervisor.
-lgc --lock-gpu-clocks= Specifies clocks as a
pair (e.g. 1500,1500) that defines the range
of desired locked GPU clock speed in MHz.
Setting this will supercede application clocks
and take effect regardless if an app is running.
Input can also be a singular desired clock value
(e.g. ).
-rgc --reset-gpu-clocks
Resets the Gpu clocks to the default values.
-ac --applications-clocks= Specifies clocks as a
pair (e.g. 2000,800) that defines GPU’s
speed in MHz while running applications on a GPU.
-rac --reset-applications-clocks
Resets the applications clocks to the default values.
-acp --applications-clocks-permission=
Toggles permission requirements for -ac and -rac commands:
0/UNRESTRICTED, 1/RESTRICTED
-pl --power-limit= Specifies maximum power management limit in watts.
-am --accounting-mode= Enable or disable Accounting Mode: 0/DISABLED, 1/ENABLED
-caa --clear-accounted-apps
Clears all the accounted PIDs in the buffer.
–auto-boost-default= Set the default auto boost policy to 0/DISABLED
or 1/ENABLED, enforcing the change only after the
last boost client has exited.
–auto-boost-permission=
Allow non-admin/root control over auto boost mode:
0/UNRESTRICTED, 1/RESTRICTED


本文链接:http://hqyman.cn/post/6649.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:





休息一下~~


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

您的IP地址是: