Skip to main content

A multi-vendor GPU querying utility with minimal dependencies

Project description

gpuq - multi-vendor GPU querying utility with minimal dependencies

This small library is a direct answer to the lack of a lightweight, cross-compatible utility to query available GPUs - regardless of what vendor, distro, or overall environment one might be using.

In particular, the implementation meets the following requirements:

  • works with multiple downstream runtimes (currently supported: CUDA and HIP)
    • will also work if you have multiple present at the same time (do you really, though?)
  • no build- or install-time dependencies (including any python packages)
  • any runtime dependencies are soft - unless the user explicitly asks for the status/presence of a particular downstream runtime, most methods will fail silently
  • consequently, the package should install and run on pretty much any machine
    • your laptop does not have a GPU? -> the package will report 0 GPUs available (duh), no exceptions, linker errors, etc.
  • allows for easy mocking (for unit tests, etc.)
  • fully typed (conforms to mypy --strict checking)

Compared to some existing alternatives, it has the following differences:

  • torch.cuda - not lightweight, also requires a different wheel for NVidia and HIP
  • gputil - NVidia specific, also broken dependencies (as of 2025)
  • gpuinfo - NVidia specific, broken import gpuinfo...
  • gpuinfonv - NVidia specific, requires pynvml
  • pyamdgpuinfo - AMD specific
  • igpu - NVidia specific, broken installation (as of 2025)
  • and so on...

The primary functionality offered is:

  • check how many GPUs are available
  • query properties for each available device - will tell you some basic info about the provider (CUDA/HIP) and other info similar to cudaGetDeviceProperties
    • the returned list is not comprehensive, though
  • respects *_VISIBLE_DEVICES and provides mapping between local (visible) and global indices
    • NOTE: this temporarily modifies env variables and therefore is not thread-safe
  • if requested, lazily provides some runtime information about each GPU as well
    • in particular, PIDs of processes using the GPU will be returned
    • NOTE: this is currently done rather naively by parsing outputs of tools like nvidia-smi or rocm-smi
  • allows to check for runtime errors that might have occurred while trying to load

How it works:

The implementation will attempt to dynamically lazy-load libcudart.so and libamdhip64.so at runtime. For GPUs to be properly reported, the libraries have to be found by the dynamic linker at the moment any relevant function call is made for the first time. (If a library fails to load, loading will be retried every time a function call is made).

Examples

Install with:

pip install gpuq

Return the number of available GPUs:

import gpuq as G

print(G.count()) # this includes GPUs from all providers, disregarding *_VISIBLE_DEVICES
print(G.count(visible_only=True)) # only visible GPUs from all providers
print(G.count(provider=G.Provider.HIP, visible_only=True)) # only visible HIP devices
# etc.

Return a list of gpu properties:

import gpuq as G

for gpu in G.query(visible_only=True, provider=G.Provider.ANY):
    print(gpu.name)

# return all visible GPUs, raise an error if no CUDA devices are present
# (note: the required check if done against the global set, not the return set - see the docs)
gpus = G.query(visible_only=True, provider=G.Provider.ANY, required=G.Provider.CUDA)

Provide mapping between local and global GPU indices:

import gpuq as G

# assume a system with 8 GPUs and CUDA_VISIBLE_DEVICES=1,7
for gpu in G.query(): # by default return visible GPUs only
    print(gpu.index, gpu.system_index)

# should print:
# 0 1
# 1 7

for gpu in G.query(visible_only=False):
    print(gpu.index, gpu.system_index, gpu.is_visible)

# should print:
# None 0 False
# 0 1 True
# None 2 False
# None 3 False
# None 4 False
# None 5 False
# None 6 False
# 1 7 True

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

gpuq-1.3.0.tar.gz (33.8 kB view details)

Uploaded Source

Built Distributions

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

