当前位置: 首页 > news >正文

linux: nvidia-smi用法详解

文章目录

  • 1. 描述
  • 2. 语法
  • 3. 参数
  • 4. 例子
    • 4.1 基础用法
    • 4.2 查看实时GPU性能
    • 4.3 限制GPU功率
    • 4.4 查看显存使用情况
    • 4.5 列出每个进程的GPU使用情况
    • 4.6 杀死占用GPU的进程
    • 4.7 导出GPU使用日志
    • 4.8 查询更多特定信息
    • 4.9 查看支持的GPU工作模式


1. 描述

nvidia-smi(NVIDIA System Management Interface)是 NVIDIA 提供的命令行工具,用于监控和管理 NVIDIA GPU 的状态和性能。通过nvidia-smi,你可以查看 GPU 的使用情况、温度、功率、显存占用、驱动版本等信息。

2. 语法

基础用法:

nvidia-smi

详细描述:

nvidia-smi [OPTION1 [ARG1]] [OPTION2 [ARG2]] ...-h,   --help                Print usage information and exit.LIST OPTIONS:-L,   --list-gpus           Display a list of GPUs connected to the system.-B,   --list-excluded-gpus  Display a list of excluded GPUs in the system.SUMMARY OPTIONS:<no arguments>              Show a summary of GPUs connected to the system.[plus any of]-i,   --id=                 Target a specific GPU.-f,   --filename=           Log to a specified file, rather than to stdout.-l,   --loop=               Probe until Ctrl+C at specified second interval.QUERY OPTIONS:-q,   --query               Display GPU or Unit info.[plus any of]-u,   --unit                Show unit, rather than GPU, attributes.-i,   --id=                 Target a specific GPU or Unit.-f,   --filename=           Log to a specified file, rather than to stdout.-x,   --xml-format          Produce XML output.--dtd                 When showing xml output, embed DTD.-d,   --display=            Display only selected information: MEMORY,UTILIZATION, ECC, TEMPERATURE, POWER, CLOCK,COMPUTE, PIDS, PERFORMANCE, SUPPORTED_CLOCKS,PAGE_RETIREMENT, ACCOUNTING, ENCODER_STATS,SUPPORTED_GPU_TARGET_TEMP, VOLTAGEFBC_STATS, ROW_REMAPPER, RESET_STATUSFlags can be combined with comma e.g. ECC,POWER.Sampling data with max/min/avg is also returned for POWER, UTILIZATION and CLOCK display types.Doesn't work with -u or -x flags.-l,   --loop=               Probe until Ctrl+C at specified second interval.-lms, --loop-ms=            Probe until Ctrl+C at specified millisecond interval.SELECTIVE QUERY OPTIONS:Allows the caller to pass an explicit list of properties to query.[one of]--query-gpu                 Information about GPU.Call --help-query-gpu for more info.--query-supported-clocks    List of supported clocks.Call --help-query-supported-clocks for more info.--query-compute-apps        List of currently active compute processes.Call --help-query-compute-apps for more info.--query-accounted-apps      List of accounted compute processes.Call --help-query-accounted-apps for more info.This query is not supported on vGPU host.--query-retired-pages       List of device memory pages that have been retired.Call --help-query-retired-pages for more info.--query-remapped-rows       Information about remapped rows.Call --help-query-remapped-rows for more info.[mandatory]--format=                   Comma separated list of format options:csv - comma separated values (MANDATORY)noheader - skip the first line with column headersnounits - don't print units for numericalvalues[plus any of]-i,   --id=                 Target a specific GPU or Unit.-f,   --filename=           Log to a specified file, rather than to stdout.-l,   --loop=               Probe until Ctrl+C at specified second interval.-lms, --loop-ms=            Probe until Ctrl+C at specified millisecond interval.DEVICE MODIFICATION OPTIONS:[any one of]-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_THREAD (DEPRECATED),2/PROHIBITED, 3/EXCLUSIVE_PROCESS--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 situationsthat would otherwise require a machine reboot.Typically useful if a double bit ECC error hasoccurred.Reset operations are not guarenteed to work inall cases and should be used with caution.-vm   --virt-mode=          Switch GPU Virtualization Mode:Sets GPU virtualization mode to 3/VGPU or 4/VSGAVirtualization mode of a GPU can only be set whenit is running on a hypervisor.-lgc  --lock-gpu-clocks=    Specifies <minGpuClock,maxGpuClock> clocks as apair (e.g. 1500,1500) that defines the range of desired locked GPU clock speed in MHz.Setting this will supercede application clocksand take effect regardless if an app is running.Input can also be a singular desired clock value(e.g. <GpuClockValue>). Optionally, --mode can bespecified to indicate a special mode.-m    --mode=               Specifies the mode for --locked-gpu-clocks.Valid modes: 0, 1-rgc  --reset-gpu-clocksResets the Gpu clocks to the default values.-lmc  --lock-memory-clocks=  Specifies <minMemClock,maxMemClock> clocks as apair (e.g. 5100,5100) that defines the range of desired locked Memory clock speed in MHz.Input can also be a singular desired clock value(e.g. <MemClockValue>).-rmc  --reset-memory-clocksResets the Memory clocks to the default values.-lmcd --lock-memory-clocks-deferred=Specifies memClock clock to lock. This limit isapplied the next time GPU is initialized.This is guaranteed by unloading and reloading the kernel module.Requires root.-rmcd --reset-memory-clocks-deferredResets the deferred Memory clocks applied.-ac   --applications-clocks= Specifies <memory,graphics> clocks as apair (e.g. 2000,800) that defines GPU'sspeed in MHz while running applications on a GPU.-rac  --reset-applications-clocksResets the applications clocks to the default values.-pl   --power-limit=        Specifies maximum power management limit in watts.Takes an optional argument --scope.-sc   --scope=              Specifies the device type for --scope: 0/GPU, 1/TOTAL_MODULE (Grace Hopper Only)-cc   --cuda-clocks=        Overrides or restores default CUDA clocks.In override mode, GPU clocks higher frequencies when running CUDA applications.Only on supported devices starting from the Volta series.Requires administrator privileges.0/RESTORE_DEFAULT, 1/OVERRIDE-am   --accounting-mode=    Enable or disable Accounting Mode: 0/DISABLED, 1/ENABLED-caa  --clear-accounted-appsClears all the accounted PIDs in the buffer.--auto-boost-default= Set the default auto boost policy to 0/DISABLEDor 1/ENABLED, enforcing the change only after thelast boost client has exited.--auto-boost-permission=Allow non-admin/root control over auto boost mode:0/UNRESTRICTED, 1/RESTRICTED-mig  --multi-instance-gpu= Enable or disable Multi Instance GPU: 0/DISABLED, 1/ENABLEDRequires root.-gtt  --gpu-target-temp=    Set GPU Target Temperature for a GPU in degree celsius.Requires administrator privileges[plus optional]-i,   --id=                 Target a specific GPU.-eow, --error-on-warning    Return a non-zero error for warnings.UNIT MODIFICATION OPTIONS:-t,   --toggle-led=         Set Unit LED state: 0/GREEN, 1/AMBER[plus optional]-i,   --id=                 Target a specific Unit.SHOW DTD OPTIONS:--dtd                 Print device DTD and exit.[plus optional]-f,   --filename=           Log to a specified file, rather than to stdout.-u,   --unit                Show unit, rather than device, DTD.--debug=                    Log encrypted debug information to a specified file. Device Monitoring:dmon                        Displays device stats in scrolling format."nvidia-smi dmon -h" for more information.daemon                      Runs in background and monitor devices as a daemon process.This is an experimental feature. Not supported on Windows baremetal"nvidia-smi daemon -h" for more information.replay                      Used to replay/extract the persistent stats generated by daemon.This is an experimental feature."nvidia-smi replay -h" for more information.Process Monitoring:pmon                        Displays process stats in scrolling format."nvidia-smi pmon -h" for more information.TOPOLOGY:topo                        Displays device/system topology. "nvidia-smi topo -h" for more information.DRAIN STATES:drain                       Displays/modifies GPU drain states for power idling. "nvidia-smi drain -h" for more information.NVLINK:nvlink                      Displays device nvlink information. "nvidia-smi nvlink -h" for more information.C2C:c2c                         Displays device C2C information. "nvidia-smi c2c -h" for more information.CLOCKS:clocks                      Control and query clock information. "nvidia-smi clocks -h" for more information.ENCODER SESSIONS:encodersessions             Displays device encoder sessions information. "nvidia-smi encodersessions -h" for more information.FBC SESSIONS:fbcsessions                 Displays device FBC sessions information. "nvidia-smi fbcsessions -h" for more information.GRID vGPU:vgpu                        Displays vGPU information. "nvidia-smi vgpu -h" for more information.MIG:mig                         Provides controls for MIG management. "nvidia-smi mig -h" for more information.COMPUTE POLICY:compute-policy              Control and query compute policies. "nvidia-smi compute-policy -h" for more information. BOOST SLIDER:boost-slider                Control and query boost sliders. "nvidia-smi boost-slider -h" for more information. POWER HINT:    power-hint                  Estimates GPU power usage. "nvidia-smi power-hint -h" for more information. BASE CLOCKS:    base-clocks                 Query GPU base clocks. "nvidia-smi base-clocks -h" for more information. CONFIDENTIAL COMPUTE:conf-compute                Control and query confidential compute. "nvidia-smi conf-compute -h" for more information. GPU PERFORMANCE MONITORING: gpm                         Control and query GPU performance monitoring unit. "nvidia-smi gpm -h" for more information. Please see the nvidia-smi(1) manual page for more detailed information.

