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 |
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file gpumutex-0.1.1.tar.gz.
File metadata
- Download URL: gpumutex-0.1.1.tar.gz
- Upload date:
- Size: 33.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31fde5dfae19f95607faa78adcfbaeec0a4b036a34a88fce9498f2db19daa134
|
|
| MD5 |
933bb81fe25f885cd1a230254cadd293
|
|
| BLAKE2b-256 |
05ff9e0c46e85353883b02791e409aba68a339656f15024505fa55655ef41151
|
Provenance
The following attestation bundles were made for gpumutex-0.1.1.tar.gz:
Publisher:
publish.yml on apaz-cli/libgpumutex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gpumutex-0.1.1.tar.gz -
Subject digest:
31fde5dfae19f95607faa78adcfbaeec0a4b036a34a88fce9498f2db19daa134 - Sigstore transparency entry: 2647330742
- Sigstore integration time:
-
Permalink:
apaz-cli/libgpumutex@86710948128f0889bbb6dab8d0eb2dfcda9d9d23 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/apaz-cli
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@86710948128f0889bbb6dab8d0eb2dfcda9d9d23 -
Trigger Event:
push
-
Statement type: