惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Help Net Security
Help Net Security
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
LINUX DO - 热门话题
Security Latest
Security Latest
A
Arctic Wolf
G
GRAHAM CLULEY
月光博客
月光博客
S
Securelist
D
Docker
J
Java Code Geeks
T
Troy Hunt's Blog
T
Tenable Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 最新话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
博客园 - 【当耐特】
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 三生石上(FineUI控件)
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
Netflix TechBlog - Medium
Vercel News
Vercel News
Forbes - Security
Forbes - Security
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
B
Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Check Point Blog
云风的 BLOG
云风的 BLOG
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
L
Lohrmann on Cybersecurity
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed

博客园 - yeren2046

RedCoins,一个免费的类似bluecoins的个人财务管理软件 记录一个栈溢出导致的崩溃问题 一个免费的图片数据标注工具 常用zip命令 git版本导致的"Permission denied (publickey). fatal: Could not read from remote repository." 只显示全部特定进程名的top信息的shell脚本 linux 上用 core 文件定位线上问题 ffmpeg 时基转换 昇腾卡通道号范围 ffmpeg视频截取 英伟达硬解码错误汇总 DVPP问题汇总 TensorRT生成INT8校准文件 结构体指定初始化 ffmpeg命令行基于英伟达显卡编解码的转码 C++11 获取当前时间戳 nvjpeg 简单使用 AV_PIX_FMT_CUDA 数据转 RGB C++ do{ } while(0)
基于CUDA查询显卡型号和显存大小
yeren2046 · 2022-09-27 · via 博客园 - yeren2046

安装驱动后,我们可以用 nvidia-smi 命令来获取显卡信息。

nvidia-smi 的一个比较好的博客 nvidia-smi详解

nvidia-smi

Tue Sep 27 11:08:37 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 515.65.01    Driver Version: 515.65.01    CUDA Version: 11.7     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:3B:00.0 Off |                  N/A |
| 38%   53C    P2   104W / 320W |   3839MiB / 10240MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
|   1  NVIDIA GeForce ...  Off  | 00000000:86:00.0 Off |                  N/A |
| 30%   36C    P8    19W / 320W |     13MiB / 10240MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
|   2  NVIDIA GeForce ...  Off  | 00000000:AF:00.0 Off |                  N/A |
| 30%   34C    P8    13W / 320W |     13MiB / 10240MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1398      G   /usr/lib/xorg/Xorg                  4MiB |
|    0   N/A  N/A      2340      C   java                             3826MiB |
|    0   N/A  N/A      2680      G   /usr/lib/xorg/Xorg                  4MiB |
|    1   N/A  N/A      1398      G   /usr/lib/xorg/Xorg                  4MiB |
|    1   N/A  N/A      2680      G   /usr/lib/xorg/Xorg                  4MiB |
|    2   N/A  N/A      1398      G   /usr/lib/xorg/Xorg                  4MiB |
|    2   N/A  N/A      2680      G   /usr/lib/xorg/Xorg                  4MiB |
+-----------------------------------------------------------------------------+

列出可用设备

nvidia-smi -L

GPU 0: NVIDIA GeForce RTX 3080 (UUID: GPU-d6daa455-a57f-f91a-a780-19d2a2c3e059)
GPU 1: NVIDIA GeForce RTX 3080 (UUID: GPU-aff98a0d-53bd-a538-d35f-70e0714cb8d2)
GPU 2: NVIDIA GeForce RTX 3080 (UUID: GPU-b1f86dba-045e-01a8-6e08-d170c25663da)

基于cuda获取显卡信息:

#define checkCudaErrors(S) do {CUresult  status; \
        status = S; \
        if (status != CUDA_SUCCESS ) std::cout << __LINE__ <<" checkCudaErrors - status = " << status << std::endl; \
        } while (false)

int CheckCUDAProperty( int devId )
{
    cuInit(0);

    CUdevice dev = devId;
    size_t memSize = 0;
    char devName[256] = {0};
    int major = 0, minor = 0;
    CUresult rlt = CUDA_SUCCESS;

    rlt = cuDeviceComputeCapability( &major, &minor, dev );
    checkCudaErrors( rlt );

    rlt = cuDeviceGetName( devName, sizeof( devName ), dev );
    checkCudaErrors( rlt );

    printf( "Using GPU Device %d: %s has SM %d.%d compute capability\n",
            dev, devName, major, minor );

    rlt = cuDeviceTotalMem( &memSize, dev );
    checkCudaErrors( rlt );

    printf( "Total amount of global memory:   %4.4f MB\n",
           (float)memSize / ( 1024 * 1024 ) );

    return 0;
}

运行结果:

Using GPU Device 1: NVIDIA GeForce RTX 3080 has SM 8.6 compute capability
Total amount of global memory:   10018.0625 MB