3. 参数

常见选项:

  • -q:显示详细信息。
  • -d:显示特定信息(如性能状态、功率等)。
  • -f:输出到文件。
  • -i:指定GPU ID。
  • -pl:设置功率限制。

4. 例子

4.1 基础用法

nvidia-smi

执行该命令会输出GPU的基本信息,包括:

  • 驱动版本
  • CUDA版本
  • 每个GPU的使用情况(温度、功率、显存占用、GPU利用率等)
  • 正在使用GPU的进程列表

在这里插入图片描述

4.2 查看实时GPU性能

使用 -l 参数可以每隔一段时间输出一次 GPU 信息:

nvidia-smi -l 2

上面的命令每2秒输出一次 GPU 状态,直到你停止(Ctrl+C)。

4.3 限制GPU功率

有时为了节省电力或控制功耗,可以限制 GPU 的功率。假设你有一个功率范围为100W-250W的 GPU,可以将其限制为150W:

nvidia-smi -pl 150

4.4 查看显存使用情况

如果你只想查看当前GPU的显存使用情况,可以使用:

nvidia-smi --query-gpu=memory.total,memory.used,memory.free --format=csv

这个命令将以CSV格式输出每块GPU的总显存、已用显存和可用显存。
在这里插入图片描述

4.5 列出每个进程的GPU使用情况

