How can I fetch VRAM and GPU cache size in Linux?

611 views Asked by At

I want to make a script (language doesn't matter) that will display VRAM size. The only working thing is sudo lspci -vnn but it doesn't work on systems with no Resizeable BAR enabled. Also glxinfo can show VRAM size but it doesn't work before graphics loading so script will fail in SSH or TTY

e. g. on my PC:

08:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 21 [Radeon RX 6800/6800 XT / 6900 XT] [1002:73bf] (rev c1) (prog-if 00 [VGA controller])
    Memory at 7800000000 (64-bit, prefetchable) [size=16G]
    Memory at 7c00000000 (64-bit, prefetchable) [size=256M]

But on my friends' laptop:

01:00.0 VGA compatible controller [0300]: NVIDIA Corporation TU117M [GeForce GTX 1650 Mobile / Max-Q] [10de:1f91] (rev a1) (prog-if 00 [VGA controller])
        Memory at a3000000 (32-bit, non-prefetchable) [size=16M]
        Memory at 90000000 (64-bit, prefetchable) [size=256M]
        Memory at a0000000 (64-bit, prefetchable) [size=32M]
  1. So how can I get real VRAM size while no X11 no Wayland are running? (so yeah hyprctl and other tools wouldn't work)

Also enabling Resizable BAR on each machine isn't an option because I don't want my script to be used on my hardware only :)

And it would be nice to see any cross-platform solutions but if you have at least 2/3 options for AMD/Nvidia(/Intel) that's also fine

  1. Also what's this 256M memory on my Radeon? I thought it was infinity cache but it has to be 128M only. Can I get cache size too?
1

There are 1 answers

0
Unknown User On

Okay, so I found the exact thing about VRAM. Someone answered my question but this answer was deleted.

Exact GPU name can be found with lsblk command but for AMD you need to extract GPU code and its revision (for my RX 6800 XT it's 73BF and revision C1) and search for the exact GPU name in this table - https://gitlab.freedesktop.org/mesa/drm/-/blob/main/data/amdgpu.ids

lspci works also fine when you need to see GPU manufacturer (AMD/Nvidia/Intel).

If you have AMD GPU as I do then you can grab PCI ID for the device with lspci command executed with -D flag (shows PCI doamin) and read the following file cat /sys/bus/pci/devices/${pci_slot}/mem_info_vram_total, it contains GPU VRAM size in bytes.

For NVIDIA GPUs you can execute nvidia-smi command but idk if it works with nouveau driver so good luck nvidia users. LANG=C nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits this command should work fine displaying total GPU VRAM size in megabytes.

Also I don't know what can Intel GPU users do in this situation.

Well, as for the cache, idk, maybe later I'll find out how to fetch cache info in Linux.

And yeah I'm using Node JS and there exist https://www.npmjs.com/package/systeminformation this library but it's so buggy so I wanted to write my own script.