Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ concurrency); adding a type is a new entry, not a code change.
Concurrency is reactive live-admission by default — the count is derived from
live host headroom, not configured, and the only knob is `reserve` percent
([ADR-0005](../doc/adr/0005-reactive-live-admission.md)); a GPU type opts into
device-count sizing with `mode: auto`. The Go listener is the authoritative
shared-GPU admission by declared VRAM with `mode: vram`
([ADR-0007](../doc/adr/0007-declared-job-vram.md)), and the older one-job-per-GPU
device-count sizing (`mode: auto`) stays valid. The Go listener is the authoritative
parser ([ADR-0003](../doc/adr/0003-go-bash-boundary.md)).

**Declaring job cores (cpu types, [ADR-0006](../doc/adr/0006-declared-job-cores.md)).**
Expand Down Expand Up @@ -261,6 +263,42 @@ sudo systemctl start scaleset-listener@cpu
`scaleset-admin sync-labels` tries an in-place update first and fails, naming
these steps, when GitHub keeps the old labels.

**Declaring job VRAM (gpu types, [ADR-0007](../doc/adr/0007-declared-job-vram.md)).**
A gpu job under `mode: vram` tells the listener how much VRAM it uses with one
`runs-on` label, so several jobs can share one GPU:

```yaml
runs-on: [self-hosted, linux, x64, gpu, vram-gb-4] # 4 GiB, shares a GPU
runs-on: [self-hosted, linux, x64, gpu, vram-gb-all] # the whole GPU
runs-on: [self-hosted, linux, x64, gpu] # no label: the whole GPU
```

The supported values are 1, 2, 4, 8, 16, 32, 64, 128 and `all`. Labels
are case-insensitive. When several labels are set, the largest wins. Jobs
without a VRAM label hold an entire GPU. Each GPU has a budget of `floor(vram_gib * (1 - reserve / 100))`
GiB (25 on an RTX 5090, 12 on an RTX 2000 Ada, at the default reserve of 20,
which is also the minimum). The listener starts a job on the lowest-index GPU
where what is running plus its declaration fits the budget and the live free
VRAM `nvidia-smi` reports, which also counts work the listener did not start,
is still at least `reserve`. A value above a GPU's budget takes that whole GPU.
The job receives `NVIDIA_VISIBLE_DEVICES=<index>` and only its
`/dev/nvidia<minor>` node plus shared control nodes. List every GPU's device
node in the type's `devices` and configure the NVIDIA runtime as in the
sample. If the probe fails, admission falls back to one whole-GPU job per
previously detected GPU. Before the first successful reading, one unpinned
job can run at a time, and it retains exclusive access until exit.
The scale set must advertise the `vram-gb-*` labels. Recreate the gpu set
while idle as above (`--type gpu`).

Nothing caps a job's real VRAM use (the fleet's GPUs have no MIG, and MPS or
HAMi limits only CUDA while Isaac/Kit render through Vulkan), shared jobs also
share the GPU's compute and run slower, and Isaac jobs need `pid: host` (#80).
The job history ledger records `gpu_index`, `vram_charged_gb` (after
clamping), `gpu_used_peak_mib` and `vram_peak_scope=whole_gpu` for pinned jobs.
The peak may include other jobs, display usage, and driver usage. To estimate
a job's own usage, sample it on an otherwise idle GPU. If sampling fails the
peak is empty. Unpinned fallback jobs record `vram_peak_scope=unavailable`.