gpuq-1.3.0-cp313-cp313-musllinux_1_2_x86_64.whl (47.0 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

gpuq-1.3.0-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (45.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

gpuq-1.3.0-cp313-cp313-macosx_11_0_arm64.whl (25.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

gpuq-1.3.0-cp312-cp312-musllinux_1_2_x86_64.whl (46.9 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

gpuq-1.3.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (45.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

gpuq-1.3.0-cp312-cp312-macosx_11_0_arm64.whl (25.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

gpuq-1.3.0-cp311-cp311-musllinux_1_2_x86_64.whl (46.9 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

gpuq-1.3.0-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (45.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

gpuq-1.3.0-cp311-cp311-macosx_11_0_arm64.whl (25.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

gpuq-1.3.0-cp310-cp310-musllinux_1_2_x86_64.whl (46.3 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

gpuq-1.3.0-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (45.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

gpuq-1.3.0-cp310-cp310-macosx_11_0_arm64.whl (25.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file gpuq-1.3.0.tar.gz.

File metadata

  • Download URL: gpuq-1.3.0.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for gpuq-1.3.0.tar.gz
Algorithm Hash digest
SHA256 626edf2241a7e6a409cafc5d6486f643fe99716b3425eb48980bfe37c0812790
MD5 a5ff8174c6fc02b3ad921a7b0f80d62f
BLAKE2b-256 2a803dea4401f4dba3c715f6d345a2ced81f2c0d0f4f56c86408097e7fa696fe

See more details on using hashes here.

File details

Details for the file gpuq-1.3.0-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gpuq-1.3.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d751aba511b73088e3132a259e19efcf55285890c21b5ba69305825d3b6b05f1
MD5 cd6b09ffab0909ef7b9f67abaa399423
BLAKE2b-256 ca50e451bf5fa9da2cddd0e18240fa3951a8c7ca520d3a1b7afc8f0b6b8ac5d0

See more details on using hashes here.

File details

Details for the file gpuq-1.3.0-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for gpuq-1.3.0-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 5bc9d0f0a73e4dd29552f0dfd6681c52ab8852fa315726a5e47311fdf4140ba9
MD5 d0d398fd242c5d151ce89089b9c48572
BLAKE2b-256 30426d2e04ea9757e71504f98bd3863b6d22c168e4c68dd4344fe0961c8e575c

See more details on using hashes here.

File details

Details for the file gpuq-1.3.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gpuq-1.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 26451ac9686652241e317d5291dde3d77416f4acba9d7692b6128a1e67fe6442
MD5 2a1b0627c6f985679a01d4aaf12adb64
BLAKE2b-256 8e3fee8fb736cd041d93199655540fee9ce91f245b0ee22ef0bfcdecdab771e5

See more details on using hashes here.

File details

Details for the file gpuq-1.3.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gpuq-1.3.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 dac9b48b6d2880911a99e15ceca72366f47df2a902e8e2b2a4a69826632acba5
MD5 4e7908d4cef2eef76171ab32b4c35f62
BLAKE2b-256 c8789979d349486b74c49fb160ee8cd7a7bf6ad0e2bff486be4c5fd9eab86570

See more details on using hashes here.

File details

Details for the file gpuq-1.3.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for gpuq-1.3.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 a4741976897478c991663e6183a793870a5402ba8fbc055e018e736be9069f1e
MD5 b7205ee927a9c479b06a46422e896335
BLAKE2b-256 2de977fbf09a68bc96d49700f1d78c5059369c0c353fa0604c5fab4c2df402f1

See more details on using hashes here.

File details

Details for the file gpuq-1.3.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gpuq-1.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7978e2755a1c709e465c74f8f43a2bbd2d7985fbf103cecd79d664794ba9f526
MD5 3ccfb2f579331f35e3591c68d5b2171d
BLAKE2b-256 cc33ca9941971b3f81bca3ed59a7495691c839b1d90bdcff4abec00039424a9f

See more details on using hashes here.

File details

Details for the file gpuq-1.3.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gpuq-1.3.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 bae2b17292784b8f2ca491d604b8f7bbd2ee923fa3e9e0f059e9a7ee12ca968f
MD5 4ddcc5641cf74da8c51b93faa69e2a3a
BLAKE2b-256 3b60c6a9e027372735cab986c41d93db0daa610bd3dd6d857d1b939217d34ba0

See more details on using hashes here.

File details

Details for the file gpuq-1.3.0-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for gpuq-1.3.0-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 db2196abd0405961257afa1feb4956a0be526506acb2ce9fe97ad74811d15040
MD5 c43661e712a2cbb8147fdb4ef7268399
BLAKE2b-256 2a93d40ddf86473d1b6bf70879228cf5393e3471c0c0e52cb0deb3ccee5701b4

See more details on using hashes here.

File details

Details for the file gpuq-1.3.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gpuq-1.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 87bbcbbb6a317c20bcf5f809e2de91c84f966f132ff0d131830dec1b50dcb591
MD5 5df726d86af3fa99684368c7850df0ef
BLAKE2b-256 0e26c793f057c690a8317b2001d43323c0e24d59d8a6219ab17509699a73b03a

See more details on using hashes here.

File details

Details for the file gpuq-1.3.0-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gpuq-1.3.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7581c84afb67cbee1c016fd23dbf965f4feba9db801593247a763d34481f4150
MD5 7ed179261d432a9a3d4642b4d9344ff3
BLAKE2b-256 3cffdbc390336c761d4c1dde11b2127470ca965ea61e50d0c3f4bb6e5097b4a6

See more details on using hashes here.

File details

Details for the file gpuq-1.3.0-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for gpuq-1.3.0-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 5131fca6a8962e3291503664dc42aad1b588623e569c6322da402f67ac724116
MD5 732c13925226956d3f45e3a7abed9a7e
BLAKE2b-256 1ba38bc9a8f97fdd1208e1cdc6de40500f65902d9b0c4cac3d54793eec759d02

See more details on using hashes here.

File details

Details for the file gpuq-1.3.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gpuq-1.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 537da1e5f18e50aace7e694ee89de37655a0a5edb69703adb733c76ecb6b4591
MD5 0545f9ff96cf024f0ff15754dbd7b1ef
BLAKE2b-256 227bcb66f7e55d3695aa3aae2df0df931fa0cc7f5299ad28e55834808bd685e6

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