Metadata-Version: 2.5
Name: rampgate-nvml
Version: 0.2.0
Summary: NVIDIA GPU probe for the rampgate admission scheduler: capacity, used memory and per-process usage through NVML, plus process-to-container mapping.
Project-URL: Homepage, https://github.com/KebanFiru/rampgate
Project-URL: Documentation, https://kebanfiru.github.io/rampgate/
Project-URL: Source, https://github.com/KebanFiru/rampgate
Project-URL: Changelog, https://github.com/KebanFiru/rampgate/blob/main/packages/rampgate-nvml/CHANGELOG.md
Project-URL: Issues, https://github.com/KebanFiru/rampgate/issues
Author: Hakan Bağıç
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Keywords: gpu,nvidia,nvml,rampgate,scheduler
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: System :: Distributed Computing
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: nvidia-ml-py>=12.535
Requires-Dist: rampgate<0.3,>=0.2
Description-Content-Type: text/markdown

# rampgate-nvml

NVIDIA GPU probe for [rampgate](https://pypi.org/project/rampgate/), an admission scheduler for jobs that ramp up their memory. It reports each GPU's capacity, used memory and per-process usage through NVML, so the scheduler can act on what jobs really use. It also maps a process to its container.

## Install

```sh
pip install rampgate-nvml
```

Requires an NVIDIA driver on the machine. Depends on `rampgate` and `nvidia-ml-py`.

## Usage

```python
from rampgate_nvml import NvmlProbe, pid_to_container_id

with NvmlProbe({0: "gpu0"}, unit="MiB") as probe:
    for device in probe.devices():            # capacity: total memory; stable_min_usage: 256 MiB
        engine.add_device(device)
    observed, processes = probe.sample(t)     # DeviceObserved per GPU, ProcessUsage per process
    for p in processes:
        container = pid_to_container_id(p.pid)  # via /proc/<pid>/cgroup; None outside a container
```

## What to expect

- **`used_total` includes everything.** `DeviceObserved.used_total` is NVML's `used`: the driver's own share and every process, managed or not. rampgate treats what it cannot attribute to a managed job as foreign usage. On the one GPU measured (RTX 4050), the driver's reservation was 371 MiB.
- **A process's usage includes its CUDA context,** measured there at about 82 MiB.
- **Usage floor.** `devices()` sets a 256 MiB Rule S floor (`stable_min_usage_mib`), so a job without a step counter that is still loading data is not marked stable at near-zero memory. Pass `0` to turn it off.
- **Containers.** `pid_to_container_id` understands cgroup v1 and v2 paths of docker (systemd and cgroupfs drivers), containerd, CRI-O and podman, including paths relative to a private cgroup namespace (`0::/../docker-<id>.scope`).
- **Host PID namespace required.** NVML lists processes by host pid, so a probe running in a container needs `docker run --pid=host` (and `--gpus all`).

Tested on one laptop GPU; multiple GPUs are not yet tested.

## Links

[Documentation](https://kebanfiru.github.io/rampgate/adapters/#rampgate-nvml) · [rampgate core](https://pypi.org/project/rampgate/) · [Source](https://github.com/KebanFiru/rampgate) · [Changelog](https://github.com/KebanFiru/rampgate/blob/main/packages/rampgate-nvml/CHANGELOG.md)

Apache-2.0.
