Skip to main content

List GPUs and VRAM amounts in Windows and Linux

Project description

gpu_list

This is a simple little utility to list GPUs and their VRAM amounts in Windows and Linux. The main reason I create this is because WMI doesn't list accurate VRAM information, and it's slow, and I hate WMI a lot. The Windows code uses no external libraries or tools. Linux code will use nvidia-smi if necessary.

How it works

In Windows, it enumerates the registry keys at SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318} and gets the info from there. It relies on the existence of HardwareInformation.qwMemorySize keys, which were added sometime in Windows 10 I think. Maybe. So this probably won't work for older Windows. I purposely didn't add support for the 32 bit registry key because it's bunk.

Vendor and Device name are looked up in the included pci.ids file from https://pci-ids.ucw.cz/

In Linux, it's a bit tougher. First it checks sysfs files mem_info_vram_total and vram_total, and uses those if found. If any NVidia devices are found it will use nvidia-smi to get an accurate VRAM total. For everything else it will check the pcie BAR memory mapping and try to estimate the VRAM. It was very close for my Intel GPU, so I kept it in. Please report any inaccurate readings.

Installation

pip install gpu_list

Usage

If you just want some quick info printed out, run gpu_list from the console, you will get output that looks like this:

┌────────────────────────────────────────┬───────────┬─────────────────────────────┬───────────┬─────────┐
│                 vendor                 │ vendor_id │            device           │ device_id │ vram_gb │
├────────────────────────────────────────┼───────────┼─────────────────────────────┼───────────┼─────────┤
│           Intel Corporation            │    8086   │        DG2 [Arc A770]       │    56a0   │  17.05  │
│           NVIDIA Corporation           │    10de   │ GA102 [GeForce RTX 3090 Ti] │    2203   │  24.15  │
│ Advanced Micro Devices, Inc. [AMD/ATI] │    1002   │           Raphael           │    164e   │   0.07  │
└────────────────────────────────────────┴───────────┴─────────────────────────────┴───────────┴─────────┘

(vram_gb = bytes / 1e9)

However, this is mostly meant to be used from code. gpu_list exports one function: get_info. It returns a list of dicts, one dict per GPU found. Each dict has the following keys: vendor, vendor_id, device, device_id, and vram_gb

Here's some example code:

from gpu_list import get_info

infos = get_info()

if infos:
    for index, info in enumerate(infos):
        print(f"Info for GPU #{index+1}")
        print("-" * 50)
        print(f"vendor = {info["vendor"]}")
        print(f"vendor_id = {info["vendor_id"]}")
        print(f"device = {info["device"]}")
        print(f"device_id = {info["device_id"]}")
        print(f"vram_gb = {info["vram_gb"]}")
        print("-" * 50)
else:
    print("Error getting GPU list!")

Running that code produces something like this:

Info for GPU #1
--------------------------------------------------
vendor = Intel Corporation
vendor_id = 8086
device = DG2 [Arc A770]
device_id = 56a0
vram_gb = 17.05
--------------------------------------------------
Info for GPU #2
--------------------------------------------------
vendor = NVIDIA Corporation
vendor_id = 10de
device = GA102 [GeForce RTX 3090 Ti]
device_id = 2203
vram_gb = 24.15
--------------------------------------------------
Info for GPU #3
--------------------------------------------------
vendor = Advanced Micro Devices, Inc. [AMD/ATI]
vendor_id = 1002
device = Raphael
device_id = 164e
vram_gb = 0.07
--------------------------------------------------

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpu_list-0.1.0.tar.gz (357.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gpu_list-0.1.0-py3-none-any.whl (360.4 kB view details)

Uploaded Python 3

File details

Details for the file gpu_list-0.1.0.tar.gz.

File metadata

  • Download URL: gpu_list-0.1.0.tar.gz
  • Upload date:
  • Size: 357.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gpu_list-0.1.0.tar.gz
Algorithm Hash digest
SHA256 89a551380d183ebb89d03d62dbcc38c65d6528fb372414067c5907c97d77dca6
MD5 5d3146abbf568167013b675564f89123
BLAKE2b-256 8e2c51df17986d8d988d3d216d8b2ba292d59ce3da25e7f1eaa2959d8fd64ed9

See more details on using hashes here.

File details

Details for the file gpu_list-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gpu_list-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 360.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gpu_list-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e8269e78f51089628be82fa8e74893978206b9b9a6ff88447069737f60795167
MD5 63c2057d7c1cdfd8c56006909303afb0
BLAKE2b-256 76050e12101da4d6f469d642efc55eeb02f22098a34846846362d128ec444128

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page