```sh
sudo install -m 0644 deploy/runner-types.sample.yaml \
/etc/github-runner-listener/runner-types.yaml
Expand Down
36 changes: 28 additions & 8 deletions deploy/runner-types.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,27 @@
# not configured (ADR-0005, #163)
# reserve: N reactive, keep N% free
# (upward-only, minimum 10)
# mode: auto size from detected GPU
# count (#113; reactive
# GPU/VRAM is #164)
# mode: vram shared GPU: admit gpu
# jobs by the VRAM they
# declare (vram-gb-<N>),
# several per GPU when
# they fit (ADR-0007, #180)
# reserve: N (vram) keep N% of each GPU free
# (upward-only, minimum 20)
# The older device-count mode (auto, one job per
# detected GPU, #113) stays valid.
# There is no fixed operator count.

runner_types:
# --- First concrete type: GPU (#113) -------------------------------------
# Auto concurrency = detected GPU count (the listener runs nvidia-smi -L and
# sizes its worker pool to one slot per GPU). Devices are passed through
# --- First concrete type: GPU (#113, #180) -------------------------------
# Shared-GPU concurrency (ADR-0007): a job declares the VRAM it needs with
# one runs-on label, vram-gb-<N> or vram-gb-all; several jobs share a GPU
# while their declarations fit the GPU's VRAM less the reserve, and the
# live free VRAM (nvidia-smi, which also counts work the listener did not
# start) still keeps the reserve. A job with no vram-gb label holds the
# whole GPU, so undeclared jobs still run one per GPU. Nothing caps a job's
# real VRAM use: declare honestly, using the gpu_used_peak_mib the job
# history ledger records. Devices are passed through
# precisely (no --privileged); the baseline container hardening + the ADR-0011
# approval gate keep unapproved untrusted code off this rootful device host.
- name: gpu
Expand All @@ -88,7 +100,9 @@ runner_types:
scale_set: gpu
# This host's runner group. Omitted = Default.
# runner_group: ci-<host>
labels: [self-hosted, linux, x64, gpu, cuda]
# Every vram-gb-* value a job may declare must be a scale-set label, since
# a job's runs-on labels must all be on the scale set.
labels: [self-hosted, linux, x64, gpu, cuda, vram-gb-1, vram-gb-2, vram-gb-4, vram-gb-8, vram-gb-16, vram-gb-32, vram-gb-64, vram-gb-128, vram-gb-all]
# Self-built GPU image (#121): the CUDA/device stack layered on the SEC-5
# base (images/runner-gpu.Dockerfile -> images/runner-base.Dockerfile, whose
# runner tarball passed verify_runner_tarball before being baked in). It
Expand All @@ -99,6 +113,9 @@ runner_types:
# and pin that digest instead.
# actions-runner 2.338.2
image: ghcr.io/ycpss91255-lab/gpu-runner@sha256:2846d90a90e9e9bc7b4baecd856600445786d9bd2af63297ebd167910e467cd8
# List every /dev/nvidia<minor> on the host. A pinned job receives the
# node matching its GPU minor, plus the shared control nodes.
# NVIDIA_VISIBLE_DEVICES is set to the GPU index.
devices:
- /dev/nvidia0
- /dev/nvidiactl
Expand All @@ -108,8 +125,11 @@ runner_types:
# sets no daemonless build_tool. Enabling the socket is ROOT-EQUIVALENT on
# the host: enable only for trusted jobs (ADR-0011 approval gate).
# docker_socket: /var/run/docker.sock
# If nvidia-smi fails, admit one whole-GPU job per known GPU, or one
# unpinned job total before the first good reading.
concurrency:
mode: auto
mode: vram
reserve: 20

# --- A second type, shown to prove "two types, no code change" (#112) -----
# The CPU sample pins the published ghcr.io/ycpss91255-lab/runner-cpu image
Expand Down
105 changes: 105 additions & 0 deletions doc/adr/0007-declared-job-vram.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# 0007 — GPU jobs declare their VRAM

> Serves: Invariant 2 — Defaults fall towards safety

- **Status**: Accepted
- **Date**: 2026-11-29

## Context

The gpu type sized its pool to the GPU count (`mode: auto`, #113): one job per
GPU, whatever the job needs. A lint or a small CUDA test then holds a 32 GB
RTX 5090 alone while other gpu jobs queue. #104 asked for reactive admission
on VRAM, and #80 for several runners on one GPU.

Two facts shape the answer. Nothing on the fleet's GPUs can cap a job's VRAM:
the RTX 5090 and the RTX 2000 Ada have no MIG, and MPS or HAMi limit only CUDA
allocations, while Isaac Sim / Kit jobs render through Vulkan. And a VRAM
overshoot is not a slowdown, as CPU oversubscription is, but an out-of-memory
failure of whichever job allocates last.

ADR-0006 already lets a cpu job declare its cores and RAM with a label. The
owner chose (2026-11-29, #180) the same shape for VRAM, backed by a live check
of the GPU.

## Decision

**A gpu job declares its VRAM with one runs-on label, the listener charges it
against a per-GPU budget, checks the GPU's live free VRAM, and pins the job to
the GPU it chose.**

- **Mode.** A runner type opts in with `concurrency: mode: vram`. Its
`reserve` defaults to 20 and is upward-only with a floor of 20, stricter
than the cpu default and floor of 10. `mode: auto` stays valid.
- **Label.** `vram-gb-<N>` (1, 2, 4 ... 64, 128) or `vram-gb-all`, matched
case-insensitively. When several labels are set, the largest wins. A job
without a VRAM label keeps the whole GPU. An N above a GPU's budget takes
that whole GPU.
- **Budget.** Per GPU, `floor(vram_total_gib * (1 - reserve / 100))`:
25 GiB on an RTX 5090 (32607 MiB) and 12 GiB on an RTX 2000 Ada (16380 MiB)
at reserve 20. A zero budget admits no jobs.
- **Admission.** The listener picks the lowest-index GPU where the VRAM
committed to running jobs plus the job's declaration fits the budget AND the
live free VRAM (`nvidia-smi`) is still at least `reserve`. The live check
counts processes the listener did not start. One GPU hosts several jobs
while their declarations fit. While no GPU fits, admission waits the settle
window and re-probes (ADR-0005).
- **Charge.** VRAM is charged after the worker slot is acquired and the
context checked (the #177 ordering), and released when the job exits or on
any failure path before it starts.
- **Pinning.** The job is handed only the chosen GPU’s `/dev/nvidia<minor>` (plus
the shared control nodes such as `nvidiactl` and `nvidia-uvm`) and
`--env NVIDIA_VISIBLE_DEVICES=<index>`. The probe reports both values. The
environment override is required because the GPU image defaults to
`NVIDIA_VISIBLE_DEVICES=all`.
- **Fail-safe.** If the probe fails, admission falls back to whole-GPU, one job
per GPU, over the last good GPU list: only a GPU with nothing committed takes
a job, charged its whole budget. With no reading ever, one job runs on the
host at a time, unpinned. It retains the host-wide reservation until exit,
including if the probe recovers.
- **Peak VRAM.** `provision-job.sh` samples the chosen GPU's used VRAM while
the job runs and writes `gpu_index`, `vram_charged_gb`,
`gpu_used_peak_mib` and `vram_peak_scope=whole_gpu` to the job's ledger
record (ADR-0002). The sampler leaves the peak empty if no sample succeeds.
Unpinned fallback jobs record `vram_peak_scope=unavailable`.
- **Boundary.** `listener/gpu-probe.sh` only reads
GPU index, device minor and memory counters via `nvidia-smi`. Go computes
budgets and selects devices (ADR-0003).

## Alternatives

- **Keep one job per GPU (`mode: auto`).** Safe, but wastes most of a large
GPU on small jobs; it remains available.
- **Live free VRAM alone, no declaration (#104's first shape).** VRAM is
allocated after a job starts, so a burst of jobs admitted against an idle
GPU would all fit the reading and then OOM together. Declarations charged
at dispatch close that window; the live check stays as the second guard.
- **Hard limits (MIG, MPS, HAMi).** No MIG on the fleet's GPUs, and MPS/HAMi
limit only CUDA, not Vulkan rendering. Rejected for now.
- **Per-process VRAM attribution for the peak.** `--query-compute-apps` misses
Vulkan/graphics contexts and container PIDs would need mapping to jobs, so
the recorded peak is the whole GPU's.

## Consequences

- Workflows own their VRAM declaration, and nothing enforces it: a job using
more than it declared can push a neighbour into OOM. The live reserve check
catches drift before the next job starts, not during a running one.
- Jobs on one GPU share its compute, so each runs slower than alone.
- Isaac Sim jobs still need `pid: host` (#80), which this does not provide.
- `gpu_used_peak_mib` is the peak for the whole GPU while the job ran. Even an
otherwise idle GPU can have driver or display usage.
- The vram-gb labels are part of the gpu scale set's routing contract, so
adding them means recreating each host's gpu set while it is idle
(ADR-0006).
- A spare runner with no assignment yet is charged the whole GPU, because its
labels are unknown until GitHub assigns a job.

## References

- #180 (this change); #104 (reactive GPU/VRAM admission); #80 (several
runners on one GPU); ADR-0005; ADR-0006; ADR-0002; ADR-0003.
- `listener/gpuprobe.go` (`CommandGPUProbe`, `jobVRAM`, `vramBudget`,
`pickGPU`, `gpuDevices`), `listener/listener.go` (`reconcile`, `admitGPU`,
`chargeGPU`, `releaseGPU`, `vramCapacity`), `listener/gpu-probe.sh`,
`listener/provision-job.sh`, `lib/runner-container.sh`.
11 changes: 11 additions & 0 deletions doc/changelog/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Added

- **GPU jobs declare their VRAM and share a GPU** (ADR-0007, #180): a gpu type
with `concurrency: mode: vram` admits a job that adds `vram-gb-<N>` or
`vram-gb-all` to `runs-on` on the first GPU where the committed VRAM plus its
declaration fits `floor(vram_gib * (1 - reserve / 100))` and the live free VRAM is
still at least `reserve` (default and minimum 20). Jobs without a VRAM label hold
the whole GPU. Pinning uses the NVIDIA device minor and runtime index. If `nvidia-smi` fails,
the listener admits one whole-GPU job per previously detected GPU or one
unpinned job if no GPU has been detected. The ledger records the charged
GiB and the sampled whole-GPU peak for pinned jobs. The gpu sample uses
`mode: vram` and lists powers of two from `vram-gb-1` through
`vram-gb-128` and `vram-gb-all`. `mode: auto` remains available.
- **CPU jobs declare RAM too** (ADR-0006 amended, #175): RAM defaults to 4 GB
per declared core, and `ram-gb-<N>` or `ram-gb-all` sets it. The listener
charges both cores and GB against per-host budgets. The cpu sample type now
Expand Down
3 changes: 2 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST_TOOLS_IMAGE := env_var_or_default('TEST_TOOLS_IMAGE', 'ghcr.io/ycpss91255-l
# recipe below. Override with COVERAGE_IMAGE=... if you want to pin a tag.
COVERAGE_IMAGE := env_var_or_default('COVERAGE_IMAGE', 'kcov/kcov:latest')

SCRIPTS := 'script/install-deps.sh script/init.sh script/add-runner.sh script/remove-runner.sh script/status.sh script/update.sh script/uninstall.sh script/cleanup.sh script/schedule-cleanup.sh script/configure.sh script/set-labels.sh script/check-token.sh lib/common.sh lib/runner-layout.sh lib/runner-service.sh lib/runner-release.sh lib/runner-config.sh lib/runner-container.sh lib/runner-build.sh lib/runner-reaper.sh lib/runner-history.sh script/history.sh listener/provision-job.sh listener/reap.sh listener/host-probe.sh listener/docker-gc.sh lib/docker-gc.sh images/build-runner-image.sh script/lint-adr.sh script/fetch-bats.sh script/coverage-gate.sh script/lint-changelog.sh script/lint-readme-sync.sh script/lint-doc-citations.sh script/deploy-listener.sh script/teardown-listener.sh lib/listener-deploy.sh'
SCRIPTS := 'script/install-deps.sh script/init.sh script/add-runner.sh script/remove-runner.sh script/status.sh script/update.sh script/uninstall.sh script/cleanup.sh script/schedule-cleanup.sh script/configure.sh script/set-labels.sh script/check-token.sh lib/common.sh lib/runner-layout.sh lib/runner-service.sh lib/runner-release.sh lib/runner-config.sh lib/runner-container.sh lib/runner-build.sh lib/runner-reaper.sh lib/runner-history.sh script/history.sh listener/provision-job.sh listener/reap.sh listener/host-probe.sh listener/gpu-probe.sh listener/docker-gc.sh lib/docker-gc.sh images/build-runner-image.sh script/lint-adr.sh script/fetch-bats.sh script/coverage-gate.sh script/lint-changelog.sh script/lint-readme-sync.sh script/lint-doc-citations.sh script/deploy-listener.sh script/teardown-listener.sh lib/listener-deploy.sh'

# Self-built runner-image Dockerfiles (#120/#121/#122), hadolint-checked. The
# test-tools image ships hadolint, so this needs no extra dependency.
Expand Down Expand Up @@ -250,6 +250,7 @@ install-listener: build-listener build-admin
install -m 0755 listener/provision-job.sh "{{DESTDIR}}{{PREFIX}}/listener/provision-job.sh"
install -m 0755 listener/reap.sh "{{DESTDIR}}{{PREFIX}}/listener/reap.sh"
install -m 0755 listener/host-probe.sh "{{DESTDIR}}{{PREFIX}}/listener/host-probe.sh"
install -m 0755 listener/gpu-probe.sh "{{DESTDIR}}{{PREFIX}}/listener/gpu-probe.sh"
install -m 0755 listener/docker-gc.sh "{{DESTDIR}}{{PREFIX}}/listener/docker-gc.sh"
install -d "{{DESTDIR}}{{PREFIX}}/lib"
install -m 0644 lib/*.sh "{{DESTDIR}}{{PREFIX}}/lib/"
Expand Down
14 changes: 14 additions & 0 deletions lib/runner-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@
# dropping a runtime the operator asked for.
: "${RUNNER_RUNTIME:=}"

# GPU pin (#180, ADR-0007): the index of the one GPU a shared-GPU (mode: vram)
# job was admitted to. The gpu image sets NVIDIA_VISIBLE_DEVICES=all, so the
# nvidia runtime would hand the job every GPU whatever --device says; a
# non-empty value adds `--env NVIDIA_VISIBLE_DEVICES=<index>` to override it.
# EMPTY (every cpu job, and the GPU fail-safe) adds nothing.
: "${RUNNER_GPU:=}"

# The runner's home INSIDE the image: where the bundled actions/runner (run.sh,
# config.sh, bin/) lives and where the job runs from. Both the self-built images
# (images/runner-base.Dockerfile: WORKDIR /home/runner, USER runner) and the
Expand Down Expand Up @@ -232,6 +239,12 @@ runner_container_run() {
if [[ -n "${RUNNER_RUNTIME}" ]]; then
runtime_args=(--runtime "${RUNNER_RUNTIME}")
fi
# GPU pin: an engine flag on the argv (an index, not a secret), never part of
# the credential env-file below.
local -a gpu_args=()
if [[ -n "${RUNNER_GPU}" ]]; then
gpu_args=(--env "NVIDIA_VISIBLE_DEVICES=${RUNNER_GPU}")
fi
# Deliver the single-use JIT credential to the container OFF the host argv
# (#136, restores the ADR-0003 invariant). Splicing `--jitconfig "${encoded}"`
# directly onto the host `<cli> run ...` argv put the credential in the HOST
Expand Down Expand Up @@ -313,6 +326,7 @@ runner_container_run() {
"${socket_args[@]}" \
"${device_args[@]}" \
"${runtime_args[@]}" \
"${gpu_args[@]}" \
"${id_args[@]}" \
--env-file "${env_file}" \
-w "${RUNNER_CONTAINER_HOME}" \
Expand Down
4 changes: 4 additions & 0 deletions listener/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ docker run --rm -e GITHUB_CONFIG_URL -e GITHUB_TOKEN -e SCALE_SET_NAME \
| `RUNNER_IMAGE` | per-job container image (default `ghcr.io/actions/actions-runner:latest`) |
| `AUTO_SIZE_DEVICES` | when set, size the pool to the detected device count (#103) instead of reactive live-admission |
| `DEVICE_DETECT_CMD` | device-enumeration command for auto-sizing (default `nvidia-smi`, one device per output line) |
| `GPU_PROBE_CMD` | per-GPU index, device minor and VRAM reader for `mode: vram` (default installed `listener/gpu-probe.sh`; ADR-0007, #180) |
| `HOST_PROBE_CMD` | host reader for reactive live-admission (default installed `listener/host-probe.sh`; ADR-0005, #163) |
| `PROVISION_SCRIPT` | default installed `listener/provision-job.sh` |
| `REAP_SCRIPT` | orphan-sweep entrypoint (default installed `listener/reap.sh`) |
Expand Down Expand Up @@ -251,6 +252,9 @@ Pin the builder images by digest in production via `RUNNER_KANIKO_IMAGE` /
record admission headroom. A batch that would breach the reserve parks and
re-probes.
The host reading is `host-probe.sh` (`HOST_PROBE_CMD`).
- **GPU VRAM admission (ADR-0007, #180):** `mode: vram` gates dispatch on
declared per-GPU VRAM and live reserve. Capacity snapshots estimate how
many GPUs can take another 1 GiB job, limited by free worker slots.
- **Auto-sizing (#103):** with `AUTO_SIZE_DEVICES` (or `mode: auto`), the bound
follows the detected device count instead of reactive admission; otherwise a
sane default. The internal semaphore is only a goroutine safety ceiling.
Expand Down
Loading