想要查看每个进程使用的显存、GPU 资源,可以运行:

nvidia-smi pmon -i 0

其中,-i 0 表示第0号 GPU,你可以根据需求选择其他 GPU。

4.6 杀死占用GPU的进程

你可以通过进程 ID(PID)找到占用显存或 GPU 资源的进程,然后使用 kill 命令终止它。例如,如果你看到进程 ID 为12345,可以这样终止它:

kill -9 12345

4.7 导出GPU使用日志

可以通过 nvidia-smi 将 GPU 信息输出到文件中,便于分析:

nvidia-smi -l 1 -f gpu_usage.log

这会将每秒的 GPU 使用情况记录到 gpu_usage.log 文件中。

4.8 查询更多特定信息

可以使用 --query-gpu 参数查询特定的信息。例如:

复制代码
nvidia-smi --query-gpu=name,temperature.gpu,utilization.gpu,memory.used --format=csv

这会以CSV格式输出GPU的名称、温度、利用率和已用显存。

4.9 查看支持的GPU工作模式

GPU 可以在不同的“性能模式”(如 P0 到 P12)下运行。可以通过 nvidia-smi 设置或查看当前的模式:

nvidia-smi --query-gpu=power.draw --format=csv

在这里插入图片描述

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 二.Unity中使用虚拟摇杆来控制角色移动
  • Unity 第一人称游戏的武器被其他物体覆盖解决方案
  • 供应RM500UCNAB-D10-SNADA模块
  • leetcode 108.将有序数组转换为二叉搜索树
  • word文档无损原样转pdf在windows平台使用python调用win32com使用pip安装pywin32
  • 嵌入式epoll面试题面试题及参考答案
  • Maven私服Nexus安装及使用
  • 第7篇:【系统分析师】计算机网络
  • openCV的python频率域滤波
  • 从底层原理上理解ClickHouse 中的 Distributed 引擎
  • 第四届长城杯部分wp
  • 【C++题解】1398. 奇偶统计
  • 依据出生人数预测高等教育发展趋势
  • [项目][WebServer][解析错误处理]详细讲解
  • 2024年上半年互联网黑灰产研究报告
  • 4月23日世界读书日 网络营销论坛推荐《正在爆发的营销革命》
  • docker-consul
  • If…else
  • java架构面试锦集:开源框架+并发+数据结构+大企必备面试题
  • Object.assign方法不能实现深复制
  • python 学习笔记 - Queue Pipes,进程间通讯
  • React as a UI Runtime(五、列表)
  • React Transition Group -- Transition 组件
  • 工作中总结前端开发流程--vue项目
  • 前嗅ForeSpider采集配置界面介绍
  • 如何用vue打造一个移动端音乐播放器
  • 世界上最简单的无等待算法(getAndIncrement)
  • 用 vue 组件自定义 v-model, 实现一个 Tab 组件。
  • - 转 Ext2.0 form使用实例
  • 1.Ext JS 建立web开发工程
  • 阿里云服务器如何修改远程端口?
  • 如何通过报表单元格右键控制报表跳转到不同链接地址 ...
  • 曜石科技宣布获得千万级天使轮投资,全方面布局电竞产业链 ...
  • ​2020 年大前端技术趋势解读
  • ​Benvista PhotoZoom Pro 9.0.4新功能介绍
  • ###STL(标准模板库)
  • #Ubuntu(修改root信息)
  • (aiohttp-asyncio-FFmpeg-Docker-SRS)实现异步摄像头转码服务器
  • (k8s)Kubernetes 从0到1容器编排之旅
  • (Redis使用系列) Springboot 在redis中使用BloomFilter布隆过滤器机制 六
  • (笔记)Kotlin——Android封装ViewBinding之二 优化
  • (三)Pytorch快速搭建卷积神经网络模型实现手写数字识别(代码+详细注解)
  • (原創) 如何使用ISO C++讀寫BMP圖檔? (C/C++) (Image Processing)
  • (转)利用ant在Mac 下自动化打包签名Android程序
  • (转载)深入super,看Python如何解决钻石继承难题
  • (自适应手机端)响应式新闻博客知识类pbootcms网站模板 自媒体运营博客网站源码下载
  • *(长期更新)软考网络工程师学习笔记——Section 22 无线局域网
  • ****三次握手和四次挥手
  • .net core Swagger 过滤部分Api
  • .net core使用RPC方式进行高效的HTTP服务访问
  • .net 开发怎么实现前后端分离_前后端分离:分离式开发和一体式发布
  • .NetCore发布到IIS
  • .NET未来路在何方?
  • .so文件(linux系统)
  • @Responsebody与@RequestBody