翻譯 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 1075 (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 python (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 Affinity 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] 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