Skip to main content

gpumutex

This library can be injected into existing CUDA programs with GPUs, such that no process also run under libgpumutex can interfere with another.

This is accomplished through relatively interesting means. See the design writeup: https://apaz.dev/blog/LD_PRELOAD.html

Linux only (glibc; uses dl_iterate_phdr/ELF parsing internally).

Installing with pip

pip install gpumutex
GPUMUTEX_VISIBLE_DEVICES=0,1,2,3 gpumutex-run -- python train.py
# or, equivalently:
gpumutex-run --visible-devices 0,1,2,3 -- python train.py
import gpumutex

gpumutex.run(["python", "train.py"], visible_devices="0,1,2,3", check=True)
gpumutex.system("python train.py", visible_devices=[0, 1, 2, 3])

Using Standalone

# Compile
cc -shared -fPIC -fvisibility=hidden -o libgpumutex.so gpumutex/libgpumutex.c -ldl -lpthread

Then to run a program under it:

LD_PRELOAD=./libgpumutex.so GPUMUTEX_VISIBLE_DEVICES=... program program_args

Configuration

Both usages below are configured the same way as the raw interposer, via environment variables. gpumutex-run and gpumutex.run()/gpumutex.system() also accept these directly as CLI flags / keyword arguments, which set the variable in the child's environment only, without touching your own:

Variable CLI flag Python kwarg Description Default
GPUMUTEX_VISIBLE_DEVICES --visible-devices visible_devices Comma-separated device indices to manage (e.g. "0,2,3"), or an iterable of indices in Python. Required; without it, the preload is inert. none (required)
GPUMUTEX_NUM_DEVICES --num-devices num_devices How many of those devices one process tree needs at once. 1
GPUMUTEX_LOCK_DIR --lock-dir lock_dir Where lockfiles and the wait queue live. /tmp/libgpumutex

Metadata

Release files for gpumutex 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gpumutex 0.2.1
File Size Uploaded Provenance
gpumutex-0.2.1.tar.gz 33.5 kB With provenance Details

Release files / gpumutex-0.2.1.tar.gz

Download URL gpumutex-0.2.1.tar.gz
Size 33.5 kB
Tags Source
SHA-256 checksum
How to use checksums
22c0d1a54a58679056ed666ef650563465dd3f7be687a014cd00a8afac0e2f56
BLAKE2b-256 checksum
How to use checksums
fe2f3997fcce4f5b8492edae080ec01e1175c0dfe7eb0559ff8f2073d148b093
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Security for gpumutex 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 1 file in this release has been uploaded with provenance metadata.

Attestation for gpumutex-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page